• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

successHandler가 작동하지 않습니다.

22.10.03 22:53 작성 조회수 828

1

우선 너무 자주 질문을 드리는 것 같아 죄송합니다.

SuccessHandler를 입력하고, 핸들러에 BreakPoint가 작동하지 않아 FailHandler와 denied를 만들어서 작동시켜 봤는데 SuccessHandler이외에는 정상 작동하는 것을 확인했습니다. 저에게는 코드에 이상한 부분이 보이지 않아 질문드리게 되었습니다. 전체 코드는 깃허브 Othkkartho/SpringSecurityLearn: 스프링 시큐리티 인프런 강의에 실전 프로젝트를 직접 해보는 프로젝트입니다. (github.com) 에 branches ch3.9,10,11입니다.

CustomAuthenticationSuccessHandler.jpg

SecurityConfig_2_1.jpg

SecurityConfig_2_2.jpg

 

답변 2

·

답변을 작성해보세요.

0

dltkdcksqkqh님의 프로필

dltkdcksqkqh

2024.01.14

저도 많은 도움이 됐습니다.

0

@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {
    setDefaultTargetUrl("/");

    SavedRequest savedRequest = requestCache.getRequest(request, response);

    if (savedRequest != null) {
        String targetUrl = savedRequest.getRedirectUrl();
        redirectStrategy.sendRedirect(request, response, targetUrl);
    }
    else {
        redirectStrategy.sendRedirect(request, response, getDefaultTargetUrl());
    }
}

 

위 코드에서

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authentication) throws IOException, ServletException {

public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {

로 해야 합니다. 즉 FilterChain chain 를 제거해야 합니다.

Override 가 정확하지 않아서 부모 클래스로 가버리고 있습니다.

아 이해했습니다. 제가 제대로 못보고, Override를 잘못했네요. 감사합니다.