기본 콘텐츠로 건너뛰기

라벨이 Spring Security인 게시물 표시

스프링 시큐리티(Spring Security) 권한 없을때 여러 결과 페이지 설정하기

Spring Security의 인가 실패시 결과 커스텀하기 Java에서 config 설정 방법으로 남김 AccessDeniedHandler()를 커스텀 해야함 public   class  CustomAccessDeniedHandler  implements  AccessDeniedHandler {       @Override      public   void  handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e)  throws  IOException, ServletException {          //스프링 시큐리티 로그인때 만든 객체         Authentication authentication  =  SecurityContextHolder.getContext().getAuthentication();          //현재 접속 url를 확인         UrlPathHelper urlPathHelper  =   new  UrlPathHelper();          String  originalURL  =  urlPathHelper.getOriginatingRequestUri(request);            //로직을 짜서 상황에 따라 보내줄 주소를 설정해주면 됨         response.sendRedirect( "/" );     } } Colored by Color Scripter cs config에 설정 @Override      protected   void  configure(HttpSecurity http)  throws  Exception {         http             .addFilterBefore(authenticationFilter(), UsernamePasswordSessionAuthenticationFilter. class )             .authorizeReque