How to redirect HTTP requests to HTTPS using Spring Security Java configuration?

前端 未结 1 1368
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-31 11:38

I have a Spring Security version 3.2.3 application that listens to both HTTP and HTTPS. I want any request to the HTTP port to be redirected to HTTPS. How do I configure tha

1条回答
  •  暖寄归人
    2020-12-31 12:42

    Replacing channelSecurity() with requiresChannel() in the code in the question appears to give the desired behaviour. The working code then looks as following:

    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
        protected void configure(HttpSecurity http) {
            http.requiresChannel().anyRequest().requiresSecure();
        }
    }
    

    0 讨论(0)
提交回复
热议问题