SpringSecurity Oauth2
-
ClientCredentialsTokenEndpointFilter.attemptAuthentication(...)
:把请求传过来客户端账号和密码封装成UsernamePasswordAuthenticationToken对象
-
DaoAuthenticationProvider.retrieveUser(...)
:返回客户端信息
-
-
TokenEndpoint.getAccessToken(...)
:请求token -
TokenGranter.grant(...)
:调用认证获取token-
AbstractTokenGranter.getOAuth2Authentication(...)
-
authenticationManager.authenticate(userAuth)
:authenticationManager的默认实现类ProviderManager,也就是相当于调用ProviderManager.authenticate(...)
方法 -
通过调用
provider的supports
方法,选出具体的provide
,再调用authenticate(...)
方法for (AuthenticationProvider provider : getProviders()) {
if (!provider.supports(toTest)) {
continue;
}
...
result = provider.authenticate(authentication);
}
-
2.AuthorizationServerConfigurerAdapter 关键配置类
/**
* 认证服务配置
*
* @author Mr.zhou 2022/3/15
**/
@Configuration
@EnableAuthorizationServer
public class AuthServerConfig extends AuthorizationServerConfigurerAdapter {
@Override
public void configure(AuthorizationServerSecurityConfigurer security) {
security
.tokenKeyAccess("permitAll()")
.checkTokenAccess("isAuthenticated()")
.allowFormAuthenticationForClients();
}
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
}
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
}
}
-
配置AuthorizationServer安全认证的相关信息,创建ClientCredentialsTokenEndpointFilter核心过滤器
-
配置OAuth2的客户端相关信息
-
配置AuthorizationServerEndpointsConfigurer众多相关类,包括配置身份认证器,配置认证方式,TokenStore,TokenGranter,OAuth2RequestFactory
3.顶级身份管理者AuthenticationManager(掌握)