Show better message for missing config keystore props (#232)
* Show better message for missing config keystore props * Removes unused ExpectedException Fixes #230
This commit is contained in:
committed by
Spencer Gibb
parent
54d55010de
commit
a6b7f70b8e
@@ -63,15 +63,20 @@ public class EncryptionBootstrapConfiguration {
|
||||
@ConditionalOnMissingBean(TextEncryptor.class)
|
||||
public TextEncryptor textEncryptor() {
|
||||
KeyStore keyStore = this.key.getKeyStore();
|
||||
if (keyStore.getLocation() != null && keyStore.getLocation().exists()) {
|
||||
return new RsaSecretEncryptor(
|
||||
new KeyStoreKeyFactory(keyStore.getLocation(),
|
||||
keyStore.getPassword().toCharArray()).getKeyPair(
|
||||
keyStore.getAlias(),
|
||||
keyStore.getSecret().toCharArray()),
|
||||
this.key.getRsa().getAlgorithm(), this.key.getRsa().getSalt(),
|
||||
this.key.getRsa().isStrong());
|
||||
if (keyStore.getLocation() != null) {
|
||||
if (keyStore.getLocation().exists()) {
|
||||
return new RsaSecretEncryptor(
|
||||
new KeyStoreKeyFactory(keyStore.getLocation(),
|
||||
keyStore.getPassword().toCharArray()).getKeyPair(
|
||||
keyStore.getAlias(),
|
||||
keyStore.getSecret().toCharArray()),
|
||||
this.key.getRsa().getAlgorithm(), this.key.getRsa().getSalt(),
|
||||
this.key.getRsa().isStrong());
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Invalid keystore location");
|
||||
}
|
||||
|
||||
return new EncryptorFactory().create(this.key.getKey());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package org.springframework.cloud.bootstrap.encrypt;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.security.crypto.encrypt.TextEncryptor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class EncryptionBootstrapConfigurationTests {
|
||||
|
||||
@Test
|
||||
@@ -35,4 +36,23 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonExistentKeystoreLocationShouldNotBeAllowed() {
|
||||
try {
|
||||
new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(false)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks1",
|
||||
"encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey",
|
||||
"encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
assertThat(false)
|
||||
.as("Should not create an application context with invalid keystore location")
|
||||
.isTrue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).hasRootCauseInstanceOf(IllegalStateException.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user