directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject directory-kerby git commit: DIRKRB-202 Change the keys in JwtTokenEncoder and JwtTokenDecoder to be non-static. Contributed by Jiajia
Date Mon, 30 Mar 2015 08:36:18 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master b6aa96875 -> a93a49afc


DIRKRB-202 Change the keys in JwtTokenEncoder and JwtTokenDecoder to be non-static. 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/a93a49af
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/a93a49af
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/a93a49af

Branch: refs/heads/master
Commit: a93a49afcaf730d508b55206bfae597b1ed0ffce
Parents: b6aa968
Author: Lin <linchen7@foxmail.com>
Authored: Mon Mar 30 16:35:44 2015 +0800
Committer: Lin <linchen7@foxmail.com>
Committed: Mon Mar 30 16:35:44 2015 +0800

----------------------------------------------------------------------
 .../provider/token/JwtTokenDecoder.java         |  8 +++---
 .../provider/token/JwtTokenEncoder.java         |  8 +++---
 .../kerberos/provider/token/TokenTest.java      | 30 +++++++++++---------
 3 files changed, 25 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a93a49af/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
index d662dff..7e85514 100644
--- 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
@@ -40,8 +40,8 @@ import java.text.ParseException;
  * JWT token decoder, implemented using Nimbus JWT library.
  */
 public class JwtTokenDecoder implements TokenDecoder {
-    private static RSAPrivateKey decryptionKey;
-    private static RSAPublicKey verifyKey;
+    private RSAPrivateKey decryptionKey;
+    private RSAPublicKey verifyKey;
 
     @Override
     public AuthToken decodeFromBytes(byte[] content) throws IOException {
@@ -125,7 +125,7 @@ public class JwtTokenDecoder implements TokenDecoder {
      *
      * @param key a private key
      */
-    public static void setDecryptionKey(RSAPrivateKey key) {
+    public void setDecryptionKey(RSAPrivateKey key) {
         decryptionKey = key;
     }
 
@@ -149,7 +149,7 @@ public class JwtTokenDecoder implements TokenDecoder {
      *
      * @param key a public key
      */
-    public static void setVerifyKey(RSAPublicKey key) {
+    public void setVerifyKey(RSAPublicKey key) {
         verifyKey = key;
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a93a49af/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 69668f6..61e994b 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
@@ -47,9 +47,9 @@ import java.text.ParseException;
 public class JwtTokenEncoder implements TokenEncoder {
     private static JWEAlgorithm jweAlgorithm = JWEAlgorithm.RSA_OAEP;
     private static EncryptionMethod encryptionMethod = EncryptionMethod.A128GCM;
-    private static RSAPublicKey encryptionKey;
     private static JWSAlgorithm jwsAlgorithm = JWSAlgorithm.RS256;
-    private static RSAPrivateKey signKey;
+    private RSAPublicKey encryptionKey;
+    private RSAPrivateKey signKey;
 
     @Override
     public byte[] encodeAsBytes(AuthToken token) throws KrbException {
@@ -122,7 +122,7 @@ public class JwtTokenEncoder implements TokenEncoder {
      *
      * @param key a public key
      */
-    public static void setEncryptionKey(RSAPublicKey key) {
+    public void setEncryptionKey(RSAPublicKey key) {
         encryptionKey = key;
     }
 
@@ -131,7 +131,7 @@ public class JwtTokenEncoder implements TokenEncoder {
      *
      * @param key a private key
      */
-    public static void setSignKey(RSAPrivateKey key) {
+    public void setSignKey(RSAPrivateKey key) {
         signKey = key;
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/a93a49af/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 2baa3be..54eb5ff 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
@@ -92,13 +92,14 @@ public class TokenTest {
 
     @Test
     public void testTokenWithEncryptedJWT() throws Exception {
-        setEncryptKey();
         TokenEncoder tokenEncoder = KrbRuntime.getTokenProvider().createTokenEncoder();
+        TokenDecoder tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        setEncryptKey((JwtTokenEncoder)tokenEncoder, (JwtTokenDecoder)tokenDecoder);
         String tokenStr = tokenEncoder.encodeAsString(authToken);
         System.out.println("Auth token: " + tokenStr);
         Assertions.assertThat(tokenStr).isNotNull();
 
-        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);
@@ -107,13 +108,14 @@ public class TokenTest {
 
     @Test
     public void testTokenWithSignedJWT() throws Exception {
-        setSignKey();
         TokenEncoder tokenEncoder = KrbRuntime.getTokenProvider().createTokenEncoder();
+        TokenDecoder tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        setSignKey((JwtTokenEncoder)tokenEncoder, (JwtTokenDecoder)tokenDecoder);
         String tokenStr = tokenEncoder.encodeAsString(authToken);
         System.out.println("Auth token: " + tokenStr);
         Assertions.assertThat(tokenStr).isNotNull();
 
-        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);
@@ -122,24 +124,26 @@ public class TokenTest {
 
     @Test
     public void testTokenWithSingedAndEncryptedJWT() throws Exception {
-        setSignKey();
-        setEncryptKey();
+
         TokenEncoder tokenEncoder = KrbRuntime.getTokenProvider().createTokenEncoder();
+        TokenDecoder tokenDecoder = KrbRuntime.getTokenProvider().createTokenDecoder();
+        setSignKey((JwtTokenEncoder)tokenEncoder, (JwtTokenDecoder)tokenDecoder);
+        setEncryptKey((JwtTokenEncoder)tokenEncoder, (JwtTokenDecoder)tokenDecoder);
         String tokenStr = tokenEncoder.encodeAsString(authToken);
         System.out.println("Auth token: " + tokenStr);
         Assertions.assertThat(tokenStr).isNotNull();
 
-        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);
     }
 
-    private void setEncryptKey() {
+    private void setEncryptKey(JwtTokenEncoder encoder, JwtTokenDecoder decoder) {
         KeyPair encryptionKeyPair = getKeyPair();
-        JwtTokenEncoder.setEncryptionKey((RSAPublicKey) encryptionKeyPair.getPublic());
-        JwtTokenDecoder.setDecryptionKey((RSAPrivateKey) encryptionKeyPair.getPrivate());
+        encoder.setEncryptionKey((RSAPublicKey) encryptionKeyPair.getPublic());
+        decoder.setDecryptionKey((RSAPrivateKey) encryptionKeyPair.getPrivate());
     }
 
     private KeyPair getKeyPair() {
@@ -152,9 +156,9 @@ public class TokenTest {
         return kpg.generateKeyPair();
     }
 
-    private void setSignKey() {
+    private void setSignKey(JwtTokenEncoder encoder, JwtTokenDecoder decoder) {
         KeyPair signKeyPair = getKeyPair();
-        JwtTokenEncoder.setSignKey((RSAPrivateKey) signKeyPair.getPrivate());
-        JwtTokenDecoder.setVerifyKey((RSAPublicKey)signKeyPair.getPublic());
+        encoder.setSignKey((RSAPrivateKey) signKeyPair.getPrivate());
+        decoder.setVerifyKey((RSAPublicKey)signKeyPair.getPublic());
     }
 }


Mime
View raw message