spring 的AbstractAuthenticationProcessingFilter提供了AuthenticationSuccessHandler,以便于登录成功之后的处理。
但是当项目的UI端和后台服务端是完全分离的情况下,Server端不应做任何URL的指定,只告诉UI登录成功与否即可。但是如果使用默认的AuthenticationSuccessHandler实现,登录成功后会自动跳转到 webapp 的根目录。
解决方案
实现AuthenticationSuccessHandler, 只设置status code,就不会用到父类中的redirect实现了。
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.setStatus(200); }
最后把自定义的success handler 注入到AbstractAuthenticationProcessingFilter的实现类即可