Top Description Inners Fields Constructors Methods
org.mortbay.jetty.security

public Class HashUserRealm

extends AbstractLifeCycle
implements UserRealm, SSORealm
Class Inheritance
All Implemented Interfaces
org.mortbay.jetty.security.SSORealm, org.mortbay.jetty.UserRealm
Known Direct Subclasses
org.mortbay.jetty.security.JDBCUserRealm
Imports
java.io.File, .FilenameFilter, .IOException, .PrintStream, java.security.Principal, java.util.ArrayList, .HashMap, .HashSet, .Iterator, .List, .Map, .Properties, .StringTokenizer, org.mortbay.component.AbstractLifeCycle, org.mortbay.jetty.Request, .Response, .UserRealm, org.mortbay.log.Log, org.mortbay.resource.Resource, org.mortbay.util.Scanner, .Scanner.BulkListener

HashMapped User Realm. An implementation of UserRealm that stores users and roles in-memory in HashMaps.

Typically these maps are populated by calling the load() method or passing a properties resource to the constructor. The format of the properties file is:

 username: password [,rolename ...]
Passwords may be clear text, obfuscated or checksummed. The class com.mortbay.Util.Password should be used to generate obfuscated passwords or password checksums. If DIGEST Authentication is used, the password must be in a recoverable format, either plain text or OBF:. The HashUserRealm also implements SSORealm but provides no implementation of SSORealm. Instead setSSORealm may be used to provide a delegate SSORealm implementation.
Author
Greg Wilkins (gregw)
See Also
Password

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class
private class

Field Summary

Modifier and TypeField and Description
public static final String
__SSO

HttpContext Attribute to set to activate SSO.

private String
private Resource
private String
private int
protected HashMap<K, V>
private Scanner
private SSORealm
protected HashMap<K, V>
Inherited from org.mortbay.component.AbstractLifeCycle:
_listeners

Constructor Summary

AccessConstructor and Description
public
HashUserRealm()

Constructor.

public
HashUserRealm(String
Realm Name
name
)

Constructor.

public
HashUserRealm(String
Realm name
name
,
String
Filename or url of user properties file.
config
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public synchronized void
addUserToRole(String userName, String roleName)

Add a user to a role.

public Principal
authenticate(String
The username.
username
,
Object
The user credentials, normally a String password.
credentials
,
Request
The request to be authenticated. Additional parameters may be extracted or set on this request as needed for the authentication mechanism (none required for BASIC and FORM authentication).
request
)

Implements org.mortbay.jetty.UserRealm.authenticate.

Authenticate a users credentials.
public void
clearSingleSignOn(String
The user to clear.
username
)

Implements org.mortbay.jetty.security.SSORealm.clearSingleSignOn.

Clear SSO for user.
public void
disassociate(Principal
A UserPrincipal allocated from this realm.
user
)

Implements org.mortbay.jetty.UserRealm.disassociate.

Dissassociate the calling context with a Principal.
protected void
protected void
public void
public String
public Resource
public String

Returns:

The realm name.
getName
()

Implements org.mortbay.jetty.UserRealm.getName.

public Principal
getPrincipal(String username)

Implements org.mortbay.jetty.UserRealm.getPrincipal.

Get the principal for a username.
public int
public Credential
getSingleSignOn(Request
The request to SSO.
request
,
Response
The response to SSO.
response
)

Implements org.mortbay.jetty.security.SSORealm.getSingleSignOn.

Get SSO credentials.
public SSORealm

Returns:

The SSORealm to delegate single sign on requests to.
getSSORealm
()

public synchronized boolean

Returns:

True if the user can act in the role.
isUserInRole
(Principal
The user, which must be from this realm
user
,
String roleName)

Implements org.mortbay.jetty.UserRealm.isUserInRole.

Check if a user is in a role.
protected void
public void
logout(Principal
A Principal previously returned from this realm
user
)

Implements org.mortbay.jetty.UserRealm.logout.

logout a user Principal.
public Principal
popRole(Principal
A UserPrincipal previously returned from pushRole
user
)

Implements org.mortbay.jetty.UserRealm.popRole.

Pop role from a Principal.
public Principal
pushRole(Principal
An existing UserPrincipal or null for an anonymous user.
user
,
String
The role to add.
role
)

Implements org.mortbay.jetty.UserRealm.pushRole.

Push role onto a Principal.
public synchronized Object

Returns:

Old UserPrinciple value or null
put
(Object
User name
name
,
Object
String password, Password or UserPrinciple instance.
credentials
)

Put user into realm.

public boolean
reauthenticate(Principal user)

Implements org.mortbay.jetty.UserRealm.reauthenticate.

Re Authenticate a Principal.
public void
setConfig(String
Filename or url of user properties file.
config
)

Load realm users from properties file.

public void
setName(String
The realm name
name
)

public void
public void
setSingleSignOn(Request
The authenticated request.
request
,
Response
The authenticated response/
response
,
Principal
The principal that has been authenticated.
principal
,
Credential
The credentials used to authenticate.
credential
)

Implements org.mortbay.jetty.security.SSORealm.setSingleSignOn.

Set SSO principal and credential.
public void
setSSORealm(SSORealm
The SSORealm to delegate single sign on requests to.
ssoRealm
)

Set the SSORealm.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from org.mortbay.component.AbstractLifeCycle:
addLifeCycleListenerisFailedisRunningisStartedisStartingisStoppedisStoppingremoveLifeCycleListenerstartstop

Field Detail

__SSOback to summary
public static final String __SSO

HttpContext Attribute to set to activate SSO.

_configback to summary
private String _config
_configResourceback to summary
private Resource _configResource
_realmNameback to summary
private String _realmName
_refreshIntervalback to summary
private int _refreshInterval
_rolesback to summary
protected HashMap<K, V> _roles
_scannerback to summary
private Scanner _scanner
_ssoRealmback to summary
private SSORealm _ssoRealm
_usersback to summary
protected HashMap<K, V> _users

Constructor Detail

HashUserRealmback to summary
public HashUserRealm()

Constructor.

HashUserRealmback to summary
public HashUserRealm(String name)

Constructor.

Parameters
name:String

Realm Name

HashUserRealmback to summary
public HashUserRealm(String name, String config) throws IOException

Constructor.

Parameters
name:String

Realm name

config:String

Filename or url of user properties file.

Method Detail

addUserToRoleback to summary
public synchronized void addUserToRole(String userName, String roleName)

Add a user to a role.

authenticateback to summary
public Principal authenticate(String username, Object credentials, Request request)

Implements org.mortbay.jetty.UserRealm.authenticate.

Doc from org.mortbay.jetty.UserRealm.authenticate.

Authenticate a users credentials. Implementations of this method may adorn the calling context to assoicate it with the authenticated principal (eg ThreadLocals). If such context associations are made, they should be considered valid until a UserRealm.deAuthenticate(UserPrincipal) call is made for this UserPrincipal.

Parameters
username:String

The username.

credentials:Object

The user credentials, normally a String password.

request:Request

The request to be authenticated. Additional parameters may be extracted or set on this request as needed for the authentication mechanism (none required for BASIC and FORM authentication).

Returns:Principal

The authenticated UserPrincipal.

clearSingleSignOnback to summary
public void clearSingleSignOn(String username)

Implements org.mortbay.jetty.security.SSORealm.clearSingleSignOn.

Doc from org.mortbay.jetty.security.SSORealm.clearSingleSignOn.

Clear SSO for user.

Parameters
username:String

The user to clear.

disassociateback to summary
public void disassociate(Principal user)

Implements org.mortbay.jetty.UserRealm.disassociate.

Doc from org.mortbay.jetty.UserRealm.disassociate.

Dissassociate the calling context with a Principal. This method is called when the calling context is not longer associated with the Principal. It should be used by an implementation to remove context associations such as ThreadLocals. The UserPrincipal object remains authenticated, as it may be associated with other contexts.

Parameters
user:Principal

A UserPrincipal allocated from this realm.

doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStart.

See Also
org.mortbay.component.AbstractLifeCycle#doStart()
doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStop.

See Also
org.mortbay.component.AbstractLifeCycle#doStop()
dumpback to summary
public void dump(PrintStream out)
getConfigback to summary
public String getConfig()
getConfigResourceback to summary
public Resource getConfigResource()
getNameback to summary
public String getName()

Implements org.mortbay.jetty.UserRealm.getName.

Returns:String

The realm name.

getPrincipalback to summary
public Principal getPrincipal(String username)

Implements org.mortbay.jetty.UserRealm.getPrincipal.

Doc from org.mortbay.jetty.UserRealm.getPrincipal.

Get the principal for a username. This method is not guaranteed to return a Principal for non-authenticated users.

getRefreshIntervalback to summary
public int getRefreshInterval()
getSingleSignOnback to summary
public Credential getSingleSignOn(Request request, Response response)

Implements org.mortbay.jetty.security.SSORealm.getSingleSignOn.

Doc from org.mortbay.jetty.security.SSORealm.getSingleSignOn.

Get SSO credentials. This call is used by an authenticator to check if a SSO exists for a request. If SSO authentiation is successful, the requests UserPrincipal and AuthUser fields are set. If available, the credential used to authenticate the user is returned. If recoverable credentials are not required then null may be return.

Parameters
request:Request

The request to SSO.

response:Response

The response to SSO.

Returns:Credential

A credential if available for SSO authenticated requests.

getSSORealmback to summary
public SSORealm getSSORealm()
Returns:SSORealm

The SSORealm to delegate single sign on requests to.

isUserInRoleback to summary
public synchronized boolean isUserInRole(Principal user, String roleName)

Implements org.mortbay.jetty.UserRealm.isUserInRole.

Check if a user is in a role.

Parameters
user:Principal

The user, which must be from this realm

Returns:boolean

True if the user can act in the role.

loadConfigback to summary
protected void loadConfig() throws IOException
logoutback to summary
public void logout(Principal user)

Implements org.mortbay.jetty.UserRealm.logout.

Doc from org.mortbay.jetty.UserRealm.logout.

logout a user Principal. Called by authentication mechanisms (eg FORM) that can detect logout.

Parameters
user:Principal

A Principal previously returned from this realm

popRoleback to summary
public Principal popRole(Principal user)

Implements org.mortbay.jetty.UserRealm.popRole.

Doc from org.mortbay.jetty.UserRealm.popRole.

Pop role from a Principal.

Parameters
user:Principal

A UserPrincipal previously returned from pushRole

Returns:Principal

The principal without the role. Most often this will be the original UserPrincipal passed.

pushRoleback to summary
public Principal pushRole(Principal user, String role)

Implements org.mortbay.jetty.UserRealm.pushRole.

Doc from org.mortbay.jetty.UserRealm.pushRole.

Push role onto a Principal. This method is used to add a role to an existing principal.

Parameters
user:Principal

An existing UserPrincipal or null for an anonymous user.

role:String

The role to add.

Returns:Principal

A new UserPrincipal object that wraps the passed user, but with the added role.

putback to summary
public synchronized Object put(Object name, Object credentials)

Put user into realm.

Parameters
name:Object

User name

credentials:Object

String password, Password or UserPrinciple instance.

Returns:Object

Old UserPrinciple value or null

reauthenticateback to summary
public boolean reauthenticate(Principal user)

Implements org.mortbay.jetty.UserRealm.reauthenticate.

Doc from org.mortbay.jetty.UserRealm.reauthenticate.

Re Authenticate a Principal. Authenicate a principal that has previously been return from the authenticate method. Implementations of this method may adorn the calling context to assoicate it with the authenticated principal (eg ThreadLocals). If such context associations are made, they should be considered valid until a UserRealm.deAuthenticate(UserPrincipal) call is made for this UserPrincipal.

Returns:boolean

True if this user is still authenticated.

setConfigback to summary
public void setConfig(String config) throws IOException

Load realm users from properties file. The property file maps usernames to password specs followed by an optional comma separated list of role names.

Parameters
config:String

Filename or url of user properties file.

setNameback to summary
public void setName(String name)
Parameters
name:String

The realm name

setRefreshIntervalback to summary
public void setRefreshInterval(int msec)
setSingleSignOnback to summary
public void setSingleSignOn(Request request, Response response, Principal principal, Credential credential)

Implements org.mortbay.jetty.security.SSORealm.setSingleSignOn.

Doc from org.mortbay.jetty.security.SSORealm.setSingleSignOn.

Set SSO principal and credential. This call is used by an authenticator to inform the SSO mechanism that a user has signed on. The SSO mechanism should record the principal and credential and update the response with any cookies etc. required.

Parameters
request:Request

The authenticated request.

response:Response

The authenticated response/

principal:Principal

The principal that has been authenticated.

credential:Credential

The credentials used to authenticate.

setSSORealmback to summary
public void setSSORealm(SSORealm ssoRealm)

Set the SSORealm. A SSORealm implementation may be set to enable support for SSO.

Parameters
ssoRealm:SSORealm

The SSORealm to delegate single sign on requests to.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object

org.mortbay.jetty.security back to summary

private Class HashUserRealm.KnownUser

extends User
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Credential
private String
Inherited from org.mortbay.jetty.security.HashUserRealm.User:
roles

Constructor Summary

AccessConstructor and Description
pack-priv
KnownUser(String name, Credential credential)

Method Summary

Modifier and TypeMethod and Description
pack-priv boolean
authenticate(Object credentials)

public String
getName()

Overrides org.mortbay.jetty.security.HashUserRealm.User.getName.

Implements java.security.Principal.getName.

Returns the name of this Principal.
public boolean
Inherited from org.mortbay.jetty.security.HashUserRealm.User:
toString

Field Detail

_credback to summary
private Credential _cred
_userNameback to summary
private String _userName

Constructor Detail

KnownUserback to summary
pack-priv KnownUser(String name, Credential credential)

Method Detail

authenticateback to summary
pack-priv boolean authenticate(Object credentials)
getNameback to summary
public String getName()

Overrides org.mortbay.jetty.security.HashUserRealm.User.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.

isAuthenticatedback to summary
public boolean isAuthenticated()

Overrides org.mortbay.jetty.security.HashUserRealm.User.isAuthenticated.

org.mortbay.jetty.security back to summary

private Class HashUserRealm.User

extends Object
implements Principal
Class Inheritance
All Implemented Interfaces
java.security.Principal
Known Direct Subclasses
org.mortbay.jetty.security.HashUserRealm.KnownUser, org.mortbay.jetty.security.HashUserRealm.WrappedUser

Field Summary

Modifier and TypeField and Description
pack-priv List<E>

Constructor Summary

AccessConstructor and Description
private
User()

Method Summary

Modifier and TypeMethod and Description
public String
getName()

Implements java.security.Principal.getName.

Returns the name of this Principal.
private UserRealm
public boolean
public String
toString()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Returns a string representation of this Principal.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

rolesback to summary
pack-priv List<E> roles

Constructor Detail

Userback to summary
private User()

Method Detail

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.

getUserRealmback to summary
private UserRealm getUserRealm()
isAuthenticatedback to summary
public boolean isAuthenticated()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.security.Principal.toString.

Doc from java.security.Principal.toString.

Returns a string representation of this Principal.

Returns:String

a string representation of this Principal.

org.mortbay.jetty.security back to summary

private Class HashUserRealm.WrappedUser

extends User
Class Inheritance

Field Summary

Modifier and TypeField and Description
private String
private Principal
Inherited from org.mortbay.jetty.security.HashUserRealm.User:
roles

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
getName()

Overrides org.mortbay.jetty.security.HashUserRealm.User.getName.

Implements java.security.Principal.getName.

Returns the name of this Principal.
pack-priv Principal
public boolean
public boolean
Inherited from org.mortbay.jetty.security.HashUserRealm.User:
toString

Field Detail

roleback to summary
private String role
userback to summary
private Principal user

Constructor Detail

WrappedUserback to summary
pack-priv WrappedUser(Principal user, String role)

Method Detail

getNameback to summary
public String getName()

Overrides org.mortbay.jetty.security.HashUserRealm.User.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.

getUserPrincipalback to summary
pack-priv Principal getUserPrincipal()
isAuthenticatedback to summary
public boolean isAuthenticated()

Overrides org.mortbay.jetty.security.HashUserRealm.User.isAuthenticated.

isUserInRoleback to summary
public boolean isUserInRole(String role)