Class Device

  • All Implemented Interfaces:
    Principal

    public class Device
    extends Object
    implements Principal
    An authenticated client of a protocol adapter representing a device.

    The device's identity and authorities are contained in a Java Web Token.

    • Constructor Detail

      • Device

        public Device​(io.jsonwebtoken.Jws<io.jsonwebtoken.Claims> token)
        Creates a new device for a token.

        The token is expected to contain the device identifier in the sub claim and the tenant identifier in the ten claim.

        Parameters:
        token - The token asserting the device's identity.
        Throws:
        NullPointerException - if the token does not contain a tenant and device identifier.
      • Device

        public Device​(String tenantId,
                      String deviceId)
        Creates a new device for a tenant and device identifier.
        Parameters:
        tenantId - The tenant.
        deviceId - The device identifier.
        Throws:
        NullPointerException - if any of the params is null.
    • Method Detail

      • checkAuthorization

        protected final Boolean checkAuthorization​(String authority)
        Checks if this device has a particular authority.

        In order for the check to succeed, the JWT must

        • not be expired
        • contain the given authorities in its aut claim
        Parameters:
        authority - The authority to check for.
        Returns:
        true if the device has the given authority, false otherwise.
      • principal

        public final io.vertx.core.json.JsonObject principal()
        Get the underlying principal of the device.
        Returns:
        JSON representation of the Principal.
      • getTenantId

        public final String getTenantId()
        Gets the identifier of the tenant this device belongs to.
        Returns:
        The identifier.
      • getDeviceId

        public final String getDeviceId()
        Gets this device's identifier.
        Returns:
        The identifier.
      • getName

        public final String getName()

        Returns the device identifier.

        Specified by:
        getName in interface Principal
      • asAddress

        public static final String asAddress​(String tenantId,
                                             String deviceId)
        Gets the device id in an address structure.
        Parameters:
        tenantId - The id of the tenant.
        deviceId - The id of the device.
        Returns:
        tenantId and deviceId as an address.
        Throws:
        NullPointerException - if any of the parameters are null.
      • asAddress

        public static final String asAddress​(Device device)
        Gets the device id in an address structure.
        Parameters:
        device - The device.
        Returns:
        tenantId and deviceId as an address.
        Throws:
        NullPointerException - if device is null.