Class SecurityToken

java.lang.Object
net.solarnetwork.dao.BasicIdentity<String>
net.solarnetwork.dao.BasicEntity<String>
net.solarnetwork.dao.BasicStringEntity
net.solarnetwork.node.domain.SecurityToken
All Implemented Interfaces:
Serializable, Comparable<String>, net.solarnetwork.dao.Entity<String>, net.solarnetwork.domain.Identity<String>

public class SecurityToken extends net.solarnetwork.dao.BasicStringEntity
A security token, for API access.

The BasicIdentity.getId() value is the security token identifier.

Since:
3.4
Version:
1.0
Author:
matt
See Also:
  • Constructor Details

    • SecurityToken

      public SecurityToken(String tokenId, String tokenSecret)
      Constructor.
      Parameters:
      tokenId - the token identifier
      tokenSecret - the token secret
      Throws:
      IllegalArgumentException - if any argument is null
    • SecurityToken

      public SecurityToken(String tokenId, Instant created, String tokenSecret, String name, String description)
      Constructor.
      Parameters:
      tokenId - the token identifier
      created - the creation date
      tokenSecret - the token secret
      name - the name
      description - the description
      Throws:
      IllegalArgumentException - if tokenId or tokenSecret are null
  • Method Details

    • tokenDetails

      public static SecurityToken tokenDetails(String tokenId, String name, String description)
      Create a token from just the detail properties.
      Parameters:
      tokenId - the token ID
      name - the name
      description - the description
      Returns:
      the token instance
    • tokenDetails

      public static SecurityToken tokenDetails(String name, String description)
      Create a token from just the detail properties.
      Parameters:
      name - the name
      description - the description
      Returns:
      the token instance
    • copyWithoutSecret

      public SecurityToken copyWithoutSecret(String newName, String newDescription)
      Create a copy without the token secret populated.
      Parameters:
      newName - if non-null then use for the name in the new copy
      newDescription - if non-null then use for the description in the new copy
      Returns:
      the copy
    • saveSigningKey

      public <T extends net.solarnetwork.security.AbstractAuthorizationBuilder<T>> T saveSigningKey(net.solarnetwork.security.AbstractAuthorizationBuilder<T> builder)
      Save the signing key from the token secret.
      Type Parameters:
      T - the builder type
      Parameters:
      builder - the authorization builder to call AbstractAuthorizationBuilder.saveSigningKey(String) on
      Returns:
      the builder instance
      Throws:
      IllegalArgumentException - if any argument is null
      net.solarnetwork.security.SecurityException - if any error occurs computing the key
    • copySecret

      public void copySecret(Consumer<String> dest)
      Copy the secret to a consumer.
      Parameters:
      dest - the consumer
    • applySecret

      public <T> T applySecret(Function<String,T> dest)
      Apply the secret to a function.
      Type Parameters:
      T - the function return type
      Parameters:
      dest - the function to apply
      Returns:
      the function result
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCreatedDate

      public Date getCreatedDate()
      Get the created date as a Date instance.
      Returns:
      the date
    • getName

      public String getName()
      Get the name.
      Returns:
      the name
    • getDescription

      public String getDescription()
      Get the description.
      Returns:
      the description