From 07fce42469f44aa74a2061fb7ac798bfc02e23c0 Mon Sep 17 00:00:00 2001 From: Fabian Nonnenmacher Date: Tue, 26 Jan 2016 14:31:56 +0100 Subject: [PATCH] Changed return type of SystemManagement.getConfigurationValue() * changed Return type to wrapper object, adding additional meta data stored in the database * updated all calls of this method * updated function calls in tests * verified correct execution of correspending tests Signed-off-by: Nonnenmacher Fabian --- .../AmqpControllerAuthentficationTest.java | 26 ++- .../hawkbit/repository/SystemManagement.java | 82 ++++---- .../model/TenantConfigurationValue.java | 179 ++++++++++++++++++ .../repository/SystemManagementTest.java | 18 +- .../model/system/SystemConfigurationRest.java | 160 +--------------- .../hawkbit/rest/resource/SystemMapper.java | 57 +----- .../hawkbit/rest/resource/SystemResource.java | 2 +- ...bstractControllerAuthenticationFilter.java | 2 +- ...thenticatedGatewaySecurityTokenFilter.java | 2 +- ...rPreAuthenticatedSecurityHeaderFilter.java | 2 +- ...AuthenticationTenantConfigurationItem.java | 2 +- ...ficateAuthenticationConfigurationItem.java | 6 +- ...yTokenAuthenticationConfigurationItem.java | 4 +- ...yTokenAuthenticationConfigurationItem.java | 3 +- 14 files changed, 277 insertions(+), 268 deletions(-) create mode 100644 hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java diff --git a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java index 1d962907b..8c4dc07c8 100644 --- a/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java +++ b/hawkbit-dmf-amqp/src/test/java/org/eclipse/hawkbit/amqp/AmqpControllerAuthentficationTest.java @@ -23,6 +23,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken; import org.eclipse.hawkbit.repository.ArtifactManagement; import org.eclipse.hawkbit.repository.ControllerManagement; import org.eclipse.hawkbit.repository.SystemManagement; +import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.security.SecurityContextTenantAware; import org.eclipse.hawkbit.security.SecurityProperties; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; @@ -58,6 +59,12 @@ public class AmqpControllerAuthentficationTest { private SystemManagement systemManagement; private AmqpControllerAuthentfication authenticationManager; + private static final TenantConfigurationValue CONFIG_VALUE_FALSE = TenantConfigurationValue + . builder().value(Boolean.FALSE).build(); + + private static final TenantConfigurationValue CONFIG_VALUE_TRUE = TenantConfigurationValue + . builder().value(Boolean.TRUE).build(); + @Before public void before() throws Exception { amqpMessageHandlerService = new AmqpMessageHandlerService(); @@ -73,7 +80,8 @@ public class AmqpControllerAuthentficationTest { authenticationManager.setSecruityProperties(secruityProperties); systemManagement = mock(SystemManagement.class); authenticationManager.setSystemManagement(systemManagement); - when(systemManagement.getConfigurationValue(any(), any())).thenReturn(Boolean.FALSE); + + when(systemManagement.getConfigurationValue(any(), eq(Boolean.class))).thenReturn(CONFIG_VALUE_FALSE); final ControllerManagement controllerManagement = mock(ControllerManagement.class); when(controllerManagement.getSecurityTokenByControllerId(anyString())).thenReturn(CONTROLLLER_ID); @@ -104,8 +112,8 @@ public class AmqpControllerAuthentficationTest { public void testAuthenticationBadCredantialsWithWrongCredential() { final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); when(systemManagement.getConfigurationValue( - eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any())) - .thenReturn(Boolean.TRUE); + eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) + .thenReturn(CONFIG_VALUE_TRUE); securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); try { authenticationManager.doAuthenticate(securityToken); @@ -121,8 +129,8 @@ public class AmqpControllerAuthentficationTest { public void testSuccessfullAuthentication() { final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); when(systemManagement.getConfigurationValue( - eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any())) - .thenReturn(Boolean.TRUE); + eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) + .thenReturn(CONFIG_VALUE_TRUE); securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); final Authentication authentication = authenticationManager.doAuthenticate(securityToken); assertThat(authentication).isNotNull(); @@ -153,8 +161,8 @@ public class AmqpControllerAuthentficationTest { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); when(systemManagement.getConfigurationValue( - eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any())) - .thenReturn(Boolean.TRUE); + eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) + .thenReturn(CONFIG_VALUE_TRUE); securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken 12" + CONTROLLLER_ID); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); @@ -175,8 +183,8 @@ public class AmqpControllerAuthentficationTest { final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION); final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345"); when(systemManagement.getConfigurationValue( - eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), any())) - .thenReturn(Boolean.TRUE); + eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class))) + .thenReturn(CONFIG_VALUE_TRUE); securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID); final Message message = amqpMessageHandlerService.getMessageConverter().toMessage(securityToken, messageProperties); diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java index bade114d1..8cdc0f980 100644 --- a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/SystemManagement.java @@ -10,7 +10,6 @@ package org.eclipse.hawkbit.repository; import java.lang.reflect.Method; import java.math.BigDecimal; -import java.time.format.DateTimeParseException; import java.util.List; import java.util.stream.Collectors; @@ -21,15 +20,11 @@ import org.eclipse.hawkbit.cache.TenancyCacheManager; import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions; import org.eclipse.hawkbit.report.model.SystemUsageReport; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; -import org.eclipse.hawkbit.repository.exception.InvalidDistributionSetTypeException; -import org.eclipse.hawkbit.repository.exception.InvalidPollingTimeException; import org.eclipse.hawkbit.repository.model.DistributionSetType; import org.eclipse.hawkbit.repository.model.SoftwareModuleType; import org.eclipse.hawkbit.repository.model.TenantConfiguration; +import org.eclipse.hawkbit.repository.model.TenantConfigurationValue; import org.eclipse.hawkbit.repository.model.TenantMetaData; -import org.eclipse.hawkbit.repository.model.helper.DurationHelper; -import org.eclipse.hawkbit.repository.specifications.DistributionSetTypeSpecification; -import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut; import org.eclipse.hawkbit.tenancy.TenantAware; import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey; import org.eclipse.persistence.config.PersistenceUnitProperties; @@ -330,6 +325,8 @@ public class SystemManagement implements EnvironmentAware { * Retrieves a configuration value from the e.g. tenant overwritten * configuration values or in case the tenant does not a have a specific * configuration the global default value hold in the {@link Environment}. + * + * @param * * @param configurationKey * the key of the configuration @@ -345,15 +342,26 @@ public class SystemManagement implements EnvironmentAware { * {@code propertyType} */ @Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()") - public T getConfigurationValue(final TenantConfigurationKey configurationKey, final Class propertyType) { + public TenantConfigurationValue getConfigurationValue(final TenantConfigurationKey configurationKey, + final Class propertyType) { + final TenantConfiguration tenantConfiguration = tenantConfigurationRepository .findByKey(configurationKey.getKeyName()); + if (tenantConfiguration != null) { - return conversionService.convert(tenantConfiguration.getValue(), propertyType); + return TenantConfigurationValue. builder().isGlobal(false).createdBy(tenantConfiguration.getCreatedBy()) + .createdAt(tenantConfiguration.getCreatedAt()) + .lastModifiedAt(tenantConfiguration.getLastModifiedAt()) + .lastModifiedBy(tenantConfiguration.getLastModifiedBy()) + .value(conversionService.convert(tenantConfiguration.getValue(), propertyType)).build(); + } else if (configurationKey.getDefaultKeyName() != null) { - final T defaultKeyNameValue = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType); - return defaultKeyNameValue != null ? defaultKeyNameValue - : conversionService.convert(configurationKey.getDefaultValue(), propertyType); + final T valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType); + + return TenantConfigurationValue. builder().isGlobal(true).createdBy(null).createdAt(null) + .lastModifiedAt(null).lastModifiedBy(null).value(valueInProperties != null ? valueInProperties + : conversionService.convert(configurationKey.getDefaultValue(), propertyType)) + .build(); } return null; } @@ -467,29 +475,33 @@ public class SystemManagement implements EnvironmentAware { } - @Transactional - @Modifying - public void updateTenantConfiguration(SystemConfigurationRequestBodyPut systemConReq) { - - DurationHelper dh = new DurationHelper(); - - TenantMetaData tenantMetaData = getTenantMetadata(); - - String ddstypeKey = systemConReq.getDefaultDistributionSetType(); - - if (distributionSetTypeRepository.findAll(DistributionSetTypeSpecification.byKey(ddstypeKey)).isEmpty()) { - throw new InvalidDistributionSetTypeException( - String.format("The specified default distribution set type %s doe not exist.", ddstypeKey)); - } - - try { - tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime())); - tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime())); - } catch (DateTimeParseException ex) { - throw new InvalidPollingTimeException(ex); - } - - updateTenantMetadata(tenantMetaData); - } + // @Transactional + // @Modifying + // public void updateTenantConfiguration(SystemConfigurationRequestBodyPut + // systemConReq) { + // + // DurationHelper dh = new DurationHelper(); + // + // TenantMetaData tenantMetaData = getTenantMetadata(); + // + // String ddstypeKey = systemConReq.getDefaultDistributionSetType(); + // + // if + // (distributionSetTypeRepository.findAll(DistributionSetTypeSpecification.byKey(ddstypeKey)).isEmpty()) + // { + // throw new InvalidDistributionSetTypeException( + // String.format("The specified default distribution set type %s doe not + // exist.", ddstypeKey)); + // } + // + // try { + // tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime())); + // tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime())); + // } catch (DateTimeParseException ex) { + // throw new InvalidPollingTimeException(ex); + // } + // + // updateTenantMetadata(tenantMetaData); + // } } diff --git a/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java new file mode 100644 index 000000000..140109596 --- /dev/null +++ b/hawkbit-repository/src/main/java/org/eclipse/hawkbit/repository/model/TenantConfigurationValue.java @@ -0,0 +1,179 @@ +package org.eclipse.hawkbit.repository.model; + +/** + * represents a tenant configuration value including some meta data + * + * @param + * type of the configuration value + */ +public class TenantConfigurationValue { + + private TenantConfigurationValue() { + } + + private T value = null; + private boolean isGlobal = true; + private Long lastModifiedAt = null; + private String lastModifiedBy = null; + private Long createdAt = null; + private String createdBy = null; + + /** + * Gets the value. + * + * @return the value + */ + public T getValue() { + return value; + } + + /** + * Checks if is global. + * + * @return true, if is global + */ + public boolean isGlobal() { + return isGlobal; + } + + /** + * Gets the last modified at. + * + * @return the last modified at + */ + public long getLastModifiedAt() { + return lastModifiedAt; + } + + /** + * Gets the last modified by. + * + * @return the last modified by + */ + public String getLastModifiedBy() { + return lastModifiedBy; + } + + /** + * Gets the created at. + * + * @return the created at + */ + public long getCreatedAt() { + return createdAt; + } + + /** + * Gets the created by. + * + * @return the created by + */ + public String getCreatedBy() { + return createdBy; + } + + /** + * Builder. + * + * @param + * the key type + * @return the tenant configuration value builder + */ + public static TenantConfigurationValueBuilder builder() { + + return new TenantConfigurationValueBuilder(); + } + + /** + * builds the tenant configuration value including some meta data + * + * @param + * type of the configuration value + */ + public static class TenantConfigurationValueBuilder { + + private final TenantConfigurationValue configuration = new TenantConfigurationValue<>(); + + /** + * Builds the. + * + * @return the tenant configuration value + */ + public TenantConfigurationValue build() { + return configuration; + } + + /** + * sets the configuration value itself + * + * @param value + * the value + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder value(final T value) { + this.configuration.value = value; + return this; + } + + /** + * set the is global attribute. + * + * @param isGlobal + * true when there is no tenant specific value, false + * otherwise + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder isGlobal(final boolean isGlobal) { + this.configuration.isGlobal = isGlobal; + return this; + } + + /** + * Sets the last modified at attribute + * + * @param lastModifiedAt + * timestamp of last modification + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder lastModifiedAt(final Long lastModifiedAt) { + this.configuration.lastModifiedAt = lastModifiedAt; + return this; + } + + /** + * sets the last modified by attribute + * + * @param lastModifiedBy + * the last modified by + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder lastModifiedBy(final String lastModifiedBy) { + this.configuration.lastModifiedBy = lastModifiedBy; + return this; + } + + /** + * sets the created at attribute + * + * @param createdAt + * defined when the configuration has been created + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder createdAt(final Long createdAt) { + this.configuration.createdAt = createdAt; + return this; + } + + /** + * sets the created by attribute + * + * @param createdBy + * defines by whom the configuration has been created + * @return the tenant configuration value builder + */ + public TenantConfigurationValueBuilder createdBy(final String createdBy) { + this.configuration.createdBy = createdBy; + return this; + } + } +} diff --git a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java index cdb76fd8d..a9461ff39 100644 --- a/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java +++ b/hawkbit-repository/src/test/java/org/eclipse/hawkbit/repository/SystemManagementTest.java @@ -159,7 +159,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { assertThat(envPropertyDefault).isNotNull(); // get the configuration from the system management - final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class); + final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class).getValue(); assertThat(envPropertyDefault).isEqualTo(defaultConfigValue); // update the tenant specific configuration @@ -169,7 +169,8 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue)); // verify that new configuration value is used - final String updatedConfigurationValue = systemManagement.getConfigurationValue(configKey, String.class); + final String updatedConfigurationValue = systemManagement.getConfigurationValue(configKey, String.class) + .getValue(); assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue); assertThat(systemManagement.getTenantConfigurations()).hasSize(1); } @@ -183,11 +184,11 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { // add value first systemManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value1)); - assertThat(systemManagement.getConfigurationValue(configKey, String.class)).isEqualTo(value1); + assertThat(systemManagement.getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value1); // update to value second systemManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value2)); - assertThat(systemManagement.getConfigurationValue(configKey, String.class)).isEqualTo(value2); + assertThat(systemManagement.getConfigurationValue(configKey, String.class).getValue()).isEqualTo(value2); } @Test @@ -197,7 +198,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { final Integer value1 = 123; systemManagement .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1))); - assertThat(systemManagement.getConfigurationValue(configKey, Integer.class)).isEqualTo(value1); + assertThat(systemManagement.getConfigurationValue(configKey, Integer.class).getValue()).isEqualTo(value1); } @Test(expected = ConversionFailedException.class) @@ -219,7 +220,7 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { // gateway token does not have default value so no configuration value // is should be available - final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class); + final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class).getValue(); assertThat(defaultConfigValue).isNull(); // update the tenant specific configuration @@ -229,13 +230,14 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB { .addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue)); // verify that new configuration value is used - final String updatedConfigurationValue = systemManagement.getConfigurationValue(configKey, String.class); + final String updatedConfigurationValue = systemManagement.getConfigurationValue(configKey, String.class) + .getValue(); assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue); // delete the tenant specific configuration systemManagement.deleteConfiguration(configKey); // ensure that now gateway token is set again, because is deleted and // must be null now - assertThat(systemManagement.getConfigurationValue(configKey, String.class)).isNull(); + assertThat(systemManagement.getConfigurationValue(configKey, String.class).getValue()).isNull(); } } diff --git a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java index ee39027a3..a73542afb 100644 --- a/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java +++ b/hawkbit-rest-api/src/main/java/org/eclipse/hawkbit/rest/resource/model/system/SystemConfigurationRest.java @@ -17,161 +17,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; public class SystemConfigurationRest { @JsonProperty - private String pollingTime; - - @JsonProperty - private String pollingOverdueTime; - - @JsonProperty - private String defaultDistributionSetType; - - @JsonProperty - private String createdBy; - - @JsonProperty - private String lastModifiedBy; - - @JsonProperty - private Long createdAt; - - @JsonProperty - private Long lastModifiedAt; - - @JsonProperty - private Map authenticationConfiguration; - - /** - * Gets the polling time. - * - * @return the polling time - */ - public String getPollingTime() { - return pollingTime; - } - - /** - * Sets the polling time. - * - * @param pollingTime - * the new polling time - */ - public void setPollingTime(String pollingTime) { - this.pollingTime = pollingTime; - } - - /** - * Gets the polling overdue time. - * - * @return the polling overdue time - */ - public String getPollingOverdueTime() { - return pollingOverdueTime; - } - - /** - * Sets the polling overdue time. - * - * @param pollingOverdueTime - * the new polling overdue time - */ - public void setPollingOverdueTime(String pollingOverdueTime) { - this.pollingOverdueTime = pollingOverdueTime; - } - - /** - * Gets the default distribution set type. - * - * @return the default distribution set type - */ - public String getDefaultDistributionSetType() { - return defaultDistributionSetType; - } - - /** - * Sets the default distribution set type. - * - * @param defaultDistributionSetType - * the new default distribution set type - */ - public void setDefaultDistributionSetType(String defaultDistributionSetType) { - this.defaultDistributionSetType = defaultDistributionSetType; - } - - /** - * Gets the created by. - * - * @return the created by - */ - public String getCreatedBy() { - return createdBy; - } - - /** - * Sets the created by. - * - * @param createdBy - * the new created by - */ - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - /** - * Gets the last modified by. - * - * @return the last modified by - */ - public String getLastModifiedBy() { - return lastModifiedBy; - } - - /** - * Sets the last modified by. - * - * @param lastModifiedBy - * the new last modified by - */ - public void setLastModifiedBy(String lastModifiedBy) { - this.lastModifiedBy = lastModifiedBy; - } - - /** - * Gets the created at. - * - * @return the created at - */ - public Long getCreatedAt() { - return createdAt; - } - - /** - * Sets the created at. - * - * @param createdAt - * the new created at - */ - public void setCreatedAt(Long createdAt) { - this.createdAt = createdAt; - } - - /** - * Gets the last modified at. - * - * @return the last modified at - */ - public Long getLastModifiedAt() { - return lastModifiedAt; - } - - /** - * Sets the last modified at. - * - * @param lastModifiedAt - * the new last modified at - */ - public void setLastModifiedAt(Long lastModifiedAt) { - this.lastModifiedAt = lastModifiedAt; - } + private Map configuration; /** * Sets the authentication configuration. @@ -180,7 +26,7 @@ public class SystemConfigurationRest { * the authentication configuration */ public void setAuthenticationConfiguration(Map authenticationConfiguration) { - this.authenticationConfiguration = authenticationConfiguration; + this.configuration = authenticationConfiguration; } /** @@ -189,6 +35,6 @@ public class SystemConfigurationRest { * @return the authentication configuration */ public Map getAuthenticationConfiguration() { - return this.authenticationConfiguration; + return this.configuration; } } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java index 47fa24b1b..a09f5fc73 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemMapper.java @@ -3,7 +3,6 @@ package org.eclipse.hawkbit.rest.resource; import java.util.HashMap; import java.util.Map; -import org.eclipse.hawkbit.repository.DistributionSetManagement; import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.model.TenantMetaData; import org.eclipse.hawkbit.repository.model.helper.DurationHelper; @@ -23,65 +22,25 @@ final public class SystemMapper { private static DurationHelper dh = new DurationHelper(); - public static SystemConfigurationRest toResponse(SystemManagement systemManagement) { + public static SystemConfigurationRest toResponse(final SystemManagement systemManagement) { - TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); + final SystemConfigurationRest sysconf = new SystemConfigurationRest(); - SystemConfigurationRest sysconf = new SystemConfigurationRest(); + final Map authconf = new HashMap(); - sysconf.setDefaultDistributionSetType(tenantMetaData.getDefaultDsType().getKey()); - sysconf.setCreatedAt(tenantMetaData.getCreatedAt()); - sysconf.setCreatedBy(tenantMetaData.getCreatedBy()); - sysconf.setLastModifiedAt(tenantMetaData.getLastModifiedAt()); - sysconf.setLastModifiedBy(tenantMetaData.getLastModifiedBy()); - - sysconf.setPollingOverdueTime(dh.durationToFormattedString(tenantMetaData.getPollingOverdueTime())); - sysconf.setPollingTime(dh.durationToFormattedString(tenantMetaData.getPollingTime())); - - Map authconf = new HashMap(); - - for (TenantConfigurationKey key : TenantConfigurationKey.values()) { - Object value; - - switch (key) { - case AUTHENTICATION_MODE_HEADER_ENABLED: - case AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED: - case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED: - value = systemManagement.getConfigurationValue(key, Boolean.class); - break; - case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME: - case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY: - case AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME: - value = systemManagement.getConfigurationValue(key, String.class); - break; - default: - LOG.warn("There is no data type specified for TenantConfigurationKey {}.", key.getKeyName()); - value = systemManagement.getConfigurationValue(key, String.class); - } + for (final TenantConfigurationKey key : TenantConfigurationKey.values()) { + final Object value = systemManagement.getConfigurationValue(key); authconf.put(key.getKeyName(), value); } - sysconf.setAuthenticationConfiguration(authconf); return sysconf; } - public static TenantMetaData fromRequest(SystemManagement systemManagement, - SystemConfigurationRequestBodyPut systemConReq, DistributionSetManagement distributionSetManagement) { - - TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); - - String ddstypeKey = systemConReq.getDefaultDistributionSetType(); - - if (distributionSetManagement.findDistributionSetTypeByKey(ddstypeKey) == null) { - throw new IllegalArgumentException( - String.format("The specified default distribution set type %s doe not exist.", ddstypeKey)); - } - - tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime())); - tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime())); + public static TenantMetaData fromRequest(final SystemManagement systemManagement, + final SystemConfigurationRequestBodyPut systemConReq) { + // TODO return null; - } } diff --git a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java index 129261715..1b805cd43 100644 --- a/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java +++ b/hawkbit-rest-resource/src/main/java/org/eclipse/hawkbit/rest/resource/SystemResource.java @@ -39,7 +39,7 @@ public class SystemResource { public ResponseEntity updateSoftwareModuleType( @RequestBody final SystemConfigurationRequestBodyPut systemConReq) { - systemManagement.updateTenantConfiguration(systemConReq); + // systemManagement.updateTenantConfiguration(systemConReq); return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK); } diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java index bbffc8748..e35ac890b 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/AbstractControllerAuthenticationFilter.java @@ -54,7 +54,7 @@ public abstract class AbstractControllerAuthenticationFilter implements PreAuthe @Override public Boolean run() { LOGGER.trace("retrieving configuration value for configuration key {}", getTenantConfigurationKey()); - return systemManagement.getConfigurationValue(getTenantConfigurationKey(), Boolean.class); + return systemManagement.getConfigurationValue(getTenantConfigurationKey(), Boolean.class).getValue(); } } diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java index 7e8848ed8..1e890e33d 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedGatewaySecurityTokenFilter.java @@ -85,7 +85,7 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra LOGGER.trace("retrieving configuration value for configuration key {}", TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY); return systemManagement.getConfigurationValue( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class); + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue(); } } diff --git a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java index 066efca53..369b618e7 100644 --- a/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java +++ b/hawkbit-security-integration/src/main/java/org/eclipse/hawkbit/security/ControllerPreAuthenticatedSecurityHeaderFilter.java @@ -143,7 +143,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont @Override public String run() { return systemManagement.getConfigurationValue( - TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class); + TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class).getValue(); } } } diff --git a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java index aae5c592d..f71adaaf2 100644 --- a/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java +++ b/hawkbit-ui/src/main/java/org/eclipse/hawkbit/ui/tenantconfiguration/authentication/AbstractAuthenticationTenantConfigurationItem.java @@ -66,7 +66,7 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay */ @Override public boolean isConfigEnabled() { - boolean b = systemManagement.getConfigurationValue(configurationKey, Boolean.class); + final boolean b = systemManagement.getConfigurationValue(configurationKey, Boolean.class).getValue(); return b; } 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 331fc976e..b4210b6fb 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 @@ -153,13 +153,15 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti configurationEnabledChange = false; configurationCaRootAuthorityChanged = false; - configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class); + configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class) + .getValue(); caRootAuthorityTextField.setValue(getCaRootAuthorityValue()); } private String getCaRootAuthorityValue() { return getSystemManagement() - .getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class); + .getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class) + .getValue(); } private void setDetailVisible(final boolean visible) { 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 6ae002263..c9fb175b8 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 @@ -168,12 +168,12 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac private String getSecurityTokenName() { return getSystemManagement().getConfigurationValue( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME, String.class); + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME, String.class).getValue(); } private String getSecurityTokenKey() { return getSystemManagement().getConfigurationValue( - TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class); + TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue(); } @Override 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 683e1cd69..768ee1d92 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 @@ -96,6 +96,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract @Override public void undo() { configurationEnabledChange = false; - configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class); + configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class) + .getValue(); } }