knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lmc...@apache.org
Subject [05/37] knox git commit: KNOX-1060 - JWT.getExpires() returns null
Date Thu, 26 Oct 2017 14:22:41 GMT
KNOX-1060 - JWT.getExpires() returns null


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/8537d424
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/8537d424
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/8537d424

Branch: refs/heads/KNOX-1049
Commit: 8537d424205dce5b032bbb4c37362d91dd3cfeb5
Parents: 935f81f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Sep 22 11:10:59 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Sep 22 11:10:59 2017 +0100

----------------------------------------------------------------------
 .../services/security/token/impl/JWTToken.java        |  8 +++++++-
 .../services/security/token/impl/JWTTokenTest.java    | 14 ++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/8537d424/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/token/impl/JWTToken.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/token/impl/JWTToken.java
b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/token/impl/JWTToken.java
index b7b8649..567c156 100644
--- a/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/token/impl/JWTToken.java
+++ b/gateway-spi/src/main/java/org/apache/hadoop/gateway/services/security/token/impl/JWTToken.java
@@ -22,6 +22,8 @@ import java.text.ParseException;
 import java.util.Date;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
+
 import org.apache.commons.codec.binary.Base64;
 import org.apache.hadoop.gateway.i18n.messages.MessagesFactory;
 
@@ -214,7 +216,11 @@ public class JWTToken implements JWT {
    */
   @Override
   public String getExpires() {
-    return getClaim(JWT.EXPIRES);
+    Date expires = getExpiresDate();
+    if (expires != null) {
+      return String.valueOf(expires.getTime());
+    }
+    return null;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/knox/blob/8537d424/gateway-spi/src/test/java/org/apache/hadoop/gateway/services/security/token/impl/JWTTokenTest.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/test/java/org/apache/hadoop/gateway/services/security/token/impl/JWTTokenTest.java
b/gateway-spi/src/test/java/org/apache/hadoop/gateway/services/security/token/impl/JWTTokenTest.java
index 4ed2ecf..6372f0c 100644
--- a/gateway-spi/src/test/java/org/apache/hadoop/gateway/services/security/token/impl/JWTTokenTest.java
+++ b/gateway-spi/src/test/java/org/apache/hadoop/gateway/services/security/token/impl/JWTTokenTest.java
@@ -23,6 +23,7 @@ import java.security.NoSuchAlgorithmException;
 import java.security.interfaces.RSAPrivateKey;
 import java.security.interfaces.RSAPublicKey;
 import java.util.ArrayList;
+import java.util.Date;
 
 import org.junit.Test;
 
@@ -206,4 +207,17 @@ public class JWTTokenTest extends org.junit.Assert {
     assertTrue(token.verify(verifier));
   }
 
+  @Test
+  public void testTokenExpiry() throws Exception {
+    String[] claims = new String[4];
+    claims[0] = "KNOXSSO";
+    claims[1] = "john.doe@example.com";
+    claims[2] = "https://login.example.com";
+    claims[3] = Long.toString( ( System.currentTimeMillis()/1000 ) + 300);
+    JWTToken token = new JWTToken("RS256", claims);
+
+    assertNotNull(token.getExpires());
+    assertNotNull(token.getExpiresDate());
+    assertEquals(token.getExpiresDate(), new Date(Long.valueOf(token.getExpires())));
+  }
 }


Mime
View raw message