-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
강의 내용 질문
23.08.10 19:50 작성 23.08.10 21:20 수정 조회수 359
1
안녕하세요 강의 너무 최고입니다.
질문이 있습니다. !!
첫번째 질문은
http
.exceptionHandling()
.authenticationEntryPoint(new AjaxLoginAuthenticationEntryPoint())
.accessDeniedHandler(ajaxAccessDeniedHandler());
설정하실때 전자는 생성자를 만들고
두번째는 왜 같은 방법으로 생성자를 만들지않고 등록을 하는건가요 ?
-> .accessDeniedHandler(ajaxAccessDeniedHandler());
이걸
.accessDeniedHandler(new AjaxAccessDeniedHandler());
이렇게 안하시는 이유가 있나요 ?
두번째 질문은 SecurityConfig 에서
@Bean
public AccessDeniedHandler accessDeniedHandler() {
CustomAccessDeniedHandler accessDeniedHandler = new CustomAccessDeniedHandler();
accessDeniedHandler.setErrorPage("/denied");
return accessDeniedHandler;
}
이 등록되어있는데
.exceptionHandling()
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"))
.accessDeniedPage("/denied")
.accessDeniedHandler(accessDeniedHandler());
이 두줄을 추가 하셨습니다.
우선적으로 여기서 첫번째 질문은
.accessDeniedPage("/denied")랑
accessDeniedHandler.setErrorPage("/denied");
이게 같은 역할을 하는것이 아닌가요 ?
그리고 마지막으로
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"))
이 내용은
CustomAuthenticationFailureHandler 에 설정된
setDefaultFailureUrl("/login?error=true&exception=" +errorMessage);
super.onAuthenticationFailure(request,response, exception);
이게 이미 처리하고 있던 내용 아닌가요 ?
마지막 질문은 .authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")) 이건
인가 예외로 생각하고
CustomAuthenticationFailureHandler 에 설정된 내용은 인증 내용이라고 생각하면 될까요 ?
답변을 작성해보세요.
0
정수원
지식공유자2023.08.11
첫번째 질문은
특별한 이유가 있는 것은 아닙니다. 편하신 대로 코드를 작성하시면 됩니다.
다만 빈으로 생성을 해야 한다면 new AjaxAccessDeniedHandler() 가 아니라 ajaxAccessDeniedHandler() 를 호출해서 빈으로 생성되도록 해야 합니다
두번째 질문은
.accessDeniedPage("/denied") 와
accessDeniedHandler.setErrorPage("/denied");
은 동일한 기능을 수행하는 것이 맞습니다.
그리고
.accessDeniedPage("/denied")
.accessDeniedHandler(accessDeniedHandler());
은 첫번째 보다 두번째가 더 우선적으로 실행이 됩니다.
세번째 질문은
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login"))
와
CustomAuthenticationFailureHandler 은 직접적인 관계가 없습니다.
new LoginUrlAuthenticationEntryPoint("/login") 은 인증 받지 못한 상태에서 인증이 필요한 어떤 자원에 접근하게 될 때 다시 인증을 받을 수 있는 화면으로 이동하도록 하는 기능이고
CustomAuthenticationFailureHandler 은 로그인을 시도하다가 실패하면 호출되는 기능입니다.
인증과 관련있다는 공통점은 있으나 서로 처리하는 시점이나 성격은 틀립니다.
네번째 질문은
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/login")) 은 인가예외가 아니라 인증예외입니다. 인가예외는 AccessDeniedHandler 가 호출됩니다.
그리고 CustomAuthenticationFailureHandler 은 로그인 즉 인증이 실패 했을 때 인증 필터가 호출하는 기능이라 보시면 됩니다.
답변 1