Moved tenant configuration functions to new management class

- moved fucntions to TenantConfigurationManagement, for better function capseling
- updated references
- updated references in tests, tests were succesfully

Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
Fabian Nonnenmacher
2016-01-27 17:00:39 +01:00
committed by Nonnenmacher Fabian
parent b56477191a
commit 6cef6aed1a
29 changed files with 466 additions and 373 deletions

View File

@@ -29,6 +29,7 @@ import org.eclipse.hawkbit.im.authentication.TenantUserPasswordAuthenticationTok
import org.eclipse.hawkbit.im.authentication.UserAuthenticationFilter;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.rest.resource.RestConstants;
import org.eclipse.hawkbit.security.ControllerTenantAwareAuthenticationDetailsSource;
import org.eclipse.hawkbit.security.DosFilter;
@@ -119,7 +120,7 @@ public class SecurityManagedConfiguration implements EnvironmentAware {
@Autowired
private ControllerManagement controllerManagement;
@Autowired
private SystemManagement systemManagement;
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private TenantAware tenantAware;
@Autowired
@@ -133,19 +134,19 @@ public class SecurityManagedConfiguration implements EnvironmentAware {
final HttpControllerPreAuthenticatedSecurityHeaderFilter securityHeaderFilter = new HttpControllerPreAuthenticatedSecurityHeaderFilter(
securityConfiguration.getRpCnHeader(), securityConfiguration.getRpSslIssuerHashHeader(),
systemManagement, tenantAware);
tenantConfigurationManagement, tenantAware);
securityHeaderFilter.setAuthenticationManager(authenticationManager());
securityHeaderFilter.setCheckForPrincipalChanges(true);
securityHeaderFilter.setAuthenticationDetailsSource(authenticationDetailsSource);
final HttpControllerPreAuthenticateSecurityTokenFilter securityTokenFilter = new HttpControllerPreAuthenticateSecurityTokenFilter(
systemManagement, tenantAware, controllerManagement);
tenantConfigurationManagement, tenantAware, controllerManagement);
securityTokenFilter.setAuthenticationManager(authenticationManager());
securityTokenFilter.setCheckForPrincipalChanges(true);
securityTokenFilter.setAuthenticationDetailsSource(authenticationDetailsSource);
final HttpControllerPreAuthenticatedGatewaySecurityTokenFilter gatewaySecurityTokenFilter = new HttpControllerPreAuthenticatedGatewaySecurityTokenFilter(
systemManagement, tenantAware);
tenantConfigurationManagement, tenantAware);
gatewaySecurityTokenFilter.setAuthenticationManager(authenticationManager());
gatewaySecurityTokenFilter.setCheckForPrincipalChanges(true);
gatewaySecurityTokenFilter.setAuthenticationDetailsSource(authenticationDetailsSource);

View File

@@ -16,7 +16,7 @@ import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.security.CoapAnonymousPreAuthenticatedFilter;
import org.eclipse.hawkbit.security.ControllerPreAuthenticateSecurityTokenFilter;
import org.eclipse.hawkbit.security.ControllerPreAuthenticatedGatewaySecurityTokenFilter;
@@ -49,7 +49,7 @@ public class AmqpControllerAuthentfication {
private ControllerManagement controllerManagement;
@Autowired
private SystemManagement systemManagement;
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private TenantAware tenantAware;
@@ -74,16 +74,16 @@ public class AmqpControllerAuthentfication {
private void addFilter() {
final ControllerPreAuthenticatedGatewaySecurityTokenFilter gatewaySecurityTokenFilter = new ControllerPreAuthenticatedGatewaySecurityTokenFilter(
systemManagement, tenantAware);
tenantConfigurationManagement, tenantAware);
filterChain.add(gatewaySecurityTokenFilter);
final ControllerPreAuthenticatedSecurityHeaderFilter securityHeaderFilter = new ControllerPreAuthenticatedSecurityHeaderFilter(
secruityProperties.getRpCnHeader(), secruityProperties.getRpSslIssuerHashHeader(), systemManagement,
tenantAware);
secruityProperties.getRpCnHeader(), secruityProperties.getRpSslIssuerHashHeader(),
tenantConfigurationManagement, tenantAware);
filterChain.add(securityHeaderFilter);
final ControllerPreAuthenticateSecurityTokenFilter securityTokenFilter = new ControllerPreAuthenticateSecurityTokenFilter(
systemManagement, controllerManagement, tenantAware);
tenantConfigurationManagement, controllerManagement, tenantAware);
filterChain.add(securityTokenFilter);
filterChain.add(new CoapAnonymousPreAuthenticatedFilter());
@@ -141,8 +141,8 @@ public class AmqpControllerAuthentfication {
this.secruityProperties = secruityProperties;
}
public void setSystemManagement(final SystemManagement systemManagement) {
this.systemManagement = systemManagement;
public void setTenantConfigurationManagement(final TenantConfigurationManagement tenantConfigurationManagement) {
this.tenantConfigurationManagement = tenantConfigurationManagement;
}
public void setTenantAware(final TenantAware tenantAware) {

View File

@@ -22,7 +22,7 @@ import org.eclipse.hawkbit.dmf.json.model.DownloadResponse;
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.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.security.SecurityContextTenantAware;
import org.eclipse.hawkbit.security.SecurityProperties;
@@ -56,7 +56,7 @@ public class AmqpControllerAuthentficationTest {
private static String CONTROLLLER_ID = "123";
private AmqpMessageHandlerService amqpMessageHandlerService;
private MessageConverter messageConverter;
private SystemManagement systemManagement;
private TenantConfigurationManagement tenantConfigurationManagement;
private AmqpControllerAuthentfication authenticationManager;
private static final TenantConfigurationValue<Boolean> CONFIG_VALUE_FALSE = TenantConfigurationValue
@@ -78,10 +78,10 @@ public class AmqpControllerAuthentficationTest {
final SecurityProperties secruityProperties = mock(SecurityProperties.class);
when(secruityProperties.getRpSslIssuerHashHeader()).thenReturn("X-Ssl-Issuer-Hash-%d");
authenticationManager.setSecruityProperties(secruityProperties);
systemManagement = mock(SystemManagement.class);
authenticationManager.setSystemManagement(systemManagement);
tenantConfigurationManagement = mock(TenantConfigurationManagement.class);
authenticationManager.setTenantConfigurationManagement(tenantConfigurationManagement);
when(systemManagement.getConfigurationValue(any(), eq(Boolean.class))).thenReturn(CONFIG_VALUE_FALSE);
when(tenantConfigurationManagement.getConfigurationValue(any(), eq(Boolean.class))).thenReturn(CONFIG_VALUE_FALSE);
final ControllerManagement controllerManagement = mock(ControllerManagement.class);
when(controllerManagement.getSecurityTokenByControllerId(anyString())).thenReturn(CONTROLLLER_ID);
@@ -111,7 +111,7 @@ public class AmqpControllerAuthentficationTest {
@Description("Tests authentication manager without wrong credential")
public void testAuthenticationBadCredantialsWithWrongCredential() {
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
when(systemManagement.getConfigurationValue(
when(tenantConfigurationManagement.getConfigurationValue(
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);
@@ -128,7 +128,7 @@ public class AmqpControllerAuthentficationTest {
@Description("Tests authentication successfull")
public void testSuccessfullAuthentication() {
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
when(systemManagement.getConfigurationValue(
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);
securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID);
@@ -160,7 +160,7 @@ public class AmqpControllerAuthentficationTest {
public void testAuthenticationMessageBadCredantialsWithWrongCredential() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
when(systemManagement.getConfigurationValue(
when(tenantConfigurationManagement.getConfigurationValue(
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);
@@ -182,7 +182,7 @@ public class AmqpControllerAuthentficationTest {
public void testSuccessfullMessageAuthentication() {
final MessageProperties messageProperties = createMessageProperties(MessageType.AUTHENTIFICATION);
final TenantSecruityToken securityToken = new TenantSecruityToken(TENANT, CONTROLLLER_ID, "12345");
when(systemManagement.getConfigurationValue(
when(tenantConfigurationManagement.getConfigurationValue(
eq(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED), eq(Boolean.class)))
.thenReturn(CONFIG_VALUE_TRUE);
securityToken.getHeaders().put(TenantSecruityToken.AUTHORIZATION_HEADER, "TargetToken " + CONTROLLLER_ID);

View File

@@ -18,7 +18,7 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -55,7 +55,7 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
private static final String CONTROLLER_DL_REQUEST_ANT_PATTERN = "/{" + TENANT_PLACE_HOLDER
+ "}/controller/artifacts/v1/**";
protected SystemManagement systemManagement;
protected TenantConfigurationManagement tenantConfigurationManagement;
protected TenantAware tenantAware;
private final AntPathMatcher pathExtractor;
@@ -70,9 +70,9 @@ public abstract class AbstractHttpControllerAuthenticationFilter extends Abstrac
* @param tenantAware
* the tenant aware service
*/
public AbstractHttpControllerAuthenticationFilter(final SystemManagement systemManagement,
public AbstractHttpControllerAuthenticationFilter(final TenantConfigurationManagement tenantConfigurationManagement,
final TenantAware tenantAware) {
this.systemManagement = systemManagement;
this.tenantConfigurationManagement = tenantConfigurationManagement;
this.tenantAware = tenantAware;
pathExtractor = new AntPathMatcher();
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
/**
@@ -45,15 +45,17 @@ public class HttpControllerPreAuthenticateSecurityTokenFilter extends AbstractHt
* the controller management to retrieve the specific target
* security token to verify
*/
public HttpControllerPreAuthenticateSecurityTokenFilter(final SystemManagement systemManagement,
final TenantAware tenantAware, final ControllerManagement controllerManagement) {
super(systemManagement, tenantAware);
public HttpControllerPreAuthenticateSecurityTokenFilter(
final TenantConfigurationManagement tenantConfigurationManagement, final TenantAware tenantAware,
final ControllerManagement controllerManagement) {
super(tenantConfigurationManagement, tenantAware);
this.controllerManagement = controllerManagement;
}
@Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticateSecurityTokenFilter(systemManagement, controllerManagement, tenantAware);
return new ControllerPreAuthenticateSecurityTokenFilter(tenantConfigurationManagement, controllerManagement,
tenantAware);
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
/**
@@ -34,14 +34,14 @@ public class HttpControllerPreAuthenticatedGatewaySecurityTokenFilter
* the tenant aware service to get configuration for the specific
* tenant
*/
public HttpControllerPreAuthenticatedGatewaySecurityTokenFilter(final SystemManagement systemManagement,
final TenantAware tenantAware) {
super(systemManagement, tenantAware);
public HttpControllerPreAuthenticatedGatewaySecurityTokenFilter(
final TenantConfigurationManagement tenantConfigurationManagement, final TenantAware tenantAware) {
super(tenantConfigurationManagement, tenantAware);
}
@Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticatedGatewaySecurityTokenFilter(systemManagement, tenantAware);
return new ControllerPreAuthenticatedGatewaySecurityTokenFilter(tenantConfigurationManagement, tenantAware);
}
}

View File

@@ -8,7 +8,7 @@
*/
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
/**
@@ -44,9 +44,9 @@ public class HttpControllerPreAuthenticatedSecurityHeaderFilter extends Abstract
* tenant
*/
public HttpControllerPreAuthenticatedSecurityHeaderFilter(final String caCommonNameHeader,
final String caAuthorityNameHeader, final SystemManagement systemManagement,
final String caAuthorityNameHeader, final TenantConfigurationManagement tenantConfigurationManagement,
final TenantAware tenantAware) {
super(systemManagement, tenantAware);
super(tenantConfigurationManagement, tenantAware);
this.caCommonNameHeader = caCommonNameHeader;
this.caAuthorityNameHeader = caAuthorityNameHeader;
}
@@ -54,7 +54,7 @@ public class HttpControllerPreAuthenticatedSecurityHeaderFilter extends Abstract
@Override
protected PreAuthenficationFilter createControllerAuthenticationFilter() {
return new ControllerPreAuthenticatedSecurityHeaderFilter(caCommonNameHeader, caAuthorityNameHeader,
systemManagement, tenantAware);
tenantConfigurationManagement, tenantAware);
}
}

View File

@@ -14,17 +14,15 @@ import java.util.Map;
import org.eclipse.hawkbit.aspects.ExceptionMappingAspectHandler;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.model.helper.AfterTransactionCommitExecutorHolder;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.helper.CacheManagerHolder;
import org.eclipse.hawkbit.repository.model.helper.PollConfigurationHelper;
import org.eclipse.hawkbit.repository.model.helper.SecurityTokenGeneratorHolder;
import org.eclipse.hawkbit.repository.model.helper.SystemManagementHolder;
import org.eclipse.hawkbit.repository.model.helper.TenantAwareHolder;
import org.eclipse.hawkbit.security.SecurityTokenGenerator;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@@ -55,21 +53,13 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
/**
* @return simple default {@link AsyncUncaughtExceptionHandler}
* implementation
* @Bean public SimpleAsyncUncaughtExceptionHandler
* simpleAsyncUncaughtExceptionHandler() { return new
* SimpleAsyncUncaughtExceptionHandler(); }
*
* /**
* @return the {@link PollConfigurationHelper} singleton bean which holds
* the polling and polling overdue configuration and make it
* accessible in beans which cannot not be autowired or retrieve
* environment variables due {@link EnvironmentAware} interface.
* @return the {@link TenantConfigurationManagement} singleton bean which
* make it accessible in beans which cannot access the service
* directly, e.g. JPA entities.
*/
@Bean
public PollConfigurationHelper pollConfigurationHelper() {
return PollConfigurationHelper.getInstance();
public TenantConfigurationManagement tenantConfigurationManagement() {
return TenantConfigurationManagement.getInstance();
}
/**
@@ -185,5 +175,4 @@ public class RepositoryApplicationConfiguration extends JpaBaseConfiguration {
public PlatformTransactionManager transactionManager() {
return new MultiTenantJpaTransactionManager();
}
}

View File

@@ -22,11 +22,8 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport;
import org.eclipse.hawkbit.repository.exception.EntityNotFoundException;
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.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
@@ -34,12 +31,7 @@ import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.annotation.Bean;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Service;
@@ -54,7 +46,7 @@ import org.springframework.validation.annotation.Validated;
@Transactional(readOnly = true)
@Validated
@Service
public class SystemManagement implements EnvironmentAware {
public class SystemManagement {
@Autowired
private EntityManager entityManager;
@@ -114,10 +106,6 @@ public class SystemManagement implements EnvironmentAware {
private final ThreadLocal<String> createInitialTenant = new ThreadLocal<>();
private final ConfigurableConversionService conversionService = new DefaultConversionService();
private Environment environment;
/**
* Calculated system usage statistics, both overall for the entire system
* and per tenant;
@@ -321,101 +309,6 @@ public class SystemManagement implements EnvironmentAware {
return tenantMetaDataRepository.save(metaData);
}
/**
* 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 <T>
*
* @param configurationKey
* the key of the configuration
* @param propertyType
* the type of the configuration value, e.g. {@code String.class}
* , {@code Integer.class}, etc
* @return the converted configuration value either from the tenant specific
* configuration stored or from the fallback default values or
* {@code null} in case key has not been configured and not default
* value exists
* @throws ConversionFailedException
* if the property cannot be converted to the given
* {@code propertyType}
*/
@Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()")
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
final Class<T> propertyType) {
final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
.findByKey(configurationKey.getKeyName());
if (tenantConfiguration != null) {
return TenantConfigurationValue.<T> 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 valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType);
return TenantConfigurationValue.<T> builder().isGlobal(true).createdBy(null).createdAt(null)
.lastModifiedAt(null).lastModifiedBy(null).value(valueInProperties != null ? valueInProperties
: conversionService.convert(configurationKey.getDefaultValue(), propertyType))
.build();
}
return null;
}
/**
* Adds or updates a specific configuration for a specific tenant.
*
* @param tenantConf
* the tenant configuration object which contains the key and
* value of the specific configuration to update
* @return the added or updated TenantConfiguration
*/
@CacheEvict(value = "tenantConfiguration", key = "#tenantConf.getKey()")
@Transactional
@Modifying
public TenantConfiguration addOrUpdateConfiguration(final TenantConfiguration tenantConf) {
TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConf.getKey());
if (tenantConfiguration != null) {
tenantConfiguration.setValue(tenantConf.getValue());
} else {
tenantConfiguration = new TenantConfiguration(tenantConf.getKey(), tenantConf.getValue());
}
return tenantConfigurationRepository.save(tenantConfiguration);
}
/**
* Deletes a specific configuration for the current tenant.
*
* @param configurationKey
* the configuration key to be deleted
*/
@CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()")
@Transactional
@Modifying
public void deleteConfiguration(final TenantConfigurationKey configurationKey) {
tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName());
}
@Transactional
public List<TenantConfiguration> getTenantConfigurations() {
return tenantConfigurationRepository.findAll();
}
/*
* (non-Javadoc)
*
* @see org.springframework.context.EnvironmentAware#setEnvironment(org.
* springframework.core.env. Environment)
*/
@Override
public void setEnvironment(final Environment environment) {
this.environment = environment;
}
private DistributionSetType createStandardSoftwareDataSetup() {
// Edge Controller Linux standard setup
@@ -472,36 +365,5 @@ public class SystemManagement implements EnvironmentAware {
return SimpleKeyGenerator.generateKey(initialTenantCreation.toUpperCase(),
initialTenantCreation.toUpperCase());
}
}
// @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);
// }
}

View File

@@ -0,0 +1,125 @@
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.EnvironmentAware;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@Transactional(readOnly = true)
@Validated
public class TenantConfigurationManagement implements EnvironmentAware {
private static final TenantConfigurationManagement INSTANCE = new TenantConfigurationManagement();
@Autowired
private TenantConfigurationRepository tenantConfigurationRepository;
private final ConfigurableConversionService conversionService = new DefaultConversionService();
private Environment environment;
public static TenantConfigurationManagement getInstance() {
return INSTANCE;
}
/**
* 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 <T>
*
* @param configurationKey
* the key of the configuration
* @param propertyType
* the type of the configuration value, e.g. {@code String.class}
* , {@code Integer.class}, etc
* @return the converted configuration value either from the tenant specific
* configuration stored or from the fallback default values or
* {@code null} in case key has not been configured and not default
* value exists
* @throws ConversionFailedException
* if the property cannot be converted to the given
* {@code propertyType}
*/
@Cacheable(value = "tenantConfiguration", key = "#configurationKey.getKeyName()")
public <T> TenantConfigurationValue<T> getConfigurationValue(final TenantConfigurationKey configurationKey,
final Class<T> propertyType) {
final TenantConfiguration tenantConfiguration = tenantConfigurationRepository
.findByKey(configurationKey.getKeyName());
if (tenantConfiguration != null) {
return TenantConfigurationValue.<T> 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 valueInProperties = environment.getProperty(configurationKey.getDefaultKeyName(), propertyType);
return TenantConfigurationValue.<T> builder().isGlobal(true).createdBy(null).createdAt(null)
.lastModifiedAt(null).lastModifiedBy(null).value(valueInProperties != null ? valueInProperties
: conversionService.convert(configurationKey.getDefaultValue(), propertyType))
.build();
}
return null;
}
/**
* Adds or updates a specific configuration for a specific tenant.
*
* @param tenantConf
* the tenant configuration object which contains the key and
* value of the specific configuration to update
* @return the added or updated TenantConfiguration
*/
@CacheEvict(value = "tenantConfiguration", key = "#tenantConf.getKey()")
@Transactional
@Modifying
public TenantConfiguration addOrUpdateConfiguration(final TenantConfiguration tenantConf) {
TenantConfiguration tenantConfiguration = tenantConfigurationRepository.findByKey(tenantConf.getKey());
if (tenantConfiguration != null) {
tenantConfiguration.setValue(tenantConf.getValue());
} else {
tenantConfiguration = new TenantConfiguration(tenantConf.getKey(), tenantConf.getValue());
}
return tenantConfigurationRepository.save(tenantConfiguration);
}
/**
* Deletes a specific configuration for the current tenant.
*
* @param configurationKey
* the configuration key to be deleted
*/
@CacheEvict(value = "tenantConfiguration", key = "#configurationKey.getKeyName()")
@Transactional
@Modifying
public void deleteConfiguration(final TenantConfigurationKey configurationKey) {
tenantConfigurationRepository.deleteByKey(configurationKey.getKeyName());
}
@Transactional
public List<TenantConfiguration> getTenantConfigurations() {
return tenantConfigurationRepository.findAll();
}
@Override
public void setEnvironment(final Environment environment) {
this.environment = environment;
}
}

View File

@@ -38,7 +38,9 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.eclipse.hawkbit.repository.model.helper.PollConfigurationHelper;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.persistence.annotations.CascadeOnDelete;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -120,6 +122,9 @@ public class TargetInfo implements Persistable<Long>, Serializable {
@Column(name = "request_controller_attributes", nullable = false)
private boolean requestControllerAttributes = true;
@Transient
private final DurationHelper durationHelper = new DurationHelper();
/**
* Constructor for {@link TargetStatus}.
*
@@ -316,8 +321,13 @@ public class TargetInfo implements Persistable<Long>, Serializable {
*/
public PollStatus getPollStatus() {
if (lastTargetQuery != null) {
final Duration pollTime = PollConfigurationHelper.getInstance().getPollTimeInterval();
final Duration overdueTime = PollConfigurationHelper.getInstance().getOverduePollTimeInterval();
final Duration pollTime = durationHelper.formattedStringToDuration(TenantConfigurationManagement
.getInstance().getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class)
.getValue());
final Duration overdueTime = durationHelper
.formattedStringToDuration(TenantConfigurationManagement.getInstance()
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class)
.getValue());
final LocalDateTime currentDate = LocalDateTime.now();
final LocalDateTime lastPollDate = LocalDateTime.ofInstant(Instant.ofEpochMilli(lastTargetQuery),
ZoneId.systemDefault());

View File

@@ -41,7 +41,7 @@ public class TenantConfigurationValue<T> {
*
* @return the last modified at
*/
public long getLastModifiedAt() {
public Long getLastModifiedAt() {
return lastModifiedAt;
}
@@ -59,7 +59,7 @@ public class TenantConfigurationValue<T> {
*
* @return the created at
*/
public long getCreatedAt() {
public Long getCreatedAt() {
return createdAt;
}

View File

@@ -42,6 +42,7 @@ import org.eclipse.hawkbit.repository.TargetInfoRepository;
import org.eclipse.hawkbit.repository.TargetManagement;
import org.eclipse.hawkbit.repository.TargetRepository;
import org.eclipse.hawkbit.repository.TargetTagRepository;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.TenantMetaDataRepository;
import org.eclipse.hawkbit.repository.model.DistributionSetType;
import org.eclipse.hawkbit.repository.model.SoftwareModuleType;
@@ -180,6 +181,10 @@ public abstract class AbstractIntegrationTest implements EnvironmentAware {
@Autowired
protected TenantAwareCacheManager cacheManager;
@Autowired
protected TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
protected RolloutManagement rolloutManagement;

View File

@@ -21,10 +21,7 @@ import org.eclipse.hawkbit.report.model.TenantUsage;
import org.eclipse.hawkbit.repository.model.DistributionSet;
import org.eclipse.hawkbit.repository.model.SoftwareModule;
import org.eclipse.hawkbit.repository.model.Target;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
@@ -151,93 +148,4 @@ public class SystemManagementTest extends AbstractIntegrationTestWithMongoDB {
});
}
@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;
final String envPropertyDefault = environment.getProperty(configKey.getDefaultKeyName());
assertThat(envPropertyDefault).isNotNull();
// get the configuration from the system management
final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class).getValue();
assertThat(envPropertyDefault).isEqualTo(defaultConfigValue);
// update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
systemManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue));
// verify that new configuration value is used
final String updatedConfigurationValue = systemManagement.getConfigurationValue(configKey, String.class)
.getValue();
assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue);
assertThat(systemManagement.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 String value1 = "firstValue";
final String value2 = "secondValue";
// add value first
systemManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), 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).getValue()).isEqualTo(value2);
}
@Test
@Description("Tests that the configuration value can be converted from String to Integer automatically")
public void tenantConfigurationValueConversion() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final Integer value1 = 123;
systemManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1)));
assertThat(systemManagement.getConfigurationValue(configKey, Integer.class).getValue()).isEqualTo(value1);
}
@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() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final String value1 = "thisIsNotANumber";
// add value as String
systemManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1)));
// try to get it as Integer
systemManagement.getConfigurationValue(configKey, Integer.class);
}
@Test
@Description("Tests that a deletion of a tenant specific configuration deletes it from the database.")
public void deleteConfigurationReturnNullConfiguration() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY;
// gateway token does not have default value so no configuration value
// is should be available
final String defaultConfigValue = systemManagement.getConfigurationValue(configKey, String.class).getValue();
assertThat(defaultConfigValue).isNull();
// update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
systemManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue));
// verify that new configuration value is used
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).getValue()).isNull();
}
}

View File

@@ -0,0 +1,113 @@
package org.eclipse.hawkbit.repository;
import static org.fest.assertions.api.Assertions.assertThat;
import org.eclipse.hawkbit.AbstractIntegrationTestWithMongoDB;
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.junit.Test;
import org.springframework.core.convert.ConversionFailedException;
import ru.yandex.qatools.allure.annotations.Description;
import ru.yandex.qatools.allure.annotations.Features;
import ru.yandex.qatools.allure.annotations.Stories;
@Features("Component Tests - Repository")
@Stories("Tenant Configuration Management")
public class TenantConfigurationManagementTest extends AbstractIntegrationTestWithMongoDB {
@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;
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);
// update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
tenantConfigurationManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), 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);
}
@Test
@Description("Tests that the tenant specific configuration can be updated")
public void updateTenantSpecifcConfiguration() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final String value1 = "firstValue";
final String value2 = "secondValue";
// add value first
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), value1));
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue())
.isEqualTo(value1);
// update to value second
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), 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() {
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())
.isEqualTo(value1);
}
@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() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED;
final String value1 = "thisIsNotANumber";
// add value as String
tenantConfigurationManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), String.valueOf(value1)));
// try to get it as Integer
tenantConfigurationManagement.getConfigurationValue(configKey, Integer.class);
}
@Test
@Description("Tests that a deletion of a tenant specific configuration deletes it from the database.")
public void deleteConfigurationReturnNullConfiguration() {
final TenantConfigurationKey configKey = TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY;
// gateway token does not have default value so no configuration value
// is should be available
final String defaultConfigValue = tenantConfigurationManagement.getConfigurationValue(configKey, String.class)
.getValue();
assertThat(defaultConfigValue).isNull();
// update the tenant specific configuration
final String newConfigurationValue = "thisIsAnotherValueForPolling";
assertThat(newConfigurationValue).isNotEqualTo(defaultConfigValue);
tenantConfigurationManagement
.addOrUpdateConfiguration(new TenantConfiguration(configKey.getKeyName(), newConfigurationValue));
// verify that new configuration value is used
final String updatedConfigurationValue = tenantConfigurationManagement
.getConfigurationValue(configKey, String.class).getValue();
assertThat(updatedConfigurationValue).isEqualTo(newConfigurationValue);
// delete the tenant specific configuration
tenantConfigurationManagement.deleteConfiguration(configKey);
// ensure that now gateway token is set again, because is deleted and
// must be null now
assertThat(tenantConfigurationManagement.getConfigurationValue(configKey, String.class).getValue()).isNull();
}
}

View File

@@ -17,16 +17,16 @@ import com.fasterxml.jackson.annotation.JsonProperty;
public class SystemConfigurationRest {
@JsonProperty
private Map<String, Object> configuration;
private Map<String, TenantConfigurationValueRest> configuration;
/**
* Sets the authentication configuration.
*
* @param authenticationConfiguration
* @param configuration
* the authentication configuration
*/
public void setAuthenticationConfiguration(Map<String, Object> authenticationConfiguration) {
this.configuration = authenticationConfiguration;
public void setConfiguration(final Map<String, TenantConfigurationValueRest> configuration) {
this.configuration = configuration;
}
/**
@@ -34,7 +34,7 @@ public class SystemConfigurationRest {
*
* @return the authentication configuration
*/
public Map<String, Object> getAuthenticationConfiguration() {
public Map<String, TenantConfigurationValueRest> getConfiguration() {
return this.configuration;
}
}

View File

@@ -0,0 +1,60 @@
package org.eclipse.hawkbit.rest.resource.model.system;
public class TenantConfigurationValueRest {
private Object value = null;
private boolean isGlobal = true;
private Long lastModifiedAt = null;
private String lastModifiedBy = null;
private Long createdAt = null;
private String createdBy = null;
public Object getValue() {
return value;
}
public void setValue(final Object value) {
this.value = value;
}
public boolean isGlobal() {
return isGlobal;
}
public void setGlobal(final boolean isGlobal) {
this.isGlobal = isGlobal;
}
public Long getLastModifiedAt() {
return lastModifiedAt;
}
public void setLastModifiedAt(final Long lastModifiedAt) {
this.lastModifiedAt = lastModifiedAt;
}
public String getLastModifiedBy() {
return lastModifiedBy;
}
public void setLastModifiedBy(final String lastModifiedBy) {
this.lastModifiedBy = lastModifiedBy;
}
public Long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(final Long createdAt) {
this.createdAt = createdAt;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(final String createdBy) {
this.createdBy = createdBy;
}
}

View File

@@ -17,10 +17,11 @@ import org.eclipse.hawkbit.im.authentication.SpPermission.SpringEvalExpressions;
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.AuthenticationConfigurationRest;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -53,6 +54,9 @@ public class SystemManagementResource {
@Autowired
private SystemManagement systemManagement;
@Autowired
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private CacheManager cacheManager;
@@ -141,9 +145,9 @@ public class SystemManagementResource {
*/
@RequestMapping(method = RequestMethod.PUT, value = "/conf/{key}")
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
public ResponseEntity<Void> addUpdateConfig(@RequestBody final AuthenticationConfigurationRest configuration,
public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration,
@PathVariable final String key) {
systemManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
tenantConfigurationManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
return ResponseEntity.ok().build();
}

View File

@@ -3,11 +3,11 @@ package org.eclipse.hawkbit.rest.resource;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.model.TenantMetaData;
import org.eclipse.hawkbit.repository.model.helper.DurationHelper;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.repository.model.TenantConfigurationValue;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationValueRest;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -22,25 +22,33 @@ final public class SystemMapper {
private static DurationHelper dh = new DurationHelper();
public static SystemConfigurationRest toResponse(final SystemManagement systemManagement) {
public static SystemConfigurationRest toResponse(
final TenantConfigurationManagement tenantConfigurationManagement) {
final SystemConfigurationRest sysconf = new SystemConfigurationRest();
final Map<String, Object> authconf = new HashMap<String, Object>();
final Map<String, TenantConfigurationValueRest> authconf = new HashMap<String, TenantConfigurationValueRest>();
for (final TenantConfigurationKey key : TenantConfigurationKey.values()) {
final Object value = systemManagement.getConfigurationValue(key);
final TenantConfigurationValueRest value = toResponse(
tenantConfigurationManagement.getConfigurationValue(key, key.getDataType()));
authconf.put(key.getKeyName(), value);
}
sysconf.setAuthenticationConfiguration(authconf);
sysconf.setConfiguration(authconf);
return sysconf;
}
public static TenantMetaData fromRequest(final SystemManagement systemManagement,
final SystemConfigurationRequestBodyPut systemConReq) {
public static TenantConfigurationValueRest toResponse(final TenantConfigurationValue<?> confValue) {
final TenantConfigurationValueRest response = new TenantConfigurationValueRest();
// TODO
return null;
response.setValue(confValue.getValue());
response.setGlobal(confValue.isGlobal());
response.setCreatedAt(confValue.getCreatedAt());
response.setCreatedBy(confValue.getCreatedBy());
response.setLastModifiedAt(confValue.getLastModifiedAt());
response.setLastModifiedBy(confValue.getLastModifiedBy());
return response;
}
}

View File

@@ -1,7 +1,7 @@
package org.eclipse.hawkbit.rest.resource;
import org.eclipse.hawkbit.repository.DistributionSetManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
import org.slf4j.Logger;
@@ -22,7 +22,7 @@ public class SystemResource {
private static final Logger LOGGER = LoggerFactory.getLogger(SystemResource.class);
@Autowired
private SystemManagement systemManagement;
private TenantConfigurationManagement tenantConfigurationManagement;
@Autowired
private DistributionSetManagement distributionSetManagement;
@@ -30,8 +30,7 @@ public class SystemResource {
@RequestMapping(method = RequestMethod.GET, value = "/conf", produces = { "application/hal+json",
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<SystemConfigurationRest> getSystemConfiguration() {
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
}
@RequestMapping(method = RequestMethod.PUT, value = "/conf", consumes = { "application/hal+json",
@@ -41,7 +40,7 @@ public class SystemResource {
// systemManagement.updateTenantConfiguration(systemConReq);
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
return new ResponseEntity<>(SystemMapper.toResponse(tenantConfigurationManagement), HttpStatus.OK);
}
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
@@ -26,13 +26,13 @@ public abstract class AbstractControllerAuthenticationFilter implements PreAuthe
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractControllerAuthenticationFilter.class);
protected final SystemManagement systemManagement;
protected final TenantConfigurationManagement tenantConfigurationManagement;
protected final TenantAware tenantAware;
private final SecurityConfigurationKeyTenantRunner configurationKeyTenantRunner;
protected AbstractControllerAuthenticationFilter(final SystemManagement systemManagement,
protected AbstractControllerAuthenticationFilter(final TenantConfigurationManagement systemManagement,
final TenantAware tenantAware) {
this.systemManagement = systemManagement;
this.tenantConfigurationManagement = systemManagement;
this.tenantAware = tenantAware;
this.configurationKeyTenantRunner = new SecurityConfigurationKeyTenantRunner();
}
@@ -54,7 +54,8 @@ 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).getValue();
return tenantConfigurationManagement.getConfigurationValue(getTenantConfigurationKey(), Boolean.class)
.getValue();
}
}

View File

@@ -12,7 +12,7 @@ import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.im.authentication.SpPermission;
import org.eclipse.hawkbit.im.authentication.TenantAwareAuthenticationDetails;
import org.eclipse.hawkbit.repository.ControllerManagement;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
@@ -55,9 +55,10 @@ public class ControllerPreAuthenticateSecurityTokenFilter extends AbstractContro
* the tenant aware service to get configuration for the specific
* tenant
*/
public ControllerPreAuthenticateSecurityTokenFilter(final SystemManagement systemManagement,
public ControllerPreAuthenticateSecurityTokenFilter(
final TenantConfigurationManagement tenantConfigurationManagement,
final ControllerManagement controllerManagement, final TenantAware tenantAware) {
super(systemManagement, tenantAware);
super(tenantConfigurationManagement, tenantAware);
this.controllerManagement = controllerManagement;
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
@@ -46,9 +46,9 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra
* the tenant aware service to get configuration for the specific
* tenant
*/
public ControllerPreAuthenticatedGatewaySecurityTokenFilter(final SystemManagement systemManagement,
final TenantAware tenantAware) {
super(systemManagement, tenantAware);
public ControllerPreAuthenticatedGatewaySecurityTokenFilter(
final TenantConfigurationManagement tenantConfigurationManagement, final TenantAware tenantAware) {
super(tenantConfigurationManagement, tenantAware);
}
@Override
@@ -84,7 +84,7 @@ public class ControllerPreAuthenticatedGatewaySecurityTokenFilter extends Abstra
public String run() {
LOGGER.trace("retrieving configuration value for configuration key {}",
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY);
return systemManagement.getConfigurationValue(
return tenantConfigurationManagement.getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue();
}
}

View File

@@ -9,7 +9,7 @@
package org.eclipse.hawkbit.security;
import org.eclipse.hawkbit.dmf.json.model.TenantSecruityToken;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.TenantAware;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.slf4j.Logger;
@@ -65,9 +65,9 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
* tenant
*/
public ControllerPreAuthenticatedSecurityHeaderFilter(final String caCommonNameHeader,
final String caAuthorityNameHeader, final SystemManagement systemManagement,
final String caAuthorityNameHeader, final TenantConfigurationManagement tenantConfigurationManagement,
final TenantAware tenantAware) {
super(systemManagement, tenantAware);
super(tenantConfigurationManagement, tenantAware);
this.caCommonNameHeader = caCommonNameHeader;
this.sslIssuerHashBasicHeader = caAuthorityNameHeader;
}
@@ -142,7 +142,7 @@ public class ControllerPreAuthenticatedSecurityHeaderFilter extends AbstractCont
private final class GetSecurityAuthorityNameTenantRunner implements TenantAware.TenantRunner<String> {
@Override
public String run() {
return systemManagement.getConfigurationValue(
return tenantConfigurationManagement.getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class).getValue();
}
}

View File

@@ -5,10 +5,10 @@ import java.time.Duration;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.ControllerPollProperties;
import org.eclipse.hawkbit.repository.SystemManagement;
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.helper.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.DurationHelper;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.tenantconfiguration.polling.DurationConfigField;
import org.eclipse.hawkbit.ui.utils.I18N;
@@ -40,7 +40,7 @@ public class PollingConfigurationView extends BaseConfigurationView
private ControllerPollProperties controllerPollProperties;
@Autowired
private transient SystemManagement systemManagement;
private transient TenantConfigurationManagement tenantConfigurationManagement;
private DurationConfigField fieldPollTime = null;
private DurationConfigField fieldPollingOverdueTime = null;
@@ -66,13 +66,13 @@ public class PollingConfigurationView extends BaseConfigurationView
globalPollTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingTime());
globalOverdueTime = durationHelper.formattedStringToDuration(controllerPollProperties.getPollingOverdueTime());
final TenantConfigurationValue<String> pollTimeConfValue = systemManagement
final TenantConfigurationValue<String> pollTimeConfValue = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.POLLING_TIME_INTERVAL, String.class);
if (!pollTimeConfValue.isGlobal()) {
tenantPollTime = durationHelper.formattedStringToDuration(pollTimeConfValue.getValue());
}
final TenantConfigurationValue<String> overdueTimeConfValue = systemManagement
final TenantConfigurationValue<String> overdueTimeConfValue = tenantConfigurationManagement
.getConfigurationValue(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL, String.class);
if (!overdueTimeConfValue.isGlobal()) {
tenantOverdueTime = durationHelper.formattedStringToDuration(overdueTimeConfValue.getValue());
@@ -97,7 +97,7 @@ public class PollingConfigurationView extends BaseConfigurationView
fieldPollingOverdueTime = DurationConfigField.builder().caption(i18n.get("configuration.polling.overduetime"))
.checkBoxLabel(i18n.get("configuration.polling.custom.value")).range(minDuration, maxDuration)
.globalDuration(globalPollTime).tenantDuration(tenantOverdueTime).build();
.globalDuration(globalOverdueTime).tenantDuration(tenantOverdueTime).build();
fieldPollingOverdueTime.addChangeListener(this);
vLayout.addComponent(fieldPollingOverdueTime);
@@ -111,14 +111,14 @@ public class PollingConfigurationView extends BaseConfigurationView
if (!compareDurations(tenantPollTime, fieldPollTime.getValue())) {
tenantPollTime = fieldPollTime.getValue();
systemManagement.addOrUpdateConfiguration(
tenantConfigurationManagement.addOrUpdateConfiguration(
new TenantConfiguration(TenantConfigurationKey.POLLING_TIME_INTERVAL.getKeyName(),
durationHelper.durationToFormattedString(tenantPollTime)));
}
if (!compareDurations(tenantOverdueTime, fieldPollingOverdueTime.getValue())) {
tenantOverdueTime = fieldPollingOverdueTime.getValue();
systemManagement.addOrUpdateConfiguration(
tenantConfigurationManagement.addOrUpdateConfiguration(
new TenantConfiguration(TenantConfigurationKey.POLLING_OVERDUE_TIME_INTERVAL.getKeyName(),
durationHelper.durationToFormattedString(tenantOverdueTime)));
}

View File

@@ -11,7 +11,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.hawkbit.repository.SystemManagement;
import org.eclipse.hawkbit.repository.TenantConfigurationManagement;
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
import org.eclipse.hawkbit.ui.components.SPUIComponentProvider;
import org.eclipse.hawkbit.ui.utils.SPUILabelDefinitions;
@@ -34,20 +34,21 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay
private static final long serialVersionUID = 1L;
private final TenantConfigurationKey configurationKey;
private final transient SystemManagement systemManagement;
private final transient TenantConfigurationManagement tenantConfigurationManagement;
private final List<ConfigurationItemChangeListener> configurationChangeListeners = new ArrayList<>();
/**
* @param configurationKey
* the key for this configuration
* @param systemManagement
* the system management to retrive the configuration value
* @param tenantConfigurationManagement
* the tenant configuration management to retrieve the
* configuration value
*/
public AbstractAuthenticationTenantConfigurationItem(final TenantConfigurationKey configurationKey,
final SystemManagement systemManagement) {
final TenantConfigurationManagement tenantConfigurationManagement) {
this.configurationKey = configurationKey;
this.systemManagement = systemManagement;
this.tenantConfigurationManagement = tenantConfigurationManagement;
}
/**
@@ -66,15 +67,16 @@ abstract class AbstractAuthenticationTenantConfigurationItem extends VerticalLay
*/
@Override
public boolean isConfigEnabled() {
final boolean b = systemManagement.getConfigurationValue(configurationKey, Boolean.class).getValue();
final boolean b = tenantConfigurationManagement.getConfigurationValue(configurationKey, Boolean.class)
.getValue();
return b;
}
/**
* @return the systemManagement
*/
protected SystemManagement getSystemManagement() {
return systemManagement;
protected TenantConfigurationManagement getTenantConfigurationManagement() {
return tenantConfigurationManagement;
}
/**

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
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;
@@ -54,8 +54,9 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
* the system management to retrie the configuration
*/
@Autowired
public CertificateAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED, systemManagement);
public CertificateAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_ENABLED, tenantConfigurationManagement);
}
/**
@@ -133,12 +134,12 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
}
if (configurationCaRootAuthorityChanged) {
final String value = caRootAuthorityTextField.getValue() != null ? caRootAuthorityTextField.getValue() : "";
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME.getKeyName(), value));
}
}
@@ -153,13 +154,13 @@ public class CertificateAuthenticationConfigurationItem extends AbstractAuthenti
configurationEnabledChange = false;
configurationCaRootAuthorityChanged = false;
configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class)
.getValue();
configurationEnabled = getTenantConfigurationManagement()
.getConfigurationValue(getConfigurationKey(), Boolean.class).getValue();
caRootAuthorityTextField.setValue(getCaRootAuthorityValue());
}
private String getCaRootAuthorityValue() {
return getSystemManagement()
return getTenantConfigurationManagement()
.getConfigurationValue(TenantConfigurationKey.AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME, String.class)
.getValue();
}

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
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;
@@ -66,8 +66,9 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
* @param systemManagement
*/
@Autowired
public GatewaySecurityTokenAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, systemManagement);
public GatewaySecurityTokenAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED, tenantConfigurationManagement);
}
/**
@@ -167,12 +168,12 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
}
private String getSecurityTokenName() {
return getSystemManagement().getConfigurationValue(
return getTenantConfigurationManagement().getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME, String.class).getValue();
}
private String getSecurityTokenKey() {
return getSystemManagement().getConfigurationValue(
return getTenantConfigurationManagement().getConfigurationValue(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY, String.class).getValue();
}
@@ -188,18 +189,18 @@ public class GatewaySecurityTokenAuthenticationConfigurationItem extends Abstrac
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED.getKeyName(),
String.valueOf(configurationEnabled)));
}
if (keyNameChanged) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME.getKeyName(),
gatewayTokenNameTextField.getValue()));
}
if (keyChanged) {
getSystemManagement().addOrUpdateConfiguration(new TenantConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(new TenantConfiguration(
TenantConfigurationKey.AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY.getKeyName(),
gatewayTokenkeyLabel.getValue()));
}

View File

@@ -10,7 +10,7 @@ package org.eclipse.hawkbit.ui.tenantconfiguration.authentication;
import javax.annotation.PostConstruct;
import org.eclipse.hawkbit.repository.SystemManagement;
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;
@@ -44,8 +44,9 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
* the system management to retrie the configuration
*/
@Autowired
public TargetSecurityTokenAuthenticationConfigurationItem(final SystemManagement systemManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, systemManagement);
public TargetSecurityTokenAuthenticationConfigurationItem(
final TenantConfigurationManagement tenantConfigurationManagement) {
super(TenantConfigurationKey.AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED, tenantConfigurationManagement);
}
/**
@@ -88,7 +89,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
@Override
public void save() {
if (configurationEnabledChange) {
getSystemManagement().addOrUpdateConfiguration(
getTenantConfigurationManagement().addOrUpdateConfiguration(
new TenantConfiguration(getConfigurationKey().getKeyName(), String.valueOf(configurationEnabled)));
}
}
@@ -96,7 +97,7 @@ public class TargetSecurityTokenAuthenticationConfigurationItem extends Abstract
@Override
public void undo() {
configurationEnabledChange = false;
configurationEnabled = getSystemManagement().getConfigurationValue(getConfigurationKey(), Boolean.class)
.getValue();
configurationEnabled = getTenantConfigurationManagement()
.getConfigurationValue(getConfigurationKey(), Boolean.class).getValue();
}
}