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.security.Principal | authenticate(java.lang.String username, java.lang.String credentials)Return the Principal associated with the specified username and
credentials, if there is one; otherwise return null .
// Does a user with this username exist?
User user = database.findUser(username);
if (user == null) {
return (null);
}
// Do the credentials specified by the user match?
// FIXME - Update all realms to support encoded passwords
boolean validated = false;
if (hasMessageDigest()) {
// Hex hashes should be compared case-insensitive
validated = (digest(credentials)
.equalsIgnoreCase(user.getPassword()));
} else {
validated =
(digest(credentials).equals(user.getPassword()));
}
if (!validated) {
if (debug >= 2) {
log(sm.getString("userDatabaseRealm.authenticateFailure",
username));
}
return (null);
}
// Construct a GenericPrincipal that represents this user
if (debug >= 2) {
log(sm.getString("userDatabaseRealm.authenticateSuccess",
username));
}
ArrayList combined = new ArrayList();
Iterator roles = user.getRoles();
while (roles.hasNext()) {
Role role = (Role) roles.next();
String rolename = role.getRolename();
if (!combined.contains(rolename)) {
combined.add(rolename);
}
}
Iterator groups = user.getGroups();
while (groups.hasNext()) {
Group group = (Group) groups.next();
roles = group.getRoles();
while (roles.hasNext()) {
Role role = (Role) roles.next();
String rolename = role.getRolename();
if (!combined.contains(rolename)) {
combined.add(rolename);
}
}
}
return (new GenericPrincipal(this, user.getUsername(),
user.getPassword(), combined));
|
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 (this.name);
|
protected java.lang.String | getPassword(java.lang.String username)Return the password associated with the given principal's user name.
return (null);
|
protected java.security.Principal | getPrincipal(java.lang.String username)Return the Principal associated with the given user name.
return (null);
|
public java.lang.String | getResourceName()Return the global JNDI name of the UserDatabase resource
we will be using.
return resourceName;
|
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.
try {
StandardServer server = (StandardServer) ServerFactory.getServer();
Context context = server.getGlobalNamingContext();
database = (UserDatabase) context.lookup(resourceName);
} catch (Throwable e) {
e.printStackTrace();
log(sm.getString("userDatabaseRealm.lookup", resourceName), e);
database = null;
}
if (database == null) {
throw new LifecycleException
(sm.getString("userDatabaseRealm.noDatabase", resourceName));
}
// Perform normal superclass initialization
super.start();
|
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;
|