SSL certificate integration in Spring boot Project

SSL certificate integration

SSL certificate setting applied in application.properties file To generate self signed SSL certificate use following command:

cd src/main/resources
keytool -genkeypair -alias local_ssl -keyalg RSA -keysize 2048 -storetype PKCS12 -keystore local-ssl.p12 -validity 365 -ext san=dns:localhost

Put following code into application.properties file

spring.application.name=ssl-certificate
server.port=8443
#server.port=8080
server.ssl.enabled: true
server.ssl.key-alias: local_ssl
server.ssl.key-store: classpath:local-ssl.p12
server.ssl.key-store-type: PKCS12
server.ssl.key-password: 12345678
server.ssl.key-store-password: 12345678

Open this URL:
https://localhost:8443/

For production use following command and use p12 file in application Convert .crt to .p12

openssl pkcs12 -export -out server.p12 -inkey server.key -in server.crt

Where server.key , is the server key . server.crt is cert file from CA or self sign

you can find source code here:

https://github.com/purab/ssl-certificate-spring-boot

Spring and Gradle – adding to the project WebJars Bootstrap

If you wanted to add bootstrap UI CSS and JS files in thymeleaf then you can use following code:

<link th:href="@{/webjars/bootstrap/5.0.0/css/bootstrap.min.css}"
rel="stylesheet" media="screen" />
<script th:src="@{/webjars/bootstrap/5.0.0/js/bootstrap.min.js}"></script>

If those styles are still not loading then refresh project and if you are using spring security then you need to add following code in your extended class of

WebSecurityConfigurerAdapter
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home","/webjars/**", "/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}

It will solve your issue