5 Replies Latest reply on Aug 23, 2007 9:18 AM by Tobias Demuth

    Beginner's problems with ClientLoginModule

    Tobias Demuth Newbie

      Greetings!

      I've got some problems with getting my JBoss-Client's login-mechanism working. I do the following: I have got a Swing-client, that shows a LoginDialog at startup. The user types in his username and password, the Jboss ClientLoginModule is used to copy that data to the server, where it has to be evaluated against a database (for test-purposes I'm using a UsersRolesLoginModule here at the moment).
      But let's have a look into my code first:

      This is the code I'm using for testing the login-procedure:

      logger.debug("Login");
      LoginContext lc = new LoginContext("cube", new CubeCallbackHandler());
      lc.login();
      
      // Let's force JBoss AS to evaluate the login-data
      Context ctx = new InitialContext(jndi);
      TestSession tsBean = (TestSession)ctx.lookup("TestSessionBean/remote");
      tsBean.echo("Hallo!");
      logger.debug("Logged in as " + lc.getSubject().getPrincipals());
      
      logger.debug("Logging out.");
      lc.logout();


      The TestSessionBean looks like this:
      @Stateless
      @SecurityDomain("cube")
      @RolesAllowed("EMPLOYEE")
      public class TestSessionBean implements TestSession {
      
       /**
       * @see de.tobiasdemuth.cube.server.TestSession#echo(java.lang.String)
       */
       public String echo(String arg) {
       System.out.println("Echo: " + arg);
       return arg;
       }
      
      }


      My client-side login.conf:
      cube {
       org.jboss.security.ClientLoginModule required;
      };


      And the server-side policy for the security-domain "cube":
      <!-- The login used by the Cube-client -->
       <application-policy name="cube">
       <authentication>
       <login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule" flag="required">
       </login-module>
       </authentication>
       </application-policy>


      And finally what happens:
      2007-08-22 13:17:15,031 - DEBUG (Starter.java:59) Login
      2007-08-22 13:17:15,046 - TRACE (ClientLoginModule.java:103) Security domain: null
      2007-08-22 13:17:15,046 - TRACE (ClientLoginModule.java:121) Enabling restore-login-identity mode
      2007-08-22 13:17:15,046 - TRACE (ClientLoginModule.java:139) Begin login
      2007-08-22 13:17:29,546 - TRACE (ClientLoginModule.java:195) Obtained login: tdemuth, credential.class: [C
      2007-08-22 13:17:29,562 - TRACE (ClientLoginModule.java:213) End login
      2007-08-22 13:17:29,562 - TRACE (ClientLoginModule.java:223) commit, subject=Betreff:
      
      2007-08-22 13:17:29,562 - DEBUG (SecurityAssociation.java:143) Using ThreadLocal: false
      2007-08-22 13:17:29,578 - TRACE (SecurityAssociation.java:460) pushSubjectContext, subject=Betreff:
      , sc=org.jboss.security.SecurityAssociation$SubjectContext@132ae7{principal=tdemuth,subject=6666040}
      2007-08-22 13:17:29,750 - TRACE (SecurityAssociation.java:190) getPrincipal, principal=tdemuth
      Exception in thread "main" javax.ejb.EJBAccessException: Authentication failure
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.handleGeneralSecurityException(Ejb3AuthenticationInterceptor.java:68)
       at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:70)
       at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
       at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
       at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
       at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:734)
       at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:560)
       at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:369)
       at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:165)
       at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:163)
       at org.jboss.remoting.Client.invoke(Client.java:1550)
       at org.jboss.remoting.Client.invoke(Client.java:530)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
       at $Proxy0.echo(Unknown Source)
       at de.tobiasdemuth.cube.frontoffice.Starter.<init>(Starter.java:64)
       at de.tobiasdemuth.cube.frontoffice.Starter.main(Starter.java:118)
       at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
       at $Proxy0.echo(Unknown Source)
       at de.tobiasdemuth.cube.frontoffice.Starter.<init>(Starter.java:64)
       at de.tobiasdemuth.cube.frontoffice.Starter.main(Starter.java:118)


      So, what's wrong?

      kind regards
      Tobias

        • 1. Re: Beginner's problems with ClientLoginModule
          Tobias Demuth Newbie

          Ok, after starting JBoss simply from the command-line instead from my IDE directly, I have seen an exception in the output there which brought me to the problem with UsersRolesLoginModule: I just hadn't the files put in the right directories :ashamed:.

          Thanks for reading,
          Tobias

          • 2. Re: Beginner's problems with ClientLoginModule
            Tobias Demuth Newbie

            Well I have problems getting this running on my MySQL-Database. I think, the problem is, that I have not configured the MySQL-Datasource correctly.

            This is my mysql-ds.xml-File:

            <?xml version="1.0" encoding="UTF-8"?>
            
            <datasources>
             <local-tx-datasource>
             <jndi-name>MySqlDS</jndi-name>
             <connection-url>jdbc:mysql://localhost:3306/cube</connection-url>
             <driver-class>com.mysql.jdbc.Driver</driver-class>
             <user-name>root</user-name>
             <password>password</password>
             <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
             <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
             <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
             <metadata>
             <type-mapping>mySQL</type-mapping>
             </metadata>
             </local-tx-datasource>
            </datasources>


            The JDBC-Driver lays in server/myServerInstance/lib.

            The log-file contains the following exception when I try to login (code is shown in my first post):
            2007-08-23 13:53:46,093 DEBUG [org.jboss.ejb3.security.Ejb3AuthenticationInterceptor] Authentication failure
            javax.security.auth.login.LoginException: Query failed
             at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:168)
             at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:206)
             at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
             at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
             at java.lang.reflect.Method.invoke(Unknown Source)
             at javax.security.auth.login.LoginContext.invoke(Unknown Source)
             at javax.security.auth.login.LoginContext.access$000(Unknown Source)
             at javax.security.auth.login.LoginContext$4.run(Unknown Source)
             at java.security.AccessController.doPrivileged(Native Method)
             at javax.security.auth.login.LoginContext.invokePriv(Unknown Source)
             at javax.security.auth.login.LoginContext.login(Unknown Source)
             at org.jboss.security.plugins.JaasSecurityManager.defaultLogin(JaasSecurityManager.java:603)
             at org.jboss.security.plugins.JaasSecurityManager.authenticate(JaasSecurityManager.java:537)
             at org.jboss.security.plugins.JaasSecurityManager.isValid(JaasSecurityManager.java:344)
             at org.jboss.aspects.security.AuthenticationInterceptor.authenticate(AuthenticationInterceptor.java:123)
             at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:66)
             at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3AuthenticationInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.java:46)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:106)
             at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
             at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:278)
             at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:106)
             at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:82)
             at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:734)
             at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:560)
             at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:369)
             at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:165)
            Caused by: org.jboss.util.NestedSQLException: Unexpected throwable while trying to create a connection: null; - nested throwable: (java.lang.reflect.UndeclaredThrowableException); - nested throwable: (org.jboss.resource.JBossResourceException: Unexpected throwable while trying to create a connection: null; - nested throwable: (java.lang.reflect.UndeclaredThrowableException))
             at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:94)
             at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:141)
             ... 29 more
            Caused by: org.jboss.resource.JBossResourceException: Unexpected throwable while trying to create a connection: null; - nested throwable: (java.lang.reflect.UndeclaredThrowableException)
             at org.jboss.resource.JBossResourceException.rethrowAsResourceException(JBossResourceException.java:61)
             at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:293)
             at org.jboss.resource.connectionmanager.JBossManagedConnectionPool$BasePool.getConnection(JBossManagedConnectionPool.java:500)
             at org.jboss.resource.connectionmanager.BaseConnectionManager2.getManagedConnection(BaseConnectionManager2.java:341)
             at org.jboss.resource.connectionmanager.TxConnectionManager.getManagedConnection(TxConnectionManager.java:315)
             at org.jboss.resource.connectionmanager.BaseConnectionManager2.allocateConnection(BaseConnectionManager2.java:396)
             at org.jboss.resource.connectionmanager.BaseConnectionManager2$ConnectionManagerProxy.allocateConnection(BaseConnectionManager2.java:842)
             at org.jboss.resource.adapter.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:88)
             ... 30 more
            Caused by: java.lang.reflect.UndeclaredThrowableException
             at org.jboss.resource.JBossResourceException.process(JBossResourceException.java:204)
             at org.jboss.resource.JBossResourceException.<init>(JBossResourceException.java:111)
             ... 38 more
            Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/Signature
             at java.lang.Class.forName0(Native Method)
             at java.lang.Class.forName(Unknown Source)
             at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.getDriver(LocalManagedConnectionFactory.java:272)
             at org.jboss.resource.adapter.jdbc.local.LocalManagedConnectionFactory.createManagedConnection(LocalManagedConnectionFactory.java:170)
             at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.createConnectionEventListener(InternalManagedConnectionPool.java:577)
             at org.jboss.resource.connectionmanager.InternalManagedConnectionPool.getConnection(InternalManagedConnectionPool.java:262)
             ... 36 more


            My login-conf.xml says the following:
            <!-- The login used by the Cube-client -->
             <application-policy name="cube">
             <authentication>
             <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
             <module-option name="password-stacking">useFirstPass</module-option>
             <module-option name="dsJndiName">java:/MySqlDS</module-option>
             <module-option name = "principalsQuery">SELECT Password FROM Principals WHERE PrincipalID=?</module-option>
             <module-option name = "rolesQuery">SELECT Role, RoleGroup FROM Roles WHERE PrincipalID=?</module-option>
             </login-module>
             </authentication>
             </application-policy>


            My database-scheme is for testing-purposes just copied from the JBoss-Handbook:
            Table Principals(PrincipalID text, Password text)
            Table Roles(PrincipalID text, Role text, RoleGroup text)


            Sorry for asking such "dumb" questions, but I don't how to track down this error. I hope, anybody can help me?!?

            Thanks in advance,
            Tobias

            • 3. Re: Beginner's problems with ClientLoginModule
              jaikiran pai Master

               

              Caused by: java.lang.NoClassDefFoundError: org/aspectj/lang/Signature


              The jar containing this class is not present in the classpath. You will have to add it to your classpath.

              • 4. Re: Beginner's problems with ClientLoginModule
                jaikiran pai Master

                A bit of googling for this particular class led me to a post which said


                This is because you are using a wrong jar file.You are using mysql-connector-java-3.1.10-bin-g.jar instead of mysql-connector-java-3.1.10-bin.jar.So remove the first jar from the classpath and start using the second jar for your application.


                See if that helps.

                • 5. Re: Beginner's problems with ClientLoginModule
                  Tobias Demuth Newbie

                  Thank you so much!

                  I just replaced the JDBC-Driver and now it works! That is pretty cool! Thank you!

                  kind regards
                  Tobias