
SpringSecurity를 추가하여 로그인을 테스트 하던 도중 아래와 같은 에러페이지가 표시됐다. 하지만 다시 home으로 이동하면 로그인이 정상적으로 되어있다.
해결 방법은 생각보다 간단했다. defaultSuccessUrl의 2번째 인자로 true를 전달해주는 것 이다.
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/","/users").permitAll()
.antMatchers("/mypage").hasRole("USER")
.antMatchers("/messages").hasRole("MANAGER")
.antMatchers("/config").hasRole("ADMIN")
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/login_proc")
// .defaultSuccessUrl("/") 오류 발생
.defaultSuccessUrl("/", true)
.authenticationDetailsSource(authenticationDetailsSource)
.permitAll();
return http.build();
}