1

如何获取用户名或UserDetail对象logout-success-url?下面是我的配置:

<form-login default-target-url="/security/loginSuccess.action" 
            always-use-default-target="false" 
            authentication-failure-url="/security/loginFailed.action"
            login-page="/security/restrictUser.action"/>    

<logout invalidate-session="true" logout-success-url="/security/logoutUser.action" />

<session-management 
  session-authentication-strategy-ref="customMsgAwareConcurrentSessionControlStartegy" 
  invalid-session-url="/security/logoutUser.action"/>

我想在其中获取请求注销的用户名logout-success-url(对我来说这是一个 Struts 2 操作方法)。我已经检查过了,但是当控件到达我的操作方法时SecurityContextHolder,它似乎被清除了。SecurityContextHolderlogout-success-url

4

1 回答 1

6

为此使用自定义LogoutSuccessHandler。在您的配置中定义 bean 并使用标签success-handler-ref的属性。<logout>

<logout success-handler-ref="customLogoutSuccessHandler" />
<beans:bean id="customLogoutSuccessHandler" class="..." />

里面CustomLogoutSuccessHandleronLogoutSuccess有参数的方法Authentication

public class CustomLogoutSuccessHandler extends
    AbstractAuthenticationTargetUrlRequestHandler implements
    LogoutSuccessHandler {

    public void onLogoutSuccess(HttpServletRequest request,
        HttpServletResponse response, Authentication authentication)
        throws IOException, ServletException {
         // use authentication to get user name
    }
}
于 2012-11-22T09:20:31.160 回答