From 1a505a2558ed29f85a756c212429ba89c4a07727 Mon Sep 17 00:00:00 2001 From: Julien HENRY Date: Wed, 26 Jun 2013 16:44:16 +0200 Subject: SONAR-4061 The property 'sonar.password' is not encryptable --- .../java/org/sonar/batch/bootstrap/BatchSettings.java | 1 + .../org/sonar/batch/bootstrap/BootstrapSettings.java | 17 ++++++++++++++--- .../main/java/org/sonar/batch/scan/ModuleSettings.java | 1 + 3 files changed, 16 insertions(+), 3 deletions(-) (limited to 'sonar-batch') diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java index 17a95e7cfc3..fc2faf0a343 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchSettings.java @@ -50,6 +50,7 @@ public class BatchSettings extends Settings { public BatchSettings(BootstrapSettings bootstrapSettings, PropertyDefinitions propertyDefinitions, ServerClient client, Configuration deprecatedConfiguration) { super(propertyDefinitions); + getEncryption().setPathToSecretKey(bootstrapSettings.property(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.bootstrapSettings = bootstrapSettings; this.client = client; this.deprecatedConfiguration = deprecatedConfiguration; diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapSettings.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapSettings.java index 588ef9c1cb1..4e005a82c7d 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BootstrapSettings.java @@ -21,7 +21,9 @@ package org.sonar.batch.bootstrap; import com.google.common.collect.Maps; import org.codehaus.plexus.util.StringUtils; +import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectReactor; +import org.sonar.api.config.Encryption; import javax.annotation.Nullable; @@ -33,6 +35,7 @@ import java.util.Properties; */ public class BootstrapSettings { private Map properties; + private final Encryption encryption; public BootstrapSettings(BootstrapProperties bootstrapProperties) { this(bootstrapProperties, null); @@ -40,7 +43,6 @@ public class BootstrapSettings { public BootstrapSettings(BootstrapProperties bootstrapProperties, @Nullable ProjectReactor projectReactor) { properties = Maps.newHashMap(); - // order is important -> bottom-up. The last one overrides all the others. properties.putAll(bootstrapProperties.properties()); if (projectReactor != null) { @@ -48,6 +50,7 @@ public class BootstrapSettings { } properties.putAll(System.getenv()); addProperties(System.getProperties()); + encryption = new Encryption(properties.get(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); } private void addProperties(Properties p) { @@ -63,10 +66,18 @@ public class BootstrapSettings { } public String property(String key) { - return properties.get(key); + String value = properties.get(key); + if (value != null && encryption.isEncrypted(value)) { + try { + value = encryption.decrypt(value); + } catch (Exception e) { + throw new IllegalStateException("Fail to decrypt the property " + key + ". Please check your secret key.", e); + } + } + return value; } public String property(String key, String defaultValue) { - return StringUtils.defaultString(properties.get(key), defaultValue); + return StringUtils.defaultString(property(key), defaultValue); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java index 91eb1393100..bae7e8e69ff 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleSettings.java @@ -44,6 +44,7 @@ public class ModuleSettings extends Settings { public ModuleSettings(BatchSettings batchSettings, ProjectDefinition project, Configuration deprecatedCommonsConf) { super(batchSettings.getDefinitions()); + getEncryption().setPathToSecretKey(batchSettings.getString(CoreProperties.ENCRYPTION_SECRET_KEY_PATH)); this.dryRun = "true".equals(batchSettings.getString(CoreProperties.DRY_RUN)); LoggerFactory.getLogger(ModuleSettings.class).info("Load module settings"); -- cgit v1.2.3