Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mortbay.jetty.security
Class HashUserRealm

    java.lang.Object
      org.mortbay.component.AbstractLifeCycle
          org.mortbay.jetty.security.HashUserRealm

All Implemented Interfaces:
  LifeCycle, SSORealm, UserRealm

Direct Known Subclasses:
  JDBCUserRealm

    public class HashUserRealm

extends AbstractLifeCycle
implements UserRealm, SSORealm

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 Class Summary

Nested classes/interfaces inherited from interface org.mortbay.component.LifeCycle
`LifeCycle.Listener`

Field Summary
`static java.lang.String` | `__SSO` HttpContext Attribute to set to activate SSO.
`protected java.util.HashMap` | `_roles`
`protected java.util.HashMap` | `_users`

Fields inherited from class org.mortbay.component.AbstractLifeCycle
`_listeners`

Constructor Summary
`HashUserRealm()` Constructor.
`HashUserRealm(java.lang.String name)` Constructor.
`HashUserRealm(java.lang.String name, java.lang.String config)` Constructor.

Method Summary
`void` | `addUserToRole(java.lang.String userName, java.lang.String roleName)` Add a user to a role.
`java.security.Principal` | `authenticate(java.lang.String username, java.lang.Object credentials, Request request)` Authenticate a users credentials.
`void` | `clearSingleSignOn(java.lang.String username)` Clear SSO for user.
`void` | `disassociate(java.security.Principal user)` Dissassociate the calling context with a Principal.
`protected void` | `doStart()`
`protected void` | `doStop()`
`void` | `dump(java.io.PrintStream out)`
`java.lang.String` | `getConfig()`
`Resource` | `getConfigResource()`
`java.lang.String` | `getName()`
`java.security.Principal` | `getPrincipal(java.lang.String username)` Get the principal for a username.
`int` | `getRefreshInterval()`
`Credential` | `getSingleSignOn(Request request, Response response)` Get SSO credentials.
`SSORealm` | `getSSORealm()`
`boolean` | `isUserInRole(java.security.Principal user, java.lang.String roleName)` Check if a user is in a role.
`protected void` | `loadConfig()`
`void` | `logout(java.security.Principal user)` logout a user Principal.
`java.security.Principal` | `popRole(java.security.Principal user)` Pop role from a Principal.
`java.security.Principal` | `pushRole(java.security.Principal user, java.lang.String role)` Push role onto a Principal.
`java.lang.Object` | `put(java.lang.Object name, java.lang.Object credentials)` Put user into realm.
`boolean` | `reauthenticate(java.security.Principal user)` Re Authenticate a Principal.
`void` | `setConfig(java.lang.String config)` Load realm users from properties file.
`void` | `setName(java.lang.String name)`
`void` | `setRefreshInterval(int msec)`
`void` | `setSingleSignOn(Request request, Response response, java.security.Principal principal, Credential credential)` Set SSO principal and credential.
`void` | `setSSORealm(SSORealm ssoRealm)` Set the SSORealm.
`java.lang.String` | `toString()`

Methods inherited from class org.mortbay.component.AbstractLifeCycle
`addLifeCycleListener, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Field Detail

### __SSO

    public static final java.lang.String __SSO

  HttpContext Attribute to set to activate SSO.

  See Also:
    Constant Field Values

### _users

    protected java.util.HashMap _users

### _roles

    protected java.util.HashMap _roles

Constructor Detail

### HashUserRealm

    public HashUserRealm()

  Constructor.

### HashUserRealm

    public HashUserRealm(java.lang.String name)

  Constructor.

  Parameters:
    `name` - Realm Name

### HashUserRealm

    public HashUserRealm(java.lang.String name,
                         java.lang.String config)
                  throws java.io.IOException

  Constructor.

  Parameters:
    `name` - Realm name
    `config` - Filename or url of user properties file.
  Throws:
    `java.io.IOException`

Method Detail

### getConfig

    public java.lang.String getConfig()

### getConfigResource

    public Resource getConfigResource()

### setConfig

    public void setConfig(java.lang.String config)
                   throws java.io.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` - Filename or url of user properties file.
  Throws:
    `java.io.IOException`

### setRefreshInterval

    public void setRefreshInterval(int msec)

### getRefreshInterval

    public int getRefreshInterval()

### loadConfig

    protected void loadConfig()
                       throws java.io.IOException

  Throws:
    `java.io.IOException`

### setName

    public void setName(java.lang.String name)

  Parameters:
    `name` - The realm name

### getName

    public java.lang.String getName()

  Specified by:
    `getName` in interface `UserRealm`
  Returns:
    The realm name.

### getPrincipal

    public java.security.Principal getPrincipal(java.lang.String username)

  Description copied from interface: `UserRealm`
  Get the principal for a username. This method is not guaranteed to return a Principal for non-authenticated users.

  Specified by:
    `getPrincipal` in interface `UserRealm`

### authenticate

    public java.security.Principal authenticate(java.lang.String username,
                                                java.lang.Object credentials,
                                                Request request)

  Description copied from interface: `UserRealm`
  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.

  Specified by:
    `authenticate` in interface `UserRealm`
  Parameters:
    `username` - The username.
    `credentials` - The user credentials, normally a String password.
    `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:
    The authenticated UserPrincipal.

### disassociate

    public void disassociate(java.security.Principal user)

  Description copied from interface: `UserRealm`
  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.

  Specified by:
    `disassociate` in interface `UserRealm`
  Parameters:
    `user` - A UserPrincipal allocated from this realm.

### pushRole

    public java.security.Principal pushRole(java.security.Principal user,
                                            java.lang.String role)

  Description copied from interface: `UserRealm`
  Push role onto a Principal. This method is used to add a role to an existing principal.

  Specified by:
    `pushRole` in interface `UserRealm`
  Parameters:
    `user` - An existing UserPrincipal or null for an anonymous user.
    `role` - The role to add.
  Returns:
    A new UserPrincipal object that wraps the passed user, but with the added role.

### popRole

    public java.security.Principal popRole(java.security.Principal user)

  Description copied from interface: `UserRealm`
  Pop role from a Principal.

  Specified by:
    `popRole` in interface `UserRealm`
  Parameters:
    `user` - A UserPrincipal previously returned from pushRole
  Returns:
    The principal without the role. Most often this will be the original UserPrincipal passed.

### put

    public java.lang.Object put(java.lang.Object name,
                                java.lang.Object credentials)

  Put user into realm.

  Parameters:
    `name` - User name
    `credentials` - String password, Password or UserPrinciple instance.
  Returns:
    Old UserPrinciple value or null

### addUserToRole

    public void addUserToRole(java.lang.String userName,
                              java.lang.String roleName)

  Add a user to a role.

  Parameters:
    `userName` -
    `roleName` -

### reauthenticate

    public boolean reauthenticate(java.security.Principal user)

  Description copied from interface: `UserRealm`
  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.

  Specified by:
    `reauthenticate` in interface `UserRealm`
  Returns:
    True if this user is still authenticated.

### isUserInRole

    public boolean isUserInRole(java.security.Principal user,
                                java.lang.String roleName)

  Check if a user is in a role.

  Specified by:
    `isUserInRole` in interface `UserRealm`
  Parameters:
    `user` - The user, which must be from this realm
    `roleName` -
  Returns:
    True if the user can act in the role.

### logout

    public void logout(java.security.Principal user)

  Description copied from interface: `UserRealm`
  logout a user Principal. Called by authentication mechanisms (eg FORM) that can detect logout.

  Specified by:
    `logout` in interface `UserRealm`
  Parameters:
    `user` - A Principal previously returned from this realm

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### dump

    public void dump(java.io.PrintStream out)

### getSSORealm

    public SSORealm getSSORealm()

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

### 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.

### getSingleSignOn

    public Credential getSingleSignOn(Request request,
                                      Response response)

  Description copied from interface: `SSORealm`
  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.

  Specified by:
    `getSingleSignOn` in interface `SSORealm`
  Parameters:
    `request` - The request to SSO.
    `response` - The response to SSO.
  Returns:
    A credential if available for SSO authenticated requests.

### setSingleSignOn

    public void setSingleSignOn(Request request,
                                Response response,
                                java.security.Principal principal,
                                Credential credential)

  Description copied from interface: `SSORealm`
  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.

  Specified by:
    `setSingleSignOn` in interface `SSORealm`
  Parameters:
    `request` - The authenticated request.
    `response` - The authenticated response/
    `principal` - The principal that has been authenticated.
    `credential` - The credentials used to authenticate.

### clearSingleSignOn

    public void clearSingleSignOn(java.lang.String username)

  Description copied from interface: `SSORealm`
  Clear SSO for user.

  Specified by:
    `clearSingleSignOn` in interface `SSORealm`
  Parameters:
    `username` - The user to clear.

### doStart

    protected void doStart()
                    throws java.lang.Exception

  Overrides:
    `doStart` in class `AbstractLifeCycle`
  Throws:
    `java.lang.Exception`
  See Also:
    `AbstractLifeCycle.doStart()`

### doStop

    protected void doStop()
                   throws java.lang.Exception

  Overrides:
    `doStop` in class `AbstractLifeCycle`
  Throws:
    `java.lang.Exception`
  See Also:
    `AbstractLifeCycle.doStop()`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.