How to redirecting HTTP to HTTPS in Java+How to redirecting HTTP to HTTPS+redirecting HTTP to HTTPS in Spring
ReportPlease briefly explain why you feel this question should be reported .
To redirect – Requests using HTTP (non-secure) for URLs whose transport guarantee is CONFIDENTIAL are automatically redirected to the same URL using HTTPS.
Add the following configuration to your web.xml
<security-constraint>
<web-resource-collection>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Spring
Spring boot SSL Configuration
First we need to configure the copy the generated keystore file (ssl-server.jks
) into the resources
folder and then open the application.properties
and add the below entries.
Configuration with HTTPS
|
Redirect HTTP requests to HTTPS
This is an optional step in case you want to redirect your HTTP traffic to HTTPS, so that the full site becomes secured. To do that in spring boot, we need to add HTTP connector at 8080
port and then we need to set redirect port 8443
. So that any request in 8080
through http, it would be automatically redirected to 8443
and https.
To do that you just need to add below configuration.
|
Build the code with maven
mvn clean install
start the application.
Run and test http://localhost:8080/secured.
** It would be automatically redirected to HTTPS secured URL.
Leave an answer