Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class JdbcApiKeyRepository
- Object
- JdbcApiKeyRepository
ImplementsApiKeyRepository
API keys kept in the server’s database, in the cn1_api_key table of
SecuritySchema. Only a key’s hash is
stored; the key itself is shown once, by ApiKeyGenerator, and never again.
@Bean
ApiKeyRepository apiKeys(DataSource dataSource) {
return new JdbcApiKeyRepository(dataSource);
}Constructors
public JdbcApiKeyRepository(DataSource dataSource) |
Methods
public void setClock(Clock clock) | The clock a key’s creation time is read from; for tests. |
public ApiKey findByHash(String hash) | The key with this hash, or null. |
public void save(ApiKey key)
throws IOException | Stores a new key. |
public boolean revoke(String id)
throws IOException | Revokes the key with this id. |
public boolean delete(String id)
throws IOException | Forgets the key with this id altogether. |
public List<ApiKey> findByOwner(String owner)
throws IOException | The keys of one owner, oldest first. |
Inherited methods
Constructor details
JdbcApiKeyRepository
public JdbcApiKeyRepository(DataSource dataSource)Method details
setClock
public void setClock(Clock clock)The clock a key’s creation time is read from; for tests.
findByHash
public 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
save
public void save(ApiKey key)
throws IOExceptionStores a new key. A scope may not contain a space.
Throws
revoke
public boolean revoke(String id)
throws IOExceptionRevokes the key with this id.
Returns
whether this call revoked it: false when there is no such key, or
it was revoked already
Throws
delete
public boolean delete(String id)
throws IOExceptionForgets the key with this id altogether.
Throws
findByOwner
public List<ApiKey> findByOwner(String owner)
throws IOExceptionThe keys of one owner, oldest first.