简体   繁体   中英

Redirect http to https on spring boot embedded undertow

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?

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()

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.

Imho this is a concern of a reverse proxy that is handling the http traffic before it comes to your application. Would that be an option for you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM