@@ -9,7 +9,6 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe
9
9
import org.springframework.security.config.http.SessionCreationPolicy
10
10
import org.springframework.security.web.SecurityFilterChain
11
11
import org.springframework.web.cors.CorsConfiguration
12
- import org.springframework.web.cors.CorsConfigurationSource
13
12
import org.springframework.web.cors.UrlBasedCorsConfigurationSource
14
13
import osahner.security.*
15
14
import osahner.service.AppAuthenticationManager
@@ -26,43 +25,45 @@ class WebConfig(
26
25
@Bean
27
26
@Throws(Exception ::class )
28
27
fun filterChain (http : HttpSecurity ): SecurityFilterChain ? {
29
- return http
30
- .cors().and ()
31
- .csrf().disable()
32
- .sessionManagement().sessionCreationPolicy(SessionCreationPolicy .STATELESS ) // no sessions
33
- .and ()
34
- .authorizeHttpRequests()
35
- .requestMatchers(" /api/**" ).permitAll()
36
- .requestMatchers(HttpMethod .GET , " /actuator/health/**" ).permitAll()
37
- .requestMatchers(HttpMethod .GET , " /actuator/info/**" ).permitAll()
38
- .requestMatchers(HttpMethod .POST , " /login" ).permitAll()
39
- .anyRequest().authenticated()
40
- .and ()
28
+ return http.cors { config ->
29
+ config.configurationSource(UrlBasedCorsConfigurationSource ().also { cors ->
30
+ CorsConfiguration ().apply {
31
+ allowedOrigins = listOf (" *" )
32
+ allowedMethods = listOf (" POST" , " PUT" , " DELETE" , " GET" , " OPTIONS" , " HEAD" )
33
+ allowedHeaders = listOf (
34
+ " Authorization" ,
35
+ " Content-Type" ,
36
+ " X-Requested-With" ,
37
+ " Accept" ,
38
+ " Origin" ,
39
+ " Access-Control-Request-Method" ,
40
+ " Access-Control-Request-Headers"
41
+ )
42
+ exposedHeaders = listOf (
43
+ " Access-Control-Allow-Origin" ,
44
+ " Access-Control-Allow-Credentials" ,
45
+ " Authorization" ,
46
+ " Content-Disposition"
47
+ )
48
+ maxAge = 3600
49
+ cors.registerCorsConfiguration(" /**" , this )
50
+ }
51
+ })
52
+ }
53
+ .csrf { csrf -> csrf.disable() }
54
+ .sessionManagement { sessionManagement ->
55
+ sessionManagement.sessionCreationPolicy(SessionCreationPolicy .STATELESS )
56
+ }
57
+ .authorizeHttpRequests { authorizeRequests ->
58
+ authorizeRequests
59
+ .requestMatchers(" /api/**" ).permitAll()
60
+ .requestMatchers(HttpMethod .GET , " /actuator/health/**" ).permitAll()
61
+ .requestMatchers(HttpMethod .GET , " /actuator/info/**" ).permitAll()
62
+ .requestMatchers(HttpMethod .POST , " /login" ).permitAll()
63
+ .anyRequest().authenticated()
64
+ }
41
65
.addFilter(JWTAuthenticationFilter (authenticationManager, securityProperties, tokenProvider))
42
66
.addFilter(JWTAuthorizationFilter (authenticationManager, securityProperties, tokenProvider))
43
67
.build()
44
68
}
45
-
46
- @Bean
47
- fun corsConfigurationSource (): CorsConfigurationSource = UrlBasedCorsConfigurationSource ().also { cors ->
48
- CorsConfiguration ().apply {
49
- allowedOrigins = listOf (" *" )
50
- allowedMethods = listOf (" POST" , " PUT" , " DELETE" , " GET" , " OPTIONS" , " HEAD" )
51
- allowedHeaders = listOf (
52
- " Authorization" ,
53
- " Content-Type" ,
54
- " X-Requested-With" ,
55
- " Accept" ,
56
- " Origin" ,
57
- " Access-Control-Request-Method" ,
58
- " Access-Control-Request-Headers"
59
- )
60
- exposedHeaders = listOf (
61
- " Access-Control-Allow-Origin" , " Access-Control-Allow-Credentials" , " Authorization" , " Content-Disposition"
62
- )
63
- maxAge = 3600
64
- cors.registerCorsConfiguration(" /**" , this )
65
- }
66
- }
67
-
68
69
}
0 commit comments