Package org.eclipse.hono.util
Class TenantObject
java.lang.Object
org.eclipse.hono.util.TenantObject
Encapsulates the tenant information that was found by the get operation of the
Tenant API.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final io.vertx.core.json.JsonObject
The JSON object to map all values to/from. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddAdapter
(Adapter adapter) Adds an adapter configuration.addTrustAnchor
(byte[] publicKey, String publicKeyAlgorithm, X500Principal subjectDn, String authIdTemplate, Boolean autoProvisioningEnabled) Adds a trusted certificate authority to use for authenticating devices of this tenant.addTrustAnchor
(PublicKey publicKey, X500Principal subjectDn, Boolean autoProvisioningEnabled) Adds a trusted certificate authority to use for authenticating devices of this tenant.static TenantObject
Creates an enabled tenant for a tenantId.static TenantObject
Creates a TenantObject for a tenantId and the enabled property.getAdapter
(String type) Gets the adapter configuration for the given type.Gets the list of configured adapters for the tenant.getAuthIdTemplate
(String subjectDn) Gets the template to generate authentication identifier for the given subject DN.io.vertx.core.json.JsonObject
Gets the default property values used for all devices of this tenant.int
getMaxTimeUntilDisconnect
(String typeName) Gets the maximum number of seconds that a protocol adapter should wait for a command targeted at a device.int
Gets the minimum message size in bytes.protected static final <T> T
getProperty
(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz) Gets a property value.protected static final <T> T
getProperty
(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz, T defaultValue) Gets a property value.final <T> T
getProperty
(String name, Class<T> clazz) Gets a property value.final <T> T
getProperty
(String name, Class<T> clazz, T defaultValue) Gets a property value.Gets the resource limits for the tenant.Gets this tenant's identifier.Gets this tenant's tracing configuration.Gets the trust anchors for this tenant.boolean
isAdapterEnabled
(String typeName) Checks if this tenant is enabled and if a given protocol adapter is enabled for this tenant.boolean
isAutoProvisioningEnabled
(String subjectDn) Checks whether auto-provisioning is enabled for a CA.boolean
Checks if this tenant is enabled.setAdapters
(List<Adapter> adapters) Sets the given list of adapters for the tenant.setDefaults
(io.vertx.core.json.JsonObject defaultProperties) Sets the default property values to use for all devices of this tenant.setMinimumMessageSize
(int payloadSize) Sets the minimum message size in bytes.setProperty
(String name, Object value) Adds a property to this tenant.setResourceLimits
(io.vertx.core.json.JsonObject resourceLimits) Sets the resource limits for the tenant.setResourceLimits
(ResourceLimits resourceLimits) Sets the resource limits for the tenant.setTracingConfig
(TenantTracingConfig tracing) Sets this tenant's tracing configuration.setTrustAnchor
(PublicKey publicKey, X500Principal subjectDn) Sets the trusted certificate authority to use for authenticating devices of this tenant.
-
Field Details
-
json
protected final io.vertx.core.json.JsonObject jsonThe JSON object to map all values to/from.
-
-
Constructor Details
-
TenantObject
Creates a new tenant.- Parameters:
tenantId
- The tenant's identifier.enabled
-true
if devices of this tenant are allowed to connect to Hono.- Throws:
NullPointerException
- if identifier isnull
.
-
-
Method Details
-
setProperty
Adds a property to this tenant.- Parameters:
name
- The property name.value
- The property value.- Returns:
- This object for command chaining.
- Throws:
NullPointerException
- if name isnull
.
-
getTenantId
Gets this tenant's identifier.- Returns:
- The identifier or
null
if not set.
-
isEnabled
public boolean isEnabled()Checks if this tenant is enabled.- Returns:
true
if this tenant is enabled.
-
setTrustAnchor
Sets the trusted certificate authority to use for authenticating devices of this tenant.This method removes all existing trust anchors.
- Parameters:
publicKey
- The CA's public key.subjectDn
- The CA's subject DN.- Returns:
- This tenant for command chaining.
- Throws:
NullPointerException
- if any of the parameters isnull
.- See Also:
-
addTrustAnchor
public TenantObject addTrustAnchor(PublicKey publicKey, X500Principal subjectDn, Boolean autoProvisioningEnabled) Adds a trusted certificate authority to use for authenticating devices of this tenant.- Parameters:
publicKey
- The CA's public key.subjectDn
- The CA's subject DN.autoProvisioningEnabled
- A flag indicating whether this CA may be used for automatic provisioning.- Returns:
- This tenant for command chaining.
- Throws:
NullPointerException
- if the public key or subjectDN parameters isnull
.
-
addTrustAnchor
public TenantObject addTrustAnchor(byte[] publicKey, String publicKeyAlgorithm, X500Principal subjectDn, String authIdTemplate, Boolean autoProvisioningEnabled) Adds a trusted certificate authority to use for authenticating devices of this tenant.- Parameters:
publicKey
- The CA's public key in encoded form.publicKeyAlgorithm
- The algorithm of the public key.subjectDn
- The CA's subject DN.authIdTemplate
- The template to generate the authentication identifier.autoProvisioningEnabled
- A flag indicating whether this CA may be used for automatic provisioning.- Returns:
- This tenant for command chaining.
- Throws:
NullPointerException
- if the public key, algorithm or subjectDN parameters isnull
.
-
getTrustAnchors
Gets the trust anchors for this tenant.This method tries to create the trust anchors based on the information from the JSON objects contained in the trusted-ca property.
The JSON objects are expected to contain
- the Base64 encoded DER encoding of the trusted certificate's public key in the public-key property and
- the subject DN of the CA in the subject-dn property.
Once a non empty set of trust anchors has been created, it will be cached and returned on subsequent invocations of this method.
- Returns:
- The set of trust anchors, may be empty.
-
isAutoProvisioningEnabled
Checks whether auto-provisioning is enabled for a CA.- Parameters:
subjectDn
- The subject DN of the CA to check.- Returns:
true
if auto-provisioning is enabled.- Throws:
NullPointerException
- if the parameter subjectDN isnull
.
-
getAuthIdTemplate
Gets the template to generate authentication identifier for the given subject DN.If no template is configured,
Optional.empty()
is returned.- Parameters:
subjectDn
- The subject DN of the CA to check.- Returns:
- The template to generate authentication identifier.
- Throws:
NullPointerException
- if the parameter subjectDN isnull
.
-
getAdapters
Gets the list of configured adapters for the tenant.- Returns:
- The list of configured adapters or
null
if not set.
-
setAdapters
Sets the given list of adapters for the tenant.- Parameters:
adapters
- The list of adapters ornull
if not set.- Returns:
- This tenant for command chaining.
- Throws:
IllegalArgumentException
- if more than one of the adapters have the same type.
-
getAdapter
Gets the adapter configuration for the given type.- Parameters:
type
- The adapter's type.- Returns:
- The adapter configuration or
null
if not set. - Throws:
NullPointerException
- if type isnull
.
-
addAdapter
Adds an adapter configuration.- Parameters:
adapter
- The adapter configuration to add.- Returns:
- This tenant for command chaining.
- Throws:
NullPointerException
- if the given adapter configuration isnull
.IllegalArgumentException
- if any of the already existing adapters has the same type.
-
isAdapterEnabled
Checks if this tenant is enabled and if a given protocol adapter is enabled for this tenant.- Parameters:
typeName
- The type name of the adapter.- Returns:
true
if this tenant and the given adapter are enabled.
-
getMaxTimeUntilDisconnect
Gets the maximum number of seconds that a protocol adapter should wait for a command targeted at a device.The returned value is determined as follows:
- if this tenant configuration extensions contains an integer typed
TenantConstants.FIELD_MAX_TTD
property specific to the given adapter type, then return its value provided it is >= 0 - otherwise, return
TenantConstants.DEFAULT_MAX_TTD
- Parameters:
typeName
- The type of protocol adapter to get the TTD for.- Returns:
- The number of seconds.
- if this tenant configuration extensions contains an integer typed
-
from
Creates an enabled tenant for a tenantId.- Parameters:
tenantId
- The tenant for which the object is constructed.- Returns:
- The TenantObject.
- Throws:
NullPointerException
- if tenantId isnull
.
-
from
Creates a TenantObject for a tenantId and the enabled property.- Parameters:
tenantId
- The tenant for which the object is constructed.enabled
-true
if the tenant shall be enabled.- Returns:
- The TenantObject.
- Throws:
NullPointerException
- if tenantId isnull
.
-
getResourceLimits
Gets the resource limits for the tenant.- Returns:
- The resource limits or
null
if not set.
-
setResourceLimits
Sets the resource limits for the tenant.- Parameters:
resourceLimits
- The resource limits configuration (may benull
).- Returns:
- This tenant for command chaining.
- Throws:
IllegalArgumentException
- if the resource limits object cannot be instantiated from the given jsonObject.
-
setResourceLimits
Sets the resource limits for the tenant.- Parameters:
resourceLimits
- The resource limits configuration (may benull
).- Returns:
- This tenant for command chaining.
-
getMinimumMessageSize
public int getMinimumMessageSize()Gets the minimum message size in bytes.- Returns:
- The minimum message size in bytes or
TenantConstants.DEFAULT_MINIMUM_MESSAGE_SIZE
if not set.
-
setMinimumMessageSize
Sets the minimum message size in bytes.- Parameters:
payloadSize
- The payload size of the incoming message.- Returns:
- The TenantObject.
- Throws:
IllegalArgumentException
- if the message payload size is negative.
-
getDefaults
public io.vertx.core.json.JsonObject getDefaults()Gets the default property values used for all devices of this tenant.- Returns:
- The default properties or an empty JSON object if no default properties have been defined for this tenant.
-
setDefaults
Sets the default property values to use for all devices of this tenant.- Parameters:
defaultProperties
- The properties or an empty JSON object if no default properties have been defined for this tenant.- Returns:
- This tenant for command chaining.
-
getTracingConfig
Gets this tenant's tracing configuration.- Returns:
- The tracing configuration or
null
if not set.
-
setTracingConfig
Sets this tenant's tracing configuration.- Parameters:
tracing
- The tracing configuration.- Returns:
- This tenant for command chaining.
-
getProperty
Gets a property value.- Type Parameters:
T
- The type of the property.- Parameters:
name
- The property name.clazz
- The target type.- Returns:
- The property value or
null
if the property is not set or is of an unexpected type. - Throws:
NullPointerException
- if name isnull
.
-
getProperty
Gets a property value.- Type Parameters:
T
- The type of the property.- Parameters:
name
- The property name.defaultValue
- A default value to return if the property isnull
.clazz
- The target type.- Returns:
- The property value or the default value if the property is not set or is of an unexpected type.
- Throws:
NullPointerException
- if name isnull
.
-
getProperty
protected static final <T> T getProperty(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz) Gets a property value.- Type Parameters:
T
- The type of the property.- Parameters:
parent
- The JSON to get the property value from.name
- The property name.clazz
- The target type.- Returns:
- The property value or
null
if the property is not set or is of an unexpected type. - Throws:
NullPointerException
- if any of the parameters isnull
.
-
getProperty
protected static final <T> T getProperty(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz, T defaultValue) Gets a property value.- Type Parameters:
T
- The type of the property.- Parameters:
parent
- The JSON to get the property value from.name
- The property name.defaultValue
- A default value to return if the property isnull
or is of an unexpected type.clazz
- The target type.- Returns:
- The property value or the given default value if the property is not set or is of an unexpected type.
- Throws:
NullPointerException
- if any of the parameters except defaultValue isnull
.
-