Skip to content

spring-boot-SSL/spring-boot-ssl-https

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring Boot Web Application running on both "http" and "https" protocols on different ports
======================================================================
HTTP and https both are not configured in the application.properties file so we need to configure https in the application.properties file and HTTP in code.
For this, we need to perform following operations
1) getting SSL certificate 
2) Enable HTTPS to Spring boot Application
3) Enable HTTP to Spring boot Application

1) getting SSL certificate 
================================================
To get SSL digital certificate for our application we have two options –

1) to create a self-signed certificate
2) to obtain SSL certificate from certification authority(CA) we call it CA certificate.

self-signed certificate generated by java keytool command. 
We need to run the keytool -genkey command from command prompt.
two types of certificate generation 
1)JKS
full command is:-
keytool -genkeypair -alias tomcat -keyalg RSA -keysize 2048 -keystore keystore.jks -validity 3650
2)PKCS12
full command is:-
keytool -genkeypair -alias tomcat -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore keystore.p12 -validity 3650

2) Enable HTTPS to Spring boot Application
==================================================

we need to configure properties in application.properties file
properties are

server.port=8443
server.ssl.key-alias=selfsigned_localhost_sslserver
server.ssl.key-password=changeit
server.ssl.key-store=classpath:ssl-server.jks
server.ssl.key-store-provider=SUN
server.ssl.key-store-type=JKS

3) Enable HTTP to Spring boot Application
====================================================
we need to configure code main application

 @Bean
    public EmbeddedServletContainerFactory servletContainer(){
        TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
        tomcat.addAdditionalTomcatConnectors(httpConnector());
        System.out.println("direct http");
        return tomcat;
    }

    private Connector httpConnector(){
        Connector connector = new Connector(TomcatEmbeddedServletContainerFactory.DEFAULT_PROTOCOL);
        connector.setScheme("http");
        connector.setPort(8080);
        connector.setSecure(false);
        return connector;
    }
    
====================================================
help full web sites are-->
https://howtodoinjava.com/spring-boot/spring-boot-ssl-https-example/
https://memorynotfound.com/spring-boot-configure-tomcat-ssl-https/
https://www.thomasvitale.com/https-spring-boot-ssl-certificate/#more-1193

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages