Custom Tenant configuration. (#395)
* Tenant configuration configurable. Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -10,9 +10,7 @@ package org.eclipse.hawkbit;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.EnvironmentAware;
|
||||
|
||||
/**
|
||||
* Defines global configuration for the controllers/clients on the provisioning
|
||||
@@ -20,8 +18,7 @@ import org.springframework.context.EnvironmentAware;
|
||||
*
|
||||
*
|
||||
* Note: many of the controller related properties can be overridden on tenant
|
||||
* level. As a result they are not defined here but in
|
||||
* {@link TenantConfigurationKey} and injected using {@link EnvironmentAware}.
|
||||
* level.
|
||||
*
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "hawkbit.controller")
|
||||
@@ -29,8 +26,8 @@ public class ControllerPollProperties implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Maximum polling time that can be configured by a tenant in HH:MM:SS
|
||||
* notation.
|
||||
* Maximum polling time that can be configured system wide and by tenant in
|
||||
* HH:MM:SS notation.
|
||||
*/
|
||||
private String maxPollingTime = "23:59:59";
|
||||
|
||||
@@ -40,6 +37,34 @@ public class ControllerPollProperties implements Serializable {
|
||||
*/
|
||||
private String minPollingTime = "00:00:30";
|
||||
|
||||
/**
|
||||
* Controller polling time that can be configured system wide and by tenant
|
||||
* in HH:MM:SS notation.
|
||||
*/
|
||||
private String pollingTime = "00:05:00";
|
||||
|
||||
/**
|
||||
* Controller polling overdue time that can be configured system wide and by
|
||||
* tenant in HH:MM:SS notation.
|
||||
*/
|
||||
private String pollingOverdueTime = "00:05:00";
|
||||
|
||||
public String getPollingTime() {
|
||||
return pollingTime;
|
||||
}
|
||||
|
||||
public void setPollingTime(final String pollingTime) {
|
||||
this.pollingTime = pollingTime;
|
||||
}
|
||||
|
||||
public String getPollingOverdueTime() {
|
||||
return pollingOverdueTime;
|
||||
}
|
||||
|
||||
public void setPollingOverdueTime(final String pollingOverdueTime) {
|
||||
this.pollingOverdueTime = pollingOverdueTime;
|
||||
}
|
||||
|
||||
public String getMaxPollingTime() {
|
||||
return maxPollingTime;
|
||||
}
|
||||
|
||||
@@ -22,12 +22,52 @@ public class HawkbitServerProperties {
|
||||
*/
|
||||
private String url = "http://localhost:8080";
|
||||
|
||||
private final Anonymous anonymous = new Anonymous();
|
||||
|
||||
private final Build build = new Build();
|
||||
|
||||
public Anonymous getAnonymous() {
|
||||
return anonymous;
|
||||
}
|
||||
|
||||
public Build getBuild() {
|
||||
return build;
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties for anonymous API access by Devices/Controllers.
|
||||
*
|
||||
*/
|
||||
public static class Anonymous {
|
||||
private final Download download = new Download();
|
||||
|
||||
public Download getDownload() {
|
||||
return download;
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties for artifact download under anonymous API access by
|
||||
* Devices/Controllers.
|
||||
*
|
||||
*/
|
||||
public static class Download {
|
||||
|
||||
/**
|
||||
* Unauthenticated artifact download possible if true.
|
||||
*/
|
||||
private boolean enabled;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(final boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build information of the hawkBit instance. Influenced by maven.
|
||||
*
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.tenancy.configuration;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.hawkbit.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationBooleanValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationPollingDurationValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationStringValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidatorException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* An enum which defines the tenant specific configurations which can be
|
||||
* configured for each tenant separately. The non overridable properties are
|
||||
* configured in {@link ControllerPollProperties} instead.
|
||||
*
|
||||
*/
|
||||
public enum TenantConfigurationKey {
|
||||
|
||||
/**
|
||||
* boolean value {@code true} {@code false}.
|
||||
*/
|
||||
AUTHENTICATION_MODE_HEADER_ENABLED("authentication.header.enabled", "hawkbit.server.ddi.security.authentication.header.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class),
|
||||
/**
|
||||
*
|
||||
*/
|
||||
AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME("authentication.header.authority", "hawkbit.server.ddi.security.authentication.header.authority", String.class, Boolean.FALSE.toString(), TenantConfigurationStringValidator.class),
|
||||
/**
|
||||
* boolean value {@code true} {@code false}.
|
||||
*/
|
||||
AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED("authentication.targettoken.enabled", "hawkbit.server.ddi.security.authentication.targettoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class),
|
||||
|
||||
/**
|
||||
* boolean value {@code true} {@code false}.
|
||||
*/
|
||||
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED("authentication.gatewaytoken.enabled", "hawkbit.server.ddi.security.authentication.gatewaytoken.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class),
|
||||
/**
|
||||
* string value which holds the name of the security token key.
|
||||
*/
|
||||
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME("authentication.gatewaytoken.name", "hawkbit.server.ddi.security.authentication.gatewaytoken.name", String.class, null, TenantConfigurationStringValidator.class),
|
||||
|
||||
/**
|
||||
* string value which holds the actual security-key of the gateway security
|
||||
* token.
|
||||
*/
|
||||
AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY("authentication.gatewaytoken.key", "hawkbit.server.ddi.security.authentication.gatewaytoken.key", String.class, null, TenantConfigurationStringValidator.class),
|
||||
|
||||
/**
|
||||
* string value which holds the polling time interval in the format HH:mm:ss
|
||||
*/
|
||||
POLLING_TIME_INTERVAL("pollingTime", "hawkbit.controller.pollingTime", String.class, null, TenantConfigurationPollingDurationValidator.class),
|
||||
|
||||
/**
|
||||
* string value which holds the polling time interval in the format HH:mm:ss
|
||||
*/
|
||||
POLLING_OVERDUE_TIME_INTERVAL("pollingOverdueTime", "hawkbit.controller.pollingOverdueTime", String.class, null, TenantConfigurationPollingDurationValidator.class),
|
||||
|
||||
/**
|
||||
* boolean value {@code true} {@code false}.
|
||||
*/
|
||||
ANONYMOUS_DOWNLOAD_MODE_ENABLED("anonymous.download.enabled", "hawkbit.server.download.anonymous.enabled", Boolean.class, Boolean.FALSE.toString(), TenantConfigurationBooleanValidator.class);
|
||||
|
||||
private final String keyName;
|
||||
private final String defaultKeyName;
|
||||
private final Class<?> dataType;
|
||||
private final String defaultValue;
|
||||
private final Class<? extends TenantConfigurationValidator> validator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param key
|
||||
* the property key name
|
||||
* @param defaultKeyName
|
||||
* the allowed values for this specific key
|
||||
* @param dataType
|
||||
* the class of the property
|
||||
* @param defaultValue
|
||||
* value which should be returned, in case there is no value in
|
||||
* the database
|
||||
* @param validator
|
||||
* Validator which validates, that property is of correct format
|
||||
*/
|
||||
TenantConfigurationKey(final String key, final String defaultKeyName, final Class<?> dataType,
|
||||
final String defaultValue, final Class<? extends TenantConfigurationValidator> validator) {
|
||||
this.keyName = key;
|
||||
this.dataType = dataType;
|
||||
this.defaultKeyName = defaultKeyName;
|
||||
this.defaultValue = defaultValue;
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the keyName
|
||||
*/
|
||||
public String getKeyName() {
|
||||
return keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultKeyName
|
||||
*/
|
||||
public String getDefaultKeyName() {
|
||||
return defaultKeyName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultValue
|
||||
*/
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the data type of the tenant configuration value. (e.g.
|
||||
* Integer.class, String.class)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Class<T> getDataType() {
|
||||
return (Class<T>) dataType;
|
||||
}
|
||||
|
||||
/**
|
||||
* validates if a object matches the allowed data format of the
|
||||
* corresponding key
|
||||
*
|
||||
* @param context
|
||||
* application context
|
||||
* @param value
|
||||
* which will be validated
|
||||
* @throws TenantConfigurationValidatorException
|
||||
* is thrown, when object is invalid
|
||||
*/
|
||||
public void validate(final ApplicationContext context, final Object value) {
|
||||
final TenantConfigurationValidator createdBean = context.getAutowireCapableBeanFactory().createBean(validator);
|
||||
try {
|
||||
createdBean.validate(value);
|
||||
} finally {
|
||||
context.getAutowireCapableBeanFactory().destroyBean(createdBean);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyName
|
||||
* name of the TenantConfigurationKey
|
||||
* @return the TenantConfigurationKey with the name keyName
|
||||
*/
|
||||
public static TenantConfigurationKey fromKeyName(final String keyName) {
|
||||
|
||||
final Optional<TenantConfigurationKey> optKey = Arrays.stream(TenantConfigurationKey.values())
|
||||
.filter(conf -> conf.getKeyName().equals(keyName)).findFirst();
|
||||
|
||||
if (optKey.isPresent()) {
|
||||
return optKey.get();
|
||||
}
|
||||
throw new InvalidTenantConfigurationKeyException("The given configuration key name does not exist.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
|
||||
*
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*/
|
||||
package org.eclipse.hawkbit.tenancy.configuration;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.ControllerPollProperties;
|
||||
import org.eclipse.hawkbit.HawkbitServerProperties.Anonymous.Download;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationStringValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidator;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.validator.TenantConfigurationValidatorException;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* Properties for tenant configuration default values.
|
||||
*
|
||||
*/
|
||||
@ConfigurationProperties("hawkbit.server.tenant")
|
||||
public class TenantConfigurationProperties {
|
||||
|
||||
private final Map<String, TenantConfigurationKey> configuration = new HashMap<>();
|
||||
|
||||
/**
|
||||
* @return full map of all configured tenant properties
|
||||
*/
|
||||
public Map<String, TenantConfigurationKey> getConfiguration() {
|
||||
return configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return full list of {@link TenantConfigurationKey}s
|
||||
*/
|
||||
public Collection<TenantConfigurationKey> getConfigurationKeys() {
|
||||
return configuration.values();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param keyName
|
||||
* name of the TenantConfigurationKey
|
||||
* @return the TenantConfigurationKey with the name keyName
|
||||
*/
|
||||
public TenantConfigurationKey fromKeyName(final String keyName) {
|
||||
return configuration.values().stream().filter(conf -> conf.getKeyName().equals(keyName)).findFirst()
|
||||
.orElseThrow(() -> new InvalidTenantConfigurationKeyException(
|
||||
"The given configuration key " + keyName + " does not exist."));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tenant specific configurations which can be configured for each tenant
|
||||
* separately by means of override of the system defaults.
|
||||
*
|
||||
*/
|
||||
public static class TenantConfigurationKey {
|
||||
/**
|
||||
* Header based authentication enabled.
|
||||
*/
|
||||
public static final String AUTHENTICATION_MODE_HEADER_ENABLED = "authentication.header.enabled";
|
||||
|
||||
/**
|
||||
* Header based authentication authority name.
|
||||
*/
|
||||
public static final String AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME = "authentication.header.authority";
|
||||
/**
|
||||
* Target token based authentication enabled.
|
||||
*/
|
||||
public static final String AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED = "authentication.targettoken.enabled";
|
||||
|
||||
/**
|
||||
* Gateway token based authentication enabled.
|
||||
*/
|
||||
public static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED = "authentication.gatewaytoken.enabled";
|
||||
|
||||
/**
|
||||
* Gateway token value.
|
||||
*/
|
||||
public static final String AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY = "authentication.gatewaytoken.key";
|
||||
|
||||
/**
|
||||
* See system default in
|
||||
* {@link ControllerPollProperties#getPollingTime()}.
|
||||
*/
|
||||
public static final String POLLING_TIME_INTERVAL = "pollingTime";
|
||||
|
||||
/**
|
||||
* See system default in
|
||||
* {@link ControllerPollProperties#getPollingOverdueTime()}.
|
||||
*/
|
||||
public static final String POLLING_OVERDUE_TIME_INTERVAL = "pollingOverdueTime";
|
||||
|
||||
/**
|
||||
* See system default {@link Download#isEnabled()}.
|
||||
*/
|
||||
public static final String ANONYMOUS_DOWNLOAD_MODE_ENABLED = "anonymous.download.enabled";
|
||||
|
||||
private String keyName;
|
||||
private String defaultValue = "";
|
||||
private Class<?> dataType = String.class;
|
||||
private Class<? extends TenantConfigurationValidator> validator = TenantConfigurationStringValidator.class;
|
||||
|
||||
public String getKeyName() {
|
||||
return keyName;
|
||||
}
|
||||
|
||||
public void setKeyName(final String keyName) {
|
||||
this.keyName = keyName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return the data type of the tenant configuration value. (e.g.
|
||||
* Integer.class, String.class)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> Class<T> getDataType() {
|
||||
return (Class<T>) dataType;
|
||||
}
|
||||
|
||||
public void setDataType(final Class<?> dataType) {
|
||||
this.dataType = dataType;
|
||||
}
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public void setDefaultValue(final String defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public Class<? extends TenantConfigurationValidator> getValidator() {
|
||||
return validator;
|
||||
}
|
||||
|
||||
public void setValidator(final Class<? extends TenantConfigurationValidator> validator) {
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
/**
|
||||
* validates if a object matches the allowed data format of the
|
||||
* corresponding key
|
||||
*
|
||||
* @param context
|
||||
* application context
|
||||
* @param value
|
||||
* which will be validated
|
||||
* @throws TenantConfigurationValidatorException
|
||||
* is thrown, when object is invalid
|
||||
*/
|
||||
public void validate(final ApplicationContext context, final Object value) {
|
||||
final TenantConfigurationValidator createdBean = context.getAutowireCapableBeanFactory()
|
||||
.createBean(validator);
|
||||
try {
|
||||
createdBean.validate(value);
|
||||
} finally {
|
||||
context.getAutowireCapableBeanFactory().destroyBean(createdBean);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user