|
3 | 3 | import cn.hutool.extra.spring.SpringUtil;
|
4 | 4 | import com.central.oauth2.common.component.CustomAuthorizationServiceIntrospector;
|
5 | 5 | import com.central.oauth2.common.component.CustomBearerTokenResolver;
|
| 6 | +import com.central.oauth2.common.enums.TokenType; |
6 | 7 | import com.central.oauth2.common.properties.SecurityProperties;
|
7 | 8 | import org.springframework.context.annotation.Bean;
|
8 | 9 | import org.springframework.context.annotation.Import;
|
9 | 10 | import org.springframework.http.HttpMethod;
|
| 11 | +import org.springframework.security.config.Customizer; |
10 | 12 | import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
11 | 13 | import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
12 | 14 | import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
|
@@ -64,8 +66,13 @@ public SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws
|
64 | 66 | http.oauth2ResourceServer(oauth2 -> {
|
65 | 67 | oauth2.authenticationEntryPoint(authenticationEntryPoint)
|
66 | 68 | .bearerTokenResolver(customBearerTokenResolver)
|
67 |
| - .accessDeniedHandler(oAuth2AccessDeniedHandler) |
68 |
| - .opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector())); |
| 69 | + .accessDeniedHandler(oAuth2AccessDeniedHandler); |
| 70 | + if (TokenType.JWT.getName().equals(securityProperties.getResourceServer().getTokenType())) { |
| 71 | + oauth2.jwt(Customizer.withDefaults()); |
| 72 | + } else { |
| 73 | + oauth2.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector())); |
| 74 | + } |
| 75 | + //.opaqueToken(token -> token.introspector(this.getOpaqueTokenIntrospector())); |
69 | 76 | });
|
70 | 77 |
|
71 | 78 | return http.build();
|
|
0 commit comments