Sunday, October 14, 2012

Login module with database connectivity in JBOSS

We need to create a MySQL database to store usernames, passwords and rolls of users. So create a database called akila_db and create two tables called myuser and myuser_roles. Then add following data to database.

myuser table
username      password
akila               akila
sithum            sithum

myuser_roles table
username    role
akila              admin
sithum           guest

Then we have to edit login-config.xml in server/xxx/conf folder.


<application-policy name = "akila_policy">
       <authentication>
          <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule" flag = "required">
             <module-option name = "unauthenticatedIdentity">guest</module-option>
                                                 <module-option name = "dsJndiName">java:/ifsds</module-option>
             <module-option name = "principalsQuery">SELECT password FROM myuser WHERE username=?</module-option>
             <module-option name = "rolesQuery">SELECT role, 'Roles' FROM myuser_roles WHERE username=?</module-option>
          </login-module>
       </authentication>
    </application-policy>


Remaining things are similar to Basic authentication login module as we discussed earlier. So click here  find out about basic authentication login module.

No comments:

Post a Comment