| Method from org.apache.catalina.realm.UserDatabaseRealm Detail: |
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) {
User user = database.findUser(username);
if (user == null) {
return null;
}
return (user.getPassword());
}
Return the password associated with the given principal's user name. |
protected Principal getPrincipal(String username) {
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);
}
Return the Principal associated with the given user name. |
public String getResourceName() {
return resourceName;
}
Return the global JNDI name of the UserDatabase resource
we will be using. |
public boolean hasRole(Principal principal,
String 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;
}
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. |
public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}
Set the global JNDI name of the UserDatabase resource
we will be using. |
public synchronized void start() throws LifecycleException {
// 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));
}
}
Prepare for active use of the public methods of this Component. |
public synchronized void stop() throws LifecycleException {
// Perform normal superclass finalization
super.stop();
// Release reference to our user database
database = null;
}
Gracefully shut down active use of the public methods of this Component. |