9 Replies Latest reply on Mar 7, 2007 8:23 PM by changemylife

    I need helps from anyone about JAAS with DatabaseServerLogin

    changemylife

      Hi everyone!

      I have a problem that I can't solve. I have two machines with hostname is "A" and "B". On A, I installed mySQL and create the database is "mydatabase" and two tables are "Roles" and "Users"
      Also on A, I installed JBoss Server (jboss-4.0.5.GA), and I select database is mysql. File "hsqldb.xml" has contents:

      ...
      <jndi-name>DefaultDS</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/mydatabase</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      <password>abc123</password>
      ...

      When I restart server on machine A, I see some messages:
      10:43:02,109 INFO [WrapperDataSourceService] Bound ConnectionMana
      :service=DataSourceBinding,name=DefaultDS' to JNDI name 'java:DefaultDS'

      On the B machine, I use Eclipse to create a EJB 3.0 project called "ActionBean". Then, I write three file ejb-jar.xml, jboss.xml and login-config.xml. They have some info important :
      ejb-jar.xml
      ...
      <enterprise-beans>
       <session>
       <ejb-name>ActionBean</ejb-name>
       <resource-ref>
       <res-ref-name>jdbc/DefaultDS</res-ref-name>
       <res-type>javax.sql.DataSource</res-type>
       <res-auth>Container</res-auth>
       </resource-ref>
       </session>
      </enterprise-beans>
      <assembly-descriptor>
       <Security-role>
       <role-name>doctor</role-name>
       </Security-role>
       <Security-role>
       <role-name>nurse</role-name>
       </Security-role>
       <method-permission>
       <role-name>doctor</role-name>
       <method>
       <ejb-name>ActionBean</ejb-name>
       <method-name>getCallInfo</method-name>
       </method>
       </method-permission>
       <method-permission>
       <role-name>nurse</role-name>
       <method>
       <ejb-name>ActionBean</ejb-name>
       <method-name>add</method-name>
       </method>
       </method-permission>
       </assembly-descriptor>
      ...

      jboss.xml
      <security-domain>DB-Domain</security-domain>
      <enterprise-beans>
       <session>
       <ejb-name>ActionBean</ejb-name>
       <resource-ref>
       <res-ref-name>jdbc/DefaultDS</res-ref-name>
       <jndi-name>java:/DefaultDS</jndi-name>
       </resource-ref>
       </session>
      </enterprise-beans>

      login-config.xml
      <application-policy name="DB-Domain">
       <authentication>
       <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule" flag="required">
       <module-option name="dsJndiName">java:/DefaultDS</module-option>
       <module-option name="principalsQuery">
       select passwd from Users where username=?</module-option>
       <module-option name="rolesQuery">
       select Role from Roles where username=?</module-option>
       </login-module>
       </authentication>
      </application-policy>

      Then, I pakage ActionBean and put three files (ejb-jar.xml,jboss.xml and login-config.xml) inside META-INF folder. JBoss server on the machine A inform all things ok!
      Also, on the machine B. I write the main class (client):
      LoginContext lc = new LoginContext("userTest", new ClientCallbackHandler());;
      lc.login();
      InitialContext ctx = new InitialContext();
      ClientAction obj = (ClientAction)ctx.lookup("ActionBean/remote");
      try{
       System.out.println(obj.getCallInfo());
       //System.out.println(obj.add());
      
       }catch(Exception e){
       System.out.println("You don't allow to do this method !");
       }
      ...

      My auth.config:
      userTest {
       org.jboss.security.ClientLoginModule required;
      };

      I imported package "jbossall-client.jar" and "jbosssx.jar". On the server(machine A), I also copied dirver "mysql-connector-java-3.1.14-bin.jar" inside \server\default\lib.
      Then, I run my main class and from console I enter username and passwd. But any informations that I entered can't call method on ActionBean (ex:obj.getCallInfo()). This mean is correct info can't call any method on ActionBean. Which wrongs ? mydatabase has two tables:
      CREATE TABLE Users(username VARCHAR(64) PRIMARY KEY, passwd VARCHAR(64))
      CREATE TABLE Roles(username VARCHAR(64), Role VARCHAR(32))

      (I were writed a simple bean to access informations from mydatabase, all things ok). Please help me to solve my problem. Thanks.

        • 1. Re: I need helps from anyone about JAAS with DatabaseServerL
          changemylife

          I wonder that some informations (username and passwd) that user enter and informations that Jboss server get from mySQL were encoded ? So, they not match ! Have any ideals ?

          • 2. Re: I need helps from anyone about JAAS with DatabaseServerL
            jaikiran

             

            Then, I run my main class and from console I enter username and passwd. But any informations that I entered can't call method on ActionBean (ex:obj.getCallInfo()).


            Do you see any exceptions?If yes, post the exception stacktrace. Also post the trace logs of security package of JBoss (look at Q4 at http://wiki.jboss.org/wiki/Wiki.jsp?page=SecurityFAQ to see how its enabled)

            • 3. Re: I need helps from anyone about JAAS with DatabaseServerL
              changemylife

              Thanks jaikiran!
              I solved my problems! But I wondered that: If I write my login-config.xml:

              <?xml version="1.0" encoding="UTF-8"?>
              
              <policy>
               <application-policy name = "DB-Domain">
               <authentication>
               <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
               flag = "required">
               <module-option name = "unauthenticatedIdentity">guest</module-option>
               <module-option name = "dsJndiName">java:/DefaultDS</module-option>
               <module-option name = "principalsQuery">SELECT PASSWD FROM USERS WHERE USERID=?</module-option>
               <module-option name = "rolesQuery">SELECT ROLEID, 'Roles' FROM ROLES WHERE USERID=?</module-option>
               </login-module>
               </authentication>
               </application-policy>
              </policy>

              When the authentication will fail! But if I use login-config.xml inside \server\default\conf and add some informations (above) the authentication success! Why ?( If I want myself write my login-config.xml)

              • 4. Re: I need helps from anyone about JAAS with DatabaseServerL
                jaikiran

                That's because JBoss never picked up the login-config.xml that you had created. JBoss looks at the login-config.xml file present in its conf folder.

                • 5. Re: I need helps from anyone about JAAS with DatabaseServerL
                  changemylife

                  Hi !
                  But when I use UserRoleLoginModule, I writed my login-config.xml. And all things ok! (DatabaseServerLoginModule is not success!).
                  Thanks.

                  • 6. Re: I need helps from anyone about JAAS with DatabaseServerL
                    jaikiran

                    That was just a co-incidence. Your file was never picked up. By default, the UserRolesLoginModule was being picked up from the login-config.xml file present in the conf folder of JBoss.

                    • 7. Re: I need helps from anyone about JAAS with DatabaseServerL
                      changemylife

                      Hi all!

                      Thanks Jaikirain! Your explains are very helpfull for me and everyone that want discovery about JBoss. Two day ago, I have two problems and I posted they on Forum but not received reply. I hope that you can explain and help me about they again.

                      1. My operating system is XP2, I use jboss-4.0.5.GA. I assume that have three person with usernames are "A", "B" and "C". And now, I want "A" and "B" are allow restart JBoss server, "C" is not allow! How I can do ?

                      2. I have two bean called "Bean1" and "Bean2". If copy both of them into deploy folder (on server), the deploy is ok! But now, how the server check to server can deploy "Bean1" not "Bean2". How I can do this ?

                      Thanks!

                      • 8. Re: I need helps from anyone about JAAS with DatabaseServerL
                        jaikiran

                         

                        1. My operating system is XP2, I use jboss-4.0.5.GA. I assume that have three person with usernames are "A", "B" and "C". And now, I want "A" and "B" are allow restart JBoss server, "C" is not allow! How I can do ?


                        changemylife, I havent done that before so i wont be of much help. I guess you will have to start JBoss as a service and then control the way JBoss is shutdown. Just a guess.

                        2. I have two bean called "Bean1" and "Bean2". If copy both of them into deploy folder (on server), the deploy is ok! But now, how the server check to server can deploy "Bean1" not "Bean2". How I can do this ?


                        I did not understand this question. Can you explain more?


                        • 9. Re: I need helps from anyone about JAAS with DatabaseServerL
                          changemylife

                          Hi!

                          1. My operating system is XP2, I use jboss-4.0.5.GA. I assume that have three person with usernames are "A", "B" and "C". And now, I want "A" and "B" are allow restart JBoss server, "C" is not allow! How I can do ?

                          ---> I installed JBoss server, and I only want the specific user can run JBoss server (ex: A allow but B not allow)
                          2. I have two bean called "Bean1" and "Bean2". If copy both of them into deploy folder (on server), the deploy is ok! But now, how the server check to server can deploy "Bean1" not "Bean2". How I can do this ?

                          ---> Assume that I have a my bean called "BeanA", and my friend have a bean called "BeanB". And now, I want JBoss server deploy only "BeanA" not "BeanB". How I do ?

                          Thanks.