6분20초쯤에
288
작성한 질문수 6
부모클래스의 onAuthenticationFailure를 호출한 이유가 이해가 가질 않는데..왜그런거죠..?
답변 1
1
네
인증에 실패하게 되면 후속처리를 하게 되는데 강의에서 보면
부모 클래스인 SimpleUrlAuthenticationFailureHandler 의 setDefaultFailureUrl("/login?error=true&exception.. ) 를 호출하고 있습니다.
public void setDefaultFailureUrl(String defaultFailureUrl) {
Assert.isTrue(UrlUtils.isValidRedirectUrl(defaultFailureUrl),
() -> "'" + defaultFailureUrl + "' is not a valid redirect URL");
this.defaultFailureUrl = defaultFailureUrl;
}
즉 예외메시지를 담아서 로그인 페이지로 이동하도록 설정하기 위한 구문입니다.
그리고 defaultFailureUrl 에 저장된 이동페이지 정보를 가지고 포워딩 혹은 리다이렉트 하는 처리를 합니다.
실은 이 처리를 직접 코드를 작성해서 구현할 수 있지만 부모 클래스인 SimpleUrlAuthenticationFailureHandler 에서 하고 있기 때문에 super.onAuthenticationFailure(request, response, exception) 를 호출하고 있습니다.
@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
AuthenticationException exception) throws IOException, ServletException {
if (this.defaultFailureUrl == null) {
if (this.logger.isTraceEnabled()) {
this.logger.trace("Sending 401 Unauthorized error since no failure URL is set");
}
else {
this.logger.debug("Sending 401 Unauthorized error");
}
response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
return;
}
saveException(request, exception);
if (this.forwardToDestination) {
this.logger.debug("Forwarding to " + this.defaultFailureUrl);
request.getRequestDispatcher(this.defaultFailureUrl).forward(request, response);
}
else {
this.redirectStrategy.sendRedirect(request, response, this.defaultFailureUrl);
}
}
onAuthenticationFailure 메소드 내에서 defaultFailureUrl 에 저장된 정보를 가지고 후속 처리를 하고 있습니다.
0
필요한 정보만 CustomAuthenticationFailureHandler 에서 실행하고 나머지 실행은 원래 기본적으로 제공되는
SimpleUrlAuthenticationFailureHandler 코드를 사용했다고 생각하면 되나요 ?
시큐리티 공부 버전 질문
0
181
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
189
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
183
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
260
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
242
1
파라미터값이 넘어가지 않습니다 ....
0
376
1
security filterChain 설정 질문이 있습니다.
0
334
1
소스 부분 질문 드립니다.
0
210
2
섹션4 7번 강의 문제가 있는거 같네요.
0
345
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
308
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
560
2
error , exception 이 잘 안됩니다.
0
287
2
thymeleaf tag 질문합니다.
0
199
2
버전업하면서 deprecated된 것들이 너무많아요
0
479
1
spring security 패치 관련
0
439
1
모바일을 사용할때 토큰말고 세션
0
858
2
DB 연동한 인가 부분에 대한 질문입니다!
0
265
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
309
1
Config 파일 생성 시 질문이 있습니다.
0
229
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
435
2
403 에러 뜹니다.
0
816
2
login_proc의 존재에 대한 간략한 설명입니다
0
277
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
288
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
192
1





