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: Improved SimpleKdcServer with token client and pkinit client, and refactored related tests
Date Fri, 25 Dec 2015 21:40:01 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 675413088 -> 604d3fcc4


Improved SimpleKdcServer with token client and pkinit client, and refactored related tests


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

Branch: refs/heads/master
Commit: 604d3fcc434b1c96d663c0283713e49bc57a7824
Parents: 6754130
Author: Kai Zheng <kai.zheng@intel.com>
Authored: Sat Dec 26 05:39:46 2015 +0800
Committer: Kai Zheng <kai.zheng@intel.com>
Committed: Sat Dec 26 05:39:46 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kdc/AnonymousPkinitKdcTest.java    | 15 ++++++-----
 .../kerberos/kdc/WithAccessTokenKdcTest.java    |  2 +-
 .../kerby/kerberos/kdc/WithCertKdcTest.java     |  7 +++---
 .../kerberos/kdc/WithIdentityTokenKdcTest.java  |  2 +-
 .../kerberos/kdc/WithTokenKdcTestBase.java      |  4 +--
 .../kerby/kerberos/kerb/server/KdcTestBase.java | 10 ++++++++
 .../kerberos/kerb/server/SimpleKdcServer.java   | 26 +++++++++++++++++++-
 7 files changed, 50 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/AnonymousPkinitKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/AnonymousPkinitKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/AnonymousPkinitKdcTest.java
index 7f1f5c2..bfd8746 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/AnonymousPkinitKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/AnonymousPkinitKdcTest.java
@@ -27,18 +27,21 @@ import org.apache.kerby.kerberos.kerb.server.KdcConfigKey;
 import org.apache.kerby.kerberos.kerb.server.KdcTestBase;
 import org.apache.kerby.kerberos.kerb.type.ticket.SgtTicket;
 import org.apache.kerby.kerberos.kerb.type.ticket.TgtTicket;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
 public class AnonymousPkinitKdcTest extends KdcTestBase {
-
     private String serverPrincipal;
+    private KrbPkinitClient pkinitClient;
 
     @Before
     public void setUp() throws Exception {
         super.setUp();
+
+        pkinitClient = getPkinitClient();
     }
 
     @Override
@@ -63,23 +66,19 @@ public class AnonymousPkinitKdcTest extends KdcTestBase {
 
     @Test
     public void testAnonymity() throws Exception {
-
-        getKrbClient().init();
-
-
         TgtTicket tgt;
-        KrbPkinitClient pkinitClient = new KrbPkinitClient(getKrbClient());
+
         try {
             tgt = pkinitClient.requestTgt();
         } catch (KrbException te) {
             te.printStackTrace();
-            assertThat(te.getMessage().contains("timeout")).isTrue();
+            Assert.fail();
             return;
         }
         assertThat(tgt).isNotNull();
 
         serverPrincipal = getServerPrincipal();
-        SgtTicket tkt = getKrbClient().requestSgt(tgt, serverPrincipal);
+        SgtTicket tkt = pkinitClient.requestSgt(tgt, serverPrincipal);
         assertThat(tkt).isNotNull();
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithAccessTokenKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithAccessTokenKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithAccessTokenKdcTest.java
index 3971265..e829625 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithAccessTokenKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithAccessTokenKdcTest.java
@@ -136,7 +136,7 @@ public class WithAccessTokenKdcTest extends WithTokenKdcTestBase {
     private void performTest() throws Exception {
         createCredentialCache(getClientPrincipal(), getClientPassword());
 
-        KrbTokenClient tokenClient = new KrbTokenClient(getKrbClient());
+        KrbTokenClient tokenClient = getTokenClient();
         try {
             SgtTicket sgtTicket = tokenClient.requestSgt(
                 getKrbToken(), getServerPrincipal(), getcCacheFile().getPath());

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithCertKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithCertKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithCertKdcTest.java
index 1705bf9..05183ea 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithCertKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithCertKdcTest.java
@@ -50,11 +50,15 @@ public class WithCertKdcTest extends KdcTestBase {
     private Certificate userCert;
     private PrivateKey userKey; //NOPMD
 
+    private KrbPkinitClient pkinitClient;
+
     @Before
     public void setUp() throws Exception {
         pkiLoader = new PkiLoader();
 
         super.setUp();
+
+        pkinitClient = getPkinitClient();
     }
 
     @Override
@@ -80,10 +84,7 @@ public class WithCertKdcTest extends KdcTestBase {
     public void testPkinit() throws Exception {
         assertThat(userCert).isNotNull();
 
-        getKrbClient().init();
-
         TgtTicket tgt;
-        KrbPkinitClient pkinitClient = new KrbPkinitClient(getKrbClient());
         try {
             String userCertPath = getClass().getResource("/usercert.pem").getPath();
             String userKeyPath = getClass().getResource("/userkey.pem").getPath();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithIdentityTokenKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithIdentityTokenKdcTest.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithIdentityTokenKdcTest.java
index 5eaa176..acac0a0 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithIdentityTokenKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithIdentityTokenKdcTest.java
@@ -137,7 +137,7 @@ public class WithIdentityTokenKdcTest extends WithTokenKdcTestBase {
         createCredentialCache(getClientPrincipal(), getClientPassword());
 
         TgtTicket tgt;
-        KrbTokenClient tokenClient = new KrbTokenClient(getKrbClient());
+        KrbTokenClient tokenClient = getTokenClient();
         try {
             tgt = tokenClient.requestTgt(getKrbToken(),
                 getcCacheFile().getPath());

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTestBase.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTestBase.java
b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTestBase.java
index f33309f..bed9e7d 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTestBase.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTestBase.java
@@ -120,10 +120,10 @@ public class WithTokenKdcTestBase extends KdcTestBase {
         TokenEncoder tokenEncoder = KrbRuntime.getTokenProvider().createTokenEncoder();
 
         if (tokenEncoder instanceof JwtTokenEncoder && signingKey != null) {
-            ((JwtTokenEncoder) tokenEncoder).setSignKey(signingKey);
+            tokenEncoder.setSignKey(signingKey);
         }
         if (tokenEncoder instanceof JwtTokenEncoder && encryptionKey != null) {
-            ((JwtTokenEncoder) tokenEncoder).setEncryptionKey(encryptionKey);
+            tokenEncoder.setEncryptionKey(encryptionKey);
         }
 
         krbToken = new KrbToken();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
index 49bf5cf..8bc4205 100644
--- a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
+++ b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
@@ -21,6 +21,8 @@ package org.apache.kerby.kerberos.kerb.server;
 
 import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.client.KrbClient;
+import org.apache.kerby.kerberos.kerb.client.KrbPkinitClient;
+import org.apache.kerby.kerberos.kerb.client.KrbTokenClient;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Before;
@@ -71,6 +73,14 @@ public abstract class KdcTestBase {
         return kdcServer.getKrbClient();
     }
 
+    protected KrbPkinitClient getPkinitClient() {
+        return kdcServer.getPkinitClient();
+    }
+
+    protected KrbTokenClient getTokenClient() {
+        return kdcServer.getTokenClient();
+    }
+
     protected String getClientPrincipalName() {
         return clientPrincipalName;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/604d3fcc/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
index 0a7ad1d..5e83207 100644
--- a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
+++ b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
@@ -23,6 +23,8 @@ import org.apache.kerby.kerberos.kerb.KrbException;
 import org.apache.kerby.kerberos.kerb.admin.Kadmin;
 import org.apache.kerby.kerberos.kerb.client.Krb5Conf;
 import org.apache.kerby.kerberos.kerb.client.KrbClient;
+import org.apache.kerby.kerberos.kerb.client.KrbPkinitClient;
+import org.apache.kerby.kerberos.kerb.client.KrbTokenClient;
 import org.apache.kerby.util.NetworkUtil;
 
 import java.io.File;
@@ -36,9 +38,11 @@ public class SimpleKdcServer extends KdcServer {
     private final KrbClient krbClnt;
     private Kadmin kadmin;
     private Krb5Conf krb5Conf;
-
     private File workDir;
 
+    private KrbPkinitClient pkinitClient;
+    private KrbTokenClient tokenClient;
+
     /**
      * Default constructor.
      *
@@ -155,6 +159,26 @@ public class SimpleKdcServer extends KdcServer {
     }
 
     /**
+     * @return PKINIT client
+     */
+    public KrbPkinitClient getPkinitClient() {
+        if (pkinitClient == null) {
+            pkinitClient = new KrbPkinitClient(krbClnt);
+        }
+        return pkinitClient;
+    }
+
+    /**
+     * @return Token client
+     */
+    public KrbTokenClient getTokenClient() {
+        if (tokenClient == null) {
+            tokenClient = new KrbTokenClient(krbClnt);
+        }
+        return tokenClient;
+    }
+
+    /**
      * Get Kadmin operation interface.
      * @return Kadmin
      */


Mime
View raw message