org.mortbay.http

Class HashUserRealm

public class HashUserRealm extends HashMap implements UserRealm, SSORealm, Externalizable

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.

Version: $Id: HashUserRealm.java,v 1.29 2005/08/13 00:01:24 gregwilkins Exp $

Author: Greg Wilkins (gregw)

See Also: Password

Field Summary
protected HashMap_roles
static String__SSO
HttpContext Attribute to set to activate SSO.
Constructor Summary
HashUserRealm()
Constructor.
HashUserRealm(String name)
Constructor.
HashUserRealm(String name, String config)
Constructor.
Method Summary
voidaddUserToRole(String userName, String roleName)
Add a user to a role.
Principalauthenticate(String username, Object credentials, HttpRequest request)
voidclearSingleSignOn(String username)
voiddisassociate(Principal user)
voiddump(PrintStream out)
StringgetName()
PrincipalgetPrincipal(String username)
CredentialgetSingleSignOn(HttpRequest request, HttpResponse response)
SSORealmgetSSORealm()
booleanisUserInRole(Principal user, String roleName)
Check if a user is in a role.
voidload(String config)
Load realm users from properties file.
voidlogout(Principal user)
PrincipalpopRole(Principal user)
PrincipalpushRole(Principal user, String role)
Objectput(Object name, Object credentials)
Put user into realm.
voidreadExternal(ObjectInput in)
booleanreauthenticate(Principal user)
voidsetName(String name)
voidsetSingleSignOn(HttpRequest request, HttpResponse response, Principal principal, Credential credential)
voidsetSSORealm(SSORealm ssoRealm)
Set the SSORealm.
StringtoString()
voidwriteExternal(ObjectOutput out)

Field Detail

_roles

protected HashMap _roles

__SSO

public static final String __SSO
HttpContext Attribute to set to activate SSO.

Constructor Detail

HashUserRealm

public HashUserRealm()
Constructor.

HashUserRealm

public HashUserRealm(String name)
Constructor.

Parameters: name Realm Name

HashUserRealm

public HashUserRealm(String name, String config)
Constructor.

Parameters: name Realm name config Filename or url of user properties file.

Method Detail

addUserToRole

public void addUserToRole(String userName, String roleName)
Add a user to a role.

Parameters: userName roleName

authenticate

public Principal authenticate(String username, Object credentials, HttpRequest request)

clearSingleSignOn

public void clearSingleSignOn(String username)

disassociate

public void disassociate(Principal user)

dump

public void dump(PrintStream out)

getName

public String getName()

Returns: The realm name.

getPrincipal

public Principal getPrincipal(String username)

getSingleSignOn

public Credential getSingleSignOn(HttpRequest request, HttpResponse response)

getSSORealm

public SSORealm getSSORealm()

Returns: The SSORealm to delegate single sign on requests to.

isUserInRole

public boolean isUserInRole(Principal user, String roleName)
Check if a user is in a role.

Parameters: user The user, which must be from this realm roleName

Returns: True if the user can act in the role.

load

public void load(String config)
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 Filename or url of user properties file.

Throws: IOException

logout

public void logout(Principal user)

popRole

public Principal popRole(Principal user)

pushRole

public Principal pushRole(Principal user, String role)

put

public Object put(Object name, Object credentials)
Put user into realm.

Parameters: name User name credentials String password, Password or UserPrinciple instance.

Returns: Old UserPrinciple value or null

readExternal

public void readExternal(ObjectInput in)

reauthenticate

public boolean reauthenticate(Principal user)

setName

public void setName(String name)

Parameters: name The realm name

setSingleSignOn

public void setSingleSignOn(HttpRequest request, HttpResponse response, Principal principal, Credential credential)

setSSORealm

public void setSSORealm(SSORealm ssoRealm)
Set the SSORealm. A SSORealm implementation may be set to enable support for SSO.

Parameters: ssoRealm The SSORealm to delegate single sign on requests to.

toString

public String toString()

writeExternal

public void writeExternal(ObjectOutput out)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.