Class ApiKey

java.lang.Object
com.codename1.backend.security.apikey.ApiKey

public final class ApiKey extends Object

What a server keeps about an API key: who it acts for, what it may do, whether it has been revoked, and the SHA-256 by which a presented key is recognized. The key itself is not here and cannot be had from this.

The prefix and the last four characters are kept for showing a person which key a row is -- cn1_...x7Qa -- which is all of a key that should ever be shown again.

  • Constructor Details

    • ApiKey

      public ApiKey(String id, String owner, List<String> scopes, String hash, String prefix, String lastFour, boolean revoked)
      Parameters:
      id - the key's own id, for naming it in a list and revoking it
      owner - whom requests made with the key are from: Authentication.getName()
      scopes - what the key grants; each becomes the authority SCOPE_x
      hash - the lowercase hexadecimal SHA-256 of the key, as ApiKeyGenerator.hash(String) computes it
      prefix - the prefix the key was made with
      lastFour - the key's last four characters
      revoked - whether the key has been withdrawn
  • Method Details

    • getId

      public String getId()
    • getOwner

      public String getOwner()
    • getScopes

      public List<String> getScopes()
    • getHash

      public String getHash()
    • getPrefix

      public String getPrefix()
    • getLastFour

      public String getLastFour()
    • isRevoked

      public boolean isRevoked()
    • getDisplayName

      public String getDisplayName()
      The key as it may be shown: its prefix and its last four characters.
    • revoke

      public ApiKey revoke()
      This key, withdrawn.
    • toString

      public String toString()
      Description copied from class: Object
      Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method. The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of: getClass().getName() + '@' + Integer.toHexString(hashCode())
      Overrides:
      toString in class Object