Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class InMemoryApiKeyRepository
- Object
- InMemoryApiKeyRepository
ImplementsApiKeyRepository
API keys held in memory: for tests, and for a server whose few keys come
from its configuration. They are gone when the process ends, and each
instance of a server that runs as several has its own.
Constructors
public InMemoryApiKeyRepository(ApiKey... keys) |
Methods
public synchronized void save(ApiKey key) | Adds a key, or replaces the one with the same hash. |
public synchronized boolean revoke(String id) | Withdraws the key with this id. |
public synchronized ApiKey findByHash(String hash) | The key with this hash, or null. |
public synchronized List<ApiKey> findAll() | Every key, in the order they were added. |
Inherited methods
Constructor details
InMemoryApiKeyRepository
public InMemoryApiKeyRepository(ApiKey... keys)Method details
save
public synchronized void save(ApiKey key)Adds a key, or replaces the one with the same hash.
revoke
public synchronized boolean revoke(String id)Withdraws the key with this id.
Returns
whether there was one
findByHash
public synchronized ApiKey findByHash(String hash)The key with this hash, or null. A revoked key is returned like any
other; refusing it is the caller’s.
Parameters
hashString- the lowercase hexadecimal SHA-256 of a presented key
findAll
public synchronized List<ApiKey> findAll()Every key, in the order they were added.