问题
I am using spring boot (1.2.3) and embedded undertow. For security reasons I would prefer to redirect any http request to https but I cannot find an example for doing this.
Here is an example for spring boot and tomcat: Spring boot - Embeded Tomcat HTTP to HTTPS redirect
Does anyone have a solution for doing this with undertow?
回答1:
you could add Spring-Security to your project and then configure Spring-Security to enforce https. You could find a small example in the JavaDoc of
org.springframework.security.config.annotation.web.builders.HttpSecurity#requiresChannel()
回答2:
Actually you're gonna have 2 ports in Spring Boot application, so you will have to create another EmbeddedServletContainerFactory telling the new port either http or https. Once the new port is created you can manage the redirect using Spring Mvc or Spring Security.
来源:https://stackoverflow.com/questions/30645167/redirect-http-to-https-on-spring-boot-embedded-undertow