2 Replies Latest reply on Apr 29, 2004 5:04 PM by James Adams

    Simple database authentication not working

    James Adams Novice

      I am trying to set up simple form-based authentication using a database. I am initially trying to secure all web resources, since my application accesses the EJBs via servlets (and is working fine without security). Later I will tighten things down so that the EJB's business methods will also have security in place.

      It seems that everything is in place but I am unable to authenticate a user when I use a valid login/password combination (I am being redirected to the login error page). No exceptions appear in the JBoss console, and the database tables appear to be populated with proper values. Hopefully someone reading this can give me a clue as to what is going wrong.

      Here is what I have done so far:

      1) I have two tables in my database, one for the user_name and password, and another for roles. The database tables look like this:

      table name: principals
      column: principal_id VARCHAR(64) primary key
      column: password VARCHAR(64)

      table name: roles
      column: principal_id VARCHAR(64)
      column: user_role VARCHAR(64)
      column: role_group VARCHAR(64)

      2) I have added an entry in $JBOSS/server/default/conf/login-config.xml to declare an application policy which uses a DatabaseServerLoginModule. In this entry I have specified the SQl to be used by the module for selecting the password and role, following the example in the JBoss Getting Started Guide (p. 57):

       <!-- added for HIM Server security -->
       <application-policy name="HIM-client-login">
       <login-module code="org.jboss.security.auth.spi.DatabaseServerLoginModule"
       <module-option name="dsJndiName">java:/OracleDS</module-option>
       <module-option name="principalsQuery">select password from principals where principal_id=?</module-option>
       <module-option name="principalsQuery">select user_role, role_group from roles where principal_id=?</module-option>

      3) I have added a security domain entry in the jboss-web.xml file:

       <!-- All secure web resources will use this security domain -->

      4) I have declared a security constraint in the web.xml file:

       <!-- security configuration -->
       <display-name>Server Configuration Security Constraint</display-name>
       <!-- the collection of resources to which the sucurity constraint applies -->
       <web-resource-name>Secure Resources</web-resource-name>
       <description>Security constraint for all resources</description>
       <!-- the pattern that this constraint applies to -->
       <!-- the HTTP methods that this constraint applies to -->
       <!-- the user roles that should be permitted access to this resource collection -->
       <description>Only allow those users that are in the following role</description>
       <!-- declare a transport guarantee, if any -->

      5) I have a simple login form (LoginForm.jsp) which encodes j_security_check:

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
       <title>HIM Client Login</title>
       <form method="POST"
       action='<%= response.encodeURL( "j_security_check" ) %>'>
       Username: <input type="text"
       Password: <input type="password"
       <input type="submit"
       <input type="reset"

      Can anyone see from the above that I have missed something, or that I have done something wrong ?

      Is there a way to get more information ? All I see in the access log file are logs of the requests for the servlet, j_security_check, and the login and error pages, and it might be helpful to have a little more information as to what is going on.

      Thanks in advance for any insight.


        • 1. Re: Simple database authentication not working
          sj_bennett Newbie

          You might need to add a <login-config> element to the 'web.xml' file. Look at Scott's 'JAAS How To' documentation and examples as a reference.


          • 2. Re: Simple database authentication not working
            James Adams Novice

            Thanks for the reply. Actually I already have a <login-config> in the web.xml which specifies FORM-based authentication as well as the login and login error pages.

            I have found my error and it was quite trivial. (I would have saved myself a days worth of frustration if I had just paid a little more attention to what I was doing when I created my entry in the login-config.xml file !) I had a duplicate principalsQuery instead of a rolesQuery in the application-policy section of the login-config.xml. Now that this has been fixed I am authenticating as expected.