Announcement Announcement Module
Collapse
No announcement yet.
Problem accessing spring beans Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem accessing spring beans

    Good day,


    Quick insight of the flow:

    Intranet Client -->(invokes) Application --> (get credentials) NTLM using Servlets --> (forwards to action) Struts using Spring -->(get modules from Jboss container) JAAS using Jboss -->(invokes) LoginModule in WAR --> uses components defined in Spring inside the same WAR

    problem
    LoginModule in WAR --> uses components defined in Spring inside the same WAR

    although struts has access to beanFactory, which is invoked via struts plugin

    how do my LoginModule inside the same WAR will have access to Spring beanFactory as it has been invoked by Jboss container.

    pllzzzz help i have been striving to get this working.

  • #2
    beanRefFactory.xml under WEB-INF directory

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
    <beans>
    <bean id="spring.global" lazy-init="true" class="org.springframework.context.support.ClassPa thXmlApplicationContext">
    <constructor-arg>
    <list>
    <value>spring/spring-config.xml</value>
    </list>
    </constructor-arg>
    </bean>
    </beans>


    and spring-config.xml is under WEB-INF\spring
    contains the following

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans default-lazy-init="false">

    <bean class="org.springframework.aop.framework.autoproxy .DefaultAdvisorAutoProxyCreator" />

    <import resource="logger/log-config.xml"/>
    <import resource="ibatis/ibatis-config.xml"/>
    <import resource="struts/struts-config-1.xml"/>
    <import resource="aop/aop-config.xml"/>
    <import resource="component/component-config.xml"/>
    <import resource="business/business-config.xml"/>
    <import resource="jaas/jaas-module-config.xml"/>

    </beans>

    BaseLoginModule.java under the same WAR but is invoked by JBoss

    and my initialize() method of JAAS is as follows
    public void initialize(Subject subject, CallbackHandler callbackHandler, Map<java.lang.String, ?> sharedState, Map<java.lang.String, ?> options) {
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;
    // initialize any configured options
    debug = "true".equalsIgnoreCase((String)options.get("debug "));

    // Accessing Spring bean from non spring context
    BeanFactoryLocator beanFactoryLocator = SingletonBeanFactoryLocator.getInstance();
    BeanFactoryReference beanFactoryReference = beanFactoryLocator.useBeanFactory("spring.global") ;
    beanFactory = beanFactoryReference.getFactory();
    }

    i am not able to get the bean factory inside this method. all the above files are under the same war.

    Comment


    • #3
      observations: it is looking for beanRefFactory.xml under conf directory of Jboss. i put the file under conf directory and got the following

      21:03:46,546 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from URL [vfsfile:/C:/jboss-5.1.0.GA/server/default/conf/beanRefFactory.xml]
      21:03:46,656 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultL istableBeanFactory@13b9df1: defining beans [spring.global]; root of factory hierarchy
      21:03:46,984 INFO [ClassPathXmlApplicationContext] Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@30fd23: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@30fd23]; startup date [Fri Aug 28 21:03:46 IST 2009]; root of context hierarchy
      21:03:47,000 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from class path resource [spring/spring-config.xml]
      21:04:08,359 ERROR [STDERR] Authentication failed:
      21:04:09,218 ERROR [STDERR] org.springframework.beans.factory.access.Bootstrap Exception: Unable to return specified BeanFactory instance: factory key [spring.global], from group with resource name [classpath*:beanRefFactory.xml]; nested exception is org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'spring.global' defined in URL [vfsfile:/C:/jboss-5.1.0.GA/server/default/conf/beanRefFactory.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationExcepti on: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlAp plicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: IOException parsing XML document from class path resource [spring/spring-config.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-config.xml] cannot be opened because it does not exist
      at org.springframework.beans.factory.access.Singleton BeanFactoryLocator.useBeanFactory(SingletonBeanFac toryLocator.java:409)
      at com.xxx.jaas.modules.BaseLoginModule.initialize(Ba seLoginModule.java:57)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at javax.security.auth.login.LoginContext.invoke(Unkn own Source)
      at javax.security.auth.login.LoginContext.access$000( Unknown Source)
      at javax.security.auth.login.LoginContext$4.run(Unkno wn Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.login.LoginContext.invokePriv( Unknown Source)
      at javax.security.auth.login.LoginContext.login(Unkno wn Source)
      at com.xxx.action.IndexAction.preAction(IndexAction.j ava:40)
      at com.xxx.action.BaseAction.dispatch(BaseAction.java :135)
      at com.xxx.action.BaseAction.execute(BaseAction.java: 116)


      i understand the above error is because, it is looking for spring/spring-config.xml under conf directory.

      is there any way that while creating the beanFactoryLocator i can specify the jar/war file location, be default it looks for beanRefFactory.xml under the directory from where the class is invoked, but if i able to refer beanRefFactory.xml under osaWeb.war \WEB-INF directory. i should be able to get the references of the beans, i guess. plz correct me if i am wrong.

      thanks,
      ram.

      Comment

      Working...
      X