@@ -2,38 +2,46 @@ package fi.hsl.jore4.mapmatching.config
2
2
3
3
import fi.hsl.jore4.mapmatching.api.MapMatchingController
4
4
import fi.hsl.jore4.mapmatching.api.RouteController
5
+ import org.springframework.context.annotation.Bean
5
6
import org.springframework.context.annotation.Configuration
6
7
import org.springframework.http.HttpMethod
8
+ import org.springframework.security.config.Customizer.withDefaults
7
9
import org.springframework.security.config.annotation.web.builders.HttpSecurity
8
10
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
9
- import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
10
11
import org.springframework.security.config.http.SessionCreationPolicy
12
+ import org.springframework.security.web.SecurityFilterChain
11
13
12
14
@Configuration
13
15
@EnableWebSecurity
14
- class WebSecurityConfig : WebSecurityConfigurerAdapter () {
16
+ class WebSecurityConfig {
15
17
16
- override fun configure (httpSec : HttpSecurity ) {
17
- httpSec
18
- .sessionManagement()
19
- .sessionCreationPolicy(SessionCreationPolicy .NEVER )
18
+ @Bean
19
+ @Throws(Exception ::class )
20
+ fun configure (httpSecurity : HttpSecurity ): SecurityFilterChain {
21
+ return httpSecurity
22
+ .sessionManagement { it.sessionCreationPolicy(SessionCreationPolicy .NEVER ) }
20
23
21
- . and ()
24
+ // CSRF is not needed.
22
25
.csrf().disable()
23
26
24
- .authorizeRequests()
25
-
26
- .antMatchers(HttpMethod .GET ,
27
- RouteController .URL_PREFIX + " /**" ,
28
- " /actuator/health" ,
29
- " /*" // matches static landing page for examining results from route API
30
- ).permitAll()
31
-
32
- .antMatchers(HttpMethod .POST ,
33
- MapMatchingController .URL_PREFIX + " /**" ,
34
- RouteController .URL_PREFIX + " /**"
35
- ).permitAll()
36
-
37
- .anyRequest().denyAll()
27
+ /* * A CORS mapping is defined in [WebConfig] within "development" Spring profile. */
28
+ .cors(withDefaults())
29
+
30
+ .authorizeHttpRequests {
31
+ it
32
+ .antMatchers(HttpMethod .GET ,
33
+ RouteController .URL_PREFIX + " /**" ,
34
+ " /actuator/health" ,
35
+ " /*" // matches static landing page for examining results from route API
36
+ ).permitAll()
37
+
38
+ .antMatchers(HttpMethod .POST ,
39
+ MapMatchingController .URL_PREFIX + " /**" ,
40
+ RouteController .URL_PREFIX + " /**"
41
+ ).permitAll()
42
+
43
+ .anyRequest().denyAll()
44
+ }
45
+ .build()
38
46
}
39
47
}
0 commit comments