Top Description Inners Fields Constructors Methods
org.apache.catalina.realm

public Class GenericPrincipal

extends Object
implements TomcatPrincipal, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, org.apache.catalina.TomcatPrincipal, java.security.Principal
Known Direct Subclasses
org.apache.catalina.realm.UserDatabaseRealm.UserDatabasePrincipal
Imports
java.io.Serializable, java.security.Principal, java.util.Arrays, .Collections, .Enumeration, .List, .Map, javax.security.auth.login.LoginContext, org.apache.catalina.TomcatPrincipal, org.ietf.jgss.GSSCredential

Generic implementation of java.security.Principal that is available for use by Realm implementations.
Author
Craig R. McClanahan

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected final Map<String, Object>
attributes

The additional attributes associated with this Principal.

protected transient GSSCredential
gssCredential

The user's delegated credentials.

protected final transient LoginContext
loginContext

The JAAS LoginContext, if any, used to authenticate this Principal.

protected final String
name

The username of the user represented by this Principal.

protected final String[]
roles

The set of roles associated with this user.

private static final long
protected final Principal
userPrincipal

The authenticated Principal to be exposed to applications.

Constructor Summary

AccessConstructor and Description
public
GenericPrincipal(String
The username of the user represented by this Principal
name
)

Construct a new Principal, associated with the specified Realm, for the specified username, with no roles.

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
List<String>
List of roles (must be Strings) possessed by this user
roles
)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
String
Unused
password
,
List<String>
List of roles (must be Strings) possessed by this user
roles
)
Deprecated This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
String
Unused
password
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
)
Deprecated This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
,
LoginContext
- If provided, this will be used to log out the user at the appropriate time
loginContext
)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
String
Unused
password
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
,
LoginContext
- If provided, this will be used to log out the user at the appropriate time
loginContext
)
Deprecated This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
,
LoginContext
- If provided, this will be used to log out the user at the appropriate time
loginContext
,
GSSCredential
- If provided, the user's delegated credentials
gssCredential
,
Map<String, Object>
- If provided, additional attributes associated with this Principal
attributes
)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

public
GenericPrincipal(String
The username of the user represented by this Principal
name
,
String
Unused
password
,
List<String>
List of roles (must be Strings) possessed by this user
roles
,
Principal
- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned
userPrincipal
,
LoginContext
- If provided, this will be used to log out the user at the appropriate time
loginContext
,
GSSCredential
- If provided, the user's delegated credentials
gssCredential
)
Deprecated This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Method Summary

Modifier and TypeMethod and Description
public Object
getAttribute(String
a String specifying the name of the attribute
name
)

Implements org.apache.catalina.TomcatPrincipal.getAttribute.

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists, or if null has been specified as the attribute's name.

public Enumeration<String>
getAttributeNames()

Implements org.apache.catalina.TomcatPrincipal.getAttributeNames.

Returns an Enumeration containing the names of the attributes available to this Principal.

public GSSCredential
public String
getName()

Implements java.security.Principal.getName.

Returns the name of this Principal.

public String[]
public Principal
public boolean

Returns:

true if this Principal has been assigned the given role, otherwise false
hasRole
(String
Role to be tested
role
)

Does the user represented by this Principal possess the specified role?

public void
logout()

Implements org.apache.catalina.TomcatPrincipal.logout.

Calls logout, if necessary, on any associated JAASLoginContext and/or GSSContext.

protected void
public String
toString()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Return a String representation of this object, which exposes only information that should be public.

private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

attributesback to summary
protected final Map<String, Object> attributes

The additional attributes associated with this Principal.

gssCredentialback to summary
protected transient GSSCredential gssCredential

The user's delegated credentials.

loginContextback to summary
protected final transient LoginContext loginContext

The JAAS LoginContext, if any, used to authenticate this Principal. Kept so we can call logout().

nameback to summary
protected final String name

The username of the user represented by this Principal.

rolesback to summary
protected final String[] roles

The set of roles associated with this user.

serialVersionUIDback to summary
private static final long serialVersionUID
userPrincipalback to summary
protected final Principal userPrincipal

The authenticated Principal to be exposed to applications.

Constructor Detail

GenericPrincipalback to summary
public GenericPrincipal(String name)

Construct a new Principal, associated with the specified Realm, for the specified username, with no roles.

Parameters
name:String

The username of the user represented by this Principal

GenericPrincipalback to summary
public GenericPrincipal(String name, List<String> roles)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

roles:List<String>

List of roles (must be Strings) possessed by this user

GenericPrincipalback to summary
public GenericPrincipal(String name, String password, List<String> roles)

Deprecated

This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

password:String

Unused

roles:List<String>

List of roles (must be Strings) possessed by this user

Annotations
@Deprecated
GenericPrincipalback to summary
public GenericPrincipal(String name, List<String> roles, Principal userPrincipal)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

GenericPrincipalback to summary
public GenericPrincipal(String name, String password, List<String> roles, Principal userPrincipal)

Deprecated

This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

password:String

Unused

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

Annotations
@Deprecated
GenericPrincipalback to summary
public GenericPrincipal(String name, List<String> roles, Principal userPrincipal, LoginContext loginContext)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

loginContext:LoginContext

- If provided, this will be used to log out the user at the appropriate time

GenericPrincipalback to summary
public GenericPrincipal(String name, String password, List<String> roles, Principal userPrincipal, LoginContext loginContext)

Deprecated

This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

password:String

Unused

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

loginContext:LoginContext

- If provided, this will be used to log out the user at the appropriate time

Annotations
@Deprecated
GenericPrincipalback to summary
public GenericPrincipal(String name, List<String> roles, Principal userPrincipal, LoginContext loginContext, GSSCredential gssCredential, Map<String, Object> attributes)

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

loginContext:LoginContext

- If provided, this will be used to log out the user at the appropriate time

gssCredential:GSSCredential

- If provided, the user's delegated credentials

attributes:Map<String, Object>

- If provided, additional attributes associated with this Principal

GenericPrincipalback to summary
public GenericPrincipal(String name, String password, List<String> roles, Principal userPrincipal, LoginContext loginContext, GSSCredential gssCredential)

Deprecated

This method will be removed in Tomcat 11 onwards

Construct a new Principal, associated with the specified Realm, for the specified username, with the specified role names (as Strings).

Parameters
name:String

The username of the user represented by this Principal

password:String

Unused

roles:List<String>

List of roles (must be Strings) possessed by this user

userPrincipal:Principal

- the principal to be returned from the request getUserPrincipal call if not null; if null, this will be returned

loginContext:LoginContext

- If provided, this will be used to log out the user at the appropriate time

gssCredential:GSSCredential

- If provided, the user's delegated credentials

Annotations
@Deprecated

Method Detail

getAttributeback to summary
public Object getAttribute(String name)

Implements org.apache.catalina.TomcatPrincipal.getAttribute.

Doc from org.apache.catalina.TomcatPrincipal.getAttribute.

Returns the value of the named attribute as an Object, or null if no attribute of the given name exists, or if null has 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 Realm implementation'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 the Principal.

Realm implementations that are provided by Tomcat will not provide complex type mapping, but will in most cases always return a result as a String object which may need custom decoding.

Realm implementations that are provided by Tomcat will not provide an implementation for this facility unless it is inherent to the storage backend of the Realm itself and metadata is available without additional user intervention or configuration.

Parameters
name:String

a String specifying the name of the attribute

Returns:Object

an Object containing the value of the attribute, or null if the attribute does not exist, or if null has been specified as the attribute's name

Annotations
@Override
getAttributeNamesback to summary
public Enumeration<String> getAttributeNames()

Implements org.apache.catalina.TomcatPrincipal.getAttributeNames.

Doc from org.apache.catalina.TomcatPrincipal.getAttributeNames.

Returns an Enumeration containing the names of the attributes available to this Principal. This method returns an empty Enumeration if the Principal has no attributes available to it.

Returns:Enumeration<String>

an Enumeration of strings containing the names of the Principal's attributes

Annotations
@Override
getGssCredentialback to summary
public GSSCredential getGssCredential()

Implements org.apache.catalina.TomcatPrincipal.getGssCredential.

Returns:GSSCredential

Doc from org.apache.catalina.TomcatPrincipal.getGssCredential.

The user's delegated credentials.

Annotations
@Override
getNameback to summary
public String getName()

Implements java.security.Principal.getName.

Doc from java.security.Principal.getName.

Returns the name of this Principal.

Returns:String

the name of this Principal.

Annotations
@Override
getRolesback to summary
public String[] getRoles()
getUserPrincipalback to summary
public Principal getUserPrincipal()

Implements org.apache.catalina.TomcatPrincipal.getUserPrincipal.

Returns:Principal

Doc from org.apache.catalina.TomcatPrincipal.getUserPrincipal.

The authenticated Principal to be exposed to applications.

Annotations
@Override
hasRoleback to summary
public boolean hasRole(String role)

Does the user represented by this Principal possess the specified role?

Parameters
role:String

Role to be tested

Returns:boolean

true if this Principal has been assigned the given role, otherwise false

logoutback to summary
public void logout() throws Exception

Implements org.apache.catalina.TomcatPrincipal.logout.

Doc from org.apache.catalina.TomcatPrincipal.logout.

Calls logout, if necessary, on any associated JAASLoginContext and/or GSSContext. May in the future be extended to cover other logout requirements.

Annotations
@Override
Exceptions
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
setGssCredentialback to summary
protected void setGssCredential(GSSCredential gssCredential)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Return a String representation of this object, which exposes only information that should be public.

Returns:String

Doc from java.security.Principal.toString.

a string representation of this Principal.

Annotations
@Override
writeReplaceback to summary
private Object writeReplace()
org.apache.catalina.realm back to summary

private Class GenericPrincipal.SerializablePrincipal

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.catalina.realm.GenericPrincipal.SerializablePrincipal
All Implemented Interfaces
java.io.Serializable

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>
private final String
private final Principal
private final String[]
private static final long

Constructor Summary

AccessConstructor and Description
pack-priv
SerializablePrincipal(String name, String[] roles, Principal principal, Map<String, Object> attributes)

Method Summary

Modifier and TypeMethod and Description
private Object
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

attributesback to summary
private final Map<String, Object> attributes
nameback to summary
private final String name
principalback to summary
private final Principal principal
rolesback to summary
private final String[] roles
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

SerializablePrincipalback to summary
pack-priv SerializablePrincipal(String name, String[] roles, Principal principal, Map<String, Object> attributes)

Method Detail

readResolveback to summary
private Object readResolve()