private CreateHashedApiKeyResponse createNewApiKey(final CreateHashedApiKeyRequest createHashedApiKeyRequest)
            throws DuplicateApiKeyException {
        LOGGER.debug(() -> LogUtil.message("Attempting to create new API key for {}",
                createHashedApiKeyRequest.getOwner()));
        Objects.requireNonNull(createHashedApiKeyRequest.getName(), "name cannot be null");
        Objects.requireNonNull(createHashedApiKeyRequest.getOwner(), "owner cannot be null");

        final CreateHashedApiKeyRequest request = ensureExpireTimeEpochMs(createHashedApiKeyRequest);

        final String apiKeyStr = apiKeyGenerator.generateRandomApiKey();
        final HashAlgorithm hashAlgorithm = Objects.requireNonNull(createHashedApiKeyRequest.getHashAlgorithm());
        final String apiKeyHash = computeApiKeyHash(apiKeyStr, hashAlgorithm);
        final HashedApiKeyParts hashedApiKeyParts = new HashedApiKeyParts(
                apiKeyHash,
                ApiKeyGenerator.extractPrefixPart(apiKeyStr));

        final HashedApiKey hashedApiKey = apiKeyDao.create(
                request,
                hashedApiKeyParts);

        LOGGER.debug(() -> LogUtil.message("Created new API key for {}", createHashedApiKeyRequest.getOwner()));
        return new CreateHashedApiKeyResponse(apiKeyStr, hashedApiKey);
    }
Fetch the verified {@link UserIdentity} for the passed API key.
If the hash of the API key matches one in the database and that key is enabled
and not expired then the {@link UserIdentity} will be returned, else an empty {@link Optional}
is returned.
stroom-security/stroom-security-impl/src/main/java/stroom/security/impl/apikey/ApiKeyService.java