当认证成功后(获取用户信息),会进行认证成功回调。我们可以配置自定义的Handler来处理认证成功后业务代码。
初始化AuthenticationSuccessHandler
在 ServerHttpSecurity 类的内部类 OAuth2LoginSpec 的 configure() 方法内,OAuth2LoginAuthenticationWebFilter 初始化了 AuthenticationSuccessHandler。如果我们没有指定 AuthenticationSuccessHandler,就创建默认的;否则使用指定的。大概创建流程如下源码所示。
private ServerAuthenticationSuccessHandler getAuthenticationSuccessHandler(ServerHttpSecurity http) {
if (this.authenticationSuccessHandler == null) {
RedirectServerAuthenticationSuccessHandler handler = new RedirectServerAuthenticationSuccessHandler();
handler.setRequestCache(http.requestCache.requestCache);
this.authenticationSuccessHandler = handler;
}
return