Class GenericPrincipal
- java.lang.Object
- 
- org.apache.catalina.realm.GenericPrincipal
 
- 
- All Implemented Interfaces:
- java.io.Serializable,- java.security.Principal,- TomcatPrincipal
 - Direct Known Subclasses:
- UserDatabaseRealm.UserDatabasePrincipal
 
 public class GenericPrincipal extends java.lang.Object implements TomcatPrincipal, java.io.Serializable Generic implementation of java.security.Principal that is available for use byRealmimplementations.- Author:
- Craig R. McClanahan
- See Also:
- Serialized Form
 
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.Object>attributesThe additional attributes associated with this Principal.protected org.ietf.jgss.GSSCredentialgssCredentialThe user's delegated credentials.protected javax.security.auth.login.LoginContextloginContextThe JAAS LoginContext, if any, used to authenticate this Principal.protected java.lang.StringnameThe username of the user represented by this Principal.protected java.lang.StringpasswordThe authentication credentials for the user represented by this Principal.protected java.lang.String[]rolesThe set of roles associated with this user.protected java.security.PrincipaluserPrincipalThe authenticated Principal to be exposed to applications.
 - 
Constructor SummaryConstructors Constructor Description GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal, javax.security.auth.login.LoginContext loginContext)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal, javax.security.auth.login.LoginContext loginContext, org.ietf.jgss.GSSCredential gssCredential, java.util.Map<java.lang.String,java.lang.Object> attributes)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectgetAttribute(java.lang.String name)Returns the value of the named attribute as anObject, ornullif no attribute of the given name exists, or ifnullhas been specified as the attribute's name.java.util.Enumeration<java.lang.String>getAttributeNames()Returns anEnumerationcontaining the names of the attributes available to this Principal.org.ietf.jgss.GSSCredentialgetGssCredential()java.lang.StringgetName()java.lang.StringgetPassword()java.lang.String[]getRoles()java.security.PrincipalgetUserPrincipal()booleanhasRole(java.lang.String role)Does the user represented by this Principal possess the specified role?voidlogout()Calls logout, if necessary, on any associated JAASLoginContext and/or GSSContext.protected voidsetGssCredential(org.ietf.jgss.GSSCredential gssCredential)java.lang.StringtoString()Return a String representation of this object, which exposes only information that should be public.
 
- 
- 
- 
Field Detail- 
nameprotected final java.lang.String name The username of the user represented by this Principal.
 - 
passwordprotected final java.lang.String password The authentication credentials for the user represented by this Principal.
 - 
rolesprotected final java.lang.String[] roles The set of roles associated with this user.
 - 
userPrincipalprotected final java.security.Principal userPrincipal The authenticated Principal to be exposed to applications.
 - 
loginContextprotected final transient javax.security.auth.login.LoginContext loginContext The JAAS LoginContext, if any, used to authenticate this Principal. Kept so we can call logout().
 - 
gssCredentialprotected transient org.ietf.jgss.GSSCredential gssCredential The user's delegated credentials.
 - 
attributesprotected final java.util.Map<java.lang.String,java.lang.Object> attributes The additional attributes associated with this Principal.
 
- 
 - 
Constructor Detail- 
GenericPrincipalpublic GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).- Parameters:
- name- The username of the user represented by this Principal
- password- Credentials used to authenticate this user
- roles- List of roles (must be Strings) possessed by this user
 
 - 
GenericPrincipalpublic GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).- Parameters:
- name- The username of the user represented by this Principal
- password- Credentials used to authenticate this user
- roles- List of roles (must be Strings) possessed by this user
- userPrincipal- - the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
 
 - 
GenericPrincipalpublic GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal, javax.security.auth.login.LoginContext loginContext)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).- Parameters:
- name- The username of the user represented by this Principal
- password- Credentials used to authenticate this user
- roles- List of roles (must be Strings) possessed by this user
- userPrincipal- - the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
- loginContext- - If provided, this will be used to log out the user at the appropriate time
 
 - 
GenericPrincipalpublic GenericPrincipal(java.lang.String name, java.lang.String password, java.util.List<java.lang.String> roles, java.security.Principal userPrincipal, javax.security.auth.login.LoginContext loginContext, org.ietf.jgss.GSSCredential gssCredential, java.util.Map<java.lang.String,java.lang.Object> attributes)Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).- Parameters:
- name- The username of the user represented by this Principal
- password- Credentials used to authenticate this user
- roles- List of roles (must be Strings) possessed by this user
- userPrincipal- - the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
- loginContext- - If provided, this will be used to log out the user at the appropriate time
- gssCredential- - If provided, the user's delegated credentials
- attributes- - If provided, additional attributes associated with this Principal
 
 
- 
 - 
Method Detail- 
getNamepublic java.lang.String getName() - Specified by:
- getNamein interface- java.security.Principal
 
 - 
getPasswordpublic java.lang.String getPassword() 
 - 
getRolespublic java.lang.String[] getRoles() 
 - 
getUserPrincipalpublic java.security.Principal getUserPrincipal() - Specified by:
- getUserPrincipalin interface- TomcatPrincipal
- Returns:
- The authenticated Principal to be exposed to applications.
 
 - 
getGssCredentialpublic org.ietf.jgss.GSSCredential getGssCredential() - Specified by:
- getGssCredentialin interface- TomcatPrincipal
- Returns:
- The user's delegated credentials.
 
 - 
setGssCredentialprotected void setGssCredential(org.ietf.jgss.GSSCredential gssCredential) 
 - 
hasRolepublic boolean hasRole(java.lang.String role) Does the user represented by this Principal possess the specified role?- Parameters:
- role- Role to be tested
- Returns:
- trueif this Principal has been assigned the given role, otherwise- false
 
 - 
toStringpublic java.lang.String toString() Return a String representation of this object, which exposes only information that should be public.- Specified by:
- toStringin interface- java.security.Principal
- Overrides:
- toStringin class- java.lang.Object
 
 - 
logoutpublic void logout() throws java.lang.ExceptionDescription copied from interface:TomcatPrincipalCalls logout, if necessary, on any associated JAASLoginContext and/or GSSContext. May in the future be extended to cover other logout requirements.- Specified by:
- logoutin interface- TomcatPrincipal
- Throws:
- java.lang.Exception- If something goes wrong with the logout. Uses Exception to allow for future expansion of this method to cover other logout mechanisms that might throw a different exception to LoginContext
 
 - 
getAttributepublic java.lang.Object getAttribute(java.lang.String name) Description copied from interface:TomcatPrincipalReturns the value of the named attribute as anObject, ornullif no attribute of the given name exists, or ifnullhas been specified as the attribute's name.Only the servlet container may set attributes to make available custom information about a Principal or the user it represents. The purpose of the method is to implement read only access to attributes which may be stored in the Realmimplementation's backend due to its inherent design.As using this method from application code will make it non portable to other EE compliant containers, it is advised this should never be used as an object storage facility tied to the Principal, but rather as simple extra additional metadata. It is recommended that a container level object is used to further process the attributes that may be associated with thePrincipal.Realmimplementations that are provided by Tomcat will not provide complex type mapping, but will in most cases always return a result as aStringobject which may need custom decoding.Realmimplementations that are provided by Tomcat will not provide an implementation for this facility unless it is inherent to the storage backend of theRealmitself and metadata is available without additional user intervention or configuration.- Specified by:
- getAttributein interface- TomcatPrincipal
- Parameters:
- name- a- Stringspecifying the name of the attribute
- Returns:
- an Objectcontaining the value of the attribute, ornullif the attribute does not exist, or ifnullhas been specified as the attribute's name
 
 - 
getAttributeNamespublic java.util.Enumeration<java.lang.String> getAttributeNames() Description copied from interface:TomcatPrincipalReturns anEnumerationcontaining the names of the attributes available to this Principal. This method returns an emptyEnumerationif the Principal has no attributes available to it.- Specified by:
- getAttributeNamesin interface- TomcatPrincipal
- Returns:
- an Enumerationof strings containing the names of the Principal's attributes
 
 
- 
 
-