Pregunta

It's about half a day I'm trying to find a way to migrate my implementations on SpringSecurity to the context of OSGi(equinox) bundles without switching to SpringDM.


Currently we have two projects:

1. I have an implementation of Spring Security based on some xml configuration files to handle authentication and authorization.
2. On the other hand, we have a huge OGSi bundled project structure with about 200 bundles which need to be integrated with a security bundle(the one described above)


As the first step to create mySpringBasedSecurityBundle I need to run this method after loading mySecurityBundle to access the security configuration xml-file located : com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml which prepared me Spring-DataSource.xml and Spring-Security.xml as following:

    private void loadApplicationContext()
    {
        SecurityContextHolder.setStrategyName(SecurityContextHolder.MODE_GLOBAL);
        new ThreadLocal<Object>();
        setApplicationContext(new ClassPathXmlApplicationContext(SPRING_CONTEXT_ADDRESS));
    }       



But unfortunately this Exception occurred:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml]; nested exception is java.io.FileNotFoundException: class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.myComp.backend.appsecurity.spring.appSecurityManager.loadApplicationContext(appSecurityManager.java:233)
at com.myComp.backend.appsecurity.spring.appSecurityManager.internalInitialize(appSecurityManager.java:106)
at com.myComp.BaseModuleManager.initialize(BaseModuleManager.java:511)
at com.myComp.BaseModuleManager.initialize(BaseModuleManager.java:1)
at com.myComp.backend.BaseBackendManager.initializeSubBackendManagers(BaseBackendManager.java:643)
at com.myComp.backend.BaseBackendManager.prepareSubBackendManagers(BaseBackendManager.java:885)
at com.myComp.backend.BackendManager.internalStart(BackendManager.java:127)
at com.myComp.BaseModuleManager.start(BaseModuleManager.java:574)
at com.myComp.BaseModuleManager.start(BaseModuleManager.java:1)
at com.myComp.application.BaseApplicationStub.startBackendManager(BaseApplicationStub.java:2407)
at com.myComp.Application.frameworkEvent(Application.java:72)
at org.eclipse.osgi.framework.internal.core.BundleContextImpl.dispatchEvent(BundleContextImpl.java:874)
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230)
at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)Caused by: java.io.FileNotFoundException: class path resource [com/myComp/backend/appsecurity/spring/resources/Spring-Context.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
.. 26 more


as much as I search the web, the only recommendation for this issue ends to the application on SpringDM, but it is not acceptable for our ProjectManager to switch to SpringDM and to be honest I have no idea about SpringDM.

Would you please help me resolve this issue using Spring Core functionalities.


Thanks alot
Moein

¿Fue útil?

Solución

You don't actually need Spring DM. It simply provides a bridge between OSGi and Spring, with some niceties like loading all your context files properly in an OSGi environment. You can do this yourself as well, but you have to compensate for the classloading issues, which is the problem you are having.

Try this to fix your classloading issues.

ApplicationContext ctx = new ClassPathXmlApplicationContext(myCtxPath)
{
    protected void initBeanDefinitionReader(XmlBeanDefinitionReader reader)
    {
        super.initBeanDefinitionReader(reader);
        reader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE);
        reader.setBeanClassLoader(getClassLoader());
    }
}

BTW, the second line of your method serves no purpose.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top