GenericPrincipalpublic class GenericPrincipal extends Object implements PrincipalGeneric implementation of java.security.Principal that
is available for use by Realm implementations. |
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 org.apache.catalina.Realm | realmThe Realm with which this Principal is associated. | protected String[] | rolesThe set of roles associated with this user. | protected Principal | userPrincipalThe 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.
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).
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).
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.String | getName()
return (this.name);
| public java.lang.String | getPassword()
return (this.password);
| public org.apache.catalina.Realm | getRealm()
return (this.realm);
| public java.lang.String[] | getRoles()
return (this.roles);
| public java.security.Principal | getUserPrincipal()
if (userPrincipal != null) {
return userPrincipal;
} else {
return this;
}
| public boolean | hasRole(java.lang.String role)Does the user represented by this Principal possess the specified role?
if("*".equals(role)) // Special 2.4 role meaning everyone
return true;
if (role == null)
return (false);
return (Arrays.binarySearch(roles, role) >= 0);
| 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("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());
|
|