Skip to content

Commit a8b701a

Browse files
committed
Fix use of deprecated WebSecurityConfigurerAdapter.
1 parent c31dc51 commit a8b701a

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

spring-boot/src/main/kotlin/fi/hsl/jore4/mapmatching/config/WebSecurityConfig.kt

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,46 @@ package fi.hsl.jore4.mapmatching.config
22

33
import fi.hsl.jore4.mapmatching.api.MapMatchingController
44
import fi.hsl.jore4.mapmatching.api.RouteController
5+
import org.springframework.context.annotation.Bean
56
import org.springframework.context.annotation.Configuration
67
import org.springframework.http.HttpMethod
8+
import org.springframework.security.config.Customizer.withDefaults
79
import org.springframework.security.config.annotation.web.builders.HttpSecurity
810
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity
9-
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter
1011
import org.springframework.security.config.http.SessionCreationPolicy
12+
import org.springframework.security.web.SecurityFilterChain
1113

1214
@Configuration
1315
@EnableWebSecurity
14-
class WebSecurityConfig : WebSecurityConfigurerAdapter() {
16+
class WebSecurityConfig {
1517

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) }
2023

21-
.and()
24+
// CSRF is not needed.
2225
.csrf().disable()
2326

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()
3846
}
3947
}

0 commit comments

Comments
 (0)