重定向拦截器在 spring MVC 中获取错误的 RequestURI

问题描述 投票:0回答:0

更新 spring 3 到 4 HandlerInterceptorAdapter preHandle 方法后,将 HttpServletRequest RequestURI 获取为 /login 但用户已成功通过身份验证并重定向到 /dashboard API

在 prehandle 方法中它总是返回登录并返回 true

onAuthenticationSuccess 方法

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
              Authentication authentication) throws IOException, ServletException {
    ....
    ....
    sendRedirect(request, response, "/" + Path.ADMIN_DASHBOARD);
    ....
    ....
}

HandlerInterceptorAdapter代码

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
  
    String reqMapParam = request.getServletPath();
    String uri = request.getRequestURI();

......
if (uri.endsWith("login")) {
   request.getSession().invalidate();
   return true;
   }
        
  response.sendRedirect(request.getContextPath() + "/dashboard");
  return false;

}

我正在使用的版本 春天 - 4.3.0.RELEASE Spring Security - 4.2.3.RELEASE

所以非常感谢任何帮助。谢谢

spring spring-4 handlerinterceptor spring-security4
© www.soinside.com 2019 - 2024. All rights reserved.