spring security oauth2.0授权服务器和资源服务器

使用@EnableAuthorizationServer并且继承AuthorizationServerConfigurerAdapter开启授权服务器

AuthorizationServerSecurityConfigurer :用于配置授权服务的安全策略

AuthenticationEntryPoint:这个用于ExceptionTranslationFilter
AccessDeniedHandler:拒绝访问的处理
tokenEndpointAuthenticationFilters:这里的过滤在BasicAuthenticationFilter前进行过滤
tokenKeyAccess:一般设置为permitAll()
checkTokenAccess:配置为isAuthenticated()   用于token获取和验证时的策略

----------------------------------------
ClientDetailsServiceConfigurer:客户端服务的配置

主要有JDBC和inMemory模式

inMemory:保存到内存中

JDBC:保存到数据库中,正式环境使用,需要注入一个DataSource对象

JdbcClientDetailsService:需要提供oauth_client_details表:

CREATE TABLE `oauth_client_details` (
  `client_id` varchar(256) NOT NULL,
  `resource_ids` varchar(256) DEFAULT NULL,
  `client_secret` varchar(256) DEFAULT NULL,
  `scope` varchar(256) DEFAULT NULL,
  `authorized_grant_types` varchar(256) DEFAULT NULL,
  `web_server_redirect_uri` varchar(256) DEFAULT NULL,
  `authorities` varchar(256) DEFAULT NULL,
  `access_token_validity` int(11) DEFAULT NULL,
  `refresh_token_validity` int(11) DEFAULT NULL,
  `additional_information` varchar(4096) DEFAULT NULL,
  `autoapprove` varchar(256) DEFAULT NULL,
  PRIMARY KEY (`client_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--------------------------------

AuthorizationServerEndpointsConfigurer:认证端点的配置

AuthorizationServerTokenServices:认证token的默认服务,提供创建token,刷新token,获取token
ConsumerTokenServices:消费token的服务,消费移除token
AuthorizationCodeServices:认证code默认服务,用于创建,消费code
ResourceServerTokenServices:资源服务的token服务,提供加载验证token,从tokenStore中获取token的信息
TokenStore:token储存器(INMEMORY,JDBC,JWT,REDIS),储存和获取token的直接操作方法
TokenEnhancer:token增强器,可在AuthorizationServerTokenServices前对token进行操作
AccessTokenConverter:token转换器
ApprovalStore:用于保存,移除,获取用户同意的接口
TokenGranter:token颁发者,authorization_code,client_credentials,implicit,refresh_token,password等默认模式
OAuth2RequestValidator:用于判断scope是否合法
UserApprovalHandler:用于判断用户是否批准请求的处理器
AuthenticationManager:认证管理器,认证的主逻辑实现

---------------------------------

@EnableResourceServer,继承ResourceServerConfigurerAdapter开启资源服务器
HttpSecurity:配置请求策略
ResourceServerSecurityConfigurer:
AuthenticationEntryPoint:认证异常处理
AccessDeniedHandler:访问拒绝处理
OAuth2AuthenticationProcessingFilter:认证请求过滤器
AuthenticationManager:认证管理,认证主逻辑
AuthenticationEventPublisher:处理认证成功和失败的事件
ResourceServerTokenServices:加载校验token
TokenStore:token储存,这里默认内存
SecurityExpressionHandler:安全表达式处理器
发布了85 篇原创文章 · 获赞 6 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/New_CJ/article/details/95764679