From 094ba10354418ada0cea5f9e22f4487d950bbcd2 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 29 Mar 2019 15:25:14 +0300 Subject: load test key from resources in default configuration --- build.gradle | 18 +----------------- src/main/java/com/juick/server/KeystoreManager.java | 9 +++------ .../server/configuration/BaseWebConfiguration.java | 5 +++-- src/main/resources/juick-test-key.p12 | Bin 0 -> 2389 bytes 4 files changed, 7 insertions(+), 25 deletions(-) create mode 100644 src/main/resources/juick-test-key.p12 diff --git a/build.gradle b/build.gradle index 2be23040..03c59e35 100644 --- a/build.gradle +++ b/build.gradle @@ -186,24 +186,8 @@ bootRun { sourceResources sourceSets.main } -bootRun.dependsOn ':generateDebugKey' compileFrontend.dependsOn 'yarn' processResources.dependsOn 'compileFrontend' sourceCompatibility = JavaVersion.VERSION_11 -targetCompatibility = JavaVersion.VERSION_11 - -class GenKey extends DefaultTask { - @OutputFile - String keystore - - @TaskAction - def generate() { - ant.genkey(alias: "1", keystore: keystore.toString(), storetype: "PKCS12", keyalg: "RSA", storepass: "secret", dname: "CN=localhost", keysize: 2048) - } -} - -task generateDebugKey(type: GenKey) { - keystore = "${projectDir}/juick.p12" -} - +targetCompatibility = JavaVersion.VERSION_11 \ No newline at end of file diff --git a/src/main/java/com/juick/server/KeystoreManager.java b/src/main/java/com/juick/server/KeystoreManager.java index 3ae7b866..61caba82 100644 --- a/src/main/java/com/juick/server/KeystoreManager.java +++ b/src/main/java/com/juick/server/KeystoreManager.java @@ -3,13 +3,10 @@ package com.juick.server; import com.juick.server.api.activity.model.objects.Person; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; +import org.springframework.core.io.Resource; import org.springframework.util.Base64Utils; -import javax.annotation.PostConstruct; import javax.net.ssl.KeyManagerFactory; -import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.security.*; @@ -28,9 +25,9 @@ public class KeystoreManager { private KeyManagerFactory kmf; - public KeystoreManager(String keystore, String keystorePassword) { + public KeystoreManager(Resource keystore, String keystorePassword) { this.keystorePassword = keystorePassword; - try (InputStream ksIs = new FileInputStream(keystore)) { + try (InputStream ksIs = keystore.getInputStream()) { ks = KeyStore.getInstance("PKCS12"); ks.load(ksIs, keystorePassword.toCharArray()); kmf = KeyManagerFactory.getInstance(KeyManagerFactory diff --git a/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java b/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java index c8b88cd1..976602e6 100644 --- a/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java +++ b/src/main/java/com/juick/server/configuration/BaseWebConfiguration.java @@ -23,6 +23,7 @@ import com.overzealous.remark.Remark; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; import org.springframework.scheduling.annotation.SchedulingConfigurer; import org.springframework.scheduling.config.ScheduledTaskRegistrar; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; @@ -40,8 +41,8 @@ import java.util.concurrent.Executors; @Configuration public class BaseWebConfiguration implements WebMvcConfigurer, SchedulingConfigurer { - @Value("${keystore:juick.p12}") - private String keystore; + @Value("${keystore:classpath:juick-test-key.p12}") + private Resource keystore; @Value("${keystore_password:secret}") private String keystorePassword; diff --git a/src/main/resources/juick-test-key.p12 b/src/main/resources/juick-test-key.p12 new file mode 100644 index 00000000..254004ec Binary files /dev/null and b/src/main/resources/juick-test-key.p12 differ -- cgit v1.2.3