FileDocCategorySizeDatePackage
GenericPrincipal.javaAPI DocGlassfish v2 API6164Fri May 04 22:32:16 BST 2007org.apache.catalina.realm

GenericPrincipal

public class GenericPrincipal extends Object implements Principal
Generic implementation of java.security.Principal that is available for use by Realm implementations.
author
Craig R. McClanahan
version
$Revision: 1.3 $ $Date: 2007/05/05 05:32:16 $

Fields Summary
protected String
name
The username of the user represented by this Principal.
protected String
password
The authentication credentials for the user represented by this Principal.
protected org.apache.catalina.Realm
realm
The Realm with which this Principal is associated.
protected String[]
roles
The set of roles associated with this user.
Constructors Summary
public GenericPrincipal(org.apache.catalina.Realm realm, String name, String password)
Construct a new Principal, associated with the specified Realm, for the specified username and password.

param
realm The Realm that owns this Principal
param
name The username of the user represented by this Principal
param
password Credentials used to authenticate this user


        this(realm, name, password, null);

    
public GenericPrincipal(org.apache.catalina.Realm realm, String name, String password, List roles)
Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).

param
realm The Realm that owns this principal
param
name The username of the user represented by this Principal
param
password Credentials used to authenticate this user
param
roles List of roles (must be Strings) possessed by this user


        super();
        this.realm = realm;
        this.name = name;
        this.password = password;
        if (roles != null) {
            this.roles = new String[roles.size()];
            this.roles = (String[]) roles.toArray(this.roles);
            if (this.roles.length > 0)
                Arrays.sort(this.roles);
        }
    
public GenericPrincipal(String name, String password, List roles)


        super();
        this.name = name;
        this.password = password;
        if (roles != null) {
            this.roles = new String[roles.size()];
            this.roles = (String[]) roles.toArray(this.roles);
            if (this.roles.length > 0)
                Arrays.sort(this.roles);
        }
    
Methods Summary
public java.lang.StringgetName()


       
        return (this.name);
    
public java.lang.StringgetPassword()


       
        return (this.password);
    
public org.apache.catalina.RealmgetRealm()


       
        return (this.realm);
    
public java.lang.String[]getRoles()


       
        return (this.roles);
    
public booleanhasRole(java.lang.String role)
Does the user represented by this Principal possess the specified role?

param
role Role to be tested


        if("*".equals(role)) // Special 2.4 role meaning everyone
            return true;
        if (role == null)
            return (false);
        return (Arrays.binarySearch(roles, role) >= 0);

    
voidsetRealm(org.apache.catalina.Realm realm)

        this.realm=realm;
    
public java.lang.StringtoString()
Return a String representation of this object, which exposes only information that should be public.


        StringBuffer sb = new StringBuffer("GenericPrincipal[");
        sb.append(this.name);
        sb.append("(");
        for( int i=0;i<roles.length; i++ ) {
            sb.append( roles[i]).append(",");
        }
        sb.append(")]");
        return (sb.toString());