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.acegisecurity.ui.switchuser
Class SwitchUserProcessingFilter

    java.lang.Object
      org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter

All Implemented Interfaces:
  javax.servlet.Filter, InitializingBean, ApplicationEventPublisherAware, MessageSourceAware

    public class SwitchUserProcessingFilter

extends Object
implements javax.servlet.Filter, InitializingBean, ApplicationEventPublisherAware, MessageSourceAware

Switch User processing filter responsible for user context switching.

This filter is similar to Unix 'su' however for Acegi-managed web applications. A common use-case for this feature is the ability to allow higher-authority users (i.e. ROLE_ADMIN) to switch to a regular user (i.e. ROLE_USER).

This filter assumes that the user performing the switch will be required to be logged in as normal (i.e. ROLE_ADMIN user). The user will then access a page/controller that enables the administrator to specify who they wish to become (see `switchUserUrl`).
Note: This URL will be required to have to appropriate security contraints configured so that only users of that role can access (i.e. ROLE_ADMIN).

On successful switch, the user's `SecurityContextHolder` will be updated to reflect the specified user and will also contain an additinal `SwitchUserGrantedAuthority` which contains the original user.

To 'exit' from a user context, the user will then need to access a URL (see `exitUserUrl`) that will switch back to the original user as identified by the `SWITCH_USER_GRANTED_AUTHORITY`.

To configure the Switch User Processing Filter, create a bean definition for the Switch User processing filter and add to the filterChainProxy.
Example:

     <bean id="switchUserProcessingFilter" class="org.acegisecurity.ui.switchuser.SwitchUserProcessingFilter">
        <property name="authenticationDao" ref="jdbcDaoImpl" />
        <property name="switchUserUrl"><value>/j_acegi_switch_user</value></property>
        <property name="exitUserUrl"><value>/j_acegi_exit_user</value></property>
        <property name="targetUrl"><value>/index.jsp</value></property>
     </bean>

See Also:
  `SwitchUserGrantedAuthority`

Field Summary
`static String` | `ACEGI_SECURITY_SWITCH_USERNAME_KEY`
`protected MessageSourceAccessor` | `messages`
`static String` | `ROLE_PREVIOUS_ADMINISTRATOR`

Constructor Summary
`SwitchUserProcessingFilter()`

Method Summary
`void` | `afterPropertiesSet()`
`protected Authentication` | `attemptExitUser(javax.servlet.http.HttpServletRequest request)` Attempt to exit from an already switched user.
`protected Authentication` | `attemptSwitchUser(javax.servlet.http.HttpServletRequest request)` Attempt to switch to another user.
`void` | `destroy()`
`void` | `doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)`
`void` | `init(javax.servlet.FilterConfig ignored)`
`protected boolean` | `requiresExitUser(javax.servlet.http.HttpServletRequest request)` Checks the request URI for the presence of `exitUserUrl`.
`protected boolean` | `requiresSwitchUser(javax.servlet.http.HttpServletRequest request)` Checks the request URI for the presence of `switchUserUrl`.
`void` | `setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)`
`void` | `setExitUserUrl(String exitUserUrl)` Set the URL to respond to exit user processing.
`void` | `setMessageSource(MessageSource messageSource)`
`void` | `setSwitchUserUrl(String switchUserUrl)` Set the URL to respond to switch user processing.
`void` | `setTargetUrl(String targetUrl)` Sets the URL to go to after a successful switch / exit user request.
`void` | `setUserDetailsService(UserDetailsService authenticationDao)` Sets the authentication data access object.

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

Field Detail

### ACEGI_SECURITY_SWITCH_USERNAME_KEY

    public static final String ACEGI_SECURITY_SWITCH_USERNAME_KEY

See Also:
  Constant Field Values

### ROLE_PREVIOUS_ADMINISTRATOR

    public static final String ROLE_PREVIOUS_ADMINISTRATOR

See Also:
  Constant Field Values

### messages

    protected MessageSourceAccessor messages

Constructor Detail

### SwitchUserProcessingFilter

    public SwitchUserProcessingFilter()

Method Detail

### afterPropertiesSet

    public void afterPropertiesSet()
                            throws Exception

  Specified by:
    `afterPropertiesSet` in interface `InitializingBean`
  Throws:
    `Exception`

### attemptExitUser

    protected Authentication attemptExitUser(javax.servlet.http.HttpServletRequest request)
                                      throws AuthenticationCredentialsNotFoundException

  Attempt to exit from an already switched user.

  Parameters:
    `request` - The http servlet request
  Returns:
    The original `Authentication` object or `null` otherwise.
  Throws:
    `AuthenticationCredentialsNotFoundException` - If no `Authentication` associated with this request.

### attemptSwitchUser

    protected Authentication attemptSwitchUser(javax.servlet.http.HttpServletRequest request)
                                        throws AuthenticationException

  Attempt to switch to another user. If the user does not exist or is not active, return null.

  Parameters:
    `request` - The http request
  Returns:
    The new `Authentication` request if successfully switched to another user, `null` otherwise.
  Throws:
    `AuthenticationException`
    `UsernameNotFoundException` - If the target user is not found.
    `LockedException` - DOCUMENT ME!
    `DisabledException` - If the target user is disabled.
    `AccountExpiredException` - If the target user account is expired.
    `CredentialsExpiredException` - If the target user credentials are expired.

### destroy

    public void destroy()

  Specified by:
    `destroy` in interface `javax.servlet.Filter`

### doFilter

    public void doFilter(javax.servlet.ServletRequest request,
                         javax.servlet.ServletResponse response,
                         javax.servlet.FilterChain chain)
                  throws IOException,
                         javax.servlet.ServletException

  Specified by:
    `doFilter` in interface `javax.servlet.Filter`
  Throws:
    `IOException`
    `javax.servlet.ServletException`
  See Also:
    `Filter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)`

### init

    public void init(javax.servlet.FilterConfig ignored)
              throws javax.servlet.ServletException

  Specified by:
    `init` in interface `javax.servlet.Filter`
  Throws:
    `javax.servlet.ServletException`

### requiresExitUser

    protected boolean requiresExitUser(javax.servlet.http.HttpServletRequest request)

  Checks the request URI for the presence of `exitUserUrl`.

  Parameters:
    `request` - The http servlet request
  Returns:
    `true` if the request requires a exit user, `false` otherwise.
  See Also:
    `exitUserUrl`

### requiresSwitchUser

    protected boolean requiresSwitchUser(javax.servlet.http.HttpServletRequest request)

  Checks the request URI for the presence of `switchUserUrl`.

  Parameters:
    `request` - The http servlet request
  Returns:
    `true` if the request requires a switch, `false` otherwise.
  See Also:
    `switchUserUrl`

### setApplicationEventPublisher

    public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
                                      throws BeansException

  Specified by:
    `setApplicationEventPublisher` in interface `ApplicationEventPublisherAware`
  Throws:
    `BeansException`

### setUserDetailsService

    public void setUserDetailsService(UserDetailsService authenticationDao)

  Sets the authentication data access object.

  Parameters:
    `authenticationDao` - The authentication dao

### setExitUserUrl

    public void setExitUserUrl(String exitUserUrl)

  Set the URL to respond to exit user processing.

  Parameters:
    `exitUserUrl` - The exit user URL.

### setMessageSource

    public void setMessageSource(MessageSource messageSource)

  Specified by:
    `setMessageSource` in interface `MessageSourceAware`

### setSwitchUserUrl

    public void setSwitchUserUrl(String switchUserUrl)

  Set the URL to respond to switch user processing.

  Parameters:
    `switchUserUrl` - The switch user URL.

### setTargetUrl

    public void setTargetUrl(String targetUrl)

  Sets the URL to go to after a successful switch / exit user request.

  Parameters:
    `targetUrl` - The target url.

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 © 2004-2005 Acegi Technology Pty Limited. All Rights Reserved.