diff --git a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
index 9b99fb79c800782f811c749b25b9e8da55349c0a..3b3ce1b141ed017c81b3fe7e9a64a3527d263849 100644
--- a/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
+++ b/zlt-commons/zlt-auth-client-spring-boot-starter/src/main/java/com/central/oauth2/common/store/AuthJwtTokenStore.java
@@ -5,6 +5,7 @@ import com.central.oauth2.common.converter.CustomUserAuthenticationConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.bootstrap.encrypt.KeyProperties;
import org.springframework.context.annotation.Bean;
+import org.springframework.core.annotation.Order;
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
@@ -23,6 +24,9 @@ import java.util.Map;
*
* @author zlt
* @date 2018/7/24 16:21
+ *
+ * Blog: https://zlt2000.gitee.io
+ * Github: https://github.com/zlt2000
*/
@ConditionalOnProperty(prefix = "zlt.oauth2.token.store", name = "type", havingValue = "authJwt")
public class AuthJwtTokenStore {
@@ -41,6 +45,7 @@ public class AuthJwtTokenStore {
}
@Bean
+ @Order(2)
public JwtAccessTokenConverter jwtAccessTokenConverter() {
final JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
KeyPair keyPair = new KeyStoreKeyFactory
@@ -59,6 +64,7 @@ public class AuthJwtTokenStore {
* @return TokenEnhancer
*/
@Bean
+ @Order(1)
public TokenEnhancer tokenEnhancer() {
return (accessToken, authentication) -> {
final Map additionalInfo = new HashMap<>(1);
diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java
index 240f1e057d46bc846d5f419dcd3111f3851d7779..a32c0af43dc39e9fe89760ed0fa13ce74571af25 100644
--- a/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java
+++ b/zlt-uaa/src/main/java/com/central/oauth/config/AuthorizationServerConfig.java
@@ -14,13 +14,9 @@ import org.springframework.security.oauth2.config.annotation.web.configurers.Aut
import org.springframework.security.oauth2.provider.TokenGranter;
import org.springframework.security.oauth2.provider.code.RandomValueAuthorizationCodeServices;
import org.springframework.security.oauth2.provider.error.WebResponseExceptionTranslator;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.security.oauth2.provider.token.TokenEnhancerChain;
import org.springframework.security.oauth2.provider.token.TokenStore;
-import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import javax.annotation.Resource;
-import java.util.Arrays;
/**
* OAuth2 授权服务器配置
@@ -47,12 +43,6 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
@Autowired
private TokenStore tokenStore;
- @Autowired(required = false)
- private JwtAccessTokenConverter jwtAccessTokenConverter;
-
- @Autowired(required = false)
- private TokenEnhancer tokenEnhancer;
-
@Autowired
private WebResponseExceptionTranslator webResponseExceptionTranslator;
@@ -71,16 +61,6 @@ public class AuthorizationServerConfig extends AuthorizationServerConfigurerAdap
*/
@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) {
- if (jwtAccessTokenConverter != null) {
- if (tokenEnhancer != null) {
- TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
- tokenEnhancerChain.setTokenEnhancers(
- Arrays.asList(tokenEnhancer, jwtAccessTokenConverter));
- endpoints.tokenEnhancer(tokenEnhancerChain);
- } else {
- endpoints.accessTokenConverter(jwtAccessTokenConverter);
- }
- }
endpoints.tokenStore(tokenStore)
.authenticationManager(authenticationManager)
.userDetailsService(userDetailsService)
diff --git a/zlt-uaa/src/main/java/com/central/oauth/config/TokenGranterConfig.java b/zlt-uaa/src/main/java/com/central/oauth/config/TokenGranterConfig.java
index 41f054194f5d4cd4f38dbbcec138de7bb1ed1f3a..e020224a36636f1fbd241b04bfa2daf0af66f3cd 100644
--- a/zlt-uaa/src/main/java/com/central/oauth/config/TokenGranterConfig.java
+++ b/zlt-uaa/src/main/java/com/central/oauth/config/TokenGranterConfig.java
@@ -22,10 +22,7 @@ import org.springframework.security.oauth2.provider.implicit.ImplicitTokenGrante
import org.springframework.security.oauth2.provider.password.ResourceOwnerPasswordTokenGranter;
import org.springframework.security.oauth2.provider.refresh.RefreshTokenGranter;
import org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory;
-import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;
-import org.springframework.security.oauth2.provider.token.DefaultTokenServices;
-import org.springframework.security.oauth2.provider.token.TokenEnhancer;
-import org.springframework.security.oauth2.provider.token.TokenStore;
+import org.springframework.security.oauth2.provider.token.*;
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider;
import java.util.ArrayList;
@@ -56,7 +53,7 @@ public class TokenGranterConfig {
private TokenStore tokenStore;
@Autowired(required = false)
- private TokenEnhancer tokenEnhancer;
+ private List tokenEnhancer;
@Autowired
private IValidateCodeService validateCodeService;
@@ -157,11 +154,20 @@ public class TokenGranterConfig {
tokenServices.setSupportRefreshToken(true);
tokenServices.setReuseRefreshToken(reuseRefreshToken);
tokenServices.setClientDetailsService(clientDetailsService);
- tokenServices.setTokenEnhancer(tokenEnhancer);
+ tokenServices.setTokenEnhancer(tokenEnhancer());
addUserDetailsService(tokenServices, this.userDetailsService);
return tokenServices;
}
+ private TokenEnhancer tokenEnhancer() {
+ if (tokenEnhancer != null) {
+ TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain();
+ tokenEnhancerChain.setTokenEnhancers(tokenEnhancer);
+ return tokenEnhancerChain;
+ }
+ return null;
+ }
+
private void addUserDetailsService(DefaultTokenServices tokenServices, UserDetailsService userDetailsService) {
if (userDetailsService != null) {
PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();