fix #I1OEEN
This commit is contained in:
+6
@@ -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
|
||||
* <p>
|
||||
* 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<String, Object> additionalInfo = new HashMap<>(1);
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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> 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();
|
||||
|
||||
Reference in New Issue
Block a user