SpringSecurity - 로그인 시 status 999 문제 해결

박민수·2023년 11월 14일

Spring

목록 보기
36/46
post-thumbnail

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();
}
profile
안녕하세요 백엔드 개발자입니다.

0개의 댓글