public String getDisplayValue() { if (isSecure()) { return "****"; } return getValue(); }
public Map<String, String> getConfigurationAsMap(boolean addSecureFields) { Map<String, String> configurationMap = new LinkedHashMap<>(); for (ConfigurationProperty currentConfiguration : this) { if (addSecureFields || !currentConfiguration.isSecure()) { configurationMap.put(currentConfiguration.getConfigKeyName(), currentConfiguration.getValue()); } } return configurationMap; }
public String forDisplay(List<ConfigurationProperty> propertiesToDisplay) { ArrayList<String> list = new ArrayList<>(); for (ConfigurationProperty property : propertiesToDisplay) { if (!property.isSecure()) { list.add(format("%s=%s", property.getConfigurationKey().getName().toLowerCase(), property.getConfigurationValue().getValue())); } } return format("[%s]", StringUtils.join(list, ", ")); }
public static List<ConfigurationProperty> getConfigurationPropertiesToBeUsedForDisplay(PluginPreferenceStore metadataStore, String pluginId, final Configuration configuration) { List<ConfigurationProperty> keysForDisplay = new ArrayList<>(); boolean pluginDoesNotExist = !metadataStore.hasPreferenceFor(pluginId); for (ConfigurationProperty property : configuration) { boolean isNotASecureProperty = !property.isSecure(); boolean isPartOfIdentity = metadataStore.hasOption(pluginId, property.getConfigurationKey().getName(), PackageConfiguration.PART_OF_IDENTITY); if (isNotASecureProperty && !StringUtils.isBlank(property.getValue()) && (pluginDoesNotExist || isPartOfIdentity)) { keysForDisplay.add(property); } } return keysForDisplay; } }
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(); } }
public void addErrorAgainstConfigurationValue(String message) { if (isSecure()) { getEncryptedConfigurationValue().errors().add("value", message); } else { getConfigurationValue().errors().add("value", message); } }
@Test public void shouldNotClearEncryptedValueWhenWhenNewValueNotProvided() { GoCipher goCipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), null, new EncryptedConfigurationValue("secureValue"), goCipher); property.handleSecureValueConfiguration(true); assertThat(property.isSecure(), is(true)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue(), is(nullValue())); assertThat(property.getEncryptedConfigurationValue(), is(notNullValue())); assertThat(property.getEncryptedValue(), is("secureValue")); }
@Test public void postConstructShouldDoNothingForPluggableTaskWithoutCorrespondingPlugin() throws Exception { ConfigurationProperty configurationProperty = ConfigurationPropertyMother.create("KEY1"); Configuration configuration = new Configuration(configurationProperty); PluggableTask task = new PluggableTask(new PluginConfiguration("abc.def", "1"), configuration); assertFalse(configurationProperty.isSecure()); task.applyPluginMetadata(); assertFalse(configurationProperty.isSecure()); }
@Test public void shouldGetEncryptValueWhenConstructedAsSecure() throws CryptoException { GoCipher goCipher = mock(GoCipher.class); String encryptedText = "encryptedValue"; when(goCipher.encrypt("secureValue")).thenReturn(encryptedText); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue("secureValue"), new EncryptedConfigurationValue("old-encrypted-text"), goCipher); property.handleSecureValueConfiguration(true); assertThat(property.isSecure(), is(true)); assertThat(property.getEncryptedValue(), is(encryptedText)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue(), is(nullValue())); }
@Test public void shouldNotEncryptWhenWhenConstructedAsNotSecure() { GoCipher goCipher = mock(GoCipher.class); ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("secureKey"), new ConfigurationValue("secureValue"), null, goCipher); property.handleSecureValueConfiguration(false); assertThat(property.isSecure(), is(false)); assertThat(property.getConfigurationKey().getName(), is("secureKey")); assertThat(property.getConfigurationValue().getValue(), is("secureValue")); assertThat(property.getEncryptedConfigurationValue(), is(nullValue())); }
@Test public void addConfiguration_shouldIgnoreEncryptionInAbsenceOfCorrespondingConfigurationInStore() throws Exception { AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfo(pluginDescriptor("plugin_id"), new PluggableInstanceSettings(new ArrayList<>()), null, null, null); store.setPluginInfo(pluginInfo); SecurityAuthConfig authConfig = new SecurityAuthConfig("id", "plugin_id"); authConfig.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(authConfig.size(), is(1)); assertFalse(authConfig.first().isSecure()); assertThat(authConfig, contains(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); }
@Test public void addConfiguration_shouldIgnoreEncryptionInAbsenceOfCorrespondingConfigurationInStore() throws Exception { ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), new PluggableInstanceSettings(new ArrayList<>()), null, null, null); store.setPluginInfo(pluginInfo); ElasticProfile profile = new ElasticProfile("id", "plugin_id"); profile.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(profile.size(), is(1)); assertFalse(profile.first().isSecure()); assertThat(profile, contains(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); }
@Test public void addConfiguration_shouldEncryptASecureVariable() throws Exception { PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true)))); AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); SecurityAuthConfig authConfig = new SecurityAuthConfig("id", "plugin_id"); authConfig.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(authConfig.size(), is(1)); assertTrue(authConfig.first().isSecure()); }
@Test public void addConfiguration_shouldEncryptASecureVariable() throws Exception { PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true)))); ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); ElasticProfile profile = new ElasticProfile("id", "plugin_id"); profile.addConfigurations(Arrays.asList(new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass")))); assertThat(profile.size(), is(1)); assertTrue(profile.first().isSecure()); }
@Test public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() { ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); artifactStore.encryptSecureConfigurations(); assertThat(artifactStore.size(), is(1)); assertFalse(artifactStore.first().isSecure()); }
@Test public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() { ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); profile.encryptSecureConfigurations(); assertThat(profile.size(), is(1)); assertFalse(profile.first().isSecure()); }
@Test public void postConstruct_shouldIgnoreEncryptionIfPluginInfoIsNotDefined() throws Exception { SecurityAuthConfig authConfig = new SecurityAuthConfig("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); authConfig.encryptSecureConfigurations(); assertThat(authConfig.size(), is(1)); assertFalse(authConfig.first().isSecure()); }
@Test public void postConstruct_shouldEncryptSecureConfigurations() throws Exception { PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true)))); AuthorizationPluginInfo pluginInfo = new AuthorizationPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); SecurityAuthConfig authConfig = new SecurityAuthConfig("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); authConfig.encryptSecureConfigurations(); assertThat(authConfig.size(), is(1)); assertTrue(authConfig.first().isSecure()); }
@Test public void postConstruct_shouldEncryptSecureConfigurations() { final PluggableInstanceSettings storeConfig = new PluggableInstanceSettings( Arrays.asList(new PluginConfiguration("password", new Metadata(true, true))) ); final ArtifactPluginInfo pluginInfo = new ArtifactPluginInfo(pluginDescriptor("plugin_id"), storeConfig, null, null, null, null); store.setPluginInfo(pluginInfo); ArtifactStore artifactStore = new ArtifactStore("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); artifactStore.encryptSecureConfigurations(); assertThat(artifactStore.size(), is(1)); assertTrue(artifactStore.first().isSecure()); }
@Test public void postConstruct_shouldEncryptSecureConfigurations() { PluggableInstanceSettings profileSettings = new PluggableInstanceSettings(Arrays.asList(new PluginConfiguration("password", new Metadata(true, true)))); ElasticAgentPluginInfo pluginInfo = new ElasticAgentPluginInfo(pluginDescriptor("plugin_id"), profileSettings, null, null, null); store.setPluginInfo(pluginInfo); ElasticProfile profile = new ElasticProfile("id", "plugin_id", new ConfigurationProperty(new ConfigurationKey("password"), new ConfigurationValue("pass"))); profile.encryptSecureConfigurations(); assertThat(profile.size(), is(1)); assertTrue(profile.first().isSecure()); }