AuthenticationException 인증
AccessDeniedException 권한
http.exceptionHandling()
.accessDeniedPage("/access-denied");
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");
}
});