diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-26 16:44:16 +0200 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2013-06-26 16:44:38 +0200 |
commit | 1a505a2558ed29f85a756c212429ba89c4a07727 (patch) | |
tree | 1291c801d6dee921dce6441f0bb4e0c27cdec83b /sonar-batch | |
parent | 64c168a91d69a0fcfb69cafba29d3f718437c764 (diff) | |
download | sonarqube-1a505a2558ed29f85a756c212429ba89c4a07727.tar.gz sonarqube-1a505a2558ed29f85a756c212429ba89c4a07727.zip |
SONAR-4061 The property 'sonar.password' is not encryptable
Diffstat (limited to 'sonar-batch')
3 files changed, 16 insertions, 3 deletions
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<String, String> 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"); |