|
26 | 26 | import org.springframework.security.oauth2.jwt.NimbusJwtDecoder;
|
27 | 27 | import org.springframework.security.oauth2.jwt.NimbusJwtEncoder;
|
28 | 28 | import org.springframework.security.web.SecurityFilterChain;
|
29 |
| -import org.springframework.web.cors.CorsConfiguration; |
30 |
| -import org.springframework.web.cors.CorsConfigurationSource; |
31 |
| -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; |
| 29 | +import org.springframework.web.servlet.config.annotation.CorsRegistry; |
| 30 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; |
32 | 31 |
|
33 |
| -import java.util.Arrays; |
34 | 32 | import java.util.List;
|
35 | 33 |
|
36 | 34 | /**
|
@@ -76,22 +74,18 @@ JwtDecoder jwtDecoder() throws JOSEException {
|
76 | 74 | }
|
77 | 75 |
|
78 | 76 | /**
|
79 |
| - *Returns CorsConfigurationSource the cors configuration |
| 77 | + *Returns WebMvcConfigurer for the cors configuration |
80 | 78 | * The bean is based on springboot configuration property cors.allowed-origins
|
81 | 79 | */
|
82 | 80 | @Bean
|
83 | 81 | @ConditionalOnProperty(value = "cors.allowed-origins")
|
84 |
| - CorsConfigurationSource corsConfigurationSource() { |
85 |
| - CorsConfiguration configuration = new CorsConfiguration(); |
86 |
| - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); |
87 |
| - if( allowedOrigins!=null && !allowedOrigins.isEmpty()) { |
88 |
| - configuration.setAllowedOrigins(allowedOrigins); |
89 |
| - configuration.setAllowedMethods(Arrays.asList("GET","POST")); |
90 |
| - configuration.addExposedHeader("x-auth-token"); |
91 |
| - configuration.setAllowedHeaders(Arrays.asList("content-type","x-auth-token")); |
92 |
| - source.registerCorsConfiguration("/**", configuration); |
93 |
| - } |
94 |
| - return source; |
| 82 | + public WebMvcConfigurer corsConfigurer() { |
| 83 | + return new WebMvcConfigurer() { |
| 84 | + @Override |
| 85 | + public void addCorsMappings( CorsRegistry registry ) { |
| 86 | + registry.addMapping("/**").allowedOrigins(allowedOrigins.toArray(new String[]{})); |
| 87 | + } |
| 88 | + }; |
95 | 89 | }
|
96 | 90 |
|
97 | 91 | @Bean
|
|
0 commit comments