| Method from org.apache.catalina.realm.MemoryRealm Detail: |
void addUser(String username,
String password,
String roles) {
// Accumulate the list of roles for this user
ArrayList< String > list = new ArrayList< String >();
roles += ",";
while (true) {
int comma = roles.indexOf(',");
if (comma < 0)
break;
String role = roles.substring(0, comma).trim();
list.add(role);
roles = roles.substring(comma + 1);
}
// Construct and cache the Principal for this user
GenericPrincipal principal =
new GenericPrincipal(this, username, password, list);
principals.put(username, principal);
}
Add a new user to the in-memory database. |
public Principal authenticate(String username,
String credentials) {
GenericPrincipal principal =
(GenericPrincipal) principals.get(username);
boolean validated = false;
if (principal != null) {
if (hasMessageDigest()) {
// Hex hashes should be compared case-insensitive
validated = (digest(credentials)
.equalsIgnoreCase(principal.getPassword()));
} else {
validated =
(digest(credentials).equals(principal.getPassword()));
}
}
if (validated) {
if (log.isDebugEnabled())
log.debug(sm.getString("memoryRealm.authenticateSuccess", username));
return (principal);
} else {
if (log.isDebugEnabled())
log.debug(sm.getString("memoryRealm.authenticateFailure", username));
return (null);
}
}
Return the Principal associated with the specified username and
credentials, if there is one; otherwise return null. |
protected synchronized Digester getDigester() {
if (digester == null) {
digester = new Digester();
digester.setValidating(false);
digester.addRuleSet(new MemoryRuleSet());
}
return (digester);
}
Return a configured Digester to use for processing
the XML input file, creating a new one if necessary. |
public String getInfo() {
// ------------------------------------------------------------- Properties
return info;
}
Return descriptive information about this Realm implementation and
the corresponding version number, in the format
<description>/<version>. |
protected String getName() {
return (name);
}
Return a short name for this Realm implementation. |
protected String getPassword(String username) {
GenericPrincipal principal =
(GenericPrincipal) principals.get(username);
if (principal != null) {
return (principal.getPassword());
} else {
return (null);
}
}
Return the password associated with the given principal's user name. |
public String getPathname() {
return pathname;
}
Return the pathname of our XML file containing user definitions. |
protected Principal getPrincipal(String username) {
return (Principal) principals.get(username);
}
Return the Principal associated with the given user name. |
protected Map getPrincipals() {
return principals;
}
Returns the principals for this realm. |
public void setPathname(String pathname) {
this.pathname = pathname;
}
Set the pathname of our XML file containing user definitions. If a
relative pathname is specified, it is resolved against "catalina.base". |
public synchronized void start() throws LifecycleException {
// Perform normal superclass initialization
super.start();
// Validate the existence of our database file
File file = new File(pathname);
if (!file.isAbsolute())
file = new File(System.getProperty("catalina.base"), pathname);
if (!file.exists() || !file.canRead())
throw new LifecycleException
(sm.getString("memoryRealm.loadExist",
file.getAbsolutePath()));
// Load the contents of the database file
if (log.isDebugEnabled())
log.debug(sm.getString("memoryRealm.loadPath",
file.getAbsolutePath()));
Digester digester = getDigester();
try {
synchronized (digester) {
digester.push(this);
digester.parse(file);
}
} catch (Exception e) {
throw new LifecycleException
(sm.getString("memoryRealm.readXml"), e);
} finally {
digester.reset();
}
}
Prepare for active use of the public methods of this Component. |
public synchronized void stop() throws LifecycleException {
// Perform normal superclass finalization
super.stop();
// No shutdown activities required
}
Gracefully shut down active use of the public methods of this Component. |