springsecurity 获取token流程分析

# 一、/oauth/token

password模式获取token源码主要操作

1、定义请求参数

springsecurity 获取token流程分析_第1张图片

增加请求头 Authorization 否则 在请求参数使用 client_id (注意! 此头为base64拼接格式为 client_id:client_secret)
在这里插入图片描述

2、下下为重点执行代码处

若定义Authorization头则进入

1、org.springframework.security.web.authentication.www.BasicAuthenticationFilter#doFilterInternal

springsecurity 获取token流程分析_第2张图片
使用client_id,client_secret 请求param 则进入
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter#doFilter
springsecurity 获取token流程分析_第3张图片

2、org.springframework.security.web.access.intercept.FilterSecurityInterceptor#invoke

springsecurity 获取token流程分析_第4张图片

3、org.springframework.web.method.support.InvocableHandlerMethod#invokeForRequest

springsecurity 获取token流程分析_第5张图片

4、org.springframework.security.oauth2.provider.endpoint.TokenEndpoint#postAccessToken

springsecurity 获取token流程分析_第6张图片

5、org.springframework.security.oauth2.provider.token.AbstractTokenGranter#getAccessToken

在这里插入图片描述

6、org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter#getOAuth2Authentication

springsecurity 获取token流程分析_第7张图片

org.springframework.security.authentication.ProviderManager#authenticate

springsecurity 获取token流程分析_第8张图片

此处选择 provider方式 根据 传入的Authentication而决定 可自定义 实现 AbstractAuthenticationToken(此抽象类实现Authentication copy password模式Ganter 切记自定义token构造器加上 super.setAuthenticated(true);)
springsecurity 获取token流程分析_第9张图片

7、org.springframework.security.oauth2.provider.token.DefaultTokenServices#createAccessToken(org.springframework.security.oauth2.provider.OAuth2Authentication, org.springframework.security.oauth2.common.OAuth2RefreshToken)

springsecurity 获取token流程分析_第10张图片

有增强 TokenEnhancer 就进入增强器咯

自此最后返回org.springframework.security.oauth2.provider.endpoint.TokenEndpoint#getResponse

.oauth2.provider.endpoint.TokenEndpoint#getResponse

springsecurity 获取token流程分析_第11张图片
最后补充AuthorizationServerTokenServices,SecurityConfigurerAdapter ,AuthenticationProvider,AbstractTokenGranter,AbstractAuthenticationProcessingFilter 还有好多就不一一列举了都可以自己扩展实现自己的逻辑加油!!!

你可能感兴趣的:(java,服务器)