我想知道如何在spring security中重定向访问被拒绝页面? 我可以在web.xml中使用某种处理程序或编辑吗?
感谢
答案 0 :(得分:13)
您是否阅读过Spring Security手册的相关章节,即AccessDeniedHandler和namespace appendix。
如果您想要更多控制权,可以使用
<http use-expressions="true">
<intercept-url pattern="/denied/*" access="permitAll" />
<access-denied-handler error-page="/denied">
<!-- The rest of your configuration -->
</http>
/denied
映射到您编写的Web控制器类。确保/denied/**
不受保护。
如果这不能回答你的问题,你能否详细解释一下你想要达到的目标?
答案 1 :(得分:2)
为此目的使用RedirectView
样品
return new ModelAndView(new RedirectView(request.getContextPath()+ "urlPath"), modelMap);
或使用redirect:前缀。
答案 2 :(得分:0)
您是否希望在页面发生跳转时重定向页面,或者您是否因为安全原因而重定向页面。只有在该页面发生异常时才需要处理程序。通过使用处理程序我们可以重定向到我们所需的目标页面。或者,如果您想每次都重定向到该特定页面以获得安全性,我们可以使用web.xml。