spring security 실습 중 WebSecurityConfigurerAdapter 사용하려 했으나 Deprecated 되어 있어
WebSecurityConfigurerAdapter spring 공식 문서를 참고하여 위의 예제코드를 수정했습니다.
spring 에서는 SecurityFilterChain을 사용하도록 권장하고 있습니다.
@Configuration
@EnableWebSecurity // 스프링 시큐리티 필터가 스프링 필터체인에 등록됨
class SecurityConfig {
@Bean
@Throws(Exception::class)
fun filterChain(http: HttpSecurity): SecurityFilterChain? {
http
.authorizeRequests { authz ->
authz
.antMatchers("/user/**").authenticated()
.antMatchers("/manager/**").access("hasRole('ROLE_ADMIN') or hasRole('ROLE_MANAGER')")
.antMatchers("/admin/**").access("hasRole('ROLE_ADMIN')")
.anyRequest().permitAll()
.and()
.formLogin()
.loginPage("/login")
}
.httpBasic(withDefaults())
return http.build()
}
}