FileDocCategorySizeDatePackage
MemoryUser.javaAPI DocGlassfish v2 API8317Fri May 04 22:32:30 BST 2007org.apache.catalina.users

MemoryUser

public class MemoryUser extends AbstractUser

Concrete implementation of {@link User} for the {@link MemoryUserDatabase} implementation of {@link UserDatabase}.

author
Craig R. McClanahan
version
$Revision: 1.3 $ $Date: 2007/05/05 05:32:29 $
since
4.1

Fields Summary
protected MemoryUserDatabase
database
The {@link MemoryUserDatabase} that owns this user.
protected ArrayList
groups
The set of {@link Group}s that this user is a member of.
protected ArrayList
roles
The set of {@link Role}s associated with this user.
Constructors Summary
MemoryUser(MemoryUserDatabase database, String username, String password, String fullName)
Package-private constructor used by the factory method in {@link MemoryUserDatabase}.

param
database The {@link MemoryUserDatabase} that owns this user
param
username Logon username of the new user
param
password Logon password of the new user
param
fullName Full name of the new user


        super();
        this.database = database;
        setUsername(username);
        setPassword(password);
        setFullName(fullName);

    
Methods Summary
public voidaddGroup(org.apache.catalina.Group group)
Add a new {@link Group} to those this user belongs to.

param
group The new group


        synchronized (groups) {
            if (!groups.contains(group)) {
                groups.add(group);
            }
        }

    
public voidaddRole(org.apache.catalina.Role role)
Add a new {@link Role} to those assigned specifically to this user.

param
role The new role


        synchronized (roles) {
            if (!roles.contains(role)) {
                roles.add(role);
            }
        }

    
public java.util.IteratorgetGroups()
Return the set of {@link Group}s to which this user belongs.



    // ------------------------------------------------------------- Properties


                    
       

        synchronized (groups) {
            return (groups.iterator());
        }

    
public java.util.IteratorgetRoles()
Return the set of {@link Role}s assigned specifically to this user.


        synchronized (roles) {
            return (roles.iterator());
        }

    
public org.apache.catalina.UserDatabasegetUserDatabase()
Return the {@link UserDatabase} within which this User is defined.


        return (this.database);

    
public booleanisInGroup(org.apache.catalina.Group group)
Is this user in the specified group?

param
group The group to check


        synchronized (groups) {
            return (groups.contains(group));
        }

    
public booleanisInRole(org.apache.catalina.Role role)
Is this user specifically assigned the specified {@link Role}? This method does NOT check for roles inherited based on {@link Group} membership.

param
role The role to check


        synchronized (roles) {
            return (roles.contains(role));
        }

    
public voidremoveGroup(org.apache.catalina.Group group)
Remove a {@link Group} from those this user belongs to.

param
group The old group


        synchronized (groups) {
            groups.remove(group);
        }

    
public voidremoveGroups()
Remove all {@link Group}s from those this user belongs to.


        synchronized (groups) {
            groups.clear();
        }

    
public voidremoveRole(org.apache.catalina.Role role)
Remove a {@link Role} from those assigned to this user.

param
role The old role


        synchronized (roles) {
            roles.remove(role);
        }

    
public voidremoveRoles()
Remove all {@link Role}s from those assigned to this user.


        synchronized (roles) {
            roles.clear();
        }

    
public java.lang.StringtoString()

Return a String representation of this user in XML format.

IMPLEMENTATION NOTE - For backwards compatibility, the reader that processes this entry will accept either username or name for the username property.


        StringBuffer sb = new StringBuffer("<user username=\"");
        sb.append(username);
        sb.append("\" password=\"");
        sb.append(password);
        sb.append("\"");
        if (fullName != null) {
            sb.append(" fullName=\"");
            sb.append(fullName);
            sb.append("\"");
        }
        synchronized (groups) {
            if (groups.size() > 0) {
                sb.append(" groups=\"");
                int n = 0;
                Iterator values = groups.iterator();
                while (values.hasNext()) {
                    if (n > 0) {
                        sb.append(',");
                    }
                    n++;
                    sb.append(((Group) values.next()).getGroupname());
                }
                sb.append("\"");
            }
        }
        synchronized (roles) {
            if (roles.size() > 0) {
                sb.append(" roles=\"");
                int n = 0;
                Iterator values = roles.iterator();
                while (values.hasNext()) {
                    if (n > 0) {
                        sb.append(',");
                    }
                    n++;
                    sb.append(((Role) values.next()).getRolename());
                }
                sb.append("\"");
            }
        }
        sb.append("/>");
        return (sb.toString());