private void setEncryptedValue(String encryptedValue) { setEncryptedValue(new EncryptedConfigurationValue(encryptedValue)); }
public void clearEmptyConfigurations() { List<ConfigurationProperty> propertiesToRemove = new ArrayList<>(); for (ConfigurationProperty configurationProperty : this) { ConfigurationValue configurationValue = configurationProperty.getConfigurationValue(); EncryptedConfigurationValue encryptedValue = configurationProperty.getEncryptedConfigurationValue(); if (StringUtils.isBlank(configurationProperty.getValue()) && (configurationValue == null || configurationValue.errors().isEmpty()) && (encryptedValue == null || encryptedValue.errors().isEmpty())) { propertiesToRemove.add(configurationProperty); } } this.removeAll(propertiesToRemove); }
public String getEncryptedValue() { return encryptedValue != null ? encryptedValue.getValue() : null; }
public void setConfigAttributes(Object attributes, SecureKeyInfoProvider secureKeyInfoProvider) { Map attributesMap = (Map) attributes; if (attributesMap.containsKey(CONFIGURATION_KEY)) { configurationKey = new ConfigurationKey(); configurationKey.setConfigAttributes(attributesMap.get(CONFIGURATION_KEY)); } if (attributesMap.containsKey(CONFIGURATION_VALUE)) { configurationValue = new ConfigurationValue(""); configurationValue.setConfigAttributes(attributesMap.get(CONFIGURATION_VALUE)); } if (attributesMap.containsKey(ENCRYPTED_VALUE)) { encryptedValue = new EncryptedConfigurationValue(); encryptedValue.setConfigAttributes(attributesMap.get(ENCRYPTED_VALUE)); } if (secureKeyInfoProvider == null) { return; } if (secureKeyInfoProvider.isSecure(configurationKey.getName())) { if (!attributesMap.containsKey(IS_CHANGED)) { setConfigurationValue(null); } else { handleSecureValueConfiguration(true); } } }
@Test public void shouldCheckIfSecureValueFieldHasNoErrors() { EncryptedConfigurationValue encryptedValue = new EncryptedConfigurationValue("encrypted-value"); assertThat(new ConfigurationProperty(new ConfigurationKey("key"), null, encryptedValue, cipher).doesNotHaveErrorsAgainstConfigurationValue(), is(true)); encryptedValue.addError("value", "some-error"); assertThat(new ConfigurationProperty(new ConfigurationKey("key"), null, encryptedValue, cipher).doesNotHaveErrorsAgainstConfigurationValue(), is(false)); }
public void handleSecureValueConfiguration(boolean isSecure) { if (isSecure) { if (configurationValue != null) { try { encryptedValue = new EncryptedConfigurationValue(isEmpty(configurationValue.getValue()) ? "" : cipher.encrypt(configurationValue.getValue())); } catch (CryptoException e) { throw new RuntimeException(e); } configurationValue = null; } } else { encryptedValue = null; } }
public boolean passwordEquals(EncryptedConfigurationValue p1, EncryptedConfigurationValue p2) { if (p1 == null && p2 == null) { return true; } if (p1 == null || p2 == null) { return false; } String password1 = p1.getValue(); String password2 = p2.getValue(); return passwordEquals(password1, password2); }
public boolean doesNotHaveErrorsAgainstConfigurationValue() { if (isSecure()) { List<String> errorsOnValue = getEncryptedConfigurationValue().errors().getAllOn("value"); return errorsOnValue == null || errorsOnValue.isEmpty(); } else { List<String> errorsOnValue = getConfigurationValue().errors().getAllOn("value"); return errorsOnValue == null || errorsOnValue.isEmpty(); } }
configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value"))); } else { configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value")));
public int passwordHashcode(EncryptedConfigurationValue value) { if (value == null) { return 0; } return passwordHashcode(value.getValue()); }
public void addErrorAgainstConfigurationValue(String message) { if (isSecure()) { getEncryptedConfigurationValue().errors().add("value", message); } else { getConfigurationValue().errors().add("value", message); } }
public ConfigurationProperty deserialize(String name, String value, String encryptedValue) { setKey(new ConfigurationKey(name)); if (isNotBlank(value) && isNotBlank(encryptedValue)) { addError("value", "You may only specify `value` or `encrypted_value`, not both!"); addError(ENCRYPTED_VALUE, "You may only specify `value` or `encrypted_value`, not both!"); } if (isNotBlank(encryptedValue)) { setEncryptedValue(new EncryptedConfigurationValue(new GoCipher().maybeReEncryptForPostConstructWithoutExceptions(encryptedValue))); } if (isNotBlank(value)) { setConfigurationValue(new ConfigurationValue(value)); } return this; } }
@PostConstruct public void initialize() { if (configurationValue == null && encryptedValue == null) { configurationValue = new ConfigurationValue(""); } if (encryptedValue != null && isNotBlank(encryptedValue.getValue())) { setEncryptedValue(cipher.maybeReEncryptForPostConstructWithoutExceptions(encryptedValue.getValue())); } }
configuration.getProperty(key).setEncryptedValue(new EncryptedConfigurationValue(configurationMetadata.get("value"))); } else { configuration.getProperty(key).setConfigurationValue(new ConfigurationValue(configurationMetadata.get("value")));
public String getValue() { if (isSecure()) { try { if (isEmpty(encryptedValue.getValue())) { return EMPTY; } return cipher.decrypt(encryptedValue.getValue()); } catch (CryptoException e) { throw new RuntimeException(format("Could not decrypt secure configuration property value for key %s", configurationKey.getName()), e); } } return configurationValue == null ? null : configurationValue.getValue(); }
public void addNewConfiguration(String key, boolean isSecure) { if (isSecure) { add(new ConfigurationProperty(new ConfigurationKey(key), new EncryptedConfigurationValue())); } else { add(new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue())); } }
configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue)); return configurationProperty; configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue)); configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encrypt(value))); if (isNotBlank(encryptedValue)) { configurationProperty.addError("encryptedValue", "encrypted_value cannot be specified to a unsecured property."); configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(encryptedValue)); configurationProperty.setEncryptedValue(new EncryptedConfigurationValue(new GoCipher().maybeReEncryptForPostConstructWithoutExceptions(configurationProperty.getEncryptedValue())));
public void addNewConfigurationWithValue(String key, String value, boolean isSecure) { if (isSecure) { add(new ConfigurationProperty(new ConfigurationKey(key), new EncryptedConfigurationValue(value))); } else { add(new ConfigurationProperty(new ConfigurationKey(key), new ConfigurationValue(value))); } }
@Test public void shouldGetEmptyValueWhenSecurePropertyValueIsNullOrEmpty() throws Exception { assertThat(new ConfigurationProperty(new ConfigurationKey("key"), null, new EncryptedConfigurationValue(""), cipher).getValue(), is("")); assertThat(new ConfigurationProperty(new ConfigurationKey("key"), null, new EncryptedConfigurationValue(null), cipher).getValue(), is("")); verify(cipher, never()).decrypt(anyString()); }
@Test public void shouldGetValueForSecureProperty() throws Exception { when(cipher.decrypt("encrypted-value")).thenReturn("decrypted-value"); ConfigurationProperty configurationProperty = new ConfigurationProperty(new ConfigurationKey("key"), null, new EncryptedConfigurationValue("encrypted-value"), cipher); assertThat(configurationProperty.getValue(), is("decrypted-value")); }