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 Details

    • json

      protected final io.vertx.core.json.JsonObject json
      The JSON object to map all values to/from.
  • Constructor Details

    • TenantObject

      public TenantObject(String tenantId, boolean enabled)
      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 is null.
  • Method Details

    • 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 is null.
    • getTenantId

      public String 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

      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 is null.
      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 is null.
    • 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 is null.
    • 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 is null.
    • getAuthIdTemplate

      public Optional<String> getAuthIdTemplate(String subjectDn)
      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 is null.
    • 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 or null 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 is null.
    • 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 is null.
      IllegalArgumentException - if any of the already existing adapters has the same type.
    • isAdapterEnabled

      public boolean isAdapterEnabled(String typeName)
      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

      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:

      1. 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
      2. otherwise, return TenantConstants.DEFAULT_MAX_TTD
      Parameters:
      typeName - The type of protocol adapter to get the TTD for.
      Returns:
      The number of seconds.
    • from

      public static TenantObject from(String tenantId)
      Creates an enabled tenant for a tenantId.
      Parameters:
      tenantId - The tenant for which the object is constructed.
      Returns:
      The TenantObject.
      Throws:
      NullPointerException - if tenantId is null.
    • 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 tenantId is null.
    • 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 be null).
      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 be null).
      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 is null.
    • 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 is null.
      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 is null.
    • 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 is null.
    • 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 is null 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 is null.