inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

5) 인증 및 인가 예외 처리 - AjaxLoginUrlAuthenticationEntryPoint, AjaxAccessDeniedHandler

강의 내용 질문

463

H K

작성한 질문수 93

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 에 설정된 내용은 인증 내용이라고 생각하면 될까요 ?

 

 

java spring-boot spring-security

답변 1

0

정수원

첫번째 질문은

특별한 이유가 있는 것은 아닙니다. 편하신 대로 코드를 작성하시면 됩니다.

다만 빈으로 생성을 해야 한다면 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 은 로그인 즉 인증이 실패 했을 때 인증 필터가 호출하는 기능이라 보시면 됩니다.

0

H K

감사합니다 이해했습니다

시큐리티 공부 버전 질문

0

175

1

[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈

0

186

1

AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우

0

176

1

강의 코드가 왜이렇게 뒤죽박죽인가요...

0

250

1

메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..

0

236

1

파라미터값이 넘어가지 않습니다 ....

0

374

1

security filterChain 설정 질문이 있습니다.

0

332

1

소스 부분 질문 드립니다.

0

209

2

섹션4 7번 강의 문제가 있는거 같네요.

0

344

2

파일이 수시로 이름이 바껴있네요 ㄷㄷ

0

305

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

556

2

error , exception 이 잘 안됩니다.

0

283

2

thymeleaf tag 질문합니다.

0

197

2

버전업하면서 deprecated된 것들이 너무많아요

0

478

1

spring security 패치 관련

0

437

1

모바일을 사용할때 토큰말고 세션

0

846

2

DB 연동한 인가 부분에 대한 질문입니다!

0

264

1

Ajax방식도 똑같이 Session방식을 사용하는건가요?

0

307

1

Config 파일 생성 시 질문이 있습니다.

0

227

1

강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..

1

431

2

403 에러 뜹니다.

0

813

2

login_proc의 존재에 대한 간략한 설명입니다

0

276

1

top.html에 로그인 링크를 만들어서 로그인을 해봤습니다

0

285

2

안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!

0

190

1