SerializablePrincipalpublic class SerializablePrincipal extends Object implements SerializableGeneric 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. |
Fields Summary |
---|
protected String | nameThe username of the user represented by this Principal. | protected String | passwordThe authentication credentials for the user represented by
this Principal. | protected transient org.apache.catalina.Realm | realmThe Realm with which this Principal is associated. | protected String[] | rolesThe 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.
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).
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.SerializablePrincipal | createPrincipal(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.String | getName()
return (this.name);
| public java.lang.String | getPassword()
return (this.password);
| public org.apache.catalina.realm.GenericPrincipal | getPrincipal(org.apache.catalina.Realm realm)
return new GenericPrincipal(realm,name,password,getRoles()!=null?Arrays.asList(getRoles()):null);
| public org.apache.catalina.Realm | getRealm()
return (this.realm);
| public java.lang.String[] | getRoles()
return (this.roles);
| public static org.apache.catalina.realm.GenericPrincipal | readPrincipal(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 void | setRealm(org.apache.catalina.Realm realm)
this.realm = realm;
| public java.lang.String | toString()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 void | writePrincipal(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]);
|
|