Class InMemoryApiKeyRepository

java.lang.Object
com.codename1.backend.security.apikey.InMemoryApiKeyRepository
All Implemented Interfaces:
ApiKeyRepository

public final class InMemoryApiKeyRepository extends Object implements ApiKeyRepository
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.
  • Constructor Details

    • InMemoryApiKeyRepository

      public InMemoryApiKeyRepository(ApiKey... keys)
  • Method Details

    • save

      public void save(ApiKey key)
      Adds a key, or replaces the one with the same hash.
    • revoke

      public boolean revoke(String id)
      Withdraws the key with this id.
      Returns:
      whether there was one
    • findByHash

      public ApiKey findByHash(String hash)
      Description copied from interface: ApiKeyRepository
      The key with this hash, or null. A revoked key is returned like any other; refusing it is the caller's.
      Specified by:
      findByHash in interface ApiKeyRepository
      Parameters:
      hash - the lowercase hexadecimal SHA-256 of a presented key
    • findAll

      public List<ApiKey> findAll()
      Every key, in the order they were added.