## org.mortbay.jetty.plus.jaas
Class JAASUserRealm

    java.lang.Object
      org.mortbay.jetty.plus.jaas.JAASUserRealm

All Implemented Interfaces:
  UserRealm

    public class JAASUserRealm

extends Object
implements UserRealm

JAASUserRealm

#### Notes

#### Usage

Field Summary
`protected String` `callbackHandlerClass`
`static String` `DEFAULT_ROLE_CLASS_NAME`
`static String[]` `DEFAULT_ROLE_CLASS_NAMES`
`protected JAASUserPrincipal` `defaultUser`
`protected String` `loginModuleName`
`protected String` `realmName`
`protected RoleCheckPolicy` `roleCheckPolicy`
`protected String[]` `roleClassNames`

Constructor Summary
`JAASUserRealm()` Constructor.
`JAASUserRealm(String name)` Constructor.

Method Summary
`Principal` `authenticate(String username, Object credentials, Request request)` Authenticate a user.
`void` `disassociate(Principal user)` Removes any auth info associated with eg.
`String` `getName()` Get the name of the realm.
`Principal` `getPrincipal(String username)` Get the principal for a username.
`String[]` `getRoleClassNames()`
`Group` `getRoles(JAASUserPrincipal principal)`
`boolean` `isUserInRole(Principal user, String role)` Check if the user is in a role.
`void` `logout(Principal user)` Logout a previously logged in user.
`Principal` `popRole(Principal user)` Pop role from a Principal.
`Principal` `pushRole(Principal user, String role)` Temporarily adds a role to a user.
`boolean` `reauthenticate(Principal user)` Re Authenticate a Principal.
`void` `setCallbackHandlerClass(String classname)`
`void` `setLoginModuleName(String name)` Set the name to use to index into the config file of LoginModules.
`void` `setName(String name)` Set the name of the realm
`void` `setRoleCheckPolicy(RoleCheckPolicy policy)`
`void` `setRoleClassNames(String[] classnames)`

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

Field Detail

### DEFAULT_ROLE_CLASS_NAME

    public static String DEFAULT_ROLE_CLASS_NAME

### DEFAULT_ROLE_CLASS_NAMES

    public static String[] DEFAULT_ROLE_CLASS_NAMES

### roleClassNames

    protected String[] roleClassNames

### callbackHandlerClass

    protected String callbackHandlerClass

### realmName

    protected String realmName

### loginModuleName

    protected String loginModuleName

### roleCheckPolicy

    protected RoleCheckPolicy roleCheckPolicy

### defaultUser

    protected JAASUserPrincipal defaultUser

Constructor Detail

### JAASUserRealm

    public JAASUserRealm()

  Constructor.

### JAASUserRealm

    public JAASUserRealm(String name)

  Constructor.

  Parameters:
    `name` - the name of the realm

Method Detail

### getName

    public String getName()

  Get the name of the realm.

  Specified by:
    `getName` in interface `UserRealm`
  Returns:
    name or null if not set.

### setName

    public void setName(String name)

  Set the name of the realm

  Parameters:
    `name` - a `String` value

### setLoginModuleName

    public void setLoginModuleName(String name)

  Set the name to use to index into the config file of LoginModules.

  Parameters:
    `name` - a `String` value

### setCallbackHandlerClass

    public void setCallbackHandlerClass(String classname)

### setRoleClassNames

    public void setRoleClassNames(String[] classnames)

### getRoleClassNames

    public String[] getRoleClassNames()

### setRoleCheckPolicy

    public void setRoleCheckPolicy(RoleCheckPolicy policy)

### getPrincipal

    public Principal getPrincipal(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`

### isUserInRole

    public boolean isUserInRole(Principal user,
                                String role)

  Description copied from interface: `UserRealm`
  Check if the user is in a role.

  Specified by:
    `isUserInRole` in interface `UserRealm`
    `role` - A role name.
  Returns:
    True if the user can act in that role.

### reauthenticate

    public boolean reauthenticate(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.

### authenticate

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

  Authenticate a user.

  Specified by:
    `authenticate` in interface `UserRealm`
  Parameters:
    `username` - provided by the user at login
    `credentials` - provided by the user at login
    `request` - a `Request` value
  Returns:
    authenticated JAASUserPrincipal or null if authenticated failed

### disassociate

    public void disassociate(Principal user)

  Removes any auth info associated with eg. the thread.

  Specified by:
    `disassociate` in interface `UserRealm`
  Parameters:
    `user` - a UserPrincipal to disassociate

### pushRole

    public Principal pushRole(Principal user,
                              String role)

  Temporarily adds a role to a user. Temporarily granting a role pushes the role onto a stack of temporary roles. Temporary roles must therefore be removed in order.

  Specified by:
    `pushRole` in interface `UserRealm`
  Parameters:
    `user` - the Principal to which to add the role
    `role` - the role name
  Returns:
    the Principal with the role added

### popRole

    public Principal popRole(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.

### getRoles

    public Group getRoles(JAASUserPrincipal principal)

### logout

    public void logout(Principal user)

  Logout a previously logged in user. This can only work for FORM authentication as BasicAuthentication is stateless. The user's LoginContext logout() method is called.

  Specified by:
    `logout` in interface `UserRealm`
  Parameters:
    `user` - an `Principal` value

Copyright © 2007 Mort Bay Consulting. All Rights Reserved.