프로그래밍/스프링[Spring]
[스프링] 시큐리티 Access Denied 페이지 설정(자바, XML)
yohoi
2023. 2. 15. 21:50
스프링 시큐리티 Access Denied 페이지 설정 방법
XML에서 설정
http 태그에 access-denied-handler 등록 후 Bean으로 정의
<!-- security:begin -->
<http
...
<access-denied-handler ref="accessDeniedHandler" />
...
</http>
<!-- security:end -->
<beans:bean id="accessDeniedHandler" class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
<beans:property name="errorPage" value="/WEB-INF/views/login/denied.jsp" /> //페이지 경로 설정
</beans:bean>
자바에서 설정
WebSecurityConfigurerAdapter을 구현한 클래스에 accessDeniedPage 설정을 하면 된다.
@Override
protected void configure(HttpSecurity http) throws Exception {
...
http
.exceptionHandling()
.accessDeniedPage("/WEB-INF/views/login/denined.jsp"); //페이지 경로
}