HTTPS login with Spring Security redirects to HTTP

2019-03-09 00:19发布

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 balancer ie. port 443 -> port 80), so from Tomcat's perspective, inbound requests are HTTP.

My login form submits to https, however the subsequent redirect goes to http (success or fail). The authentication was successful, and I can go back to https and I'm logged in.

My login configuration looks like so:

<security:form-login
    default-target-url="/home"
    login-page="/"
    login-processing-url="/processlogin"
    authentication-failure-url="/?login_error=1"/>

What do I need to change to make default-target-url and authentication-failure-url go to https?

  • Tomcat 6
  • Spring Security 3.0.x

8条回答
劳资没心,怎么记你
2楼-- · 2019-03-09 01:08

In my case, I had to REMOVE the property server.use-forward-headers=true.

This is my setup:

Digital Ocean LB --> Kubernetes cluster with Ingress --> Spring boot Application

查看更多
叼着烟拽天下
3楼-- · 2019-03-09 01:09

use below lines of code in web.xml

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Login and Restricted Space URLs</web-resource-name>
    <url-pattern>/j_security_check</url-pattern>
    <url-pattern>/loginpage.rose</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>

it makes forced to use HTTPS.

查看更多
登录 后发表回答