From 4be880587a2db1bcb3c804617ebf3ccbfe8bc624 Mon Sep 17 00:00:00 2001 From: Fabian Nonnenmacher Date: Thu, 28 Jan 2016 18:16:31 +0100 Subject: [PATCH] Added validation before saving TenantConfiguration and updated tests * run the validation methodes inside the storing methode, to make sure that only valid values are written inside the database * updated TenantConfigurationManagementTest to match the validation * added new Tests to test all validators Signed-off-by: Nonnenmacher Fabian --- .../configuration/TenantConfigurationKey.java | 11 +- .../TenantConfigurationManagement.java | 33 ++-- .../TenantConfigurationManagementTest.java | 164 ++++++++++++++---- .../resources/application-test.properties | 1 + .../resource/SystemManagementResource.java | 17 +- .../PollingConfigurationView.java | 11 +- ...ficateAuthenticationConfigurationItem.java | 8 +- ...yTokenAuthenticationConfigurationItem.java | 18 +- ...yTokenAuthenticationConfigurationItem.java | 4 +- 9 files changed, 193 insertions(+), 74 deletions(-) diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java index 5cc02a91d..632b77b87 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/configuration/TenantConfigurationKey.java @@ -8,6 +8,8 @@ */ package org.eclipse.hawkbit.tenancy.configuration; +import java.util.Arrays; + import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationBooleanValidator; import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator; import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationStringValidator; @@ -19,9 +21,6 @@ import org.springframework.context.ApplicationContext; * An enum which defines the tenant specific configurations which can be * configured for each tenant seperately. * - * - * - * */ public enum TenantConfigurationKey { @@ -150,4 +149,10 @@ public enum TenantConfigurationKey { context.getAutowireCapableBeanFactory().destroyBean(createBean); } } + + public static TenantConfigurationKey fromKeyName(final String keyName) { + + return Arrays.stream(TenantConfigurationKey.values()).filter(conf -> conf.getKeyName().equals(keyName)) + .findFirst().get(); + } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java index 75210d9ef..0837a8d24 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/TenantConfigurationManagement.java @@ -1,13 +1,12 @@ package org.eclipse.hawkbit.repository; -import java.util.List; - import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; +import org.springframework.context.ApplicationContext; import org.springframework.context.EnvironmentAware; import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.support.ConfigurableConversionService; @@ -26,6 +25,9 @@ public class TenantConfigurationManagement implements EnvironmentAware { @Autowired private TenantConfigurationRepository tenantConfigurationRepository; + @Autowired + private ApplicationContext applicationContext; + private final ConfigurableConversionService conversionService = new DefaultConversionService(); private Environment environment; @@ -58,6 +60,11 @@ public class TenantConfigurationManagement implements EnvironmentAware { public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey, final Class propertyType) { + if (configurationKey.getDataType() != propertyType) { + throw new IllegalAccessError(String.format("The key %s does not handle values in the type %s.", + configurationKey.getKeyName(), propertyType)); + } + final TenantConfiguration tenantConfiguration = tenantConfigurationRepository .findByKey(configurationKey.getKeyName()); @@ -90,14 +97,17 @@ public class TenantConfigurationManagement implements EnvironmentAware { @CacheEvict(value = "tenantConfiguration", key = "#tenantConf.getKey()") @Transactional @Modifying - public TenantConfiguration addOrUpdateConfiguration(final TenantConfiguration tenantConf) { - TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConf.getKey()); + public void addOrUpdateConfiguration(final TenantConfigurationKey tenantConfkey, final Object value) { + + tenantConfkey.validate(applicationContext, value); + + TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConfkey.getKeyName()); if (tenantConfiguration != null) { - tenantConfiguration.setValue(tenantConf.getValue()); + tenantConfiguration.setValue(value.toString()); } else { - tenantConfiguration = new TenantConfiguration(tenantConf.getKey(), tenantConf.getValue()); + tenantConfiguration = new TenantConfiguration(tenantConfkey.getKeyName(), value.toString()); } - return tenantConfigurationRepository.save(tenantConfiguration); + tenantConfigurationRepository.save(tenantConfiguration); } /** @@ -113,10 +123,11 @@ public class TenantConfigurationManagement implements EnvironmentAware { tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName()); } - @Transactional - public List getTenantConfigurations() { - return tenantConfigurationRepository.findAll(); - } + // @Transactional + // public List getTenantConfigurations() { + // + // return tenantConfigurationRepository.findAll(); + // } @Override public void setEnvironment(final Environment environment) { diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java index 73130407e..67f6915e1 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/TenantConfigurationManagementTest.java @@ -2,11 +2,17 @@ package org.eclipse.hawkbit.repository; import static org.fest.assertions.api.Assertions.assertThat; +import java.time.Duration; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; +import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; +import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException; import org.junit.Test; -import org.springframework.core.convert.ConversionFailedException; import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Features; @@ -16,70 +22,75 @@ import ru.yandex.qatools.allure.annotations.Stories; @Stories("Tenant Configuration Management") public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB { + final DurationHelper durationHelper = new DurationHelper(); + @Test @Description("Tests that tenant specific configuration can be persisted and in case the tenant does not have specific configuration the default from environment is used instead.") - public void storeTenantSpecificConfiguration() { - final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; + public void storeTenantSpecificConfigurationAsString() { + final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME; final String envPropertyDefault = environment.getProperty(configKey.getDefaultKeyName()); assertThat(envPropertyDefault).isNotNull(); // get the configuration from the system management - final String defaultConfigValue = tenantConfigurationManagement.getConfigurationValue(configKey, String.class) - .getValue(); - assertThat(envPropertyDefault).isEqualTo(defaultConfigValue); + final TenantConfigurationValue defaultConfigValue = tenantConfigurationManagement + .getConfigurationValue(configKey, String.class); + + assertThat(defaultConfigValue.isGlobal()).isEqualTo(true); + assertThat(defaultConfigValue.getValue()).isEqualTo(envPropertyDefault); // update the tenant specific configuration - final String newConfigurationValue = "thisIsAnotherValueForPolling"; - assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue); - tenantConfigurationManagement - .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue)); + final String newConfigurationValue = "thisIsAnotherTokenName"; + assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue.getValue()); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, newConfigurationValue); // verify that new configuration value is used - final String updatedConfigurationValue = tenantConfigurationManagement - .getConfigurationValue(configKey, String.class).getValue(); - assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue); - assertThat(tenantConfigurationManagement.getTenantConfigurations()).hasSize(1); + final TenantConfigurationValue updatedConfigurationValue = tenantConfigurationManagement + .getConfigurationValue(configKey, String.class); + + assertThat(updatedConfigurationValue.isGlobal()).isEqualTo(false); + assertThat(updatedConfigurationValue.getValue()).isEqualTo(newConfigurationValue); + // assertThat(tenantConfigurationManagement.getTenantConfigurations()).hasSize(1); } @Test @Description("Tests that the tenant specific configuration can be updated") public void updateTenantSpecifcConfiguration() { - final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; + final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME; final String value1 = "firstValue"; final String value2 = "secondValue"; // add value first - tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value1)); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1); assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()) .isEqualTo(value1); // update to value second - tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value2)); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2); assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()) .isEqualTo(value2); } @Test @Description("Tests that the configuration value can be converted from String to Integer automatically") - public void tenantConfigurationValueConversion() { + public void storeAndUpdateTenantSpecificConfigurationAsBoolean() { final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; - final Integer value1 = 123; - tenantConfigurationManagement - .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1))); - assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Integer.class).getValue()) + final Boolean value1 = true; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1); + assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue()) .isEqualTo(value1); + final Boolean value2 = false; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2); + assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue()) + .isEqualTo(value2); } - @Test(expected = ConversionFailedException.class) - @Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Integer") - public void wrongTenantConfigurationValueConversionThrowsException() { + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Boolean") + public void wrongTenantConfigurationValueTypeThrowsException() { final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; - final String value1 = "thisIsNotANumber"; + final String value1 = "thisIsNotABoolean"; // add value as String - tenantConfigurationManagement - .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1))); - // try to get it as Integer - tenantConfigurationManagement.getConfigurationValue(configKey, Integer.class); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1); } @Test @@ -96,8 +107,7 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi // update the tenant specific configuration final String newConfigurationValue = "thisIsAnotherValueForPolling"; assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue); - tenantConfigurationManagement - .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue)); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, newConfigurationValue); // verify that new configuration value is used final String updatedConfigurationValue = tenantConfigurationManagement @@ -110,4 +120,92 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi // must be null now assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull(); } + + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Test that an Exception is thrown, when an integer is stored but a string expected.") + public void storesIntegerWhenStringIsExpected() { + final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME; + final Integer wrongDataype = 123; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + } + + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Test that an Exception is thrown, when an integer is stored but a boolean expected.") + public void storesIntegerWhenBooleanIsExpected() { + final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED; + final Integer wrongDataype = 123; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + } + + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Test that an Exception is thrown, when an integer is stored as PollingTime.") + public void storesIntegerWhenPollingIntervalIsExpected() { + final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + final Integer wrongDataype = 123; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongDataype); + } + + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.") + public void storesWrongFormattedStringAsPollingInterval() { + final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + final String wrongFormatted = "wrongFormatted"; + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, wrongFormatted); + } + + @Test(expected = TenantConfigurationValidatorException.class) + @Description("Test that an Exception is thrown, when an invalid formatted string is stored as PollingTime.") + public void storesTooSmallDurationAsPollingInterval() { + final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + + final String tooSmallDuration = durationHelper + .durationToFormattedString(durationHelper.getDurationByTimeValues(0, 0, 1)); + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, tooSmallDuration); + } + + @Test + @Description("Stores a correct formatted PollignTime and reads it again.") + public void storesCorrectDurationAsPollingInterval() { + final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + + final Duration duration = durationHelper.getDurationByTimeValues(1, 2, 0); + assertThat(duration).isEqualTo(Duration.ofHours(1).plusMinutes(2)); + + tenantConfigurationManagement.addOrUpdateConfiguration(configKey, + durationHelper.durationToFormattedString(duration)); + + final String storedDurationString = tenantConfigurationManagement.getConfigurationValue(configKey, String.class) + .getValue(); + assertThat(duration).isEqualTo(durationHelper.formattedStringToDuration(storedDurationString)); + } + + @Test(expected = IllegalAccessError.class) + @Description("Request a config value in a wrong Value") + public void requestConfigValueWithWrongType() { + tenantConfigurationManagement.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, Object.class); + } + + @Test + @Description("Verifies that every TenenatConfiguraationKeyName exists only once") + public void verifyThatAllKeysAreDifferent() { + final Map keynames = new HashMap(); + + Arrays.stream(TenantConfigurationKey.values()).forEach(key -> { + + if (keynames.containsKey(key.getKeyName())) { + throw new IllegalStateException("The key names are not unique"); + } + + keynames.put(key.getKeyName(), null); + }); + } + + @Test + @Description("Get TenantConfigurationKeyByName") + public void getTenantConfigurationKeyByName() { + final TenantConfigurationKey configKey = TenantConfigurationKey.POLLING_TIME_INTERVAL; + + assertThat(TenantConfigurationKey.fromKeyName(configKey.getKeyName())).isEqualTo(configKey); + } + } diff --git a/hawkbit-repository/src/test/resources/application-test.properties b/hawkbit-repository/src/test/resources/application-test.properties index e5fb04a21..8e8169a64 100644 --- a/hawkbit-repository/src/test/resources/application-test.properties +++ b/hawkbit-repository/src/test/resources/application-test.properties @@ -11,6 +11,7 @@ spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value} spring.data.mongodb.port=28017 hawkbit.server.controller.security.authentication.header.enabled=true +hawkbit.server.controller.security.authentication.gatewaytoken.name=TestToken hawkbit.server.artifact.repo.upload.maxFileSize=5MB diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java index b533ff96a..0a430223c 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemManagementResource.java @@ -18,11 +18,11 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.rest.resource.model.system.CacheRest; import org.eclipse.hawkbit.rest.resource.model.system.SystemStatisticsRest; import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationRest; import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest; +import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -147,7 +147,20 @@ public class SystemManagementResource { @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) public ResponseEntity addUpdateConfig(@RequestBody final TenantConfigurationRest configuration, @PathVariable final String key) { - tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue())); + + // TODO Quick and dirty to stay compatible, but these rest interface + // won't be necessary in future + + Object value; + if (configuration.getValue().equals(Boolean.TRUE)) { + value = true; + } else if (configuration.getValue().equals(Boolean.FALSE)) { + value = false; + } else { + value = configuration.getValue(); + } + + tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.fromKeyName(key), value); return ResponseEntity.ok().build(); } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java index 3e3c84fcc..016e5eb6d 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/PollingConfigurationView.java @@ -6,7 +6,6 @@ import javax.annotation.PostConstruct; import org.eclipse.hawkbit.ControllerPollProperties; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -111,16 +110,14 @@ public class PollingConfigurationView extends BaseConfigurationView if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) { tenantPollTime = fieldPollTime.getValue(); - tenantConfigurationManagement.addOrUpdateConfiguration( - new TenantConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL.getKeyName(), - durationHelper.durationToFormattedString(tenantPollTime))); + tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL, + durationHelper.durationToFormattedString(tenantPollTime)); } if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) { tenantOverdueTime = fieldPollingOverdueTime.getValue(); - tenantConfigurationManagement.addOrUpdateConfiguration( - new TenantConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL.getKeyName(), - durationHelper.durationToFormattedString(tenantOverdueTime))); + tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, + durationHelper.durationToFormattedString(tenantOverdueTime)); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java index 0263b202e..cf2744718 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/CertificateAuthenticationConfigurationItem.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.utils.I18N; @@ -134,13 +133,12 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti @Override public void save() { if (configurationEnabledChange) { - getTenantConfigurationManagement().addOrUpdateConfiguration( - new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled))); + getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); } if (configurationCaRootAuthorityChanged) { final String value = caRootAuthorityTextField.getValue() != null ? caRootAuthorityTextField.getValue() : ""; - getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( - TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME.getKeyName(), value)); + getTenantConfigurationManagement() + .addOrUpdateConfiguration(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, value); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java index 556d4e08c..12bfae7c6 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/GatewaySecurityTokenAuthenticationConfigurationItem.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; @@ -189,20 +188,19 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac @Override public void save() { if (configurationEnabledChange) { - getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED.getKeyName(), - String.valueOf(configurationEnabled))); + getTenantConfigurationManagement().addOrUpdateConfiguration( + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, configurationEnabled); } if (keyNameChanged) { - getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME.getKeyName(), - gatewayTokenNameTextField.getValue())); + getTenantConfigurationManagement().addOrUpdateConfiguration( + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME, + gatewayTokenNameTextField.getValue()); } if (keyChanged) { - getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY.getKeyName(), - gatewayTokenkeyLabel.getValue())); + getTenantConfigurationManagement().addOrUpdateConfiguration( + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, + gatewayTokenkeyLabel.getValue()); } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java index 4e9bd0572..616e64769 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/TargetSecurityTokenAuthenticationConfigurationItem.java @@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication; import javax.annotation.PostConstruct; import org.eclipse.hawkbit.repository.TenantConfigurationManagement; -import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.ui.utils.I18N; import org.springframework.beans.factory.annotation.Autowired; @@ -89,8 +88,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract @Override public void save() { if (configurationEnabledChange) { - getTenantConfigurationManagement().addOrUpdateConfiguration( - new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled))); + getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled); } }