Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Running Spring boot application port 8080 on EC2 instance.

AWS ELB configured to redirect

     80 -> 8080
     443 (SSL termination happens here) -> 8080

Application uses Spring Security and if you user arrives to http://example.com it will redirect to . I would like to login page to use SSL.

Spring security snippet:

 http.requiresChannel().antMatchers("/login", "/logout").requiresSecure();

We are running into redirect loop which makes sense.

To Spring Boot application it looks like all requests are made to non-secured port 8080, it redirects to https://example.com, goes through ELB and again gets request on 8080

Any ideas on how to run this with AWS ELB ???

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
2.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Looks like this did the trick:

@Component
public class TomcatCustomizer implements EmbeddedServletContainerCustomizer {

@Override
public void customize(ConfigurableEmbeddedServletContainer container) {
    TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
    tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
        @Override
        public void customize(Connector connector) {
            connector.setSecure(true);  
        }
    });

}

}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...