簡體   English   中英

使用Spring Security登錄后無法重定向到其他頁面

[英]Cannot redirect to different pages after Login with Spring Security

我正在使用Spring Security登錄到我的應用程序,並且嘗試登錄后重定向到某些頁面,但是我無法連接,我認為這是spring-security.xml的問題,這是我的代碼:

MyAuthenticationSuccessHandler

public class MyAuthenticationSuccessHandler implements AuthenticationSuccessHandler {
  ...
  @Override
  public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
    ...
    // check if user is active after successfully logging in
    if (!isActiveStatus(authentication)) {
      logger.info("User [" + username + "] is not longer active.");
      authentication.setAuthenticated(false);
      response.sendRedirect(request.getContextPath() + "/home/welcome?notactive");
      return;
    }
    ...
  }
  ...
}

spring-security.xml

....
<security:intercept-url pattern="/home/**" access="permitAll" />
<security:intercept-url pattern="/" access="permitAll" />
<security:intercept-url pattern="/**" access="isAuthenticated()" />
<security:form-login login-page="/home/welcome?login"
  default-target-url="/home/welcome"
  authentication-success-handler-ref="MyAuthenticationSuccessHandler"
  authentication-failure-handler-ref="MyAuthenticationFailureHandler" />
....

使用此代碼,應用程序將始終重定向到/home/welcome?login而永遠不會重定向到/home/welcome?notactive 任何想法?

提前致謝。

您似乎正在嘗試手動發送重定向,SuccessHandler具有它自己的機制:

        getRedirectStrategy().sendRedirect(request, response, "/home/welcome?notactive");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM