春季安全:在SSL加速器后需要通道 ="https"

8
我们正在使用F5 BIG-IP设备来终止SSL连接,并通过启用了Spring的应用程序使用纯HTTP连接到应用程序服务器。此外,我们配置了F5以发送带有http或https值的X-Forwarded-Proto头。
现在,我们希望通过配置拦截URL来强制使用HTTPS:
<security:intercept-url pattern="/login.action" requires-channel="https" />

但是这只有在Servlet容器中的协议方案是HTTPS时才有效,因此我们需要解释HTTP头。

有什么想法吗?

谢谢 Simon

3个回答

8

继承SecureChannelProcessorInsecureChannelProcessor类并重写decide()方法。您需要复制并粘贴一些代码,例如Secure的代码:

    @Override
    public void decide(FilterInvocation invocation, Collection<ConfigAttribute> config) throws IOException, ServletException {
      Assert.isTrue((invocation != null) && (config != null), 
                       "Nulls cannot be provided");

      for (ConfigAttribute attribute : config) {
          if (supports(attribute)) {
              if (invocation.getHttpRequest().
                      getHeader("X-Forwarded-Proto").equals("http")) {
                  entryPoint.commence(invocation.getRequest(),
                      invocation.getResponse());
              }
          }
      }
    }

然后使用BeanPostProcessor将这些ChannelProcessors设置到 ChannelDecisionManagerImpl bean上。

1

1
我尝试过这个方法,但它似乎只适用于使用嵌入式Tomcat实例的情况,而不是将应用程序部署为WAR文件到外部Tomcat实例上。 - Jason H
按照参考文档的要求,只有通过 extends WebSecurityConfigurerAdapter 的存在,请求才会被重定向到 /login。请勿添加其他内容。 - Chloe

0

这是目前最好的解决方案。 - Fernando Fradegrada
链接已失效。我甚至不知道承认标头与强制SSL有什么关系。 - Chloe

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接