|
28 | 28 | import org.springframework.security.web.SecurityFilterChain;
|
29 | 29 | import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
|
30 | 30 | import org.springframework.security.web.util.matcher.MediaTypeRequestMatcher;
|
| 31 | +import org.springframework.security.oauth2.server.authorization.token.OAuth2TokenClaimsContext; |
31 | 32 |
|
32 | 33 | import com.nimbusds.jose.jwk.JWKSet;
|
33 | 34 | import com.nimbusds.jose.jwk.RSAKey;
|
@@ -116,11 +117,29 @@ private static KeyPair generateRsaKey() {
|
116 | 117 |
|
117 | 118 | Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
|
118 | 119 |
|
| 120 | + @Bean |
| 121 | + public OAuth2TokenCustomizer<OAuth2TokenClaimsContext> accessTokenCustomizer() { |
| 122 | + logger.info("Creating accessTokenCustomizer ..."); |
| 123 | + return (context) -> { |
| 124 | + logger.info("Calling accessTokenCustomizer with tokenType: {}", context.getTokenType().getValue()); |
| 125 | + AbstractAuthenticationToken principal = context.getPrincipal(); |
| 126 | + logger.info("registered client: {}", context.getRegisteredClient()); |
| 127 | + logger.info("principal : {}", principal); |
| 128 | + logger.info("token format : {} ", |
| 129 | + context.getRegisteredClient().getTokenSettings().getAccessTokenFormat().getValue()); |
| 130 | + logger.info("authorities : {}", principal.getAuthorities()); |
| 131 | + logger.info("authorized scopes : {}", context.getAuthorizedScopes()); |
| 132 | + |
| 133 | + context.getClaims() |
| 134 | + .audience(AudienceAuthority.getAll(principal)) |
| 135 | + .claim("extra_scope", ScopeAuthority.getAuthorites(principal)); |
| 136 | + }; |
| 137 | + } |
119 | 138 | @Bean
|
120 | 139 | public OAuth2TokenCustomizer<JwtEncodingContext> jwtTokenCustomizer() {
|
121 | 140 | logger.info("Creating jwtTokenCustomizer ...");
|
122 | 141 | return (context) -> {
|
123 |
| - logger.info("Calling jwtTokenCustomizer with tokenType: {}", context.getTokenType()); |
| 142 | + logger.info("Calling jwtTokenCustomizer with tokenType: {}", context.getTokenType().getValue()); |
124 | 143 | if (OAuth2TokenType.ACCESS_TOKEN.equals(context.getTokenType())) {
|
125 | 144 | AbstractAuthenticationToken principal = context.getPrincipal();
|
126 | 145 | logger.info("registered client: {}", context.getRegisteredClient());
|
|
0 commit comments