1
1
package net .coderic .core .api .config ;
2
2
3
- import com .nimbusds .jose .JOSEException ;
4
- import com .nimbusds .jose .jwk .JWK ;
5
- import com .nimbusds .jose .jwk .JWKSet ;
6
- import com .nimbusds .jose .jwk .RSAKey ;
7
3
import org .springframework .beans .factory .annotation .Value ;
8
4
import org .springframework .context .annotation .Bean ;
9
5
import org .springframework .context .annotation .Configuration ;
10
- import org .springframework .security .config .Customizer ;
11
6
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
12
7
import org .springframework .security .config .annotation .web .configuration .EnableWebSecurity ;
13
8
import org .springframework .security .config .annotation .web .configurers .AbstractHttpConfigurer ;
14
9
import org .springframework .security .config .http .SessionCreationPolicy ;
15
- import org .springframework .security .oauth2 .jwt .JwtDecoder ;
16
- import org .springframework .security .oauth2 .jwt .JwtDecoders ;
17
- import org .springframework .security .oauth2 .jwt .NimbusJwtDecoder ;
18
10
import org .springframework .security .oauth2 .server .resource .authentication .JwtAuthenticationConverter ;
19
11
import org .springframework .security .web .SecurityFilterChain ;
20
- import org .springframework .security .web .authentication .logout .HeaderWriterLogoutHandler ;
21
- import org .springframework .security .web .header .writers .ClearSiteDataHeaderWriter ;
22
12
import org .springframework .security .web .header .writers .frameoptions .XFrameOptionsHeaderWriter ;
23
- import org .springframework .security .web .util .matcher .AntPathRequestMatcher ;
24
- import org .springframework .web .cors .CorsConfiguration ;
25
- import org .springframework .web .cors .CorsConfigurationSource ;
26
- import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
27
-
28
- import javax .crypto .spec .SecretKeySpec ;
29
- import java .io .IOException ;
30
- import java .net .URL ;
31
- import java .security .PublicKey ;
32
- import java .security .interfaces .RSAPublicKey ;
33
- import java .text .ParseException ;
34
- import java .util .Arrays ;
35
13
36
14
@ Configuration
37
15
@ EnableWebSecurity
@@ -86,22 +64,8 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
86
64
);
87
65
return http .build ();
88
66
}
89
- @ Bean
90
- public CorsConfigurationSource corsConfigurationSource () {
91
- CorsConfiguration configuration = new CorsConfiguration ();
92
- configuration .setAllowedOrigins (Arrays .asList ("https://example.com" , "http://localhost:4200" ));
93
- configuration .setAllowedMethods (Arrays .asList ("GET" ,"POST" ,"PUT" ,"PATCH" ,"HEAD" ,"OPTIONS" ));
94
- configuration .addAllowedHeader ("Content-Type" );
95
- configuration .addAllowedHeader ("Authorization" );
96
- configuration .getMaxAge ();
97
- configuration .setAllowCredentials (true );
98
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
99
- source .registerCorsConfiguration ("/**" , configuration ); // allow all paths
100
- return source ;
101
- }
102
67
103
68
private JwtAuthenticationConverter jwtAuthenticationConverter () {
104
- JwtAuthenticationConverter converter = new JwtAuthenticationConverter ();
105
- return converter ;
69
+ return new JwtAuthenticationConverter ();
106
70
}
107
71
}
0 commit comments