moresandeep commented on a change in pull request #284: KNOX-2266 - Tokens 
Should Include a Unique Identifier
URL: https://github.com/apache/knox/pull/284#discussion_r390034382
 
 

 ##########
 File path: 
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java
 ##########
 @@ -184,33 +195,22 @@ public long renewToken(final String token, long 
renewInterval) throws UnknownTok
   @Override
   public void revokeToken(final JWTToken token) throws UnknownTokenException {
     if (token == null) {
-      throw new IllegalArgumentException("Token data cannot be null.");
+      throw new IllegalArgumentException("Token identifier cannot be null.");
     }
 
-    revokeToken(token.getPayload());
+    revokeToken(TokenUtils.getTokenId(token));
   }
 
   @Override
-  public void revokeToken(final String token) throws UnknownTokenException {
+  public void revokeToken(final String tokenId) throws UnknownTokenException {
     /* no reason to keep revoked tokens around */
-    removeToken(token);
-    log.revokedToken(TokenUtils.getTokenDisplayText(token));
+    removeToken(tokenId);
+    log.revokedToken(tokenId);
   }
 
   @Override
   public boolean isExpired(final JWTToken token) throws UnknownTokenException {
-    return isExpired(token.getPayload());
-  }
-
-  @Override
-  public boolean isExpired(final String token) throws UnknownTokenException {
-    boolean isExpired;
-    isExpired = isUnknown(token); // Check if the token exist
-    if (!isExpired) {
-      // If it not unknown, check its expiration
-      isExpired = (getTokenExpiration(token) <= System.currentTimeMillis());
-    }
-    return isExpired;
+    return getTokenExpiration(token) <= System.currentTimeMillis();
 
 Review comment:
   This method would throw `UnknownTokenException` if a token is not found. 
Exceptions are expensive (filling up stack trace and unwinding it every time it 
is passed to a new method) so should `getTokenExpiration(token)` return some 
negative value instead?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to