Announcement Announcement Module
Collapse
No announcement yet.
JndiObjectFactoryBean, LocalSessionFactoryBean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JndiObjectFactoryBean, LocalSessionFactoryBean

    I have a strange but probably easy problem with the JndiObjectFactoryBean. I have built a web application based on hibernate and spring wich works as a charm. But at a later point I also wrote a JAASLoginModule for Tomcat 5 with the same settings for the JndiObjectFactoryBean and the LocalSessionFactoryBean. When the login module is being called i get an error saying:

    Code:
    javax.security.auth.login.LoginException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SessionFactory' defined in class path resource [auth_context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.jndi.JndiObjectFactoryBean] to required type [javax.sql.DataSource] for property 'dataSource']
    PropertyAccessExceptionsException (1 errors)
    When I read the source code for JndiObjectFactoryBean this makes sense since I am trying to set the datasource to the bean of type JndiObjectFactoryBean:

    Code:
    <bean id="DataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
     <property name="jndiName"><value>jdbc/CollabraDB</value></property>
     <property name="resourceRef"><value>true</value></property>
    </bean>
    
    <bean id="SessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    	<property name="dataSource"><ref local="DataSource"/></property>
    	<property name="mappingResources">
    	  <list>
    			<value>auth_datamodel.hbm.xml</value>
    	  </list>
    	</property>
    	<property name="hibernateProperties">
    	  <props>
    	    <prop key="hibernate.dialect">net.sf.hibernate.dialect.PostgreSQLDialect</prop>
    	    <prop key="hibernate.query.substitutions">true=1 false=0</prop>
    	    <prop key="hibernate.show_sql">false</prop>
    	  </props>
    	</property>
    </bean>
    The jndi definition is:
    Code:
    <Resource name="jdbc/CollabraDB" auth="Container" type="javax.sql.DataSource"/>
    <ResourceParams name="jdbc/CollabraDB">
    	<parameter>
    		<name>factory</name>
    		<value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    	</parameter>
    	<parameter>
    		<name>username</name>
    		<value>username</value>
    	</parameter>
    <!-- 		<parameter>
    		<name>password</name>
    		<value></value>
    	</parameter>-->
    	<parameter>
    		<name>driverClassName</name>
    		<value>org.postgresql.Driver</value>
    	</parameter>
    	<parameter>
    		<name>url</name>
    		<value>jdbc&#58;postgresql&#58;//127.0.0.1&#58;5432/collabra</value>
    	</parameter>
    	<parameter>
    		<name>maxActive</name>
    		<value>20</value>
    	</parameter>
    	<parameter>
    		<name>maxIdle</name>
    		<value>10</value>
    	</parameter>
    	<parameter>
    		<name>maxWait</name>
    		<value>-1</value>
    	</parameter>
    </ResourceParams>
    The strange part is that the exact same config works for the webapp but not for the loginmodule. I am guessing this has somethign to do with some missing jars or something similar.

    If someone could shed som light over this i would greatly appreciate it.

    Cheers
    /Fredrik

  • #2
    I do not see why this should not work. Could you provide the complete stackTrace?

    Comment


    • #3
      I have found that the loginmodule works fine as long as it is deployed in the WEB-INF/lib folder of the application on Windows. However on RedHat ES the loginmodule cannot be found if deployed in the WEB-INF/lib directory.

      If I move the loginmodule to common/lib the module is found on both platforms but the error shown below is thrown for both platforms (I am using tomcat 5.0.28 on both windows and RHES 3.0):

      Code:
      javax.security.auth.login.LoginException&#58; org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'SessionFactory' defined in class path resource &#91;auth_context.xml&#93;&#58; Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException&#58; PropertyAccessExceptionsException &#40;1 errors&#41;; nested propertyAccessExceptions are&#58; &#91;org.springframework.beans.TypeMismatchException&#58; Failed to convert property value of type &#91;org.springframework.jndi.JndiObjectFactoryBean&#93; to required type &#91;javax.sql.DataSource&#93; for property 'dataSource'&#93;
      PropertyAccessExceptionsException &#40;1 errors&#41;
      org.springframework.beans.TypeMismatchException&#58; Failed to convert property value of type &#91;org.springframework.jndi.JndiObjectFactoryBean&#93; to required type &#91;javax.sql.DataSource&#93; for property 'dataSource'
              at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary&#40;BeanWrapperImpl.java&#58;942&#41;
              at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;711&#41;
              at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;617&#41;
              at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;758&#41;
              at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;785&#41;
              at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;774&#41;
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;784&#41;
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;601&#41;
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;258&#41;
              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;193&#41;
              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;240&#41;
              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;163&#41;
              at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;236&#41;
              at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;304&#41;
              at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;80&#41;
              at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;65&#41;
              at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;56&#41;
              at se.collabra.security.auth.LoginModule.initialize&#40;LoginModule.java&#58;80&#41;
              at sun.reflect.NativeMethodAccessorImpl.invoke0&#40;Native Method&#41;
              at sun.reflect.NativeMethodAccessorImpl.invoke&#40;NativeMethodAccessorImpl.java&#58;79&#41;
              at sun.reflect.DelegatingMethodAccessorImpl.invoke&#40;DelegatingMethodAccessorImpl.java&#40;Compiled Code&#41;&#41;
              at java.lang.reflect.Method.invoke&#40;Method.java&#40;Compiled Code&#41;&#41;
              at javax.security.auth.login.LoginContext.invoke&#40;LoginContext.java&#58;685&#41;
              at javax.security.auth.login.LoginContext.access$000&#40;LoginContext.java&#58;150&#41;
              at javax.security.auth.login.LoginContext$4.run&#40;LoginContext.java&#58;633&#41;
              at java.security.AccessController.doPrivileged1&#40;Native Method&#41;
              at java.security.AccessController.doPrivileged&#40;AccessController.java&#58;350&#41;
              at javax.security.auth.login.LoginContext.invokeModule&#40;LoginContext.java&#58;630&#41;
              at javax.security.auth.login.LoginContext.login&#40;LoginContext.java&#58;556&#41;
              at org.apache.catalina.realm.JAASRealm.authenticate&#40;JAASRealm.java&#58;281&#41;
              at org.apache.catalina.authenticator.FormAuthenticator.authenticate&#40;FormAuthenticator.java&#58;229&#41;
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke&#40;AuthenticatorBase.java&#58;446&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;102&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.java&#58;137&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;104&#41;
              at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.java&#58;117&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;102&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineValve.java&#58;109&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;104&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;929&#41;
              at org.apache.coyote.tomcat5.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;160&#41;
              at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java&#58;799&#41;
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection&#40;Http11Protocol.java&#58;705&#41;
              at org.apache.tomcat.util.net.TcpWorkerThread.runIt&#40;PoolTcpEndpoint.java&#58;577&#41;
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;683&#41;
              at java.lang.Thread.run&#40;Thread.java&#58;568&#41;
      
              at javax.security.auth.login.LoginContext.invoke&#40;LoginContext.java&#58;753&#41;
              at javax.security.auth.login.LoginContext.access$000&#40;LoginContext.java&#58;150&#41;
              at javax.security.auth.login.LoginContext$4.run&#40;LoginContext.java&#58;633&#41;
              at java.security.AccessController.doPrivileged1&#40;Native Method&#41;
              at java.security.AccessController.doPrivileged&#40;AccessController.java&#58;350&#41;
              at javax.security.auth.login.LoginContext.invokeModule&#40;LoginContext.java&#58;630&#41;
              at javax.security.auth.login.LoginContext.login&#40;LoginContext.java&#58;556&#41;
              at org.apache.catalina.realm.JAASRealm.authenticate&#40;JAASRealm.java&#58;281&#41;
              at org.apache.catalina.authenticator.FormAuthenticator.authenticate&#40;FormAuthenticator.java&#58;229&#41;
              at org.apache.catalina.authenticator.AuthenticatorBase.invoke&#40;AuthenticatorBase.java&#58;446&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;102&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.StandardHostValve.invoke&#40;StandardHostValve.java&#58;137&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;104&#41;
              at org.apache.catalina.valves.ErrorReportValve.invoke&#40;ErrorReportValve.java&#58;117&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;102&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.StandardEngineValve.invoke&#40;StandardEngineValve.java&#58;109&#41;
              at org.apache.catalina.core.StandardValveContext.invokeNext&#40;StandardValveContext.java&#58;104&#41;
              at org.apache.catalina.core.StandardPipeline.invoke&#40;StandardPipeline.java&#58;520&#41;
              at org.apache.catalina.core.ContainerBase.invoke&#40;ContainerBase.java&#58;929&#41;
              at org.apache.coyote.tomcat5.CoyoteAdapter.service&#40;CoyoteAdapter.java&#58;160&#41;
              at org.apache.coyote.http11.Http11Processor.process&#40;Http11Processor.java&#58;799&#41;
              at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection&#40;Http11Protocol.java&#58;705&#41;
              at org.apache.tomcat.util.net.TcpWorkerThread.runIt&#40;PoolTcpEndpoint.java&#58;577&#41;
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run&#40;ThreadPool.java&#58;683&#41;
              at java.lang.Thread.run&#40;Thread.java&#58;568&#41;

      Comment

      Working...
      X