org.apache.catalina.realm

Class GenericPrincipal

public class GenericPrincipal extends Object implements Principal

Generic implementation of java.security.Principal that is available for use by Realm implementations.

Version: $Revision: 832626 $ $Date: 2009-11-04 01:08:46 +0100 (Wed, 04 Nov 2009) $

Author: Craig R. McClanahan

Field Summary
protected LoginContextloginContext
The JAAS LoginContext, if any, used to authenticate this Principal.
protected Stringname
The username of the user represented by this Principal.
protected Stringpassword
The authentication credentials for the user represented by this Principal.
protected Realmrealm
The Realm with which this Principal is associated.
protected String[]roles
The set of roles associated with this user.
protected PrincipaluserPrincipal
The authenticated Principal to be exposed to applications.
Constructor Summary
GenericPrincipal(Realm realm, String name, String password)
Construct a new Principal, associated with the specified Realm, for the specified username and password.
GenericPrincipal(Realm realm, String name, String password, List<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(Realm realm, String name, String password, List<String> 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).
GenericPrincipal(Realm realm, String name, String password, List<String> roles, Principal userPrincipal, LoginContext loginContext)
Construct a new Principal, associated with the specified Realm, for the specified username and password, with the specified role names (as Strings).
Method Summary
StringgetName()
StringgetPassword()
RealmgetRealm()
String[]getRoles()
PrincipalgetUserPrincipal()
booleanhasRole(String role)
Does the user represented by this Principal possess the specified role?
voidlogout()
Calls logout, if necessary, on any associated JAASLoginContext.
StringtoString()
Return a String representation of this object, which exposes only information that should be public.

Field Detail

loginContext

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

name

protected String name
The username of the user represented by this Principal.

password

protected String password
The authentication credentials for the user represented by this Principal.

realm

protected Realm realm
The Realm with which this Principal is associated.

roles

protected String[] roles
The set of roles associated with this user.

userPrincipal

protected Principal userPrincipal
The authenticated Principal to be exposed to applications.

Constructor Detail

GenericPrincipal

public GenericPrincipal(Realm realm, String name, String password)
Construct a new Principal, associated with the specified Realm, for the specified username and password.

Parameters: realm The Realm that owns this Principal name The username of the user represented by this Principal password Credentials used to authenticate this user

GenericPrincipal

public GenericPrincipal(Realm realm, String name, String password, List<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: realm The Realm that owns this principal 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

GenericPrincipal

public GenericPrincipal(Realm realm, String name, String password, List<String> 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).

Parameters: realm The Realm that owns this principal 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

GenericPrincipal

public GenericPrincipal(Realm realm, String name, String password, List<String> roles, Principal userPrincipal, 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: realm The Realm that owns this principal 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

Method Detail

getName

public String getName()

getPassword

public String getPassword()

getRealm

public Realm getRealm()

getRoles

public String[] getRoles()

getUserPrincipal

public Principal getUserPrincipal()

hasRole

public boolean hasRole(String role)
Does the user represented by this Principal possess the specified role?

Parameters: role Role to be tested

logout

public void logout()
Calls logout, if necessary, on any associated JAASLoginContext. May in the future be extended to cover other logout requirements.

Throws: 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

toString

public String toString()
Return a String representation of this object, which exposes only information that should be public.
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.