|
||||||||||
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 ROLE_PREVIOUS_ADMINISTRATOR
.
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 org.springframework.context.support.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(org.springframework.context.ApplicationEventPublisher eventPublisher)
|
void |
setAuthenticationDetailsSource(AuthenticationDetailsSource authenticationDetailsSource)
|
void |
setExitUserUrl(String exitUserUrl)
Set the URL to respond to exit user processing. |
void |
setMessageSource(org.springframework.context.MessageSource messageSource)
|
void |
setSwitchUserAuthorityChanger(SwitchUserAuthorityChanger switchUserAuthorityChanger)
|
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 userDetailsService)
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 org.springframework.context.support.MessageSourceAccessor messages
Constructor Detail |
---|
public SwitchUserProcessingFilter()
Method Detail |
---|
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
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.Filter
IOException
javax.servlet.ServletException
Filter.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.Filter
javax.servlet.ServletException
protected boolean requiresExitUser(javax.servlet.http.HttpServletRequest request)
request
- The http servlet request
true
if the request requires a exit user, false
otherwise.exitUserUrl
protected 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(org.springframework.context.ApplicationEventPublisher eventPublisher) throws org.springframework.beans.BeansException
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
org.springframework.beans.BeansException
public void setAuthenticationDetailsSource(AuthenticationDetailsSource authenticationDetailsSource)
public void setExitUserUrl(String exitUserUrl)
exitUserUrl
- The exit user URL.public void setMessageSource(org.springframework.context.MessageSource messageSource)
setMessageSource
in interface org.springframework.context.MessageSourceAware
public void setSwitchUserUrl(String switchUserUrl)
switchUserUrl
- The switch user URL.public void setTargetUrl(String targetUrl)
targetUrl
- The target url.public void setUserDetailsService(UserDetailsService userDetailsService)
userDetailsService
- The UserDetailsService to usepublic void setSwitchUserAuthorityChanger(SwitchUserAuthorityChanger switchUserAuthorityChanger)
switchUserAuthorityChanger
- to use to fine-tune the authorities granted to subclasses (may be null if
SwitchUserProcessingFilter shoudl not fine-tune the authorities)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |