Kotlin DSL 활용
import org.springframework.security.config.annotation.web.invoke시큐리티 5.3부터 Kotlin 환경에서 스프링 시큐리티를 사용하실 때 DSL을 지원받을 수 있습니다.
공식문서에 나와있습니다.(https://docs.spring.io/spring-security/reference/servlet/configuration/kotlin.html)
이 DSL을 사용한 예제 프로젝트도 제공됩니다. (https://github.com/spring-projects/spring-security-samples/tree/main/servlet/spring-boot/kotlin/hello-security)
DSL 문 삽입은 IDE의 지원을 받을 수 없어서 위 import 문을 직접 작성해야합니다.
@Configuration
class SecurityConfig {
@Bean
fun securityFilterChain(http: HttpSecurity): SecurityFilterChain {
http {
authorizeHttpRequests {
authorize("/", permitAll)
authorize(anyRequest, authenticated)
}
formLogin {}
rememberMe { }
sessionManagement {
sessionCreationPolicy = SessionCreationPolicy.STATELESS
}
}
return http.build()
}
}
예를 들면 위와 같이 DSL의 지원을 받아 설정을 구성할 수 있습니다.
람다 표현식을 작성하지 않고 설정할 수 있습니다.

IDE를 통해 DSL 설정 클래스를 쭉 따라가보면 어떤 파라미터를 전달하면 될지 확인할 수 있는데 이를 참고하면 좀 더 편리하게 설정을 사용할 수 있습니다.
다만 일부 설정은 제공되지 않는 것도 있어서 해당하는 부분은 Spring에서 제공되는 API 그대로 사용하셔야합니다.
답변 0
로그아웃-logout()-2 강에서 겟방식 로그아웃 호출 후 화면이동 질문입니다.
0
28
2
단원별 소스코드
0
60
2
CustomAuthenticationProvider 추가 관련 문의
0
69
2
AOP 의존성 명칭 변경
0
65
1
빈 1개 등록 시 다른 해결 방법
0
65
1
@Bean으로 AuthenticationProvider를 등록 시 http.authenticationProvider 함수를 이용해서 추가해줘야되나요?
0
85
2
OIDC의 id token에 담긴 데이터에 대해
0
74
1
loginPage("/loginPage") 질문드립니다.
0
69
1
@EnableWebSecurity
0
147
1
트랜잭션과 롤백
0
99
1
68. 인증 이벤트 - AuthenticationEventPublisher 활용 강좌 음성 문제
0
89
2
AuthenticationManager 사용 방법
0
148
2
HttpSecurity.authorizeHttpRequests() - 2 강의 부분에 대한 질문
0
104
2
spring security 6.3에서는 HttpSecurity가 만들어지기 전 WebSecurity가 먼저 만들어지는게 맞나요??
0
190
1
init(B Builder), configure(B builder) 에 대하여 질문 드립니다.
0
106
2
메타 주석 질문
0
68
1
동시세션제어 기능에서 로그아웃하기
0
147
3
로그인 후, redirect 에서 error
0
138
3
Session 생성 타이밍에 대한 질문
0
84
2
강의 참고 내용을 개발 로그로 작성해도 될지 문의드립니다.
0
133
2
customAuthentication 관련
0
127
2
authenticationManagerBuilder 주입받은거 vs 만든 거
0
110
1
UserDetailsService()에서 UserDetail이 아닌 타입을 반환할 수 있나요?
0
101
1
9:28 패턴 3의 경우 마지막으로 설정한 것만 적용되는 것 같습니다.
0
159
2





