아틴
Atin
아틴
전체 방문자
오늘
어제
  • 분류 전체보기 (460)
    • Devlopment (246)
      • 정리 글 (20)
      • MicroServices (0)
      • Reactive, Concurrenc.. (12)
      • Java (44)
      • Spring (20)
      • C,C++,Ruby,Python (52)
      • Mobile (39)
      • Web (35)
      • Tip & Info (14)
      • Unit Test (7)
    • Infra (44)
      • OS (21)
      • RDBMS (13)
      • NoSQL&Cache (5)
      • AWS (4)
    • Computer Science (11)
    • Etc (156)

블로그 메뉴

  • Home
  • Guestbook

공지사항

인기 글

태그

  • 자바
  • jsp
  • 안드로이드
  • Ruby on Rails
  • Python
  • Linux
  • 해킨토시
  • Android
  • 여행
  • mysql
  • 아이폰
  • Java
  • TRPG
  • Dungeons & Dragons
  • 던젼 앤 드래곤즈
  • 정읍
  • CSS
  • 전라도
  • C
  • javascript

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
아틴

Atin

Devlopment/Spring

[SpringSecurity] Method 레벨에서 AccessDeniedException 처리하기

2017. 2. 7. 13:45
반응형

SpringSecurity를 설정하다보니 Method레벨(global-method-security)에서의 AccessDeniedException은 그 전에 설정해놓은 <access-denied-handler>에 걸리지 않는 것을 알게 되었다.


왜 그런가 찾다보니 스택오버플로우[1]에서 답을 찾았는데

내 상황이 답을 준것처럼 처리하기에는 정확히 맞지 않는 상황이었다.


- StackOverFlow 번역 -

access-denied-handler는 AccessDeniedException가 발생할 때 ExceptionTranslationFilter에 의해 사용됩니다.

그러나 org.springframework.web.servlet.DispatcherServlet은 먼저 예외 처리를 시도했다.

특히 defaultErrorView로 정의 된 org.springframework.web.servlet.handler.SimpleMappingExceptionResolver가 있는데, 결과적으로 SimpleMappingExceptionResolver는 적절한 뷰로 리디렉션하여 예외를 소비하므로 결과적으로 ExceptionTranslationFilter에 버블링 될 예외가 없습니다.


수정은 간단했다. 모든 AccessDeniedException을 무시하도록 SimpleMappingExceptionResolver를 구성하십시오.


applicationContext.xml


이제는 AccessDeniedException이 발생할 때마다 SimpleMappingExceptionResolver를 무시하고 ExceptionTranslationFilter를 통해 예외 처리를 하게 됩니다.



- 내 해결 방식 -

내 프로젝트에서는 위와 같이 설정하기 난해한 부분이 있어서 중복이여서 아쉽지만 web.xml에 이동 페이지를 설정하게 해주었다.


web.xml



Reference

[1] Spring Security ignoring access-denied-handler with Method Level Security (http://stackoverflow.com/questions/21171882/spring-security-ignoring-access-denied-handler-with-method-level-security)



반응형
저작자표시 비영리 변경금지 (새창열림)

'Devlopment > Spring' 카테고리의 다른 글

Spring File 읽어오기  (0) 2017.07.01
RestController의 기본 컨텐츠 타입 변경  (0) 2017.03.07
Spring message 설정하기  (0) 2017.02.20
Spring에서 Webjars 사용하기  (0) 2017.02.20
[Spring Security] 필터 Filter, SecurityFilterChain 이해하기  (1) 2017.02.08
Spring Security custom expression  (0) 2017.02.01
Spring Security 관련 레퍼런스 정리  (0) 2017.02.01
Jackson에서 null string 안 보이게 설정  (1) 2016.08.12
JPA Hibernate 사용 중 ORA-00001: 무결성 제약 조건( ORA-00001 에러  (0) 2016.06.07
Spring에서 기본적인 component-scan 설정  (0) 2016.05.23
    'Devlopment/Spring' 카테고리의 다른 글
    • Spring에서 Webjars 사용하기
    • [Spring Security] 필터 Filter, SecurityFilterChain 이해하기
    • Spring Security custom expression
    • Spring Security 관련 레퍼런스 정리
    아틴
    아틴

    티스토리툴바