• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

요청을 확인할 수 있는 방법이 있을까요??

23.07.07 16:34 작성 23.07.07 16:35 수정 조회수 359

0

안녕하세요 선생님 좋은강의 정말 감사드립니다!

선생님 혹시 사용자의 어떤 request에 의해서 CustomAccessDeniedHandler 여기로 오게 되는지 디버그를 이용해서 확인하고 싶다면 어떤 필터를 확인하면 알 수 있을까요??

답변 1

답변을 작성해보세요.

0

AccessDeniedHandler 를 호출하는 곳은 몇 군데 있는데 일반적으로 권한문제로 인해 접근이 불가한 리소스를 호출할 때 시큐리티가 AccessDeniedHandler 를 실행시키게 됩니다.

호출하는 필터 클래스는 ExceptionTranslationFilter 이고 내부 소스를 보면

private void handleAccessDeniedException(HttpServletRequest request, HttpServletResponse response,
FilterChain chain, AccessDeniedException exception) throws ServletException, IOException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
boolean isAnonymous = this.authenticationTrustResolver.isAnonymous(authentication);
if (isAnonymous || this.authenticationTrustResolver.isRememberMe(authentication)) {
if (logger.isTraceEnabled()) {
logger.trace(LogMessage.format("Sending %s to authentication entry point since access is denied",
authentication), exception);
}
sendStartAuthentication(request, response, chain,
new InsufficientAuthenticationException(
this.messages.getMessage("ExceptionTranslationFilter.insufficientAuthentication",
"Full authentication is required to access this resource")));
}
else {
if (logger.isTraceEnabled()) {
logger.trace(
LogMessage.format("Sending %s to access denied handler since access is denied", authentication),
exception);
}
this.accessDeniedHandler.handle(request, response, exception);
}
}

로 되어 있는데 맨 마지막에 AccessDeniedHandler 를 실행시키고 있습니다.

여기에 디버깅을 걸어 놓고 호출해 보시기 바랍니다.

참고로 ExceptionTranslationFilter 를 호출하는 필터 클래스는 FilterSecurityInterceptor 이고 내부에 보시면

private void attemptAuthorization(Object object, Collection<ConfigAttribute> attributes,
Authentication authenticated) {
try {
this.accessDecisionManager.decide(authenticated, object, attributes);
}
catch (AccessDeniedException ex) {
if (this.logger.isTraceEnabled()) {
this.logger.trace(LogMessage.format("Failed to authorize %s with attributes %s using %s", object,
attributes, this.accessDecisionManager));
}
else if (this.logger.isDebugEnabled()) {
this.logger.debug(LogMessage.format("Failed to authorize %s with attributes %s", object, attributes));
}
publishEvent(new AuthorizationFailureEvent(object, attributes, authenticated, ex));
throw ex;
}
}

가 있는데 저기 예외를 처리하는 구문이 있습니다.

AccessDeniedException 을 받아서 다시 throw ex 하고 있습니다.

이 예외를 ExceptionTranslationFilter 가 받게 됩니다.

참고하시기 바랍니다.

hong090992님의 프로필

hong090992

질문자

2023.07.08

선생님 친절한 답변 너무 감사합니다!!