@Configuration @ConditionalOnClass(value={org.springframework.security.oauth2.common.OAuth2AccessToken.class,org.springframework.web.servlet.config.annotation.WebMvcConfigurer.class}) @ConditionalOnBean(value=AbstractSecurityConfig.class) @AutoConfigureBefore(value=org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.class) @EnableConfigurationProperties(value=Oauth2Properties.class) @Import(value=OAuth2RedisAutoConfiguration.class) @ConditionalOnProperty(prefix="yishuifengxiao.security", name="enable", havingValue="true", matchIfMissing=true) public class Oauth2ExtendAutoConfiguration extends Object
Constructor and Description |
---|
Oauth2ExtendAutoConfiguration() |
Modifier and Type | Method and Description |
---|---|
org.springframework.security.oauth2.provider.approval.ApprovalStore |
approvalStore(org.springframework.security.oauth2.provider.token.TokenStore tokenStore)
Interface for saving, retrieving and revoking user approvals (per client, per
scope).
|
org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator |
auth2ResponseExceptionTranslator()
自定义异常转换器
|
org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator<org.springframework.security.oauth2.common.exceptions.OAuth2Exception> |
authWebResponseExceptionTranslator()
Oauth2Server中用于异常转换
|
void |
checkConfig() |
org.springframework.security.oauth2.provider.ClientDetailsService |
customClientDetailsService(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder) |
org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler |
expressionHandler(org.springframework.context.ApplicationContext applicationContext)
必须加入,不然自定义权限表达式不生效
|
OAuth2TokenUtil |
oAuth2TokenUtil(org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService,
org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices authorizationServerTokenServices,
org.springframework.security.oauth2.provider.authentication.TokenExtractor tokenExtractor,
org.springframework.security.oauth2.provider.token.ConsumerTokenServices consumerTokenServices,
org.springframework.security.core.userdetails.UserDetailsService userDetailsService,
org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
token生成工具
|
javax.servlet.Filter |
tokenEndpointFilter(HandlerProcessor handlerProcessor,
PropertyResource propertyResource,
SecurityHelper securityHelper,
org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService,
org.springframework.security.crypto.password.PasswordEncoder passwordEncoder,
Oauth2Properties oauth2Properties)
配置一个过滤器,用于在oauth2中提前验证用户名和密码以及clientId
|
org.springframework.security.oauth2.provider.token.TokenEnhancer |
tokenEnhancer()
注入token加强工具
|
org.springframework.security.oauth2.provider.authentication.TokenExtractor |
tokenExtractor()
自定义token提取器
|
org.springframework.security.oauth2.provider.token.TokenStore |
tokenStore() |
TokenStrategy |
tokenStrategy(org.springframework.security.oauth2.provider.token.TokenStore tokenStore,
org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices authorizationServerTokenServices)
token自动续签策略工具
|
org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler |
userApprovalHandler(org.springframework.security.oauth2.provider.token.TokenStore tokenStore,
org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService)
Basic interface for determining whether a given client authentication request
has been approved by the current user.
|
@ConditionalOnMissingBean(value=org.springframework.security.oauth2.provider.token.TokenStore.class) @Bean public org.springframework.security.oauth2.provider.token.TokenStore tokenStore()
@Bean(value="customClientDetailsService") @ConditionalOnMissingBean(name="customClientDetailsService") public org.springframework.security.oauth2.provider.ClientDetailsService customClientDetailsService(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
@Bean public org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler expressionHandler(org.springframework.context.ApplicationContext applicationContext)
必须加入,不然自定义权限表达式不生效
在 Oauth2Resource 中被public void configure(ResourceServerSecurityConfigurer resources)收集并配置applicationContext
- spring上下文@Bean @ConditionalOnMissingBean(value=org.springframework.security.oauth2.provider.token.TokenEnhancer.class) public org.springframework.security.oauth2.provider.token.TokenEnhancer tokenEnhancer()
@Bean @ConditionalOnMissingBean(value=org.springframework.security.oauth2.provider.authentication.TokenExtractor.class) public org.springframework.security.oauth2.provider.authentication.TokenExtractor tokenExtractor()
@Bean @ConditionalOnMissingBean(value=TokenStrategy.class) public TokenStrategy tokenStrategy(org.springframework.security.oauth2.provider.token.TokenStore tokenStore, org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices authorizationServerTokenServices)
tokenStore
- token存取器authorizationServerTokenServices
- AuthorizationServerTokenServices实例@Bean @ConditionalOnMissingBean(value=OAuth2TokenUtil.class) public OAuth2TokenUtil oAuth2TokenUtil(@Qualifier(value="customClientDetailsService") org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService, org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices authorizationServerTokenServices, org.springframework.security.oauth2.provider.authentication.TokenExtractor tokenExtractor, org.springframework.security.oauth2.provider.token.ConsumerTokenServices consumerTokenServices, org.springframework.security.core.userdetails.UserDetailsService userDetailsService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
clientDetailsService
- ClientDetailsServiceauthorizationServerTokenServices
- AuthorizationServerTokenServicestokenExtractor
- token提取器consumerTokenServices
- ConsumerTokenServicesuserDetailsService
- UserDetailsServicepasswordEncoder
- 密码加密器@Bean(value="auth2ResponseExceptionTranslator") @ConditionalOnMissingBean(name="auth2ResponseExceptionTranslator") public org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator auth2ResponseExceptionTranslator()
@Bean public org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler userApprovalHandler(org.springframework.security.oauth2.provider.token.TokenStore tokenStore, @Qualifier(value="customClientDetailsService") org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService)
tokenStore
- token存取器clientDetailsService
- ClientDetailsService@Bean public org.springframework.security.oauth2.provider.approval.ApprovalStore approvalStore(org.springframework.security.oauth2.provider.token.TokenStore tokenStore)
tokenStore
- token存取器@Bean(value="authWebResponseExceptionTranslator") @ConditionalOnMissingBean(name="authWebResponseExceptionTranslator") public org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator<org.springframework.security.oauth2.common.exceptions.OAuth2Exception> authWebResponseExceptionTranslator()
@Bean(value="tokenEndpointFilter") @ConditionalOnMissingBean(name="tokenEndpointFilter") public javax.servlet.Filter tokenEndpointFilter(HandlerProcessor handlerProcessor, PropertyResource propertyResource, SecurityHelper securityHelper, @Qualifier(value="customClientDetailsService") org.springframework.security.oauth2.provider.ClientDetailsService clientDetailsService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, Oauth2Properties oauth2Properties)
handlerProcessor
- 协助处理器propertyResource
- 资源管理器securityHelper
- 安全信息处理器clientDetailsService
- ClientDetailsServicepasswordEncoder
- 加密器oauth2Properties
- oauth2扩展支持属性配置@PostConstruct public void checkConfig()
Copyright © 2021. All rights reserved.