FileDocCategorySizeDatePackage
SerializablePrincipal.javaAPI DocApache Tomcat 6.0.146150Fri Jul 20 04:20:32 BST 2007org.apache.catalina.ha.session

SerializablePrincipal

public class SerializablePrincipal extends Object implements Serializable
Generic implementation of java.security.Principal that is available for use by Realm implementations. The GenericPrincipal does NOT implement serializable and I didn't want to change that implementation hence I implemented this one instead.
author
Filip Hanik
version
$Revision: 467222 $ $Date: 2006-10-24 05:17:11 +0200 (mar., 24 oct. 2006) $

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 transient 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 SerializablePrincipal()

        super();
    
public SerializablePrincipal(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 SerializablePrincipal(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);
        }

    
Methods Summary
public static org.apache.catalina.ha.session.SerializablePrincipalcreatePrincipal(org.apache.catalina.realm.GenericPrincipal principal)

        if ( principal==null) return null;
        return new SerializablePrincipal(principal.getRealm(),
                                         principal.getName(),
                                         principal.getPassword(),
                                         principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null);
    
public java.lang.StringgetName()


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


       
        return (this.password);
    
public org.apache.catalina.realm.GenericPrincipalgetPrincipal(org.apache.catalina.Realm realm)

        return new GenericPrincipal(realm,name,password,getRoles()!=null?Arrays.asList(getRoles()):null);
    
public org.apache.catalina.RealmgetRealm()


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


       
        return (this.roles);
    
public static org.apache.catalina.realm.GenericPrincipalreadPrincipal(java.io.ObjectInput in, org.apache.catalina.Realm realm)

        String name = in.readUTF();
        boolean hasPwd = in.readBoolean();
        String pwd = null;
        if ( hasPwd ) pwd = in.readUTF();
        int size = in.readInt();
        String[] roles = new String[size];
        for ( int i=0; i<size; i++ ) roles[i] = in.readUTF();
        return new GenericPrincipal(realm,name,pwd,Arrays.asList(roles));
    
public 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("SerializablePrincipal[");
        sb.append(this.name);
        sb.append("]");
        return (sb.toString());

    
public static voidwritePrincipal(org.apache.catalina.realm.GenericPrincipal p, java.io.ObjectOutput out)

        out.writeUTF(p.getName());
        out.writeBoolean(p.getPassword()!=null);
        if ( p.getPassword()!= null ) out.writeUTF(p.getPassword());
        String[] roles = p.getRoles();
        if ( roles == null ) roles = new String[0];
        out.writeInt(roles.length);
        for ( int i=0; i<roles.length; i++ ) out.writeUTF(roles[i]);