You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by co...@apache.org on 2017/09/22 09:36:35 UTC
knox git commit: KNOX-1058 - Fix JWTToken.parseToken
Repository: knox
Updated Branches:
refs/heads/master c833bf907 -> 935f81fb0
KNOX-1058 - Fix JWTToken.parseToken
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/935f81fb
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/935f81fb
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/935f81fb
Branch: refs/heads/master
Commit: 935f81fb0f446a18eb09d5c710f679e4012a7cc1
Parents: c833bf9
Author: Colm O hEigeartaigh <co...@apache.org>
Authored: Fri Sep 22 10:36:27 2017 +0100
Committer: Colm O hEigeartaigh <co...@apache.org>
Committed: Fri Sep 22 10:36:27 2017 +0100
----------------------------------------------------------------------
.../services/security/token/impl/JWTToken.java | 16 +++-------------
.../services/security/token/impl/JWTTokenTest.java | 10 +++-------
2 files changed, 6 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/935f81fb/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 49d8609..b7b8649 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
@@ -40,13 +40,8 @@ public class JWTToken implements JWT {
SignedJWT jwt = null;
- private JWTToken(byte[] header, byte[] claims, byte[] signature) throws ParseException {
- try {
- jwt = new SignedJWT(new Base64URL(new String(header, "UTF8")), new Base64URL(new String(claims, "UTF8")),
- new Base64URL(new String(signature, "UTF8")));
- } catch (UnsupportedEncodingException e) {
- log.unsupportedEncoding(e);
- }
+ private JWTToken(String header, String claims, String signature) throws ParseException {
+ jwt = new SignedJWT(new Base64URL(header), new Base64URL(claims), new Base64URL(signature));
}
public JWTToken(String serializedJWT) throws ParseException {
@@ -147,12 +142,7 @@ public class JWTToken implements JWT {
public static JWTToken parseToken(String wireToken) throws ParseException {
log.parsingToken(wireToken);
String[] parts = wireToken.split("\\.");
- JWTToken jwt = new JWTToken(Base64.decodeBase64(parts[0]), Base64.decodeBase64(parts[1]), Base64.decodeBase64(parts[2]));
-// System.out.println("header: " + token.header);
-// System.out.println("claims: " + token.claims);
-// System.out.println("payload: " + new String(token.payload));
-
- return jwt;
+ return new JWTToken(parts[0], parts[1], parts[2]);
}
/* (non-Javadoc)
http://git-wip-us.apache.org/repos/asf/knox/blob/935f81fb/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 ef4023d..4ed2ecf 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
@@ -34,8 +34,7 @@ import com.nimbusds.jose.crypto.RSASSAVerifier;
public class JWTTokenTest extends org.junit.Assert {
private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0MTY5MjkxMDksImp0aSI6ImFhN2Y4ZDBhOTVjIiwic2NvcGVzIjpbInJlcG8iLCJwdWJsaWNfcmVwbyJdfQ.XCEwpBGvOLma4TCoh36FU7XhUbcskygS81HE1uHLf0E";
- private static final String HEADER = "{\"alg\":\"RS256\", \"type\":\"JWT\"}";
- private static final String CLAIMS = "{\"iss\": \"gateway\", \"prn\": \"john.doe@example.com\", \"aud\": \"https://login.example.com\", \"exp\": \"1363360913\"}";
+ private static final String HEADER = "{\"typ\":\"JWT\",\"alg\":\"HS256\"}";
private RSAPublicKey publicKey;
private RSAPrivateKey privateKey;
@@ -49,15 +48,12 @@ public class JWTTokenTest extends org.junit.Assert {
privateKey = (RSAPrivateKey) kp.getPrivate();
}
+ @Test
public void testTokenParsing() throws Exception {
JWTToken token = JWTToken.parseToken(JWT_TOKEN);
assertEquals(token.getHeader(), HEADER);
- assertEquals(token.getClaims(), CLAIMS);
- assertEquals(token.getIssuer(), "gateway");
- assertEquals(token.getPrincipal(), "john.doe@example.com");
- assertEquals(token.getAudience(), "https://login.example.com");
- assertEquals(token.getExpires(), "1363360913");
+ assertEquals(token.getClaim("jti"), "aa7f8d0a95c");
}
@Test