Spring Security:SSL加速器后面的requires-channel ="https"

sim*_*cen 8 ssl accelerator spring-security

我们正在使用F5 BIG-IP设备终止SSL连接,并通过普通HTTP连接到具有弹簧启用应用程序的应用程序服务器.我们还配置了F5以发送一个以http或https为值的X-Forwarded-Proto标头.

现在我们想通过配置拦截网址来强制执行HTTPS:

<security:intercept-url pattern="/login.action" requires-channel="https" />
Run Code Online (Sandbox Code Playgroud)

但这仅在servlet containter中的协议方案是HTTPS时才有效,因此我们需要解释HTTP头.

知道怎么做吗?

谢谢西蒙

sou*_*ica 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());
              }
          }
      }
    }
Run Code Online (Sandbox Code Playgroud)

然后使用BeanPostProcessor 在ChannelDecisionManagerImpl bean 上设置这些ChannelProcessors .