Spring Security: requires-channel=“https” behind SSL accelerator

狂风中的少年 提交于 2019-11-28 23:55:43

Subclass SecureChannelProcessor and InsecureChannelProcessor overriding decide(). You'll need to copy and paste some code, for example for 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());
              }
          }
      }
    }

Then set these ChannelProcessors on the ChannelDecisionManagerImpl bean using a BeanPostProcessor.

I know this question/answer is 4 years old, but it help me to find the solution to my problem. But in modern Spring Boot applications, the fix is easier. Just add the following entry in your application.yaml:

server.tomcat.protocol_header: x-forwarded-proto

Mor information here: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html#howto-enable-https

Even simpler nowadays :

server.use-forward-headers: true

Enabled by default for Cloud Foundry and Heroku, but not for others such as AWS.

Documentation (section 73.7) : https://docs.spring.io/spring-boot/docs/1.5.x/reference/html/howto-embedded-servlet-containers.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!