4
4
5
5
import org .springframework .context .annotation .Bean ;
6
6
import org .springframework .context .annotation .Configuration ;
7
- import org .springframework .security .config .Customizer ;
8
7
import org .springframework .security .config .annotation .method .configuration .EnableGlobalMethodSecurity ;
9
8
import org .springframework .security .config .annotation .web .builders .HttpSecurity ;
10
9
import org .springframework .security .config .annotation .web .configurers .oauth2 .server .resource .OAuth2ResourceServerConfigurer ;
11
10
import org .springframework .security .core .authority .AuthorityUtils ;
12
11
import org .springframework .security .oauth2 .server .resource .authentication .JwtAuthenticationConverter ;
13
12
import org .springframework .security .oauth2 .server .resource .authentication .JwtGrantedAuthoritiesConverter ;
14
13
import org .springframework .security .web .SecurityFilterChain ;
15
- import org .springframework .security .web .csrf .CookieCsrfTokenRepository ;
16
- import org .springframework .web .cors .CorsConfiguration ;
17
- import org .springframework .web .cors .CorsConfigurationSource ;
18
- import org .springframework .web .cors .UrlBasedCorsConfigurationSource ;
19
14
20
15
@ Configuration
21
16
@ EnableGlobalMethodSecurity (prePostEnabled = true )
@@ -26,24 +21,11 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, AccessRuleAuth
26
21
// @formatter:off
27
22
http
28
23
.authorizeHttpRequests ((authz ) -> authz .anyRequest ().access (access ))
29
- .cors (Customizer .withDefaults ())
30
24
.oauth2ResourceServer (OAuth2ResourceServerConfigurer ::jwt );
31
25
// @formatter:on
32
26
return http .build ();
33
27
}
34
28
35
- @ Bean
36
- CorsConfigurationSource corsConfigurationSource () {
37
- UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource ();
38
- CorsConfiguration config = new CorsConfiguration ();
39
- config .addAllowedHeader ("*" );
40
- config .addAllowedMethod ("*" );
41
- config .addAllowedOrigin ("http://127.0.0.1:8000" );
42
- config .setAllowCredentials (true );
43
- source .registerCorsConfiguration ("/**" , config );
44
- return source ;
45
- }
46
-
47
29
@ Bean
48
30
public JwtAuthenticationConverter jwtAuthenticationConverter () {
49
31
JwtGrantedAuthoritiesConverter authoritiesConverter = new JwtGrantedAuthoritiesConverter ();
0 commit comments