使用Conditional控制,便于自定义token增强处理 和 tokenStore

This commit is contained in:
b2baccline
2020-10-30 00:41:48 +08:00
parent 1f3b3d2e3e
commit 9a57281e2c

View File

@@ -7,6 +7,7 @@ import com.hccake.ballcat.admin.oauth.exception.CustomWebResponseExceptionTransl
import com.hccake.ballcat.admin.oauth.mobile.MobileTokenGranter; import com.hccake.ballcat.admin.oauth.mobile.MobileTokenGranter;
import com.hccake.ballcat.common.redis.config.CachePropertiesHolder; import com.hccake.ballcat.common.redis.config.CachePropertiesHolder;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn; import org.springframework.context.annotation.DependsOn;
@@ -104,6 +105,7 @@ public class CustomAuthorizationServerConfigurer implements AuthorizationServerC
*/ */
@Bean @Bean
@DependsOn("cachePropertiesHolder") @DependsOn("cachePropertiesHolder")
@ConditionalOnMissingBean
public TokenStore tokenStore() { public TokenStore tokenStore() {
RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory); RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);
tokenStore.setPrefix(CachePropertiesHolder.keyPrefix() + SecurityConst.OAUTH_PREFIX); tokenStore.setPrefix(CachePropertiesHolder.keyPrefix() + SecurityConst.OAUTH_PREFIX);
@@ -115,6 +117,7 @@ public class CustomAuthorizationServerConfigurer implements AuthorizationServerC
* @return TokenEnhancer Token增强处理器 * @return TokenEnhancer Token增强处理器
*/ */
@Bean @Bean
@ConditionalOnMissingBean
public TokenEnhancer tokenEnhancer() { public TokenEnhancer tokenEnhancer() {
return new CustomTokenEnhancer(); return new CustomTokenEnhancer();
} }