6 Replies Latest reply on Aug 15, 2008 12:01 PM by Pavel Klavík

    Problem with authorization in standalone client

    Pavel Klavík Newbie

      Hi,

      I am programming standalone client and I would like to use DatabaseServerLoginModule. So I added these lines to login-config.xml.

       <application-policy name = "Konfigurator">
       <authentication>
       <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
       flag = "required">
       <module-option name = "unauthenticatedIdentity">guest</module-option>
       <module-option name = "dsJndiName">java:/MySQLDS</module-option>
       <module-option name = "principalsQuery">SELECT password FROM Users WHERE login=?</module-option>
       <module-option name = "rolesQuery">SELECT roles, 'Roles' FROM UserRoles WHERE login=?</module-option>
       </login-module>
       </authentication>
       </application-policy>
      


      At my client I am using following code to login:
       System.setProperty("java.security.auth.login.config", "auth.conf");
       Konektor.KonektorHandler handler = new Konektor.KonektorHandler(userName, password);
       try
       {
       LoginContext lc = new LoginContext("Konfigurator", handler);
       lc.login();
       }
       catch (Exception e)
       {
       System.out.println( "Login Exception: " + e.getMessage() );
       }
      
      


      Here is code of auth.conf:
      Konfigurator {
       org.jboss.security.auth.spi.DatabaseServerLoginModule required;
      };
      


      And here is definition of KonektorHandler:
       class KonektorHandler implements CallbackHandler
       {
       private String login;
       private String password;
      
       public KonektorHandler(String login, String password)
       {
       this.login = login;
       this.password = password;
       }
      
       public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
       {
       for (int i = 0; i < callbacks.length; i++)
       {
       if (callbacks instanceof NameCallback)
       {
       NameCallback nc = (NameCallback)callbacks;
       nc.setName(login);
       }
       else if (callbacks instanceof PasswordCallback)
       {
       PasswordCallback pc = (PasswordCallback)callbacks;
       pc.setPassword(password.toCharArray());
       }
       else
       {
       throw new UnsupportedCallbackException(callbacks, "Unrecognized Callback");
       }
       }
       }
       }
      


      But when I am running client, I receave following exception at function LoginContext.login() and I don't understand it at all.
       [java] Login Exception: java.lang.NoClassDefFoundError: org/jboss/system/ServiceMBeanSupport
       [java] at java.lang.ClassLoader.defineClass1(Native Method)
       [java] at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
       [java] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
       [java] at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
       [java] at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
       [java] at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
       [java] at java.security.AccessController.doPrivileged(Native Method)
       [java] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
       [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
       [java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
       [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       [java] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
       [java] at org.jboss.tm.TransactionManagerLocator.tryJNDI(TransactionManagerLocator.java:96)
       [java] at org.jboss.tm.TransactionManagerLocator.locate(TransactionManagerLocator.java:77)
       [java] at org.jboss.tm.TransactionDemarcationSupport.suspendAnyTransaction(TransactionDemarcationSupport.java:48)
       [java] at org.jboss.security.auth.spi.DatabaseServerLoginModule.getUsersPassword(DatabaseServerLoginModule.java:132)
       [java] at org.jboss.security.auth.spi.UsernamePasswordLoginModule.login(UsernamePasswordLoginModule.java:206)
       [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       [java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       [java] at java.lang.reflect.Method.invoke(Method.java:597)
       [java] at javax.security.auth.login.LoginContext.invoke(LoginContext.java:769)
       [java] at javax.security.auth.login.LoginContext.access$000(LoginContext.java:186)
       [java] at javax.security.auth.login.LoginContext$4.run(LoginContext.java:683)
       [java] at java.security.AccessController.doPrivileged(Native Method)
       [java] at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:680)
       [java] at javax.security.auth.login.LoginContext.login(LoginContext.java:579)
       [java] at Konektor.loginToSystem(Unknown Source)
       [java] at MainWindow.tryLogin(Unknown Source)
       [java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       [java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      


      Is there something that I am missing?? Whats wrong?!

      Thanks.

        • 1. Re: Problem with authorization in standalone client
          Ragav Gomatam Novice

          Check your classpath on your client..It has to have all the jaas libraries plus some specific jboss libraries as well.

          java.lang.NoClassDefFoundError
          indicates there is a dependency jar that is missing in your classpath

          • 2. Re: Problem with authorization in standalone client
            Pavel Klavík Newbie

            I have following classpath, can you tell what I am missing:

            echo $CLASSPATH
            .:/usr/jboss/jboss-4.2.3.GA/client/jnp-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-j2ee.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-common.jar:/usr/jboss/jboss-4.2.3.GA/client/log4j.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossall-client.jar:/usr/jboss/jboss-4.2.3.GA/server/default/conf/jboss-log4j.xml
            


            • 3. Re: Problem with authorization in standalone client
              Pavel Klavík Newbie

              I was looking at my classpaths and currently I have all jars in {$JBOSS-HOME}/client and {$JBOSS-HOME}/server/default/lib included and still it doesn't work.

              • 4. Re: Problem with authorization in standalone client
                Ragav Gomatam Novice

                check in which jar file where this class

                org/jboss/system/ServiceMBeanSupport
                occurs. ALso I think you need jbosssx-client.jar too. I think that class is in jboss-system-client.jar. Which version of jboss are you using ? I don't see thid class in 4.2.3 GA inside jboss-system-client.jar ?

                • 5. Re: Problem with authorization in standalone client
                  Ragav Gomatam Novice

                  Hi..The class is under jboss-system.jar which is under %JBOSS_HOME%/lib folder. Put it in the classpath & you are set.

                  • 6. Re: Problem with authorization in standalone client
                    Pavel Klavík Newbie

                    I have all classes in my classpaths, I know it is incorrect, but it is not my problem to solve it now (and I think for client is sufficent jboss-all.jar):

                    /usr/jboss/jboss-4.2.3.GA/server/default/lib/activation.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/antlr.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/autonumber-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/bcel.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/bindingservice-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/bsf.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/bsh-deployer.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/bsh.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/cglib.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/commons-codec.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/commons-collections.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/commons-httpclient.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/commons-logging.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/dom4j.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/ejb3-persistence.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/el-api.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/hibernate-annotations.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/hibernate-entitymanager.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/hibernate3.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/hsqldb-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/hsqldb.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/javassist.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jaxen.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-common-jdbc-wrapper.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-ejb3x.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-hibernate.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-iiop.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-j2ee.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jaxrpc.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jaxws-ext.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jaxws.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jca.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jsr77.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-jsr88.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-management.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-monitoring.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-remoting-int.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-remoting.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-saaj.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-serialization.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-srp.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-transaction.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss-vfs.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jboss.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossjta-integration.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossjta.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossmq.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbosssx.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossts-common.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossws-common.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossws-framework.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossws-jboss42.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jbossws-spi.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jmx-adaptor-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jnpserver.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/joesnmp.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/jsp-api.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/log4j-snmp-appender.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/log4j.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/mail-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/mail.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/mysql-connector-java-5.1.6-bin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/properties-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/quartz.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/scheduler-plugin-example.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/scheduler-plugin.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/servlet-api.jar:/usr/jboss/jboss-4.2.3.GA/server/default/lib/xmlentitymgr.jar:/usr/jboss/jboss-4.2.3.GA/client/FastInfoset.jar:/usr/jboss/jboss-4.2.3.GA/client/activation.jar:/usr/jboss/jboss-4.2.3.GA/client/antlr.jar:/usr/jboss/jboss-4.2.3.GA/client/avalon-framework.jar:/usr/jboss/jboss-4.2.3.GA/client/commons-codec.jar:/usr/jboss/jboss-4.2.3.GA/client/commons-httpclient.jar:/usr/jboss/jboss-4.2.3.GA/client/commons-logging.jar:/usr/jboss/jboss-4.2.3.GA/client/concurrent.jar:/usr/jboss/jboss-4.2.3.GA/client/ejb3-persistence.jar:/usr/jboss/jboss-4.2.3.GA/client/getopt.jar:/usr/jboss/jboss-4.2.3.GA/client/hibernate-annotations.jar:/usr/jboss/jboss-4.2.3.GA/client/hibernate-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jacorb.jar:/usr/jboss/jboss-4.2.3.GA/client/javassist.jar:/usr/jboss/jboss-4.2.3.GA/client/jaxb-api.jar:/usr/jboss/jboss-4.2.3.GA/client/jaxb-impl.jar:/usr/jboss/jboss-4.2.3.GA/client/jaxb-xjc.jar:/usr/jboss/jboss-4.2.3.GA/client/jaxws-rt.jar:/usr/jboss/jboss-4.2.3.GA/client/jaxws-tools.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-annotations-ejb3.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-aop-jdk50-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-aspect-jdk50-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-common-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-deployment.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-ejb3-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-ejb3x.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-iiop-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-j2ee.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-jaxrpc.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-jaxws-ext.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-jaxws.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-jsr77-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-remoting.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-saaj.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-serialization.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-srp-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-system-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-transaction-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jboss-xml-binding.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossall-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbosscx-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossha-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossjmx-ant.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossmq-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbosssx-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossws-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossws-common.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossws-framework.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossws-jboss42.jar:/usr/jboss/jboss-4.2.3.GA/client/jbossws-spi.jar:/usr/jboss/jboss-4.2.3.GA/client/jettison.jar:/usr/jboss/jboss-4.2.3.GA/client/jmx-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jmx-invoker-adaptor-client.jar:/usr/jboss/jboss-4.2.3.GA/client/jnp-client.jar:/usr/jboss/jboss-4.2.3.GA/client/log4j.jar:/usr/jboss/jboss-4.2.3.GA/client/logkit.jar:/usr/jboss/jboss-4.2.3.GA/client/mail.jar:/usr/jboss/jboss-4.2.3.GA/client/policy.jar:/usr/jboss/jboss-4.2.3.GA/client/scout.jar:/usr/jboss/jboss-4.2.3.GA/client/servlet-api.jar:/usr/jboss/jboss-4.2.3.GA/client/stax-api.jar:/usr/jboss/jboss-4.2.3.GA/client/stax-ex.jar:/usr/jboss/jboss-4.2.3.GA/client/streambuffer.jar:/usr/jboss/jboss-4.2.3.GA/client/trove.jar:/usr/jboss/jboss-4.2.3.GA/client/wsdl4j.jar:/usr/jboss/jboss-4.2.3.GA/client/wstx.jar:/usr/jboss/jboss-4.2.3.GA/client/xmlsec.jar:/home/klavikp/qtjambi/qtjambi-4.4.0_01.jar:/home/klavikp/qtjambi/qtjambi-designer-4.4.0_01.jar:/home/klavikp/qtjambi/qtjambi-examples-4.4.0_01.jar:/home/klavikp/qtjambi/qtjambi-linux32-gcc-4.4.0_01.jar:/home/klavikp/AplikacniServer/jar/AplikacniServer.har:/home/klavikp/AplikacniServer/jar/Konfigurator.jar:/home/klavikp/AplikacniServer/jar/QtClient.jar
                    


                    But I found the error, it was inside client auth.conf files, correct form should be this one:
                    Konfigurator {
                     org.jboss.security.ClientLoginModule required;
                    };