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

@@ -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));
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}
}

View File

@@ -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);
}
}