Skip to content

Commit

Permalink
KNOX-3038 - Teh expires_in field in OAuthResource response returns th…
Browse files Browse the repository at this point in the history
…e configured token TTL.

Additionally, removed the override of the getExpiry() method because in the database the meaning of expiration time must remain the same as in the parent class.
  • Loading branch information
smolnar82 committed May 9, 2024
1 parent a3a33aa commit a36d21a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,13 @@ public Response getAuthenticationToken() {
// let's get the subset of the KnoxToken Response needed for OAuth
String accessToken = resp.responseMap.accessToken;
String passcode = resp.responseMap.passcode;
long expires = (long) resp.responseMap.map.get(EXPIRES_IN);
String tokenType = (String) resp.responseMap.map.get(TOKEN_TYPE);

// build and return the expected OAuth response
final HashMap<String, Object> map = new HashMap<>();
map.put(ACCESS_TOKEN, accessToken);
map.put(TOKEN_TYPE, tokenType);
map.put(EXPIRES_IN, expires);
map.put(EXPIRES_IN, getTokenLifetimeInSeconds());
map.put(ISSUED_TOKEN_TYPE, ISSUED_TOKEN_TYPE_ACCESS_TOKEN_VALUE);
// let's use the passcode as the refresh token
map.put(REFRESH_TOKEN, passcode);
Expand All @@ -103,8 +102,7 @@ public Response getAuthenticationToken() {
}
}

@Override
protected long getExpiry() {
private long getTokenLifetimeInSeconds() {
long secs = tokenTTL/1000;

String lifetimeStr = request.getParameter(LIFESPAN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1657,21 +1657,8 @@ private static void validateRevocationResponse(final Response response,


private String getTagValue(String token, String tagName) {
if (!token.contains(tagName)) {
return null;
}
String searchString = "\"" + tagName + "\":";
String value = token.substring(token.indexOf(searchString) + searchString.length());
if (value.startsWith("\"")) {
value = value.substring(1);
}
if (value.contains("\"")) {
return value.substring(0, value.indexOf('\"'));
} else if (value.contains(",")) {
return value.substring(0, value.indexOf(','));
} else {
return value.substring(0, value.length() - 1);
}
final Map<String, String> tokenMap = JsonUtils.getMapFromJsonString(token);
return tokenMap == null ? null : tokenMap.get(tagName);
}

/**
Expand Down

0 comments on commit a36d21a

Please sign in to comment.