에러 회고
[회고] spring security 6.2.2 formlogin not found
Unagi_zoso
2024. 2. 21. 03:27
환경
- spring boot 3.2.2
- java 17
- spring security 6.2.2
상황
인터넷 예제를 보며 spring security 6 버전 이상인 상황에서 security config 를 작성 중 spring security 에서 기본 제공되는 form login 을 사용하는데 이것을 잘 찾지 못하고 404 Not Found 에러가 발생하였다.
public SecurityFilterChain filterChain(HttpSecurity http) {
http
.formLogin(form -> form
.loginPage("/login")
.permitAll()
);
// ...
}
특이한 문제는 없어보여 계속 진행을 하였으나 계속해서 문제가 발생하였다
해결
공식문서에 잘 나와있었다!
위의 방식은 커스텀 로그인 폼 화면을 보여주기 위한 예라 할 수 있다.
In the preceding configuration, Spring Security renders a default login page. Most production applications require a custom login form.
The following configuration demonstrates how to provide a custom login form.
따라서 스프링 시큐리티 기본 제공 로그인 폼을 사용하고 싶다면 다음과 같이 사용하면 된다.
public SecurityFilterChain filterChain(HttpSecurity http) {
http
.formLogin(withDefaults());
// ...
}
스프링 시큐리티는 5.2 버전 이후부터 람다 DSL 을 이용해 보기좋고 획일화된 코드를 적을 수 있도록 신경을 쓰는 듯 하다. 스프링 시큐리티 매 버전 마다 새로운 모습이 자주 보여 늘 검색하면서 적용하는 것 같다.
참조
https://docs.spring.io/spring-security/reference/servlet/authentication/passwords/form.html