2 Replies Latest reply on Feb 22, 2012 2:22 AM by Stephen Coy

    AS7 custom login Datasource issue

    ashman Newbie

      Hi everyone,

       

      I am trying to migrate an application from JBoss 4.0.5 to AS 7.1.0. I have sucessfully deployed the ear, but am now having a problem with the login. The application uses a custom login (in a jar, which I have deployed as a module). This seems to be working. But in the login class, it fails to connect to the datasource, and I just do not understand why. the datasource is bound correctly when the server starts up:

       

      14:27:12,246 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-3) JBAS010400: Bound data source [java:jboss/jdbc/TxSecurityDataSource]

       

      My web.xml has the security constraints, auth-constraints and the role-name all set up. Furthermore, the web.xml has

       

       

       

       

       

       

       

      <login-config>

           <auth-method>FORM</auth-method>

           <form-login-config>

                <form-login-page>/common.Login.do</form-login-page>

                <form-error-page>/common.FailedLogin.do</form-error-page>

           </form-login-page>

      </login-config>

      My standalone.xml has the datasource defined as:

                     <datasource jta="false" jndi-name="java:jboss/jdbc/TxSecurityDataSource" pool-name="Security" enabled="true" use-ccm="false">

                          <connection-url>jdbc:oracle:thin@USTPRDX.uni.com:1123:DD7</connection-url>
                          <driver-class>oracle.jdbc.OracleDriver</driver-class>
                          <driver>oracle</driver>
                          <security>
                              <user-name>testusername</user-name>
                              <password>testpassword</password>
                          </security>
                          <validation>
                              <validate-on-match>false</validate-on-match>
                              <background-validation>false</background-validation>
                              <background-validation-millis>0</background-validation-millis>
                          </validation>
                          <statement>
                              <prepared-statement-cache-size>0</prepared-statement-cache-size>
                              <share-prepared-statements>false</share-prepared-statements>
                          </statement>
                      </datasource>

       

                      <drivers>
                          <driver name="oracle" module="com.oracle.ojdbc6">
                              <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                          </driver>
                      </drivers>
       

      and the security domain defined as:

                <security-domain name="unidomain" cache-type="default">

                          <authentication>
                              <login-module code="UsersRoles" flag="required">
                                  <module-option name="usersProperties" value="${jboss.server.config.dir}/users.properties"/>
                                  <module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/>
                              </login-module>
                              <login-module code="com.uni.common.security.UniLoginModule" flag="sufficient" module="unilogin">
                                  <module-option name="dsJndiName" value="java:jboss/jdbc/TxSecurityDataSource"/>
                                  <module-option name="principalsQuery" value="select passwd from USERS where UPPER(LOGIN_NAME)= UPPER(?) "/>
                                  <module-option name="rolesQuery" value="select g.role_name UserRoles, 'Roles' from USERS U,LMS_USER_GROUP UG,L_GROUP G WHERE U.user_ID = UG.user_ID and UG.group_ID = G.group_ID and upper(U.login_name)=upper(?) and U.user_status='USER_ACTV'"/>
                                  <module-option name="hashAlgorithm" value="MD5"/>
                                  <module-option name="hashEncoding" value="hex"/>
                              </login-module>
                          </authentication>
                </security-domain>

       

      and finally, the jboss-web.xml point to the security domain:

      <security-domain>java:/jaas/unidomain</security-domain>

       

       

      I believe this all works, because i get the login page, and after entering the username and password, I get the error page, and can see that the custom module has been executed. During the execution of the custom login module however, there was a failute to connect to the datasource.I can see the following error on the server:

       

      15:40:12,634 WARN  [org.jboss.jca.core.connectionmanager.pool.strategy.OnePool] (http-127.0.0.1-127.0.0.1-8080-5) IJ000604: Throwable while attempting to get a new connection: null: javax.resource.ResourceException: Could not create connection
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:277)
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:235)
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:758)
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:343)
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:400)
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:365)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:329)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:302)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
      at com.unistudios.common.security.UniLoginModule.getConnection(UniLoginModule.java:158) [UniLoginModule.jar:]
      at com.unistudios.common.security.UniLoginModule.login(UniLoginModule.java:46) [UniLoginModule.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_01]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_01]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_01]
      at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.invoke(LoginContext.java:784) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696) [rt.jar:1.7.0_01]
      at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:695) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.login(LoginContext.java:594) [rt.jar:1.7.0_01]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.defaultLogin(JBossCachedAuthenticationManager.java:449) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.proceedWithJaasLogin(JBossCachedAuthenticationManager.java:383) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.authenticate(JBossCachedAuthenticationManager.java:361) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.isValid(JBossCachedAuthenticationManager.java:160) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.as.web.security.JBossWebRealm.authenticate(JBossWebRealm.java:215) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:280) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:381) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
      at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_01]
      Caused by: java.sql.SQLException: Invalid Oracle URL specified
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:441)
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:249)
      ... 38 more

      15:40:12,664 ERROR [com.unistudios.common.security.UniLoginModule] (http-127.0.0.1-127.0.0.1-8080-5) SQL Error getting a connection: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/jdbc/TxSecurityDataSource
      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:137)
      at com.unistudios.common.security.UniLoginModule.getConnection(UniLoginModule.java:158) [UniLoginModule.jar:]
      at com.unistudios.common.security.UniLoginModule.login(UniLoginModule.java:46) [UniLoginModule.jar:]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_01]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_01]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_01]
      at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.invoke(LoginContext.java:784) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext$4.run(LoginContext.java:698) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext$4.run(LoginContext.java:696) [rt.jar:1.7.0_01]
      at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:695) [rt.jar:1.7.0_01]
      at javax.security.auth.login.LoginContext.login(LoginContext.java:594) [rt.jar:1.7.0_01]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.defaultLogin(JBossCachedAuthenticationManager.java:449) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.proceedWithJaasLogin(JBossCachedAuthenticationManager.java:383) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.authenticate(JBossCachedAuthenticationManager.java:361) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.security.authentication.JBossCachedAuthenticationManager.isValid(JBossCachedAuthenticationManager.java:160) [picketbox-infinispan-4.0.6.final.jar:4.0.6.final]
      at org.jboss.as.web.security.JBossWebRealm.authenticate(JBossWebRealm.java:215) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.authenticator.FormAuthenticator.authenticate(FormAuthenticator.java:280) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:381) [jbossweb-7.0.10.Final.jar:]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:154) [jboss-as-web-7.1.0.Final.jar:7.1.0.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.10.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.10.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.10.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.10.Final.jar:]
      at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_01]
      Caused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/jdbc/TxSecurityDataSource
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:390)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:302)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:464)
      at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:129)
      ... 29 more
      Caused by: javax.resource.ResourceException: IJ000658: Unexpected throwable while trying to create a connection: null
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:371)
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getSimpleConnection(AbstractPool.java:400)
      at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:365)
      at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:329)
      ... 32 more
      Caused by: javax.resource.ResourceException: Could not create connection
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:277)
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:235)
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.createConnectionEventListener(SemaphoreArrayListManagedConnectionPool.java:758)
      at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreArrayListManagedConnectionPool.getConnection(SemaphoreArrayListManagedConnectionPool.java:343)
      ... 35 more
      Caused by: java.sql.SQLException: Invalid Oracle URL specified
      at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:441)
      at org.jboss.jca.adapters.jdbc.local.LocalManagedConnectionFactory.getLocalManagedConnection(LocalManagedConnectionFactory.java:249)
      ... 38 more

       

      The custom login class looks like this (I have only included the relevat sections):

       

      package com.uni.common.security;

      import java.io.IOException;
      import java.sql.CallableStatement;
      import java.sql.Connection;
      import java.sql.SQLException;
      import java.sql.Types;

      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      import javax.security.auth.callback.Callback;
      import javax.security.auth.callback.NameCallback;
      import javax.security.auth.callback.PasswordCallback;
      import javax.security.auth.callback.UnsupportedCallbackException;
      import javax.security.auth.login.LoginException;
      import javax.sql.DataSource;

      import org.apache.log4j.Logger;
      import org.jboss.security.auth.spi.DatabaseServerLoginModule;

       

      public class UniLoginModule extends DatabaseServerLoginModule {

      private static Logger log = Logger.getLogger(UniversalLoginModule.class);

        public UniversalLoginModule() {

         super();
        }

      ...

       

      private Connection getConnection() throws SQLException, NamingException {


           try {

            Context ctx = new InitialContext();

            //DataSource ds = (DataSource) ctx.lookup(dsJndiName);

            DataSource ds = (DataSource) ctx.lookup("java:jboss/jdbc/TxSecurityDataSource");

            Connection c = ds.getConnection();


            return c;

           }

           catch (NamingException e) {

           log.error("Naming Error getting a connection", e);

           throw e;

           }

           catch (SQLException e) {

           log.error("SQL Error getting a connection", e);

           throw e;

           }

      }

       

      I have spent so much time on this, it's driving me mad! I don't understand why the lookup is not working. I have used both the dsJndiName and a hard-coded datasource, but none of them are working. Does anyone have any idea what I could be doing wrong?

       

      Thanks,

      Ash