FileDocCategorySizeDatePackage
GenericPrincipal.javaAPI DocApache Tomcat 6.0.145962Fri Jul 20 04:20:32 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: 543691 $ $Date: 2007-06-02 03:37:08 +0200 (sam., 02 juin 2007) $

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.
protected Principal
userPrincipal
The authenticated Principal to be exposed to applications.
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

        this(realm, name, password, roles, null);
    
public GenericPrincipal(org.apache.catalina.Realm realm, String name, String password, List roles, Principal userPrincipal)
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
param
userPrincipal - the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned


        super();
        this.realm = realm;
        this.name = name;
        this.password = password;
        this.userPrincipal = userPrincipal;
        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 java.security.PrincipalgetUserPrincipal()


       
        if (userPrincipal != null) {
            return userPrincipal;
        } else {
            return this;
        }
    
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());