Fields Summary |
---|
protected org.apache.catalina.UserDatabase | databaseThe UserDatabase we will use to authenticate users
and identify associated roles. |
protected final String | infoDescriptive information about this Realm implementation. |
protected static final String | nameDescriptive information about this Realm implementation. |
protected String | resourceNameThe global JNDI name of the UserDatabase resource
we will be utilizing. |
private static org.apache.catalina.util.StringManager | smThe string manager for this package. |
Methods Summary |
---|
public java.lang.String | getInfo()Return descriptive information about this Realm implementation and
the corresponding version number, in the format
<description>/<version> .
// ------------------------------------------------------------- Properties
return info;
|
protected java.lang.String | getName()Return a short name for this Realm implementation.
return (name);
|
protected java.lang.String | getPassword(java.lang.String username)Return the password associated with the given principal's user name.
User user = database.findUser(username);
if (user == null) {
return null;
}
return (user.getPassword());
|
protected java.security.Principal | getPrincipal(java.lang.String username)Return the Principal associated with the given user name.
User user = database.findUser(username);
if(user == null) {
return null;
}
List<String> roles = new ArrayList<String>();
Iterator uroles = user.getRoles();
while(uroles.hasNext()) {
Role role = (Role)uroles.next();
roles.add(role.getName());
}
Iterator groups = user.getGroups();
while(groups.hasNext()) {
Group group = (Group)groups.next();
uroles = group.getRoles();
while(uroles.hasNext()) {
Role role = (Role)uroles.next();
roles.add(role.getName());
}
}
return new GenericPrincipal(this, username, user.getPassword(), roles, user);
|
public java.lang.String | getResourceName()Return the global JNDI name of the UserDatabase resource
we will be using.
return resourceName;
|
public boolean | hasRole(java.security.Principal principal, java.lang.String role)Return true if the specified Principal has the specified
security role, within the context of this Realm; otherwise return
false . This implementation returns true
if the User has the role, or if any Group
that the User is a member of has the role.
if( principal instanceof GenericPrincipal) {
GenericPrincipal gp = (GenericPrincipal)principal;
if(gp.getUserPrincipal() instanceof User) {
principal = gp.getUserPrincipal();
}
}
if(! (principal instanceof User) ) {
//Play nice with SSO and mixed Realms
return super.hasRole(principal, role);
}
if("*".equals(role)) {
return true;
} else if(role == null) {
return false;
}
User user = (User)principal;
Role dbrole = database.findRole(role);
if(dbrole == null) {
return false;
}
if(user.isInRole(dbrole)) {
return true;
}
Iterator groups = user.getGroups();
while(groups.hasNext()) {
Group group = (Group)groups.next();
if(group.isInRole(dbrole)) {
return true;
}
}
return false;
|
public void | setResourceName(java.lang.String resourceName)Set the global JNDI name of the UserDatabase resource
we will be using.
this.resourceName = resourceName;
|
public synchronized void | start()Prepare for active use of the public methods of this Component.
// Perform normal superclass initialization
super.start();
try {
StandardServer server = (StandardServer) ServerFactory.getServer();
Context context = server.getGlobalNamingContext();
database = (UserDatabase) context.lookup(resourceName);
} catch (Throwable e) {
containerLog.error(sm.getString("userDatabaseRealm.lookup",
resourceName),
e);
database = null;
}
if (database == null) {
throw new LifecycleException
(sm.getString("userDatabaseRealm.noDatabase", resourceName));
}
|
public synchronized void | stop()Gracefully shut down active use of the public methods of this Component.
// Perform normal superclass finalization
super.stop();
// Release reference to our user database
database = null;
|