Added specific configuration failure when an encrypt key has not been configured.
@@ -30,6 +30,8 @@ import com.thinkbiganalytics.security.core.encrypt.EncryptedStringDeserializer;
import com.thinkbiganalytics.security.core.encrypt.EncryptionService;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.bootstrap.encrypt.EncryptionBootstrapConfiguration;
@@ -38,6 +40,7 @@ import org.springframework.cloud.bootstrap.encrypt.RsaProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
+import org.springframework.security.crypto.encrypt.TextEncryptor;
/**
*
@@ -47,9 +50,17 @@ import org.springframework.context.annotation.Import;
@Import({ EncryptionBootstrapConfiguration.class })
public class SecurityCoreConfig {
+ @Autowired()
+ private KeyProperties key;
+
@Bean
@ConditionalOnMissingBean
- public EncryptionService encryptionService() {
+ public EncryptionService encryptionService(@Autowired(required=false) TextEncryptor encrypter) {
+ // Special test to see if the missing encryptor was due to a missing encrypt key in the configuration.
+ if (encrypter == null && StringUtils.isBlank(key.getKey())) {
+ throw new IllegalStateException("No encryption/decryption key has been configured - please see configuration documentation");
+ }
+
return new EncryptionService();
}
