• 마지막에서 두번째 필터이다.
  • 다음 필터가 FilterSecurityInterceptor인데 둘은 밀접한 관계가 있다.
  • ExceptionTranslatorFilter가 try, catch로 감싼 다음 다음 필터처리를 한다.
  • AccessDecisionManager, AffirmativeBased 구현체를 이용해서 인가(권한) 처리를 하는데 이때에 두가지 예외가 발생할 수 있다.
    • AuthenticationException 인증

      • AuthenticationEntryPoint를 이용해서 처리한다. 인증 가능한 페이지로 보낸다. (로그인 페이지)
    • AccessDeniedException 권한

      • AccessDeniedHandler를 이용해서 처리. 기본은 403 페이지를 보여주는 것
      • 에러 페이지를 커스터마이징 할 수 있다.
      http.exceptionHandling()
      				.accessDeniedPage("/access-denied");
      

      • 더 많은 일을 시키기 위해(로그기록 등) AccessDeniedHandler를 등록할 수도 있다.
      http.exceptionHandling()
      			.accessDeniedHandler(new AccessDeniedHandler() {
      				@Override
      				public void handle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AccessDeniedException e) throws IOException, ServletException {
      					UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
      					String username = principal.getUsername();
      					System.out.println(username + " is denied to access " + httpServletRequest.getRequestURI());
      					httpServletResponse.sendRedirect("/access-denied");
      				}
      			});
      
      • 원래는 별도 클래스로 빼야 함