【问题标题】:How to change HTTP status code when Spring Security's "requires-channel" directive is used?使用 Spring Security 的“requires-channel”指令时如何更改 HTTP 状态码?
【发布时间】:2013-10-15 12:00:39
【问题描述】:

我想强制我的 webapp 下的某些 URL 只能通过 HTTPS 访问,而其余的只能通过 HTTP 访问。我使用以下配置通过 Spring Security 3.1.1 实现了这一点:

<security:intercept-url pattern="/cart" requires-channel="https" />
<security:intercept-url pattern="/login" requires-channel="https" />

使用此配置,当我尝试在 HTTP 下打开“/login”时,我会自动重定向到 HTTPS 下的“/login”,这完全符合要求。问题是状态码 - 使用 302 执行重定向(临时移动)。是否可以将该状态码更改为 301(永久移动)?

【问题讨论】:

    标签: spring spring-mvc spring-security


    【解决方案1】:

    同样的问题已在此处进行了更详细的描述和回答:Override the ChannelProcessingFilter with Spring Security 3.0.5 does not work

    编辑:另一种方法是保留默认的 retryWithHttpEntryPoint 和 retryWithHttpsEntryPoint bean,仅提供自定义 RedirectStrategy 实现。

    【讨论】:

      猜你喜欢
      • 2012-08-03
      • 2015-10-19
      • 1970-01-01
      • 2014-07-24
      • 2011-09-18
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 2016-07-31
      相关资源
      最近更新 更多