一、原理分析
spring security提供了一个接口 AuthenticationSuccessHandler,该接口中只有一个方法,用来进行登录成功后的操作
public interface AuthenticationSuccessHandler {
/**
* Called when a user has been successfully authenticated.
*
* @param request the request which caused the successful authentication
* @param response the response
* @param authentication the Authentication object which was created during
* the authentication process.
*/
void onAuthenticationSuccess(HttpServletRequest request,
HttpServletResponse response, Authentication authentication)
throws IOException, ServletException;
}
我们可以通过实现该接口来自定义登录成功后的操作,但spring security提供了一个SavedRequestAwareAuthenticationSuccessHandler实现类,这个实现类可以记住用户未登录前要访问的地址,这样登录成功后就可以把用户再跳转到他想去的页面。所以我们一般使用继承这个类的方式来实现自定义登录后续操作的功能。
二、实现方式
2.1 自定义Auth