HTTPS login with Spring Security redirects to HTTP

后端 未结 9 1976
梦如初夏
梦如初夏 2021-01-31 02:12

I have a Spring web app, secured with Spring Security, running on EC2. In front of the EC2 instance is an Elastic Load Balancer with an SSL cert (https terminates at the load ba

9条回答
  •  情歌与酒
    2021-01-31 02:38

    Your spring configuration should be agnostic to the used protocol. If you use something like "requires-channel", you'll run into problems sooner or later, especially if you want to deploy the same application to a development environment without https.

    Instead, consider to configure your tomcat properly. You can do this with RemoteIpValve. Depending on which headers the loadbalancer sends, your server.xml configuration needs to contain something like this:

    
    

    Spring will determine the absolute redirect address based on the ServletRequest, so change the httpsServerPort if you are using something else than 443:

    The httpsServerPort is the port returned by ServletRequest.getServerPort() when the protocolHeader indicates https protocol

提交回复
热议问题