|
|
@ -11,13 +11,11 @@ import org.springframework.http.HttpMethod;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.authentication.AuthenticationManager;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
|
|
|
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
|
|
|
|
import org.springframework.security.oauth2.common.DefaultOAuth2AccessToken;
|
|
|
|
import org.springframework.security.oauth2.common.OAuth2AccessToken;
|
|
|
|
|
|
|
|
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
|
|
|
|
import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer;
|
|
|
|
import org.springframework.security.oauth2.provider.OAuth2Authentication;
|
|
|
|
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore;
|
|
|
|
import org.springframework.security.oauth2.provider.token.TokenStore;
|
|
|
|
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
|
|
|
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;
|
|
|
@ -118,22 +116,16 @@ public class AuthServerConfig extends AuthorizationServerConfigurerAdapter
|
|
|
|
@Bean
|
|
|
|
@Bean
|
|
|
|
public TokenEnhancer tokenEnhancer()
|
|
|
|
public TokenEnhancer tokenEnhancer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return new TokenEnhancer()
|
|
|
|
return (accessToken, authentication) -> {
|
|
|
|
{
|
|
|
|
if (authentication.getUserAuthentication() != null)
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (accessToken instanceof DefaultOAuth2AccessToken)
|
|
|
|
Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();
|
|
|
|
{
|
|
|
|
LoginUser user = (LoginUser) authentication.getUserAuthentication().getPrincipal();
|
|
|
|
DefaultOAuth2AccessToken token = (DefaultOAuth2AccessToken) accessToken;
|
|
|
|
additionalInformation.put(SecurityConstants.DETAILS_USER_ID, user.getUserId());
|
|
|
|
LoginUser user = (LoginUser) authentication.getUserAuthentication().getPrincipal();
|
|
|
|
additionalInformation.put(SecurityConstants.DETAILS_USERNAME, user.getUsername());
|
|
|
|
Map<String, Object> additionalInformation = new LinkedHashMap<String, Object>();
|
|
|
|
((DefaultOAuth2AccessToken) accessToken).setAdditionalInformation(additionalInformation);
|
|
|
|
additionalInformation.put(SecurityConstants.DETAILS_USERNAME, authentication.getName());
|
|
|
|
}
|
|
|
|
additionalInformation.put(SecurityConstants.DETAILS_USER_ID, user.getUserId());
|
|
|
|
return accessToken;
|
|
|
|
token.setAdditionalInformation(additionalInformation);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return accessToken;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|