directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerby git commit: DIRKRB-198 Separate the TokenDecoder from TokenEncoder. Contributed by Jiajia
Date Fri, 27 Mar 2015 08:19:03 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 6af11b6ce -> bf116de47


DIRKRB-198 Separate the TokenDecoder from TokenEncoder. Contributed by Jiajia


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/bf116de4
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/bf116de4
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/bf116de4

Branch: refs/heads/master
Commit: bf116de47a4499f600226ba304fe557d8d2b4b38
Parents: 6af11b6
Author: Drankye <drankye@gmail.com>
Authored: Sat Mar 28 00:16:08 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Sat Mar 28 00:16:08 2015 +0800

----------------------------------------------------------------------
 ...kinit-1.0-SNAPSHOT-jar-with-dependencies.jar | Bin 0 -> 3510337 bytes
 ...y-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar | Bin 0 -> 7965000 bytes
 .../kerberos/kerb/provider/TokenDecoder.java    |  44 ++++++++++++++++
 .../kerberos/kerb/provider/TokenEncoder.java    |  17 +------
 .../kerberos/kerb/provider/TokenProvider.java   |   6 +++
 .../kerby/kerberos/kerb/spec/base/KrbToken.java |  11 +++-
 .../provider/token/JwtTokenDecoder.java         |  50 +++++++++++++++++++
 .../provider/token/JwtTokenEncoder.java         |  17 -------
 .../provider/token/JwtTokenProvider.java        |   6 +++
 .../kerberos/provider/token/TokenTest.java      |   4 +-
 .../kerby/kerberos/tool/token/TokenInit.java    |   4 +-
 11 files changed, 123 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kdc-tool/kinit/kinit-dist/kinit/kinit-1.0-SNAPSHOT-jar-with-dependencies.jar
----------------------------------------------------------------------
diff --git a/kdc-tool/kinit/kinit-dist/kinit/kinit-1.0-SNAPSHOT-jar-with-dependencies.jar
b/kdc-tool/kinit/kinit-dist/kinit/kinit-1.0-SNAPSHOT-jar-with-dependencies.jar
new file mode 100644
index 0000000..ff44e4f
Binary files /dev/null and b/kdc-tool/kinit/kinit-dist/kinit/kinit-1.0-SNAPSHOT-jar-with-dependencies.jar
differ

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-kdc/kerby-kdc-dist/kerby-kdc/kerby-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar
----------------------------------------------------------------------
diff --git a/kerby-kdc/kerby-kdc-dist/kerby-kdc/kerby-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar
b/kerby-kdc/kerby-kdc-dist/kerby-kdc/kerby-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar
new file mode 100644
index 0000000..fca3d41
Binary files /dev/null and b/kerby-kdc/kerby-kdc-dist/kerby-kdc/kerby-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar
differ

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenDecoder.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenDecoder.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenDecoder.java
new file mode 100644
index 0000000..847dec6
--- /dev/null
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenDecoder.java
@@ -0,0 +1,44 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.kerb.provider;
+
+import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
+
+import java.io.IOException;
+
+/**
+ * An AuthToken decoder.
+ */
+public interface TokenDecoder {
+
+    /**
+     * Decode a token from a bytes array.
+     * @param content
+     * @return token
+     */
+    public AuthToken decodeFromBytes(byte[] content) throws IOException;
+
+    /**
+     * Decode a token from a string.
+     * @param content
+     * @return token
+     */
+    public AuthToken decodeFromString(String content) throws IOException;
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.java
index 7441fb5..879dea2 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenEncoder.java
@@ -22,10 +22,8 @@ package org.apache.kerby.kerberos.kerb.provider;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
 
-import java.io.IOException;
-
 /**
- * An AuthToken encoder and decoder.
+ * An AuthToken encoder.
  */
 public interface TokenEncoder {
 
@@ -37,24 +35,11 @@ public interface TokenEncoder {
     public byte[] encodeAsBytes(AuthToken token) throws KrbException;
 
     /**
-     * Decode a token from a bytes array.
-     * @param content
-     * @return token
-     */
-    public AuthToken decodeFromBytes(byte[] content) throws IOException;
-
-    /**
      * Encode a token resulting in a string.
      * @param token
      * @return string representation
      */
     public String encodeAsString(AuthToken token) throws KrbException;
 
-    /**
-     * Decode a token from a string.
-     * @param content
-     * @return token
-     */
-    public AuthToken decodeFromString(String content) throws IOException;
 
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.java
index aea25d3..54ae0b9 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/provider/TokenProvider.java
@@ -33,6 +33,12 @@ public interface TokenProvider extends KrbProvider {
     public TokenEncoder createTokenEncoder();
 
     /**
+     * Create a token decoder.
+     * @return token decoder
+     */
+    public TokenDecoder createTokenDecoder();
+
+    /**
      * Create a token factory that can be used to construct concrete token.
      * @return token factory
      */

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/base/KrbToken.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/base/KrbToken.java
b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/base/KrbToken.java
index 29e1271..686feb5 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/base/KrbToken.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/spec/base/KrbToken.java
@@ -24,6 +24,7 @@ import org.apache.kerby.asn1.type.Asn1Integer;
 import org.apache.kerby.asn1.type.Asn1OctetString;
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.KrbRuntime;
+import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
 import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
 import org.apache.kerby.kerberos.kerb.spec.KrbSequenceType;
 
@@ -41,6 +42,7 @@ import java.util.Map;
  */
 public class KrbToken extends KrbSequenceType implements AuthToken {
     private static TokenEncoder tokenEncoder;
+    private static TokenDecoder tokenDecoder;
 
     private static int TOKEN_FORMAT = 0;
     private static int TOKEN_VALUE = 1;
@@ -69,7 +71,7 @@ public class KrbToken extends KrbSequenceType implements AuthToken {
     @Override
     public void decode(ByteBuffer content) throws IOException {
         super.decode(content);
-        this.innerToken = getTokenEncoder().decodeFromBytes(getTokenValue());
+        this.innerToken = getTokenDecoder().decodeFromBytes(getTokenValue());
     }
 
     private static TokenEncoder getTokenEncoder() {
@@ -79,6 +81,13 @@ public class KrbToken extends KrbSequenceType implements AuthToken {
         return tokenEncoder;
     }
 
+    private static TokenDecoder getTokenDecoder() {
+        if (tokenDecoder == null) {
+            tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        }
+        return tokenDecoder;
+    }
+
     public TokenFormat getTokenFormat() {
         Integer value = getFieldAsInteger(TOKEN_FORMAT);
         return TokenFormat.fromValue(value);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
new file mode 100644
index 0000000..97f0ec3
--- /dev/null
+++ b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenDecoder.java
@@ -0,0 +1,50 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ *
+ */
+package org.apache.kerby.kerberos.provider.token;
+
+import com.nimbusds.jwt.PlainJWT;
+import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
+import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
+
+import java.io.IOException;
+import java.text.ParseException;
+
+/**
+ * JWT token decoder, implemented using Nimbus JWT library.
+ */
+public class JwtTokenDecoder implements TokenDecoder {
+
+    @Override
+    public AuthToken decodeFromBytes(byte[] content) throws IOException {
+        String tokenStr = String.valueOf(content);
+
+        return decodeFromString(tokenStr);
+    }
+
+    @Override
+    public AuthToken decodeFromString(String content) throws IOException {
+        try {
+            PlainJWT jwt = PlainJWT.parse(content);
+            return new JwtAuthToken(jwt.getJWTClaimsSet());
+        } catch (ParseException e) {
+            throw new IOException("Failed to parse JWT token string", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
index 474b869..80c3947 100644
--- a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
+++ b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenEncoder.java
@@ -40,13 +40,6 @@ public class JwtTokenEncoder implements TokenEncoder {
     }
 
     @Override
-    public AuthToken decodeFromBytes(byte[] content) throws IOException {
-        String tokenStr = String.valueOf(content);
-
-        return decodeFromString(tokenStr);
-    }
-
-    @Override
     public String encodeAsString(AuthToken token) throws KrbException {
         if (! (token instanceof JwtAuthToken) ) {
             throw new KrbException("Unexpected AuthToken, not JwtAuthToken");
@@ -58,14 +51,4 @@ public class JwtTokenEncoder implements TokenEncoder {
         String tokenStr = jwt.serialize();
         return tokenStr;
     }
-
-    @Override
-    public AuthToken decodeFromString(String content) throws IOException {
-        try {
-            PlainJWT jwt = PlainJWT.parse(content);
-            return new JwtAuthToken(jwt.getJWTClaimsSet());
-        } catch (ParseException e) {
-            throw new IOException("Failed to parse JWT token string", e);
-        }
-    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenProvider.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenProvider.java
b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenProvider.java
index e439766..85f34c8 100644
--- a/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenProvider.java
+++ b/kerby-provider/token-provider/src/main/java/org/apache/kerby/kerberos/provider/token/JwtTokenProvider.java
@@ -19,6 +19,7 @@
  */
 package org.apache.kerby.kerberos.provider.token;
 
+import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
 import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
 import org.apache.kerby.kerberos.kerb.provider.TokenFactory;
 import org.apache.kerby.kerberos.kerb.provider.TokenProvider;
@@ -35,6 +36,11 @@ public class JwtTokenProvider implements TokenProvider {
     }
 
     @Override
+    public TokenDecoder createTokenDecoder() {
+        return new JwtTokenDecoder();
+    }
+
+    @Override
     public TokenFactory createTokenFactory() {
         return new TokenFactory() {
             @Override

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-provider/token-provider/src/test/java/org/apache/kerby/kerberos/provider/token/TokenTest.java
----------------------------------------------------------------------
diff --git a/kerby-provider/token-provider/src/test/java/org/apache/kerby/kerberos/provider/token/TokenTest.java
b/kerby-provider/token-provider/src/test/java/org/apache/kerby/kerberos/provider/token/TokenTest.java
index 19ec379..82fa888 100644
--- a/kerby-provider/token-provider/src/test/java/org/apache/kerby/kerberos/provider/token/TokenTest.java
+++ b/kerby-provider/token-provider/src/test/java/org/apache/kerby/kerberos/provider/token/TokenTest.java
@@ -20,6 +20,7 @@
 package org.apache.kerby.kerberos.provider.token;
 
 import org.apache.kerby.kerberos.kerb.KrbRuntime;
+import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
 import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
 import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
 import org.assertj.core.api.Assertions;
@@ -77,7 +78,8 @@ public class TokenTest {
         System.out.println("Auth token: " + tokenStr);
         Assertions.assertThat(tokenStr).isNotNull();
 
-        AuthToken token2 = tokenEncoder.decodeFromString(tokenStr);
+        TokenDecoder tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        AuthToken token2 = tokenDecoder.decodeFromString(tokenStr);
         System.out.println("Decoded token's subject: " + token2.getSubject());
         Assertions.assertThat(token2.getSubject()).isEqualTo(SUBJECT);
         Assertions.assertThat(token2.getIssuer()).isEqualTo(ISSUER);

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/bf116de4/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenInit.java
----------------------------------------------------------------------
diff --git a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenInit.java
b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenInit.java
index 20a6694..5caa468 100644
--- a/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenInit.java
+++ b/kerby-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/token/TokenInit.java
@@ -20,6 +20,7 @@
 package org.apache.kerby.kerberos.tool.token;
 
 import org.apache.kerby.kerberos.kerb.KrbRuntime;
+import org.apache.kerby.kerberos.kerb.provider.TokenDecoder;
 import org.apache.kerby.kerberos.kerb.provider.TokenEncoder;
 import org.apache.kerby.kerberos.kerb.spec.base.AuthToken;
 import org.apache.kerby.kerberos.provider.token.JwtTokenProvider;
@@ -91,7 +92,8 @@ public class TokenInit {
         TokenCache.writeToken(tokenStr);
         System.out.println("Issued token: " + tokenStr);
 
-        AuthToken token2 = tokenEncoder.decodeFromString(tokenStr);
+        TokenDecoder tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        AuthToken token2 = tokenDecoder.decodeFromString(tokenStr);
         System.out.println("Decoded token's subject: " + token2.getSubject());
     }
 }


Mime
View raw message