directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [03/14] directory-kerberos git commit: More refactoring
Date Wed, 11 Mar 2015 21:48:16 GMT
More refactoring


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

Branch: refs/heads/installation
Commit: ab8c0d555d50837dd3d6b2ad347ee6d41ad409ff
Parents: 79ab37e
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Thu Feb 12 17:00:54 2015 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Thu Feb 12 17:00:54 2015 +0000

----------------------------------------------------------------------
 .../kerby/kerberos/kerb/client/KrbClient.java   |   4 +-
 .../kerby/kerberos/kerb/client/KrbContext.java  |   6 +-
 .../kerberos/kerb/server/TestKdcServer.java     | 122 -------------------
 .../kerby/kerberos/kerb/server/KdcTestBase.java |  26 +++-
 .../kerberos/kerb/server/TestKdcServer.java     | 122 +++++++++++++++++++
 .../kerby/kerberos/kerb/server/KdcServer.java   |   2 +-
 6 files changed, 152 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbClient.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbClient.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbClient.java
index b5521e7..5c0b360 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbClient.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbClient.java
@@ -65,7 +65,7 @@ public class KrbClient {
      * @param kdcHost
      * @param kdcPort
      */
-    public KrbClient(String kdcHost, short kdcPort) {
+    public KrbClient(String kdcHost, int kdcPort) {
         this(new KrbConfig());
 
         setKdcHost(kdcHost);
@@ -98,7 +98,7 @@ public class KrbClient {
      *
      * @param kdcPort
      */
-    public void setKdcPort(short kdcPort) {
+    public void setKdcPort(int kdcPort) {
         context.setKdcPort(kdcPort);
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbContext.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbContext.java
b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbContext.java
index 12b155f..e9de501 100644
--- a/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbContext.java
+++ b/kerby-kerb/kerb-client/src/main/java/org/apache/kerby/kerberos/kerb/client/KrbContext.java
@@ -27,7 +27,7 @@ public class KrbContext {
     private String kdcRealm;
     private KrbConfig config;
     private String kdcHost;
-    private short kdcPort;
+    private int kdcPort;
     private long timeout = 10L;
     private PreauthHandler preauthHandler;
 
@@ -48,14 +48,14 @@ public class KrbContext {
         this.kdcHost = kdcHost;
     }
 
-    public short getKdcPort() {
+    public int getKdcPort() {
         if (kdcPort > 0) {
             return kdcPort;
         }
         return config.getKdcPort();
     }
 
-    public void setKdcPort(short kdcPort) {
+    public void setKdcPort(int kdcPort) {
         this.kdcPort = kdcPort;
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
b/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
deleted file mode 100644
index 0bac5e2..0000000
--- a/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- *  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.server;
-
-import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.keytab.Keytab;
-import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
-import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
-import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-
-public class TestKdcServer extends SimpleKdcServer {
-
-    public static final String ORG_DOMAIN = KdcConfigKey.KDC_DOMAIN.getPropertyKey();
-    public static final String KDC_REALM = KdcConfigKey.KDC_REALM.getPropertyKey();
-    public static final String KDC_HOST = KdcConfigKey.KDC_HOST.getPropertyKey();
-    public static final String KDC_TCP_PORT = KdcConfigKey.KDC_TCP_PORT.getPropertyKey();
-    public static final String WORK_DIR = KdcConfigKey.WORK_DIR.getPropertyKey();
-
-    private static final Properties DEFAULT_CONFIG = new Properties();
-    static {
-        DEFAULT_CONFIG.setProperty(KDC_HOST, "localhost");
-        DEFAULT_CONFIG.setProperty(KDC_TCP_PORT, "8018");
-        DEFAULT_CONFIG.setProperty(ORG_DOMAIN, "test.com");
-        DEFAULT_CONFIG.setProperty(KDC_REALM, "TEST.COM");
-    }
-
-    public static Properties createConf() {
-        return (Properties) DEFAULT_CONFIG.clone();
-    }
-
-    public TestKdcServer() {
-        this(createConf());
-    }
-
-    public TestKdcServer(Properties conf) {
-        super();
-        getKdcConfig().getConf().addPropertiesConfig(conf);
-    }
-
-    @Override
-    public void init() {
-        super.init();
-
-        createPrincipals("krbtgt");
-    }
-
-    public String getKdcRealm() {
-        return getKdcConfig().getKdcRealm();
-    }
-
-    public synchronized void createPrincipal(String principal, String password) {
-        KrbIdentity identity = new KrbIdentity(principal);
-        List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
-        List<EncryptionKey> encKeys = null;
-        try {
-            encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
-        } catch (KrbException e) {
-            throw new RuntimeException("Failed to generate encryption keys", e);
-        }
-        identity.addKeys(encKeys);
-        getIdentityService().addIdentity(identity);
-    }
-
-    public void createPrincipals(String ... principals) {
-        String passwd;
-        for (String principal : principals) {
-            passwd = UUID.randomUUID().toString();
-            createPrincipal(fixPrincipal(principal), passwd);
-        }
-    }
-
-    private String fixPrincipal(String principal) {
-        if (! principal.contains("@")) {
-            principal += "@" + getKdcRealm();
-        }
-        return principal;
-    }
-
-    public void exportPrincipals(File keytabFile) throws IOException {
-        Keytab keytab = new Keytab();
-
-        List<KrbIdentity> identities = getIdentityService().getIdentities();
-        for (KrbIdentity identity : identities) {
-            PrincipalName principal = identity.getPrincipal();
-            KerberosTime timestamp = new KerberosTime();
-            for (EncryptionType encType : identity.getKeys().keySet()) {
-                EncryptionKey ekey = identity.getKeys().get(encType);
-                int keyVersion = ekey.getKvno();
-                keytab.addEntry(new KeytabEntry(principal, timestamp, keyVersion, ekey));
-            }
-        }
-
-        keytab.store(keytabFile);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/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 1751474..19f7fe3 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
@@ -19,6 +19,9 @@
  */
 package org.apache.kerby.kerberos.kerb.server;
 
+import java.io.IOException;
+import java.net.ServerSocket;
+
 import org.apache.kerby.kerberos.kerb.client.KrbClient;
 import org.junit.After;
 import org.junit.Before;
@@ -30,8 +33,8 @@ public abstract class KdcTestBase {
     protected String serverPrincipal;
 
     protected String hostname = "localhost";
-    protected short tcpPort = 8088;
-    protected short udpPort = 8089;
+    protected int tcpPort;
+    protected int udpPort;
 
     protected TestKdcServer kdcServer;
     protected KrbClient krbClnt;
@@ -43,6 +46,9 @@ public abstract class KdcTestBase {
     }
 
     protected void setUpKdcServer() throws Exception {
+        tcpPort = getServerPort();
+        udpPort = getServerPort();
+        
         kdcServer = new TestKdcServer();
         kdcServer.setKdcHost(hostname);
         kdcServer.setKdcTcpPort(tcpPort);
@@ -62,7 +68,23 @@ public abstract class KdcTestBase {
         krbClnt.setKdcRealm(kdcServer.getKdcRealm());
     }
 
+    /**
+     * Get a server socket point for testing usage, either TCP or UDP.
+     * @return server socket point
+     */
+    private static int getServerPort() {
+        int serverPort = 0;
+
+        try {
+            ServerSocket serverSocket = new ServerSocket(0);
+            serverPort = serverSocket.getLocalPort();
+            serverSocket.close();
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to get a server socket point");
+        }
 
+        return serverPort;
+    }
 
     @After
     public void tearDown() throws Exception {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
new file mode 100644
index 0000000..0bac5e2
--- /dev/null
+++ b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcServer.java
@@ -0,0 +1,122 @@
+/**
+ *  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.server;
+
+import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.keytab.Keytab;
+import org.apache.kerby.kerberos.kerb.keytab.KeytabEntry;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.spec.KerberosTime;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
+import org.apache.kerby.kerberos.kerb.spec.common.PrincipalName;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+public class TestKdcServer extends SimpleKdcServer {
+
+    public static final String ORG_DOMAIN = KdcConfigKey.KDC_DOMAIN.getPropertyKey();
+    public static final String KDC_REALM = KdcConfigKey.KDC_REALM.getPropertyKey();
+    public static final String KDC_HOST = KdcConfigKey.KDC_HOST.getPropertyKey();
+    public static final String KDC_TCP_PORT = KdcConfigKey.KDC_TCP_PORT.getPropertyKey();
+    public static final String WORK_DIR = KdcConfigKey.WORK_DIR.getPropertyKey();
+
+    private static final Properties DEFAULT_CONFIG = new Properties();
+    static {
+        DEFAULT_CONFIG.setProperty(KDC_HOST, "localhost");
+        DEFAULT_CONFIG.setProperty(KDC_TCP_PORT, "8018");
+        DEFAULT_CONFIG.setProperty(ORG_DOMAIN, "test.com");
+        DEFAULT_CONFIG.setProperty(KDC_REALM, "TEST.COM");
+    }
+
+    public static Properties createConf() {
+        return (Properties) DEFAULT_CONFIG.clone();
+    }
+
+    public TestKdcServer() {
+        this(createConf());
+    }
+
+    public TestKdcServer(Properties conf) {
+        super();
+        getKdcConfig().getConf().addPropertiesConfig(conf);
+    }
+
+    @Override
+    public void init() {
+        super.init();
+
+        createPrincipals("krbtgt");
+    }
+
+    public String getKdcRealm() {
+        return getKdcConfig().getKdcRealm();
+    }
+
+    public synchronized void createPrincipal(String principal, String password) {
+        KrbIdentity identity = new KrbIdentity(principal);
+        List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
+        List<EncryptionKey> encKeys = null;
+        try {
+            encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
+        } catch (KrbException e) {
+            throw new RuntimeException("Failed to generate encryption keys", e);
+        }
+        identity.addKeys(encKeys);
+        getIdentityService().addIdentity(identity);
+    }
+
+    public void createPrincipals(String ... principals) {
+        String passwd;
+        for (String principal : principals) {
+            passwd = UUID.randomUUID().toString();
+            createPrincipal(fixPrincipal(principal), passwd);
+        }
+    }
+
+    private String fixPrincipal(String principal) {
+        if (! principal.contains("@")) {
+            principal += "@" + getKdcRealm();
+        }
+        return principal;
+    }
+
+    public void exportPrincipals(File keytabFile) throws IOException {
+        Keytab keytab = new Keytab();
+
+        List<KrbIdentity> identities = getIdentityService().getIdentities();
+        for (KrbIdentity identity : identities) {
+            PrincipalName principal = identity.getPrincipal();
+            KerberosTime timestamp = new KerberosTime();
+            for (EncryptionType encType : identity.getKeys().keySet()) {
+                EncryptionKey ekey = identity.getKeys().get(encType);
+                int keyVersion = ekey.getKvno();
+                keytab.addEntry(new KeytabEntry(principal, timestamp, keyVersion, ekey));
+            }
+        }
+
+        keytab.store(keytabFile);
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/ab8c0d55/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
index a0c514e..4e723d9 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServer.java
@@ -113,7 +113,7 @@ public class KdcServer {
         this.kdcTcpPort = kdcTcpPort;
     }
 
-    public void setKdcUdpPort(short kdcUdpPort) {
+    public void setKdcUdpPort(int kdcUdpPort) {
         this.kdcUdpPort = kdcUdpPort;
     }
 


Mime
View raw message