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 <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-28 18:16:31 +01:00
committed by Nonnenmacher Fabian
parent d83286c94a
commit 4be880587a
9 changed files with 193 additions and 74 deletions

View File

@@ -8,6 +8,8 @@
*/ */
package org.eclipse.hawkbit.tenancy.configuration; 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.TenantConfigurationBooleanValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator; import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator;
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationStringValidator; 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 * An enum which defines the tenant specific configurations which can be
* configured for each tenant seperately. * configured for each tenant seperately.
* *
*
*
*
*/ */
public enum TenantConfigurationKey { public enum TenantConfigurationKey {
@@ -150,4 +149,10 @@ public enum TenantConfigurationKey {
context.getAutowireCapableBeanFactory().destroyBean(createBean); context.getAutowireCapableBeanFactory().destroyBean(createBean);
} }
} }
public static TenantConfigurationKey fromKeyName(final String keyName) {
return Arrays.stream(TenantConfigurationKey.values()).filter(conf -> conf.getKeyName().equals(keyName))
.findFirst().get();
}
} }

View File

@@ -1,13 +1,12 @@
package org.eclipse.hawkbit.repository; package org.eclipse.hawkbit.repository;
import java.util.List;
import org.eclipse.hawkbit.repository.model.TenantConfiguration; import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
import org.springframework.context.ApplicationContext;
import org.springframework.context.EnvironmentAware; import org.springframework.context.EnvironmentAware;
import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.support.ConfigurableConversionService; import org.springframework.core.convert.support.ConfigurableConversionService;
@@ -26,6 +25,9 @@ public class TenantConfigurationManagement implements EnvironmentAware {
@Autowired @Autowired
private TenantConfigurationRepository tenantConfigurationRepository; private TenantConfigurationRepository tenantConfigurationRepository;
@Autowired
private ApplicationContext applicationContext;
private final ConfigurableConversionService conversionService = new DefaultConversionService(); private final ConfigurableConversionService conversionService = new DefaultConversionService();
private Environment environment; private Environment environment;
@@ -58,6 +60,11 @@ public class TenantConfigurationManagement implements EnvironmentAware {
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey, public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
final Class<T> propertyType) { final Class<T> 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 final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
.findByKey(configurationKey.getKeyName()); .findByKey(configurationKey.getKeyName());
@@ -90,14 +97,17 @@ public class TenantConfigurationManagement implements EnvironmentAware {
@CacheEvict(value = "tenantConfiguration", key = "#tenantConf.getKey()") @CacheEvict(value = "tenantConfiguration", key = "#tenantConf.getKey()")
@Transactional @Transactional
@Modifying @Modifying
public TenantConfiguration addOrUpdateConfiguration(final TenantConfiguration tenantConf) { public void addOrUpdateConfiguration(final TenantConfigurationKey tenantConfkey, final Object value) {
TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConf.getKey());
tenantConfkey.validate(applicationContext, value);
TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConfkey.getKeyName());
if (tenantConfiguration != null) { if (tenantConfiguration != null) {
tenantConfiguration.setValue(tenantConf.getValue()); tenantConfiguration.setValue(value.toString());
} else { } 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()); tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName());
} }
@Transactional // @Transactional
public List<TenantConfiguration> getTenantConfigurations() { // public List<TenantConfiguration> getTenantConfigurations() {
return tenantConfigurationRepository.findAll(); //
} // return tenantConfigurationRepository.findAll();
// }
@Override @Override
public void setEnvironment(final Environment environment) { public void setEnvironment(final Environment environment) {

View File

@@ -2,11 +2,17 @@ package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat; 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.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.TenantConfigurationKey;
import org.eclipse.hawkbit.tenancy.configuration.validator.exceptions.TenantConfigurationValidatorException;
import org.junit.Test; import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import ru.yandex.qatools.allure.annotations.Description; import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features; import ru.yandex.qatools.allure.annotations.Features;
@@ -16,70 +22,75 @@ import ru.yandex.qatools.allure.annotations.Stories;
@Stories("Tenant Configuration Management") @Stories("Tenant Configuration Management")
public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB { public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB {
final DurationHelper durationHelper = new DurationHelper();
@Test @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.") @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() { public void storeTenantSpecificConfigurationAsString() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME;
final String envPropertyDefault = environment.getProperty(configKey.getDefaultKeyName()); final String envPropertyDefault = environment.getProperty(configKey.getDefaultKeyName());
assertThat(envPropertyDefault).isNotNull(); assertThat(envPropertyDefault).isNotNull();
// get the configuration from the system management // get the configuration from the system management
final String defaultConfigValue = tenantConfigurationManagement.getConfigurationValue(configKey, String.class) final TenantConfigurationValue<String> defaultConfigValue = tenantConfigurationManagement
.getValue(); .getConfigurationValue(configKey, String.class);
assertThat(envPropertyDefault).isEqualTo(defaultConfigValue);
assertThat(defaultConfigValue.isGlobal()).isEqualTo(true);
assertThat(defaultConfigValue.getValue()).isEqualTo(envPropertyDefault);
// update the tenant specific configuration // update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling"; final String newConfigurationValue = "thisIsAnotherTokenName";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue); assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue.getValue());
tenantConfigurationManagement tenantConfigurationManagement.addOrUpdateConfiguration(configKey, newConfigurationValue);
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue));
// verify that new configuration value is used // verify that new configuration value is used
final String updatedConfigurationValue = tenantConfigurationManagement final TenantConfigurationValue<String> updatedConfigurationValue = tenantConfigurationManagement
.getConfigurationValue(configKey, String.class).getValue(); .getConfigurationValue(configKey, String.class);
assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue);
assertThat(tenantConfigurationManagement.getTenantConfigurations()).hasSize(1); assertThat(updatedConfigurationValue.isGlobal()).isEqualTo(false);
assertThat(updatedConfigurationValue.getValue()).isEqualTo(newConfigurationValue);
// assertThat(tenantConfigurationManagement.getTenantConfigurations()).hasSize(1);
} }
@Test @Test
@Description("Tests that the tenant specific configuration can be updated") @Description("Tests that the tenant specific configuration can be updated")
public void updateTenantSpecifcConfiguration() { 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 value1 = "firstValue";
final String value2 = "secondValue"; final String value2 = "secondValue";
// add value first // add value first
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value1)); tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()) assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue())
.isEqualTo(value1); .isEqualTo(value1);
// update to value second // update to value second
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value2)); tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2);
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()) assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue())
.isEqualTo(value2); .isEqualTo(value2);
} }
@Test @Test
@Description("Tests that the configuration value can be converted from String to Integer automatically") @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 TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final Integer value1 = 123; final Boolean value1 = true;
tenantConfigurationManagement tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1))); assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue())
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Integer.class).getValue())
.isEqualTo(value1); .isEqualTo(value1);
final Boolean value2 = false;
tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value2);
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, Boolean.class).getValue())
.isEqualTo(value2);
} }
@Test(expected = ConversionFailedException.class) @Test(expected = TenantConfigurationValidatorException.class)
@Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Integer") @Description("Tests that the get configuration throws exception in case the value cannot be automatically converted from String to Boolean")
public void wrongTenantConfigurationValueConversionThrowsException() { public void wrongTenantConfigurationValueTypeThrowsException() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED; final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final String value1 = "thisIsNotANumber"; final String value1 = "thisIsNotABoolean";
// add value as String // add value as String
tenantConfigurationManagement tenantConfigurationManagement.addOrUpdateConfiguration(configKey, value1);
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1)));
// try to get it as Integer
tenantConfigurationManagement.getConfigurationValue(configKey, Integer.class);
} }
@Test @Test
@@ -96,8 +107,7 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
// update the tenant specific configuration // update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling"; final String newConfigurationValue = "thisIsAnotherValueForPolling";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue); assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
tenantConfigurationManagement tenantConfigurationManagement.addOrUpdateConfiguration(configKey, newConfigurationValue);
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue));
// verify that new configuration value is used // verify that new configuration value is used
final String updatedConfigurationValue = tenantConfigurationManagement final String updatedConfigurationValue = tenantConfigurationManagement
@@ -110,4 +120,92 @@ public class TenantConfigurationManagementTest extends AbstractIntegrationTestWi
// must be null now // must be null now
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull(); 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<String, Void> keynames = new HashMap<String, Void>();
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);
}
} }

View File

@@ -11,6 +11,7 @@ spring.data.mongodb.uri=mongodb://localhost/spArtifactRepository${random.value}
spring.data.mongodb.port=28017 spring.data.mongodb.port=28017
hawkbit.server.controller.security.authentication.header.enabled=true hawkbit.server.controller.security.authentication.header.enabled=true
hawkbit.server.controller.security.authentication.gatewaytoken.name=TestToken
hawkbit.server.artifact.repo.upload.maxFileSize=5MB hawkbit.server.artifact.repo.upload.maxFileSize=5MB

View File

@@ -18,11 +18,11 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport;
import org.eclipse.hawkbit.report.model.TenantUsage; import org.eclipse.hawkbit.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; 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.CacheRest;
import org.eclipse.hawkbit.rest.resource.model.system.SystemStatisticsRest; 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.TenantConfigurationRest;
import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest; import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -147,7 +147,20 @@ public class SystemManagementResource {
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN) @PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration, public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration,
@PathVariable final String key) { @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(); return ResponseEntity.ok().build();
} }

View File

@@ -6,7 +6,6 @@ import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ControllerPollProperties; import org.eclipse.hawkbit.ControllerPollProperties;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper; import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
@@ -111,16 +110,14 @@ public class PollingConfigurationView extends BaseConfigurationView
if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) { if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) {
tenantPollTime = fieldPollTime.getValue(); tenantPollTime = fieldPollTime.getValue();
tenantConfigurationManagement.addOrUpdateConfiguration( tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL,
new TenantConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL.getKeyName(), durationHelper.durationToFormattedString(tenantPollTime));
durationHelper.durationToFormattedString(tenantPollTime)));
} }
if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) { if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) {
tenantOverdueTime = fieldPollingOverdueTime.getValue(); tenantOverdueTime = fieldPollingOverdueTime.getValue();
tenantConfigurationManagement.addOrUpdateConfiguration( tenantConfigurationManagement.addOrUpdateConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL,
new TenantConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL.getKeyName(), durationHelper.durationToFormattedString(tenantOverdueTime));
durationHelper.durationToFormattedString(tenantOverdueTime)));
} }
} }

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
@@ -134,13 +133,12 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
@Override @Override
public void save() { public void save() {
if (configurationEnabledChange) { if (configurationEnabledChange) {
getTenantConfigurationManagement().addOrUpdateConfiguration( getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled);
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
} }
if (configurationCaRootAuthorityChanged) { if (configurationCaRootAuthorityChanged) {
final String value = caRootAuthorityTextField.getValue() != null ? caRootAuthorityTextField.getValue() : ""; final String value = caRootAuthorityTextField.getValue() != null ? caRootAuthorityTextField.getValue() : "";
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( getTenantConfigurationManagement()
TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME.getKeyName(), value)); .addOrUpdateConfiguration(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, value);
} }
} }

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.security.SecurityTokenGenerator; import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider; import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
@@ -189,20 +188,19 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
@Override @Override
public void save() { public void save() {
if (configurationEnabledChange) { if (configurationEnabledChange) {
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( getTenantConfigurationManagement().addOrUpdateConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED.getKeyName(), TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, configurationEnabled);
String.valueOf(configurationEnabled)));
} }
if (keyNameChanged) { if (keyNameChanged) {
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( getTenantConfigurationManagement().addOrUpdateConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME.getKeyName(), TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME,
gatewayTokenNameTextField.getValue())); gatewayTokenNameTextField.getValue());
} }
if (keyChanged) { if (keyChanged) {
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration( getTenantConfigurationManagement().addOrUpdateConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY.getKeyName(), TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY,
gatewayTokenkeyLabel.getValue())); gatewayTokenkeyLabel.getValue());
} }
} }

View File

@@ -11,7 +11,6 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement; import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.utils.I18N; import org.eclipse.hawkbit.ui.utils.I18N;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -89,8 +88,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
@Override @Override
public void save() { public void save() {
if (configurationEnabledChange) { if (configurationEnabledChange) {
getTenantConfigurationManagement().addOrUpdateConfiguration( getTenantConfigurationManagement().addOrUpdateConfiguration(getConfigurationKey(), configurationEnabled);
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
} }
} }