본문 바로가기
Spring/boot

spring boot 로그인 실패 시 후속 작업 (리다이렉트)

by 무대포 개발자 2020. 10. 5.
728x90
반응형

spring boot 로그인 실패 시 후속 작업 (리다이렉트)

  • AuthenticationFailureHandler implements 한 후, @Component 달아주면 됨.
  • redirect 를 아래와 같이 하면 contextRootPath + "/login" 으로 redirect 가 됨.
@Component
public class AuthenticationFailureHandlerImpl implements AuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException e) throws IOException, ServletException {

            response.sendRedirect("/login");

    }
}

주의사항

  • 위와 같이 redirect 하게 되면, 로컬에서 띄웠고, contextRootPath 가 localhost:8080 라 가정.
  • 그럼 http://localhost:8080/login 으로 redirect 가 되는데.
  • 이 때, http 를 https 로 바꾸고 싶다면 spring boot 설정 파일에 아래와 같이 설정해줘야 함.
server:
  tomcat:
    use-relative-redirects: true 

refeence

댓글