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