KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > auth > spi > DatabaseCertLoginModule


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.security.auth.spi;
8
9 import java.security.acl.Group JavaDoc;
10 import java.util.Map JavaDoc;
11
12 import javax.security.auth.Subject JavaDoc;
13 import javax.security.auth.callback.CallbackHandler JavaDoc;
14 import javax.security.auth.login.LoginException JavaDoc;
15
16 /**
17  * A Certificate Login Module that gets its role information from a database.
18  *
19  * This module is the functional equivelant of the
20  * {@link org.jboss.security.auth.spi.DatabaseServerLoginModule} minus the
21  * usersQuery.
22  * @see org.jboss.security.auth.spi.DatabaseServerLoginModule
23  *
24  * @author <a HREF="mailto:jasone@greenrivercomputing.com">Jason Essington</a>
25  * @author Scott.Stark@jboss.org
26  * @version $Revision: 1.2.4.1 $
27  */

28 public class DatabaseCertLoginModule extends BaseCertLoginModule
29 {
30    /** The JNDI name of the DataSource to use */
31    private String JavaDoc dsJndiName;
32    /** The sql query to obtain the user roles */
33    private String JavaDoc rolesQuery = "select Role, RoleGroup from Roles where PrincipalID=?";
34    
35    /**
36     * @param options -
37     * dsJndiName: The name of the DataSource of the database containing the
38     * Principals, Roles tables
39     * rolesQuery: The prepared statement query, equivalent to:
40     * "select Role, RoleGroup from Roles where PrincipalID=?"
41     */

42    public void initialize(Subject JavaDoc subject, CallbackHandler JavaDoc callbackHandler,
43       Map JavaDoc sharedState, Map JavaDoc options)
44    {
45       super.initialize(subject, callbackHandler, sharedState, options);
46       dsJndiName = (String JavaDoc) options.get("dsJndiName");
47       if( dsJndiName == null )
48          dsJndiName = "java:/DefaultDS";
49       
50       Object JavaDoc tmp = options.get("rolesQuery");
51       if( tmp != null )
52          rolesQuery = tmp.toString();
53       
54       log.trace("DatabaseServerLoginModule, dsJndiName="+dsJndiName);
55       log.trace("rolesQuery="+rolesQuery);
56    }
57
58    /**
59     * @see org.jboss.security.auth.spi.DatabaseServerLoginModule#getRoleSets
60     */

61    protected Group JavaDoc[] getRoleSets() throws LoginException JavaDoc
62    {
63       String JavaDoc username = getUsername();
64       Group JavaDoc[] roleSets = Util.getRoleSets(username, dsJndiName, rolesQuery, this);
65       return roleSets;
66    }
67    
68 }
69
Popular Tags