Package org.eclipse.hono.util
Class TenantObject
- java.lang.Object
-
- org.eclipse.hono.util.TenantObject
-
public final class TenantObject extends Object
Encapsulates the tenant information that was found by the get operation of the Tenant API.
-
-
Field Summary
Fields Modifier and Type Field Description protected io.vertx.core.json.JsonObject
json
The JSON object to map all values to/from.
-
Constructor Summary
Constructors Constructor Description TenantObject()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TenantObject
addAdapter(Adapter adapter)
Adds an adapter configuration.TenantObject
addTrustAnchor(byte[] publicKey, String publicKeyAlgorithm, X500Principal subjectDn, Boolean autoProvisioningEnabled)
Adds a trusted certificate authority to use for authenticating devices of this tenant.TenantObject
addTrustAnchor(PublicKey publicKey, X500Principal subjectDn, Boolean autoProvisioningEnabled)
Adds a trusted certificate authority to use for authenticating devices of this tenant.static TenantObject
from(Boolean enabled)
Creates a TenantObject from the enabled property.static TenantObject
from(String tenantId, Boolean enabled)
Creates a TenantObject for a tenantId and the enabled property.Adapter
getAdapter(String type)
Gets the adapter configuration for the given type.List<Adapter>
getAdapters()
Gets the list of configured adapters for the tenant.io.vertx.core.json.JsonObject
getDefaults()
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
getMinimumMessageSize()
Gets the minimum message size in bytes.protected static <T> T
getProperty(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz)
Gets a property value.protected static <T> T
getProperty(io.vertx.core.json.JsonObject parent, String name, Class<T> clazz, T defaultValue)
Gets a property value.<T> T
getProperty(String name, Class<T> clazz)
Gets a property value.<T> T
getProperty(String name, Class<T> clazz, T defaultValue)
Gets a property value.ResourceLimits
getResourceLimits()
Gets the resource limits for the tenant.String
getTenantId()
Gets this tenant's identifier.TenantTracingConfig
getTracingConfig()
Gets this tenant's tracing configuration.Set<TrustAnchor>
getTrustAnchors()
Gets the trust anchors for this tenant.boolean
isAdapterEnabled(String typeName)
Checks if a given protocol adapter is enabled for this tenant.boolean
isAutoProvisioningEnabled(String subjectDn)
Checks whether auto-provisioning is enabled for a CA.boolean
isEnabled()
Checks if this tenant is enabled.TenantObject
setAdapters(List<Adapter> adapters)
Sets the given list of adapters for the tenant.TenantObject
setDefaults(io.vertx.core.json.JsonObject defaultProperties)
Sets the default property values to use for all devices of this tenant.TenantObject
setEnabled(boolean flag)
Sets whether this tenant is enabled.TenantObject
setMinimumMessageSize(int payloadSize)
Sets the minimum message size in bytes.TenantObject
setProperty(String name, Object value)
Adds a property to this tenant.TenantObject
setResourceLimits(io.vertx.core.json.JsonObject resourceLimits)
Sets the resource limits for the tenant.TenantObject
setResourceLimits(ResourceLimits resourceLimits)
Sets the resource limits for the tenant.TenantObject
setTenantId(String tenantId)
Sets this tenant's identifier.TenantObject
setTracingConfig(TenantTracingConfig tracing)
Sets this tenant's tracing configuration.TenantObject
setTrustAnchor(PublicKey publicKey, X500Principal subjectDn)
Sets the trusted certificate authority to use for authenticating devices of this tenant.
-
-
-
Method Detail
-
setProperty
public TenantObject setProperty(String name, Object value)
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
public String getTenantId()
Gets this tenant's identifier.- Returns:
- The identifier or
null
if not set.
-
setTenantId
public TenantObject setTenantId(String tenantId)
Sets this tenant's identifier.- Parameters:
tenantId
- The identifier.- Returns:
- This tenant for command chaining.
-
isEnabled
public boolean isEnabled()
Checks if this tenant is enabled.- Returns:
true
if this tenant is enabled.
-
setEnabled
public TenantObject setEnabled(boolean flag)
Sets whether this tenant is enabled.- Parameters:
flag
-true
if this tenant is enabled.- Returns:
- This tenant for command chaining.
-
setTrustAnchor
public TenantObject setTrustAnchor(PublicKey publicKey, X500Principal subjectDn)
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(PublicKey, X500Principal, Boolean)
-
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, 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.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
public Set<TrustAnchor> 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
public boolean isAutoProvisioningEnabled(String subjectDn)
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
.
-
getAdapters
public List<Adapter> getAdapters()
Gets the list of configured adapters for the tenant.- Returns:
- The list of configured adapters or
null
if not set.
-
setAdapters
public TenantObject setAdapters(List<Adapter> adapters)
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
public Adapter getAdapter(String type)
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
public TenantObject addAdapter(Adapter adapter)
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
public boolean isAdapterEnabled(String typeName)
Checks 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
public int getMaxTimeUntilDisconnect(String typeName)
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
public static TenantObject from(String tenantId, Boolean enabled)
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 any of tenantId or enabled isnull
.
-
from
public static TenantObject from(Boolean enabled)
Creates a TenantObject from the enabled property.- Parameters:
enabled
-true
if the tenant shall be enabled.- Returns:
- The TenantObject.
- Throws:
NullPointerException
- if enabled isnull
.
-
getResourceLimits
public ResourceLimits getResourceLimits()
Gets the resource limits for the tenant.- Returns:
- The resource limits or
null
if not set.
-
setResourceLimits
public TenantObject setResourceLimits(io.vertx.core.json.JsonObject resourceLimits)
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
public TenantObject setResourceLimits(ResourceLimits resourceLimits)
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
public TenantObject setMinimumMessageSize(int payloadSize)
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
public TenantObject setDefaults(io.vertx.core.json.JsonObject defaultProperties)
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
public TenantTracingConfig getTracingConfig()
Gets this tenant's tracing configuration.- Returns:
- The tracing configuration or
null
if not set.
-
setTracingConfig
public TenantObject setTracingConfig(TenantTracingConfig tracing)
Sets this tenant's tracing configuration.- Parameters:
tracing
- The tracing configuration.- Returns:
- This tenant for command chaining.
-
getProperty
public final <T> T getProperty(String name, Class<T> clazz)
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
public final <T> T getProperty(String name, Class<T> clazz, T defaultValue)
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
.
-
-