Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public final class ApiKey

  1. Object
  2. ApiKey

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.

Constructors

public ApiKey(String id, String owner, List<String> scopes, String hash, String prefix, String lastFour, boolean revoked)

Methods

public String getId()
public String getOwner()
public List<String> getScopes()
public String getHash()
public String getPrefix()
public String getLastFour()
public boolean isRevoked()
public String getDisplayName()The key as it may be shown: its prefix and its last four characters.
public ApiKey revoke()This key, withdrawn.
public String toString()Returns a string representation of the object.

Inherited methods

Constructor details

ApiKey

public ApiKey(String id, String owner, List<String> scopes, String hash, String prefix, String lastFour, boolean revoked)

Parameters

id String
the key’s own id, for naming it in a list and revoking it
owner String
whom requests made with the key are from: Authentication.getName()
scopes List<String>
what the key grants; each becomes the authority SCOPE_x
hash String
the lowercase hexadecimal SHA-256 of the key, as ApiKeyGenerator.hash computes it
prefix String
the prefix the key was made with
lastFour String
the key’s last four characters
revoked boolean
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()
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())