improved logging
This commit is contained in:
@ -151,20 +151,42 @@ public class ApiKeyService implements Serializable {
|
||||
|
||||
private ApiKeyEntity getValidKey(String userName, String apiKey, String authorizationHeader) throws JWTException {
|
||||
AccountEntity userAccount = accountControl.getAccountEntity(userName, false);
|
||||
if (userAccount == null) {
|
||||
throw new JWTException("AccountControl exception");
|
||||
}
|
||||
List<ApiKeyEntity> apiKeys = getUsersApiKeys(userAccount);
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Found {} keys for user {}", apiKeys.size(), userName);
|
||||
}
|
||||
|
||||
Iterator<ApiKeyEntity> it = apiKeys.iterator();
|
||||
ApiKeyEntity keyToLogout = null;
|
||||
while (keyToLogout == null && it.hasNext()) {
|
||||
ApiKeyEntity key = it.next();
|
||||
if (key.getApiKey().equals(apiKey)) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Found API key in database");
|
||||
}
|
||||
|
||||
ZonedDateTime issuedOn = ZonedDateTime.ofInstant(key.getIssuedOn().toInstant(), ZoneOffset.UTC);
|
||||
String testString = JWTEncoder.encode(password, issuer, issuedOn, key.getAccount().getUsername(), key.getApiKey(), key.getExpiration());
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Successfully created validation JWT for user {}", userName);
|
||||
}
|
||||
|
||||
if (authorizationHeader.equals(testString)) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Found valid key for user {}", userName);
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("No valid key for user {} found", userName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user