我有一个使用 SwitchUserFilter 的应用程序。在正常情况下,切换和退出工作正常,但是如果我们在用户实际没有切换时给出退出URL,则用户退出(期望),但当他再次尝试登录时,应用程序尝试将他重定向到他试图访问的最后一页(即切换用户URL)..再次发现用户没有切换,因此抛出错误,用户已注销,因此循环继续。
以下是我的spring配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!-- - Sample namespace-based configuration - -->
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security pre-post-annotations="enabled">
<!-- AspectJ pointcut expression that locates our "post" method and applies
security that way <protect-pointcut expression="execution(* bigbank.*Service.post*(..))"
access="ROLE_TELLER"/> -->
</global-method-security>
<http use-expressions="true">
<intercept-url pattern="/**" access="isAuthenticated()" />
<custom-filter after="FILTER_SECURITY_INTERCEPTOR" ref="switchUserProcessingFilter" />
<form-login />
<logout invalidate-session="true" logout-url="/do/logout" />
</http>
<!-- Usernames/Passwords are rod/koala dianne/emu scott/wombat peter/opal -->
<authentication-manager>
<authentication-provider>
<user-service id="userService">
<user name="rod" password="koala" authorities="supervisor, teller, user" />
<user name="dianne" password="emu" authorities="teller, user" />
<user name="scott" password="wombat" authorities="user" />
<user name="peter" password="opal" authorities="user" />
</user-service>
</authentication-provider>
</authentication-manager>
<beans:bean id="switchUserProcessingFilter"
class="org.springframework.security.web.authentication.switchuser.SwitchUserFilter">
<beans:property name="userDetailsService" ref="userService">
</beans:property>
<beans:property name="switchUserUrl" value="/switchUser" />
<beans:property name="exitUserUrl" value="/exitUser" />
<beans:property name="targetUrl" value="/index.jsp" />
</beans:bean>
</beans:beans>
有关如何处理的任何建议?
实际情况可能是我切换用户,会话超时。不知道会话超时,用户尝试点击“退出用户”网址,然后将其重定向到登录页面,上述周期继续。
答案 0 :(得分:0)
正如this线程中所提到的,我实现了一个自定义登录成功处理程序,模仿SavedRequestAwareAuthenticationSuccessHandler
,这是默认的登录成功处理程序。它
检索我们尝试访问的URL,然后从请求缓存重定向到登录页面(ExceptionTranslationFilter
存储它的位置,看到我们未经过身份验证)并重定向到该URL。我只是将它配置为在遇到“ exitUser ”之类的内容时转到根网址