【问题标题】:how to redirect the access denied page in spring security?如何在spring security中重定向访问被拒绝页面?
【发布时间】:2012-01-16 02:16:43
【问题描述】:

我想知道如何在spring security中重定向访问被拒绝页面? 我应该使用某种处理程序还是在 web.xml 中进行编辑?

谢谢

【问题讨论】:

    标签: java spring redirect spring-security access-denied


    【解决方案1】:

    您是否阅读过 Spring Security 手册的相关章节,即AccessDeniedHandlernamespace 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/** 不受保护。

    如果这不能回答您的问题,您能否更详细地解释一下您想要实现的目标?

    【讨论】:

    • 我不确定 cmets 是否适合这样说,但您可能会考虑在您的个人资料中说您实际上是 Spring-Security 的开发人员之一。它可以让您对 spring-security 标签的回答更具可信度(您应该拥有 IMO)。
    【解决方案2】:

    为此使用RedirectView

    样本

           return new ModelAndView(new RedirectView(request.getContextPath()+ "urlPath"), modelMap);
    

    或使用redirect: 前缀。

    【讨论】:

      【解决方案3】:

      您想在页面发生异常时重定向页面还是出于安全原因重定向页面。仅当该页面发生异常时才需要处理程序。通过使用处理程序,我们可以重定向到我们所需的目标页面。或者,如果您想每次都重定向到该特定页面以确保安全,我们可以使用 web.xml。

      【讨论】:

      • 我是为了权威。
      猜你喜欢
      • 2012-03-03
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      • 2015-11-13
      • 1970-01-01
      • 2020-12-19
      • 2014-09-25
      • 2023-03-05
      相关资源
      最近更新 更多