directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject directory-kerberos git commit: Add support for server load configure from config file And enhance kdc server to respect some more items in config file.
Date Fri, 13 Mar 2015 06:13:20 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 0b649f508 -> cb5c66e92


Add support for server load configure from config file And enhance kdc server to respect some
more items in config file.


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

Branch: refs/heads/master
Commit: cb5c66e920149439c9d06a2bc13af7915a84a050
Parents: 0b649f5
Author: hazel <linchen7@foxmail.com>
Authored: Fri Mar 13 14:13:12 2015 +0800
Committer: hazel <linchen7@foxmail.com>
Committed: Fri Mar 13 14:13:12 2015 +0800

----------------------------------------------------------------------
 kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh        | 18 +++++++-
 .../kerberos/kdc/server/KerbyKdcServer.java     | 44 +++++++++++++++-----
 .../kerby/kerberos/kerb/server/KdcConfig.java   |  4 +-
 .../kerberos/kerb/server/KdcConfigKey.java      |  4 +-
 .../kerberos/kerb/server/TestKdcConfigLoad.java | 20 +++++----
 .../kerb-server/src/test/resources/kdc.conf     |  2 +
 6 files changed, 67 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh
----------------------------------------------------------------------
diff --git a/kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh b/kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh
index 07d6214..ce39497 100644
--- a/kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh
+++ b/kerby-kdc/kerby-kdc-dist/bin/kerbykdc.sh
@@ -1,4 +1,20 @@
 #!/bin/bash
-confdir=/etc/kerby/kdc.conf
+# 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.
+confdir=/etc/kerby/conf
 workingdir=/usr/kerby/kdc/
 java -jar ../kerby-kdc/kerby-kdc-1.0-SNAPSHOT-jar-with-dependencies.jar -start ${confdir}
${workingdir}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/server/KerbyKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/server/KerbyKdcServer.java
b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/server/KerbyKdcServer.java
index f9a85bb..003dd36 100644
--- a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/server/KerbyKdcServer.java
+++ b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/server/KerbyKdcServer.java
@@ -19,11 +19,15 @@
  */
 package org.apache.kerby.kerberos.kdc.server;
 
+import org.apache.kerby.config.Conf;
 import org.apache.kerby.config.Config;
 import org.apache.kerby.kerberos.kdc.identitybackend.LdapIdentityBackend;
 import org.apache.kerby.kerberos.kerb.identity.IdentityService;
 import org.apache.kerby.kerberos.kerb.server.KdcServer;
 
+import java.io.File;
+import java.io.IOException;
+
 /**
  * The mentioned Kerby KDC server implementation
  */
@@ -38,7 +42,26 @@ public class KerbyKdcServer extends KdcServer {
         initIdentityService();
     }
 
-    private static KdcServer server;
+    public void init(String confDir, String workDir) throws IOException {
+        init();
+        initConfig(confDir);
+    }
+
+    /**
+     * init config from configuration file
+     */
+    private void initConfig(String confDirString) throws IOException {
+        Conf conf = kdcConfig.getConf();
+
+        File confDir = new File(confDirString);
+        File[] files = confDir.listFiles();
+        for (File file : files) {
+            conf.addIniConfig(file);
+        }
+
+    }
+
+    private static KerbyKdcServer server;
     private static final String USAGE = "Usage: " + KerbyKdcServer.class.getSimpleName()
+ " -start conf-dir working-dir|-stop";
 
     public static void main(String[] args) {
@@ -53,18 +76,17 @@ public class KerbyKdcServer extends KdcServer {
                 return;
             }
             String confDir = args[1];
-            String workingDir = args[2];
-
-            //FIXME host and config should be loaded from configuration.
-            String serverHost = "localhost";
-            short serverPort = 8015;
+            String workDir = args[2];
 
-            server = new KdcServer();
-            server.setKdcHost(serverHost);
-            server.setKdcTcpPort(serverPort);
-            server.init();
+            server = new KerbyKdcServer();
+            try {
+                server.init(confDir, workDir);
+            } catch (IOException e) {
+                System.err.println("Something wrong with configuration files or work files");
+                return;
+            }
             server.start();
-            System.out.println("KDC Server(" + KerbyKdcServer.class.getSimpleName() + ")
started.");
+            System.out.println(KerbyKdcServer.class.getSimpleName() + " started.");
         } else if (args[0].equals("-stop")) {
             //server.stop();//FIXME can't get the server instance here
             System.out.println("KDC Server stoped.");

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfig.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfig.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfig.java
index a3a4703..da4bfe3 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfig.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfig.java
@@ -58,7 +58,7 @@ public class KdcConfig {
     }
 
     public String getKdcHost() {
-        return conf.getString(KdcConfigKey.KDC_HOST);
+        return KrbConfHelper.getStringUnderSection(conf, KdcConfigKey.KDC_HOST);
     }
 
     public int getKdcPort() {
@@ -94,7 +94,7 @@ public class KdcConfig {
     }
 
     public String getKdcRealm() {
-        return conf.getString(KdcConfigKey.KDC_REALM);
+        return KrbConfHelper.getStringUnderSection(conf, KdcConfigKey.KDC_REALM);
     }
 
     public String getKdcDomain() {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfigKey.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfigKey.java
b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfigKey.java
index 6792d06..497160a 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfigKey.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcConfigKey.java
@@ -25,13 +25,13 @@ public enum KdcConfigKey implements SectionConfigKey {
     KRB_DEBUG(true),
     WORK_DIR,
     KDC_SERVICE_NAME("Kerby_KDC_Server"),
-    KDC_HOST("127.0.0.1"),
+    KDC_HOST("127.0.0.1", "kdcdefaults"),
     KDC_PORT(8015, "kdcdefaults"),
     KDC_ALLOW_UDP(true, "kdcdefaults"),
     KDC_UDP_PORT(8016, "kdcdefaults"),
     KDC_TCP_PORT(8015, "kdcdefaults"),
     KDC_DOMAIN("example.com"),
-    KDC_REALM("EXAMPLE.COM"),
+    KDC_REALM("EXAMPLE.COM", "kdcdefaults"),
     TGS_PRINCIPAL("krbtgt@EXAMPLE.COM"),
     PREAUTH_REQUIRED(true),
     ALLOWABLE_CLOCKSKEW(5 * 60L),

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
index 7f00a3a..55bd799 100644
--- a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
+++ b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/TestKdcConfigLoad.java
@@ -36,18 +36,20 @@ public class TestKdcConfigLoad {
         URL confFileUrl = TestKdcConfigLoad.class.getResource("/kdc.conf");
         File confFile = new File(confFileUrl.toURI());
 
-        KdcConfig krbConfig = new KdcConfig();
-        Conf conf = krbConfig.getConf();
+        KdcConfig kdcConfig = new KdcConfig();
+        Conf conf = kdcConfig.getConf();
         conf.addIniConfig(confFile);
 
-        assertThat(krbConfig.getDefaultLoggingLocation()).isEqualTo("FILE:/var/log/krb5libs.log");
-        assertThat(krbConfig.getKdcLoggingLocation()).isEqualTo("FILE:/var/log/krb5kdc.log");
-        assertThat(krbConfig.getAdminLoggingLocation()).isEqualTo("FILE:/var/log/kadmind.log");
+        assertThat(kdcConfig.getDefaultLoggingLocation()).isEqualTo("FILE:/var/log/krb5libs.log");
+        assertThat(kdcConfig.getKdcLoggingLocation()).isEqualTo("FILE:/var/log/krb5kdc.log");
+        assertThat(kdcConfig.getAdminLoggingLocation()).isEqualTo("FILE:/var/log/kadmind.log");
 
-        assertThat(krbConfig.getKdcUdpPort()).isEqualTo(88);
-        assertThat(krbConfig.getKdcTcpPort()).isEqualTo(8014);
-        assertThat(krbConfig.isRestrictAnonymousToTgt()).isTrue();
-        assertThat(krbConfig.getKdcMaxDgramReplySize()).isEqualTo(4096);
+        assertThat(kdcConfig.getKdcHost()).isEqualTo("localhost");
+        assertThat(kdcConfig.getKdcUdpPort()).isEqualTo(88);
+        assertThat(kdcConfig.getKdcTcpPort()).isEqualTo(8014);
+        assertThat(kdcConfig.getKdcRealm()).isEqualTo("TEST.COM");
+        assertThat(kdcConfig.isRestrictAnonymousToTgt()).isTrue();
+        assertThat(kdcConfig.getKdcMaxDgramReplySize()).isEqualTo(4096);
 
         /* will be moved to LdapLdentityBackend module
         String[] ldapContainerDn = krbConfig.getLdapKerberosContainerDn();

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/cb5c66e9/kerby-kerb/kerb-server/src/test/resources/kdc.conf
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/resources/kdc.conf b/kerby-kerb/kerb-server/src/test/resources/kdc.conf
index 8f286a1..aee9c3a 100644
--- a/kerby-kerb/kerb-server/src/test/resources/kdc.conf
+++ b/kerby-kerb/kerb-server/src/test/resources/kdc.conf
@@ -21,8 +21,10 @@
   admin_server = FILE:/var/log/kadmind.log
 
 [kdcdefaults]
+  kdc_host = localhost
   kdc_udp_port = 88
   kdc_tcp_port = 8014
+  kdc_realm = TEST.COM
   restrict_anonymous_to_tgt = true
   kdc_max_dgram_reply_size = 4096
 


Mime
View raw message