|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.acegisecurity.ui.switchuser.SwitchUserProcessingFilter
public class SwitchUserProcessingFilter
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>
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 |
|---|
public static final String ACEGI_SECURITY_SWITCH_USERNAME_KEY
public static final String ROLE_PREVIOUS_ADMINISTRATOR
protected MessageSourceAccessor messages
| Constructor Detail |
|---|
public SwitchUserProcessingFilter()
| Method Detail |
|---|
public void afterPropertiesSet()
throws Exception
afterPropertiesSet in interface InitializingBeanException
protected Authentication attemptExitUser(javax.servlet.http.HttpServletRequest request)
throws AuthenticationCredentialsNotFoundException
request - The http servlet request
Authentication object or
null otherwise.
AuthenticationCredentialsNotFoundException - If no
Authentication associated with this request.
protected Authentication attemptSwitchUser(javax.servlet.http.HttpServletRequest request)
throws AuthenticationException
request - The http request
Authentication request if
successfully switched to another user,
null otherwise.
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.public void destroy()
destroy in interface javax.servlet.Filter
public void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.FilterIOException
javax.servlet.ServletExceptionFilter.doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse, javax.servlet.FilterChain)
public void init(javax.servlet.FilterConfig ignored)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionprotected boolean requiresExitUser(javax.servlet.http.HttpServletRequest request)
request - The http servlet request
true if the request
requires a exit user,
false otherwise.exitUserUrlprotected boolean requiresSwitchUser(javax.servlet.http.HttpServletRequest request)
request - The http servlet
request
true if the
request requires a switch,
false
otherwise.switchUserUrl
public void setApplicationEventPublisher(ApplicationEventPublisher eventPublisher)
throws BeansException
setApplicationEventPublisher in interface ApplicationEventPublisherAwareBeansExceptionpublic void setUserDetailsService(UserDetailsService authenticationDao)
authenticationDao - The
authentication daopublic void setExitUserUrl(String exitUserUrl)
exitUserUrl - The exit user
URL.public void setMessageSource(MessageSource messageSource)
setMessageSource in interface MessageSourceAwarepublic void setSwitchUserUrl(String switchUserUrl)
switchUserUrl - The switch
user URL.public void setTargetUrl(String targetUrl)
targetUrl - The target url.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||