Skip to content

eugenelesnov/spring-boot-starter-rest

Repository files navigation

Build Status Conventional Commits

spring-boot-starter-rest

Spring Boot starter provides fast SSL RestTemplate setup for your backend

How to use

  1. Add to your build.gradle:
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
  1. Add dependency (do not forget to change the tag):
dependencies {
    implementation 'com.github.EugeneLesnov:spring-boot-starter-rest:Tag'
}
  1. Provide required SSL properties:
server:
    ssl:
        enabled: true
        key-store: /path/to/key.keystore
        key-store-password: password
        key-alias: alias
        trust-store: /path/to/truststore
        trust-store-password: password
        connection-default-max-per-route: 40 # optional property, defaults to 25
  1. Additionally, you can implement HostnameVerifier interface and make it a bean. Otherwise, starter uses NoopHostnameVerifier instance (verification is off).

Here's a short example:

public class CustomHostnameVerifier implements HostnameVerifier {

    public CustomHostnameVerifier() {}

    @Override
    public boolean verify(String hostname, SSLSession session) {
        // do your verify stuff
        return false;
    }
}

Then:

@Bean
public HostnameVerifier hostnameVerifier() {
    return new CustomHostnameVerifier();
}

How to generate self-signed certificate with keytool ?

1. keytool -genkey -keystore key.keystore -alias certificateAlias -keyalg RSA -keysize 2048 -validity 3950

2. keytool -selfcert -alias certificateAlias -keystore key.keystore -validity 3950

3. keytool -export -alias certificateAlias -keystore key.keystore -rfc -file certificateAlias.cer

4. keytool -importcert -alias certificateAlias -file certificateAlias.cer -keystore truststore