directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject [1/2] directory-kerby git commit: DIRKRB-200 Pluggable network transport for KDC server
Date Sun, 05 Apr 2015 04:00:25 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 8856764c3 -> 2cf323e65


DIRKRB-200 Pluggable network transport for KDC server


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

Branch: refs/heads/master
Commit: e89299f7f1d7d844078976c6599ade0da7471ba6
Parents: 6a437e9
Author: Drankye <drankye@gmail.com>
Authored: Sun Apr 5 11:53:50 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Sun Apr 5 11:53:50 2015 +0800

----------------------------------------------------------------------
 .../kerby/kerberos/kdc/JsonBackendKdcTest.java  |  16 +-
 .../apache/kerby/kerberos/kdc/KerbyKdcTest.java |   1 -
 .../kerby/kerberos/kdc/WithCertKdcTest.java     |   5 +-
 .../kerby/kerberos/kdc/WithTokenKdcTest.java    |   5 +-
 .../kerby/kerberos/kdc/KerbyKdcServer.java      |   5 +-
 .../kerby/kerberos/kerb/server/KdcTestBase.java |  15 +-
 .../kerberos/kerb/server/TestKdcServer.java     |  13 +-
 .../kerby/kerberos/kerb/server/KdcTest.java     |   1 -
 .../kerb/server/MultiRequestsKdcTest.java       |   1 -
 .../kerberos/kerb/server/BackendConfig.java     |  33 ++
 .../kerby/kerberos/kerb/server/KdcContext.java  |  45 +--
 .../kerby/kerberos/kerb/server/KdcHandler.java  | 155 ----------
 .../kerby/kerberos/kerb/server/KdcServer.java   | 298 +++++--------------
 .../kerberos/kerb/server/KdcServerOption.java   | 132 ++++++++
 .../kerby/kerberos/kerb/server/KdcSetting.java  |  94 ++++++
 .../kerberos/kerb/server/SimpleKdcServer.java   |  25 --
 .../server/impl/AbstractInternalKdcServer.java  | 176 +++++++++++
 .../kerb/server/impl/InternalKdcServer.java     |  59 ++++
 .../server/impl/event/EventBasedKdcServer.java  |  76 +++++
 .../kerb/server/impl/event/KdcHandler.java      | 101 +++++++
 .../kerb/server/replay/ReplayCheckService.java  |   6 +-
 .../kerberos/kerb/server/request/AsRequest.java |   2 +-
 .../kerb/server/request/KdcRequest.java         |   4 +-
 .../kerb/server/request/TgsRequest.java         |   2 +-
 .../kerberos/kerb/server/KdcSimpleTest.java     |  90 ------
 .../kerberos/kerb/server/SimpleKdcTest.java     |  90 ++++++
 26 files changed, 882 insertions(+), 568 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
index 35b9a11..40fb0f2 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/JsonBackendKdcTest.java
@@ -19,10 +19,8 @@
  */
 package org.apache.kerby.kerberos.kdc;
 
-import org.apache.kerby.config.Conf;
-import org.apache.kerby.config.Config;
 import org.apache.kerby.kerberos.kdc.identitybackend.JsonIdentityBackend;
-import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
+import org.apache.kerby.kerberos.kerb.server.BackendConfig;
 import org.junit.AfterClass;
 import org.junit.Test;
 
@@ -32,21 +30,19 @@ public class JsonBackendKdcTest extends KerbyKdcTest {
     private static File jsonBackendFile;
 
     @Override
-    protected void setUpKdcServer() throws Exception {
-        super.setUpKdcServer();
+    protected void prepareKdcServer() throws Exception {
+        super.prepareKdcServer();
 
         File testDir = new File(System.getProperty("test.dir", "target"));
         jsonBackendFile = new File(testDir, "json-backend-file");
         String jsonBackendFileString = jsonBackendFile.getAbsolutePath();
 
-        Config backendConfig = new Conf();
+        BackendConfig backendConfig = new BackendConfig();
         backendConfig.setString(
                 JsonIdentityBackend.JSON_IDENTITY_BACKEND_FILE, jsonBackendFileString);
+        kdcServer.setBackendConfig(backendConfig);
 
-        IdentityBackend backend = new JsonIdentityBackend(backendConfig);
-        backend.initialize();
-
-        kdcServer.setBackend(backend);
+        kdcServer.init();
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/KerbyKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/KerbyKdcTest.java b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/KerbyKdcTest.java
index 0413ac4..5b62724 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/KerbyKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/KerbyKdcTest.java
@@ -40,7 +40,6 @@ public abstract class KerbyKdcTest extends KdcTestBase {
 
     protected void performKdcTest() throws Exception {
         kdcServer.start();
-        assertThat(kdcServer.isStarted()).isTrue();
 
         File testDir = new File(System.getProperty("test.dir", "target"));
         File testConfDir = new File(testDir, "conf");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/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 b211f68..d61428c 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
@@ -65,8 +65,8 @@ public class WithCertKdcTest extends KdcTestBase {
     }
 
     @Override
-    protected void setUpKdcServer() throws Exception {
-        super.setUpKdcServer();
+    protected void prepareKdcServer() throws Exception {
+        super.prepareKdcServer();
         kdcServer.createPrincipals(clientPrincipal);
     }
 
@@ -75,7 +75,6 @@ public class WithCertKdcTest extends KdcTestBase {
         assertThat(userCert).isNotNull();
 
         kdcServer.start();
-        assertThat(kdcServer.isStarted()).isTrue();
         krbClnt.init();
 
         TgtTicket tgt = null;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTest.java b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTest.java
index 6442323..dce118c 100644
--- a/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTest.java
+++ b/kerby-kdc-test/src/test/java/org/apache/kerby/kerberos/kdc/WithTokenKdcTest.java
@@ -81,15 +81,14 @@ public class WithTokenKdcTest extends KdcTestBase {
     }
 
     @Override
-    protected void setUpKdcServer() throws Exception {
-        super.setUpKdcServer();
+    protected void prepareKdcServer() throws Exception {
+        super.prepareKdcServer();
         kdcServer.createPrincipals(clientPrincipal);
     }
 
     //@Test
     public void testKdc() throws Exception {
         kdcServer.start();
-        assertThat(kdcServer.isStarted()).isTrue();
         krbClnt.init();
 
         TgtTicket tgt;

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/KerbyKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/KerbyKdcServer.java b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/KerbyKdcServer.java
index f0d014b..13839a9 100644
--- a/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/KerbyKdcServer.java
+++ b/kerby-kdc/src/main/java/org/apache/kerby/kerberos/kdc/KerbyKdcServer.java
@@ -77,6 +77,7 @@ public class KerbyKdcServer extends KdcServer {
     }
 
     /**
+     * TODO: THIS IS TO BE MOVED TO KDC-INIT !!
      * Verify whether tgt identity has been added.
      * If no, add it to identity backend.
      */
@@ -90,7 +91,7 @@ public class KerbyKdcServer extends KdcServer {
 
     private void createPrincipal(String principal, String password) {
         KrbIdentity identity = new KrbIdentity(fixPrincipal(principal));
-        List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
+        List<EncryptionType> encTypes = getKdcSetting().getKdcConfig().getEncryptionTypes();
         List<EncryptionKey> encKeys = null;
         try {
             encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
@@ -111,7 +112,7 @@ public class KerbyKdcServer extends KdcServer {
 
     private String fixPrincipal(String principal) {
         if (! principal.contains("@")) {
-            principal += "@" + getKdcRealm();
+            principal += "@" + getKdcSetting().getKdcRealm();
         }
         return principal;
     }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java b/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
index a4c6235..46a9add 100644
--- a/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
+++ b/kerby-kerb/kerb-kdc-test/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcTestBase.java
@@ -51,13 +51,17 @@ public abstract class KdcTestBase {
             udpPort = getServerPort();
         }
 
-        setUpKdcServer();
+        setUpKkdcServer();
+
         setUpClient();
         createPrincipals();
     }
 
-    protected void setUpKdcServer() throws Exception {
-        kdcServer = new TestKdcServer();
+    /**
+     * Prepare KDC startup options and config.
+     * @throws Exception
+     */
+    protected void prepareKdcServer() throws Exception {
         kdcServer.setKdcHost(hostname);
         if (tcpPort > 0) {
             kdcServer.setKdcTcpPort(tcpPort);
@@ -66,12 +70,15 @@ public abstract class KdcTestBase {
         if (udpPort > 0) {
             kdcServer.setKdcUdpPort(udpPort);
         }
+    }
 
+    protected void setUpKkdcServer() throws Exception {
+        kdcServer = new TestKdcServer();
+        prepareKdcServer();
         kdcServer.init();
 
         kdcRealm = kdcServer.getKdcRealm();
         clientPrincipal = "drankye@" + kdcRealm;
-
         serverPrincipal = "test-service/localhost@" + kdcRealm;
     }
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/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
index 1374c97..675be13 100644
--- 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
@@ -35,13 +35,13 @@ import java.io.IOException;
 import java.util.List;
 import java.util.UUID;
 
-public class TestKdcServer extends SimpleKdcServer {
+public class TestKdcServer extends KdcServer {
 
     /**
      * Prepare KDC configuration for the test.
      */
     protected void prepareKdcConfig() {
-        KdcConfig kdcConfig = getKdcConfig();
+        KdcConfig kdcConfig = getKdcSetting().getKdcConfig();
 
         kdcConfig.setString(KdcConfigKey.KDC_HOST, "localhost");
         kdcConfig.setInt(KdcConfigKey.KDC_TCP_PORT, 8018);
@@ -61,12 +61,12 @@ public class TestKdcServer extends SimpleKdcServer {
     }
 
     public String getKdcRealm() {
-        return getKdcConfig().getKdcRealm();
+        return getKdcSetting().getKdcRealm();
     }
 
     public synchronized void createPrincipal(String principal, String password) {
         KrbIdentity identity = new KrbIdentity(principal);
-        List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
+        List<EncryptionType> encTypes = getKdcSetting().getKdcConfig().getEncryptionTypes();
         List<EncryptionKey> encKeys = null;
         try {
             encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
@@ -77,11 +77,6 @@ public class TestKdcServer extends SimpleKdcServer {
         getIdentityService().addIdentity(identity);
     }
 
-    public void setBackend(IdentityBackend backend) {
-        super.setBackend(backend);
-    }
-
-
     public void createPrincipals(String ... principals) {
         String passwd;
         for (String principal : principals) {

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTest.java b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTest.java
index 41fdc34..d959c8c 100644
--- a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTest.java
+++ b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcTest.java
@@ -39,7 +39,6 @@ public abstract class KdcTest extends KdcTestBase {
 
     protected void performKdcTest() throws Exception {
         kdcServer.start();
-        assertThat(kdcServer.isStarted()).isTrue();
 
         File testDir = new File(System.getProperty("test.dir", "target"));
         File testConfDir = new File(testDir, "conf");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/MultiRequestsKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/MultiRequestsKdcTest.java b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/MultiRequestsKdcTest.java
index bf1c864..f0af7fd 100644
--- a/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/MultiRequestsKdcTest.java
+++ b/kerby-kerb/kerb-kdc-test/src/test/java/org/apache/kerby/kerberos/kerb/server/MultiRequestsKdcTest.java
@@ -41,7 +41,6 @@ public class MultiRequestsKdcTest extends KdcTestBase {
     @Test
     public void multiRequestsTest() throws Exception {
         kdcServer.start();
-        assertThat(kdcServer.isStarted()).isTrue();
 
         File testDir = new File(System.getProperty("test.dir", "target"));
         File testConfDir = new File(testDir, "conf");

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/BackendConfig.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/BackendConfig.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/BackendConfig.java
new file mode 100644
index 0000000..acbee82
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/BackendConfig.java
@@ -0,0 +1,33 @@
+/**
+ *  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.config.Conf;
+import org.apache.kerby.kerberos.kerb.common.KrbConfHelper;
+import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
+
+import java.util.List;
+
+/**
+ * Kerb KDC side backend configuration API.
+ */
+public class BackendConfig extends Conf {
+
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcContext.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcContext.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcContext.java
index bb7b467..a1c68b0 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcContext.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcContext.java
@@ -23,22 +23,23 @@ import org.apache.kerby.kerberos.kerb.identity.IdentityService;
 import org.apache.kerby.kerberos.kerb.server.preauth.PreauthHandler;
 import org.apache.kerby.kerberos.kerb.server.replay.ReplayCheckService;
 
-import java.util.List;
-
 public class KdcContext {
-    private KdcConfig config;
-    private List<String> supportedKdcRealms;
-    private String kdcRealm;
+    private final KdcSetting kdcSetting;
+
     private IdentityService identityService;
     private ReplayCheckService replayCache;
     private PreauthHandler preauthHandler;
 
-    public void init(KdcConfig config) {
-        this.config = config;
+    public KdcContext(KdcSetting kdcSetting) {
+        this.kdcSetting = kdcSetting;
+    }
+
+    public KdcSetting getKdcSetting() {
+        return kdcSetting;
     }
 
     public KdcConfig getConfig() {
-        return config;
+        return kdcSetting.getKdcConfig();
     }
 
     public void setPreauthHandler(PreauthHandler preauthHandler) {
@@ -49,29 +50,6 @@ public class KdcContext {
         return this.preauthHandler;
     }
 
-    public List<String> getSupportedKdcRealms() {
-        return supportedKdcRealms;
-    }
-
-    public void setSupportedKdcRealms(List<String> supportedKdcRealms) {
-        this.supportedKdcRealms = supportedKdcRealms;
-    }
-
-    public void setKdcRealm(String realm) {
-        this.kdcRealm = realm;
-    }
-
-    public String getServerRealm() {
-        return config.getKdcRealm();
-    }
-
-    public String getKdcRealm() {
-        if (kdcRealm != null) {
-            return kdcRealm;
-        }
-        return config.getKdcRealm();
-    }
-
     public void setReplayCache(ReplayCheckService replayCache) {
         this.replayCache = replayCache;
     }
@@ -84,8 +62,11 @@ public class KdcContext {
         this.identityService = identityService;
     }
 
-
     public IdentityService getIdentityService() {
         return identityService;
     }
+
+    public String getKdcRealm() {
+        return kdcSetting.getKdcRealm();
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcHandler.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcHandler.java
deleted file mode 100644
index 7a0a3d7..0000000
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcHandler.java
+++ /dev/null
@@ -1,155 +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.KrbUtil;
-import org.apache.kerby.kerberos.kerb.identity.IdentityService;
-import org.apache.kerby.kerberos.kerb.server.preauth.PreauthHandler;
-import org.apache.kerby.kerberos.kerb.server.replay.ReplayCheckService;
-import org.apache.kerby.kerberos.kerb.server.request.AsRequest;
-import org.apache.kerby.kerberos.kerb.server.request.KdcRequest;
-import org.apache.kerby.kerberos.kerb.server.request.TgsRequest;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.spec.base.KrbMessage;
-import org.apache.kerby.kerberos.kerb.spec.base.KrbMessageType;
-import org.apache.kerby.kerberos.kerb.spec.kdc.AsReq;
-import org.apache.kerby.kerberos.kerb.spec.kdc.KdcReq;
-import org.apache.kerby.kerberos.kerb.spec.kdc.TgsReq;
-import org.apache.kerby.transport.MessageHandler;
-import org.apache.kerby.transport.Transport;
-import org.apache.kerby.transport.event.MessageEvent;
-import org.apache.kerby.transport.tcp.TcpTransport;
-
-import java.net.InetSocketAddress;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class KdcHandler extends MessageHandler {
-
-    private List<String> kdcRealms = new ArrayList<String>(1);
-    private Map<String, KdcContext> kdcContexts;
-
-    private KdcConfig kdcConfig;
-    private PreauthHandler preauthHandler;
-
-    // TODO: per realm for below
-    private IdentityService identityService;
-    private ReplayCheckService replayCheckService;
-
-    /**
-     * Should be called when all the necessary properties are set
-     */
-    public void init() {
-        loadKdcRealms();
-
-        preauthHandler = new PreauthHandler();
-        preauthHandler.init(kdcConfig);
-
-        kdcContexts = new HashMap<String, KdcContext>(1);
-        for (String realm : kdcRealms) {
-            initRealmContext(realm);
-        }
-    }
-
-    private void initRealmContext(String kdcRealm) {
-        KdcContext kdcContext = new KdcContext();
-        kdcContext.init(kdcConfig);
-        kdcContext.setKdcRealm(kdcRealm);
-        kdcContext.setPreauthHandler(preauthHandler);
-        kdcContext.setIdentityService(identityService);
-        kdcContext.setReplayCache(replayCheckService);
-
-        kdcContexts.put(kdcRealm, kdcContext);
-    }
-
-    public void setKdcRealm(String realm) {
-        this.kdcRealms.add(realm);
-    }
-
-    public void setConfig(KdcConfig config) {
-        this.kdcConfig = config;
-    }
-
-    public void setIdentityService(IdentityService identityService) {
-        this.identityService = identityService;
-    }
-
-    @Override
-    protected void handleMessage(MessageEvent event) throws Exception {
-        ByteBuffer message = event.getMessage();
-        Transport transport = event.getTransport();
-
-        KrbMessage krbRequest = KrbUtil.decodeMessageOld(message);
-        KdcRequest kdcRequest = null;
-
-        KrbMessageType messageType = krbRequest.getMsgType();
-        if (messageType == KrbMessageType.TGS_REQ || messageType
-                == KrbMessageType.AS_REQ) {
-            KdcReq kdcReq = (KdcReq) krbRequest;
-            String realm = getRequestRealm(kdcReq);
-            if (realm == null || !kdcContexts.containsKey(realm)) {
-                throw new KrbException("Invalid realm from kdc request: " + realm);
-            }
-
-            KdcContext kdcContext = kdcContexts.get(realm);
-            if (messageType == KrbMessageType.TGS_REQ) {
-                kdcRequest = new TgsRequest((TgsReq) kdcReq, kdcContext);
-            } else if (messageType == KrbMessageType.AS_REQ) {
-                kdcRequest = new AsRequest((AsReq) kdcReq, kdcContext);
-            }
-        }
-
-        InetSocketAddress clientAddress = transport.getRemoteAddress();
-        kdcRequest.setClientAddress(clientAddress.getAddress());
-        boolean isTcp = (transport instanceof TcpTransport);
-        kdcRequest.isTcp(isTcp);
-
-        try {
-            kdcRequest.process();
-
-            KrbMessage krbResponse = kdcRequest.getReply();
-            KrbUtil.sendMessageOld(krbResponse, transport);
-        } catch (Exception e) {
-            //TODO: log the error
-            System.out.println("Error occured while processing request:"
-                    + e.getMessage());
-        }
-    }
-
-    private void loadKdcRealms() {
-        if (kdcRealms.isEmpty()) {
-            kdcRealms.add(kdcConfig.getKdcRealm());
-        }
-    }
-
-    private String getRequestRealm(KdcReq kdcReq) {
-        String realm = kdcReq.getReqBody().getRealm();
-        if (realm == null && kdcReq.getReqBody().getCname() != null) {
-            realm = kdcReq.getReqBody().getCname().getRealm();
-        }
-        if (realm == null || realm.isEmpty()) {
-            realm = "NULL-KDC-REALM";
-        }
-        return realm;
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/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 c29a22b..bf98f03 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
@@ -19,181 +19,75 @@
  */
 package org.apache.kerby.kerberos.kerb.server;
 
-import org.apache.kerby.config.Conf;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.event.EventHub;
-import org.apache.kerby.kerberos.kerb.common.KrbStreamingDecoder;
+import org.apache.kerby.KOptions;
 import org.apache.kerby.kerberos.kerb.identity.IdentityService;
-import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
-import org.apache.kerby.kerberos.kerb.identity.backend.MemoryIdentityBackend;
-import org.apache.kerby.transport.Network;
+import org.apache.kerby.kerberos.kerb.server.impl.InternalKdcServer;
+import org.apache.kerby.kerberos.kerb.server.impl.event.EventBasedKdcServer;
 
 import java.io.File;
-import java.io.IOException;
 
 public class KdcServer {
-    private String kdcHost;
-    private int kdcTcpPort;
-    private Boolean allowUdp;
-    private int kdcUdpPort;
-    private String kdcRealm;
+    private KOptions commonOptions;
+    private InternalKdcServer innerKdc;
 
-    private boolean started;
-    private String serviceName;
-
-    private KdcHandler kdcHandler;
-    private EventHub eventHub;
-
-    private KdcConfig kdcConfig;
-    private Conf backendConfig;
+    /**
+     * Default constructor.
+     */
+    public KdcServer() {
+        commonOptions = new KOptions();
+    }
 
-    private IdentityBackend backend;
-    private File workDir;
-    private File confDir;
+    /**
+     * Set KDC config.
+     * @param kdcConfig
+     */
+    public void setKdcConfig(KdcConfig kdcConfig) {
+        commonOptions.add(KdcServerOption.KDC_CONFIG, kdcConfig);
+    }
 
     /**
-     * Set runtime folder.
-     * @param workDir
+     * Set backend config.
+     * @param backendConfig
      */
-    public void setWorkDir(File workDir) {
-        this.workDir = workDir;
+    public void setBackendConfig(BackendConfig backendConfig) {
+        commonOptions.add(KdcServerOption.BACKEND_CONFIG, backendConfig);
     }
 
     /**
      * Set conf dir where configuration resources can be loaded. Mainly:
      * kdc.conf, that contains kdc server related items.
      * backend.conf, that contains identity backend related items.
+     *
+     * Note confDir is only used when KDC and backend config aren't set.
+     *
      * @param confDir
      */
     public void setConfDir(File confDir) {
-        this.confDir = confDir;
+        commonOptions.add(KdcServerOption.CONF_DIR, confDir);
     }
 
     /**
-     * Get configuration folder.
-     * @return
+     * Set KDC realm for ticket request
+     * @param realm
      */
-    public File getConfDir() {
-        return confDir;
+    public void setKdcRealm(String realm) {
+        commonOptions.add(KdcServerOption.KDC_REALM, realm);
     }
 
     /**
-     * Get the backend identity service.
-     * @return
+     * Set KDC host.
+     * @param kdcHost
      */
-    public IdentityService getIdentityService() {
-        return backend;
-    }
-
-    public void init() {
-        try {
-            initConfig();
-        } catch (IOException e) {
-            throw new RuntimeException("Failed to load configurations", e);
-        }
-
-        initBackend();
+    public void setKdcHost(String kdcHost) {
+        commonOptions.add(KdcServerOption.KDC_HOST, kdcHost);
     }
 
     /**
-     * Prepare kdc and backend config, loading kdc.conf and backend.conf.
-     * It can be override to add more configuration resources.
-     *
-     * @throws IOException
+     * Set KDC tcp port.
+     * @param kdcTcpPort
      */
-    protected void initConfig() throws IOException {
-        kdcConfig = new KdcConfig();
-        backendConfig = new Conf();
-
-        if (confDir != null && confDir.exists()) {
-            File kdcConfFile = new File(confDir, "kdc.conf");
-            if (kdcConfFile.exists()) {
-                kdcConfig.addIniConfig(kdcConfFile);
-            }
-
-            File backendConfFile = new File(confDir, "backend.conf");
-            if (backendConfFile.exists()) {
-                backendConfig.addIniConfig(backendConfFile);
-            }
-        }
-    }
-
-    private void initBackend() {
-        String backendClassName = backendConfig.getString(
-                KdcConfigKey.KDC_IDENTITY_BACKEND);
-        if (backendClassName == null) {
-            backendClassName = MemoryIdentityBackend.class.getCanonicalName();
-        }
-
-        Class backendClass = null;
-        try {
-            backendClass = Class.forName(backendClassName);
-        } catch (ClassNotFoundException e) {
-            throw new RuntimeException("Failed to load backend class: "
-                    + backendClassName);
-        }
-
-        try {
-            backend = (IdentityBackend) backendClass.newInstance();
-        } catch (InstantiationException e) {
-            throw new RuntimeException("Failed to create backend: "
-                    + backendClassName);
-        } catch (IllegalAccessException e) {
-            throw new RuntimeException("Failed to create backend: "
-                    + backendClassName);
-        }
-
-        backend.setConfig(backendConfig);
-        backend.initialize();
-    }
-
-    public void start() {
-        try {
-            doStart();
-        } catch (Exception e) {
-            throw new RuntimeException("Failed to start " + getServiceName(), e);
-        }
-
-        started = true;
-    }
-
-    public String getKdcRealm() {
-        if (kdcRealm != null) {
-            return kdcRealm;
-        }
-        return kdcConfig.getKdcRealm();
-    }
-
-    private String getKdcHost() {
-        if (kdcHost != null) {
-            return kdcHost;
-        }
-        return kdcConfig.getKdcHost();
-    }
-
-    private int getKdcTcpPort() {
-        if (kdcTcpPort > 0) {
-            return kdcTcpPort;
-        }
-        return kdcConfig.getKdcTcpPort();
-    }
-
-    private boolean allowUdp() {
-        if (allowUdp != null) {
-            return allowUdp;
-        }
-        return kdcConfig.allowKdcUdp();
-    }
-
-    private int getKdcUdpPort() {
-        if (kdcUdpPort > 0) {
-            return kdcUdpPort;
-        }
-        return kdcConfig.getKdcUdpPort();
-    }
-
-    public void setKdcHost(String kdcHost) {
-        this.kdcHost = kdcHost;
+    public void setKdcTcpPort(int kdcTcpPort) {
+        commonOptions.add(KdcServerOption.KDC_TCP_PORT, kdcTcpPort);
     }
 
     /**
@@ -201,15 +95,7 @@ public class KdcServer {
      * @param allowUdp
      */
     public void setAllowUdp(boolean allowUdp) {
-        this.allowUdp = allowUdp;
-    }
-
-    /**
-     * Set KDC tcp port.
-     * @param kdcTcpPort
-     */
-    public void setKdcTcpPort(int kdcTcpPort) {
-        this.kdcTcpPort = kdcTcpPort;
+        commonOptions.add(KdcServerOption.ALLOW_UDP, allowUdp);
     }
 
     /**
@@ -217,99 +103,61 @@ public class KdcServer {
      * @param kdcUdpPort
      */
     public void setKdcUdpPort(int kdcUdpPort) {
-        this.kdcUdpPort = kdcUdpPort;
+        commonOptions.add(KdcServerOption.KDC_UDP_PORT, kdcUdpPort);
     }
 
     /**
-     * Set KDC realm.
-     * @param realm
+     * Use event model. By default blocking model is used.
      */
-    public void setKdcRealm(String realm) {
-        this.kdcRealm = realm;
-    }
-
-    public boolean enableDebug() {
-        return kdcConfig.enableDebug();
-    }
-
-    protected void doStart() throws Exception {
-        backend.start();
-
-        prepareHandler();
-
-        this.eventHub = new EventHub();
-
-        eventHub.register(kdcHandler);
-
-        Network network = new Network();
-        network.setStreamingDecoder(new KrbStreamingDecoder());
-        eventHub.register(network);
-
-        eventHub.start();
-        network.tcpListen(getKdcHost(), getKdcTcpPort());
-        if (allowUdp()) {
-            network.udpListen(getKdcHost(), getKdcUdpPort());
-        }
+    public void useEventModel() {
+        commonOptions.add(KdcServerOption.USE_EVENT_MODEL);
     }
 
-    private void prepareHandler() {
-        this.kdcHandler = new KdcHandler();
-        kdcHandler.setConfig(kdcConfig);
-        kdcHandler.setIdentityService(backend);
-        if (kdcRealm != null) {
-            kdcHandler.setKdcRealm(kdcRealm);
-        }
-        kdcHandler.init();
-    }
-
-    public void stop() {
-        try {
-            doStop();
-        } catch (Exception e) {
-            throw new RuntimeException("Failed to stop " + getServiceName());
-        }
-
-        started = false;
+    /**
+     * Set runtime folder.
+     * @param workDir
+     */
+    public void setWorkDir(File workDir) {
+        commonOptions.add(KdcServerOption.USE_EVENT_MODEL);
     }
 
-    protected void doStop() throws Exception {
-        backend.stop();
-
-        eventHub.stop();
+    public void enableDebug() {
+        commonOptions.add(KdcServerOption.USE_EVENT_MODEL);
     }
 
     /**
-     * Get the KDC config.
-     * @return
+     * Get KDC setting.
+     * @return setting
      */
-    protected KdcConfig getKdcConfig() {
-        return kdcConfig;
+    public KdcSetting getKdcSetting() {
+        return innerKdc.getKdcSetting();
     }
 
     /**
-     * Get backend config.
-     * @return
+     * Get identity service.
+     * @return IdentityService
      */
-    protected Config getBackendConfig() {
-        return backendConfig;
-    }
-
-    public boolean isStarted() {
-        return started;
+    public IdentityService getIdentityService() {
+        return innerKdc.getIdentityService();
     }
 
-    protected void setServiceName(String name) {
-        this.serviceName = name;
+    /**
+     * Init the KDC server.
+     */
+    public void init() {
+        if (commonOptions.contains(KdcServerOption.USE_EVENT_MODEL)) {
+            innerKdc = new EventBasedKdcServer();
+        } else {
+            innerKdc = new EventBasedKdcServer(); //TODO
+        }
+        innerKdc.init(commonOptions);
     }
 
-    protected String getServiceName() {
-        if (serviceName != null) {
-            return serviceName;
-        }
-        return kdcConfig.getKdcServiceName();
+    public void start() {
+        innerKdc.start();
     }
 
-    protected void setBackend(IdentityBackend backend) {
-        this.backend = backend;
+    public void stop() {
+        innerKdc.stop();
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServerOption.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServerOption.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServerOption.java
new file mode 100644
index 0000000..652bae1
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcServerOption.java
@@ -0,0 +1,132 @@
+/**
+ *  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.KOption;
+import org.apache.kerby.KOptionType;
+
+/**
+ * KDC server startup options
+ */
+public enum KdcServerOption implements KOption {
+    NONE("NONE"),
+    USE_EVENT_MODEL("use event model", KOptionType.NOV),
+    KDC_CONFIG("kdc config", KOptionType.OBJ),
+    BACKEND_CONFIG("backend config", KOptionType.OBJ),
+    CONF_DIR("conf dir", KOptionType.DIR),
+    KDC_REALM("kdc realm", KOptionType.STR),
+    KDC_HOST("kdc host", KOptionType.STR),
+    KDC_TCP_PORT("kdc tcp port", KOptionType.INT),
+    ALLOW_UDP("allow udp", KOptionType.BOOL),
+    KDC_UDP_PORT("kdc udp port", KOptionType.INT),
+    ;
+
+    private String name;
+    private KOptionType type;
+    private String description;
+    private Object value;
+
+    KdcServerOption(String description) {
+        this(description, KOptionType.NOV); // As a flag by default
+    }
+
+    KdcServerOption(String description, KOptionType type) {
+        this.description = description;
+        this.type = type;
+    }
+
+    KdcServerOption(String name, String description) {
+        this(name, description, KOptionType.NOV); // As a flag by default
+    }
+
+    KdcServerOption(String name, String description, KOptionType type) {
+        this.name = name;
+        this.description = description;
+        this.type = type;
+    }
+
+    @Override
+    public String getOptionName() {
+        return name();
+    }
+
+    public void setType(KOptionType type) {
+        this.type = type;
+    }
+
+    public KOptionType getType() {
+        return this.type;
+    }
+
+    @Override
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @Override
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    @Override
+    public String getName() {
+        if (name != null) {
+            return name;
+        }
+        return name();
+    }
+
+    @Override
+    public String getDescription() {
+        return this.description;
+    }
+
+    @Override
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    @Override
+    public Object getValue() {
+        return value;
+    }
+
+    public static KdcServerOption fromName(String name) {
+        if (name != null) {
+            for (KdcServerOption ko : values()) {
+                if (ko.getName().equals(name)) {
+                    return (KdcServerOption) ko;
+                }
+            }
+        }
+        return NONE;
+    }
+
+    public static KdcServerOption fromOptionName(String optionName) {
+        if (optionName != null) {
+            for (KdcServerOption ko : values()) {
+                if (ko.getOptionName().equals(optionName)) {
+                    return (KdcServerOption) ko;
+                }
+            }
+        }
+        return NONE;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcSetting.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcSetting.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcSetting.java
new file mode 100644
index 0000000..b32119e
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/KdcSetting.java
@@ -0,0 +1,94 @@
+/**
+ *  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.KOptions;
+
+import java.io.File;
+
+/**
+ * KDC setting that combines startup options and kdc config.
+ */
+public class KdcSetting {
+    private final KOptions startupOptions;
+    private final KdcConfig kdcConfig;
+
+    public KdcSetting(KOptions startupOptions, KdcConfig config) {
+        this.startupOptions = startupOptions;
+        this.kdcConfig = config;
+    }
+
+    /**
+     * Get the KDC config.
+     * @return
+     */
+    public KdcConfig getKdcConfig() {
+        return kdcConfig;
+    }
+
+    public File getConfDir() {
+        return  startupOptions.getDirOption(KdcServerOption.CONF_DIR);
+    }
+
+    public String getKdcHost() {
+        String kdcHost = startupOptions.getStringOption(
+                KdcServerOption.KDC_HOST);
+        if (kdcHost == null) {
+            kdcHost = kdcConfig.getKdcHost();
+        }
+        return kdcHost;
+    }
+
+    public int getKdcTcpPort() {
+        int tcpPort = startupOptions.getIntegerOption(KdcServerOption.KDC_TCP_PORT);
+        if (tcpPort < 1) {
+            tcpPort = kdcConfig.getKdcTcpPort();
+        }
+        return tcpPort;
+    }
+
+    public boolean allowUdp() {
+        Boolean allowUdp = startupOptions.getBooleanOption(KdcServerOption.ALLOW_UDP);
+        if (allowUdp == null) {
+            allowUdp = kdcConfig.allowKdcUdp();
+        }
+        return allowUdp;
+    }
+
+    public int getKdcUdpPort() {
+        int udpPort = startupOptions.getIntegerOption(KdcServerOption.KDC_UDP_PORT);
+        if (udpPort < 1) {
+            udpPort = kdcConfig.getKdcUdpPort();
+        }
+        return udpPort;
+    }
+
+    /**
+     * Get KDC realm.
+     * @return KDC realm
+     */
+    public String getKdcRealm() {
+        String kdcRealm = startupOptions.getStringOption(KdcServerOption.KDC_REALM);
+        if (kdcRealm == null || kdcRealm.isEmpty()) {
+            kdcRealm = kdcConfig.getKdcRealm();
+        }
+        return kdcRealm;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
deleted file mode 100644
index 6874be8..0000000
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
+++ /dev/null
@@ -1,25 +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;
-
-public class SimpleKdcServer extends KdcServer {
-
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
new file mode 100644
index 0000000..53a285a
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/AbstractInternalKdcServer.java
@@ -0,0 +1,176 @@
+/**
+ *  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.impl;
+
+import org.apache.kerby.KOptions;
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kerb.identity.IdentityService;
+import org.apache.kerby.kerberos.kerb.identity.backend.IdentityBackend;
+import org.apache.kerby.kerberos.kerb.identity.backend.MemoryIdentityBackend;
+import org.apache.kerby.kerberos.kerb.server.*;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * Abstract KDC server implementation.
+ */
+public class AbstractInternalKdcServer implements InternalKdcServer {
+
+    private boolean started;
+
+    private KdcConfig kdcConfig;
+    private Conf backendConfig;
+    private KdcSetting kdcSetting;
+    private IdentityBackend backend;
+
+    @Override
+    public KdcSetting getKdcSetting() {
+        return kdcSetting;
+    }
+
+    public boolean isStarted() {
+        return started;
+    }
+
+    protected String getServiceName() {
+        return kdcConfig.getKdcServiceName();
+    }
+
+    protected IdentityBackend getBackend() {
+        return backend;
+    }
+
+    @Override
+    public void init(KOptions startupOptions) {
+        try {
+            initConfig(startupOptions);
+        } catch (IOException e) {
+            throw new RuntimeException("Failed to load configurations", e);
+        }
+
+        this.kdcSetting = new KdcSetting(startupOptions, kdcConfig);
+
+        initBackend();
+    }
+
+    /**
+     * Prepare kdc and backend config, loading kdc.conf and backend.conf.
+     * It can be override to add more configuration resources.
+     *
+     * @throws java.io.IOException
+     */
+    private void initConfig(KOptions startupOptions) throws IOException {
+        if (startupOptions.contains(KdcServerOption.KDC_CONFIG)) {
+            this.kdcConfig = (KdcConfig) startupOptions.getOptionValue(
+                    KdcServerOption.KDC_CONFIG);
+        } else {
+            this.kdcConfig = new KdcConfig();
+            File confDir = startupOptions.getDirOption(KdcServerOption.CONF_DIR);
+            if (confDir != null && confDir.exists()) {
+                File kdcConfFile = new File(confDir, "kdc.conf");
+                if (kdcConfFile.exists()) {
+                    kdcConfig.addIniConfig(kdcConfFile);
+                }
+            }
+        }
+
+        if (startupOptions.contains(KdcServerOption.BACKEND_CONFIG)) {
+            this.backendConfig = (BackendConfig) startupOptions.getOptionValue(
+                    KdcServerOption.BACKEND_CONFIG);
+        } else {
+            backendConfig = new BackendConfig();
+            File confDir = startupOptions.getDirOption(KdcServerOption.CONF_DIR);
+            if (confDir != null && confDir.exists()) {
+                File backendConfFile = new File(confDir, "backend.conf");
+                if (backendConfFile.exists()) {
+                    backendConfig.addIniConfig(backendConfFile);
+                }
+            }
+        }
+    }
+
+    private void initBackend() {
+        String backendClassName = backendConfig.getString(
+                KdcConfigKey.KDC_IDENTITY_BACKEND);
+        if (backendClassName == null) {
+            backendClassName = MemoryIdentityBackend.class.getCanonicalName();
+        }
+
+        Class backendClass = null;
+        try {
+            backendClass = Class.forName(backendClassName);
+        } catch (ClassNotFoundException e) {
+            throw new RuntimeException("Failed to load backend class: "
+                    + backendClassName);
+        }
+
+        try {
+            backend = (IdentityBackend) backendClass.newInstance();
+        } catch (InstantiationException e) {
+            throw new RuntimeException("Failed to create backend: "
+                    + backendClassName);
+        } catch (IllegalAccessException e) {
+            throw new RuntimeException("Failed to create backend: "
+                    + backendClassName);
+        }
+
+        backend.setConfig(backendConfig);
+        backend.initialize();
+    }
+
+    @Override
+    public void start() {
+        try {
+            doStart();
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to start " + getServiceName(), e);
+        }
+
+        started = true;
+    }
+
+    public boolean enableDebug() {
+        return kdcConfig.enableDebug();
+    }
+
+    @Override
+    public IdentityService getIdentityService() {
+        return backend;
+    }
+
+    protected void doStart() throws Exception {
+        backend.start();
+    }
+
+    public void stop() {
+        try {
+            doStop();
+        } catch (Exception e) {
+            throw new RuntimeException("Failed to stop " + getServiceName());
+        }
+
+        started = false;
+    }
+
+    protected void doStop() throws Exception {
+        backend.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/InternalKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/InternalKdcServer.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/InternalKdcServer.java
new file mode 100644
index 0000000..349d8c2
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/InternalKdcServer.java
@@ -0,0 +1,59 @@
+/**
+ *  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.impl;
+
+import org.apache.kerby.KOptions;
+import org.apache.kerby.kerberos.kerb.identity.IdentityService;
+import org.apache.kerby.kerberos.kerb.server.KdcContext;
+import org.apache.kerby.kerberos.kerb.server.KdcSetting;
+
+/**
+ * An internal KDC server interface.
+ */
+public interface InternalKdcServer {
+
+    /**
+     * Initialize with KDC startup options.
+     * @param options
+     */
+    public void init(KOptions options);
+
+    /**
+     * Start the KDC server.
+     */
+    public void start();
+
+    /**
+     * Stop the KDC server.
+     */
+    public void stop();
+
+    /**
+     * Get KDC setting.
+     * @return setting
+     */
+    public KdcSetting getKdcSetting();
+
+    /**
+     * Get identity service.
+     * @return IdentityService
+     */
+    public IdentityService getIdentityService();
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/EventBasedKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/EventBasedKdcServer.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/EventBasedKdcServer.java
new file mode 100644
index 0000000..8b50b73
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/EventBasedKdcServer.java
@@ -0,0 +1,76 @@
+/**
+ *  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.impl.event;
+
+import org.apache.kerby.event.EventHub;
+import org.apache.kerby.kerberos.kerb.common.KrbStreamingDecoder;
+import org.apache.kerby.kerberos.kerb.server.KdcContext;
+import org.apache.kerby.kerberos.kerb.server.impl.AbstractInternalKdcServer;
+import org.apache.kerby.kerberos.kerb.server.preauth.PreauthHandler;
+import org.apache.kerby.transport.Network;
+
+/**
+ * Event based KDC server.
+ */
+public class EventBasedKdcServer extends AbstractInternalKdcServer {
+
+    private KdcHandler kdcHandler;
+    private EventHub eventHub;
+
+    @Override
+    protected void doStart() throws Exception {
+        super.doStart();
+
+        prepareHandler();
+
+        this.eventHub = new EventHub();
+
+        eventHub.register(kdcHandler);
+
+        Network network = new Network();
+        network.setStreamingDecoder(new KrbStreamingDecoder());
+        eventHub.register(network);
+
+        eventHub.start();
+        network.tcpListen(getKdcSetting().getKdcHost(),
+                getKdcSetting().getKdcTcpPort());
+        if (getKdcSetting().allowUdp()) {
+            network.udpListen(getKdcSetting().getKdcHost(),
+                    getKdcSetting().getKdcUdpPort());
+        }
+    }
+
+    private void prepareHandler() {
+        KdcContext kdcContext = new KdcContext(getKdcSetting());
+        kdcContext.setIdentityService(getBackend());
+        PreauthHandler preauthHandler = new PreauthHandler();
+        preauthHandler.init(kdcContext.getConfig());
+        kdcContext.setPreauthHandler(preauthHandler);
+
+        this.kdcHandler = new KdcHandler(kdcContext);
+    }
+
+    @Override
+    protected void doStop() throws Exception {
+        super.doStop();
+
+        eventHub.stop();
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/KdcHandler.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/KdcHandler.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/KdcHandler.java
new file mode 100644
index 0000000..b4f6670
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/impl/event/KdcHandler.java
@@ -0,0 +1,101 @@
+/**
+ *  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.impl.event;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.common.KrbUtil;
+import org.apache.kerby.kerberos.kerb.server.KdcContext;
+import org.apache.kerby.kerberos.kerb.server.request.AsRequest;
+import org.apache.kerby.kerberos.kerb.server.request.KdcRequest;
+import org.apache.kerby.kerberos.kerb.server.request.TgsRequest;
+import org.apache.kerby.kerberos.kerb.spec.base.KrbMessage;
+import org.apache.kerby.kerberos.kerb.spec.base.KrbMessageType;
+import org.apache.kerby.kerberos.kerb.spec.kdc.AsReq;
+import org.apache.kerby.kerberos.kerb.spec.kdc.KdcReq;
+import org.apache.kerby.kerberos.kerb.spec.kdc.TgsReq;
+import org.apache.kerby.transport.MessageHandler;
+import org.apache.kerby.transport.Transport;
+import org.apache.kerby.transport.event.MessageEvent;
+import org.apache.kerby.transport.tcp.TcpTransport;
+
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+
+/**
+ * KDC handler to process client requests. Currently only one realm is supported.
+ */
+public class KdcHandler extends MessageHandler {
+
+    private final KdcContext kdcContext;
+
+    public KdcHandler(KdcContext kdcContext) {
+        this.kdcContext = kdcContext;
+    }
+
+    @Override
+    protected void handleMessage(MessageEvent event) throws Exception {
+        ByteBuffer message = event.getMessage();
+        Transport transport = event.getTransport();
+
+        KrbMessage krbRequest = KrbUtil.decodeMessageOld(message);
+        KdcRequest kdcRequest = null;
+
+        KrbMessageType messageType = krbRequest.getMsgType();
+        if (messageType == KrbMessageType.TGS_REQ || messageType
+                == KrbMessageType.AS_REQ) {
+            KdcReq kdcReq = (KdcReq) krbRequest;
+            String realm = getRequestRealm(kdcReq);
+            if (realm == null || ! kdcContext.getKdcRealm().equals(realm)) {
+                throw new KrbException("Invalid realm from kdc request: " + realm);
+            }
+
+            if (messageType == KrbMessageType.TGS_REQ) {
+                kdcRequest = new TgsRequest((TgsReq) kdcReq, kdcContext);
+            } else if (messageType == KrbMessageType.AS_REQ) {
+                kdcRequest = new AsRequest((AsReq) kdcReq, kdcContext);
+            }
+        }
+
+        InetSocketAddress clientAddress = transport.getRemoteAddress();
+        kdcRequest.setClientAddress(clientAddress.getAddress());
+        boolean isTcp = (transport instanceof TcpTransport);
+        kdcRequest.isTcp(isTcp);
+
+        try {
+            kdcRequest.process();
+
+            KrbMessage krbResponse = kdcRequest.getReply();
+            KrbUtil.sendMessageOld(krbResponse, transport);
+        } catch (Exception e) {
+            //TODO: log the error
+            System.out.println("Error occured while processing request:"
+                    + e.getMessage());
+        }
+    }
+
+    private String getRequestRealm(KdcReq kdcReq) {
+        String realm = kdcReq.getReqBody().getRealm();
+        if (realm == null && kdcReq.getReqBody().getCname() != null) {
+            realm = kdcReq.getReqBody().getCname().getRealm();
+        }
+
+        return realm;
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/replay/ReplayCheckService.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/replay/ReplayCheckService.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/replay/ReplayCheckService.java
index 485621f..b4017e8 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/replay/ReplayCheckService.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/replay/ReplayCheckService.java
@@ -19,7 +19,7 @@
  */
 package org.apache.kerby.kerberos.kerb.server.replay;
 
-public interface ReplayCheckService
-{
-    boolean checkReplay(String clientPrincipal, String serverPrincipal, long requestTime, int microseconds);
+public interface ReplayCheckService {
+    boolean checkReplay(String clientPrincipal, String serverPrincipal,
+                        long requestTime, int microseconds);
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/AsRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/AsRequest.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/AsRequest.java
index 23d6196..85cf9fe 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/AsRequest.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/AsRequest.java
@@ -41,7 +41,7 @@ public class AsRequest extends KdcRequest {
         AsRep reply = new AsRep();
 
         reply.setCname(getClientEntry().getPrincipal());
-        reply.setCrealm(kdcContext.getServerRealm());
+        reply.setCrealm(kdcContext.getKdcRealm());
         reply.setTicket(ticket);
 
         EncKdcRepPart encKdcRepPart = makeEncKdcRepPart();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/KdcRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/KdcRequest.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/KdcRequest.java
index ca4767e..99b742a 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/KdcRequest.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/KdcRequest.java
@@ -232,7 +232,7 @@ public abstract class KdcRequest {
         PrincipalName clientPrincipal = request.getReqBody().getCname();
         String clientRealm = request.getReqBody().getRealm();
         if (clientRealm == null || clientRealm.isEmpty()) {
-            clientRealm = kdcContext.getServerRealm();
+            clientRealm = kdcContext.getKdcRealm();
         }
         clientPrincipal.setRealm(clientRealm);
 
@@ -434,7 +434,7 @@ public abstract class KdcRequest {
         PrincipalName principal = request.getReqBody().getSname();
         String serverRealm = request.getReqBody().getRealm();
         if (serverRealm == null || serverRealm.isEmpty()) {
-            serverRealm = kdcContext.getServerRealm();
+            serverRealm = kdcContext.getKdcRealm();
         }
         principal.setRealm(serverRealm);
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/TgsRequest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/TgsRequest.java b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/TgsRequest.java
index 2f5327a..76804e5 100644
--- a/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/TgsRequest.java
+++ b/kerby-kerb/kerb-server/src/main/java/org/apache/kerby/kerberos/kerb/server/request/TgsRequest.java
@@ -138,7 +138,7 @@ public class TgsRequest extends KdcRequest {
         TgsRep reply = new TgsRep();
 
         reply.setCname(getClientEntry().getPrincipal());
-        reply.setCrealm(kdcContext.getServerRealm());
+        reply.setCrealm(kdcContext.getKdcRealm());
         reply.setTicket(ticket);
 
         EncKdcRepPart encKdcRepPart = makeEncKdcRepPart();

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcSimpleTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcSimpleTest.java b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcSimpleTest.java
deleted file mode 100644
index a20775f..0000000
--- a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcSimpleTest.java
+++ /dev/null
@@ -1,90 +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.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.ServerSocket;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-public class KdcSimpleTest {
-
-    private String serverHost = "localhost";
-    private int serverPort = 0;
-
-    private SimpleKdcServer kdcServer;
-
-    @Before
-    public void setUp() throws Exception {
-        kdcServer = new SimpleKdcServer();
-        kdcServer.setKdcHost(serverHost);
-        serverPort = getServerPort();
-        kdcServer.setKdcTcpPort(serverPort);
-        kdcServer.init();
-        kdcServer.start();
-    }
-
-    @Test
-    public void testKdc() throws IOException, InterruptedException {
-        Thread.sleep(15);
-
-        SocketChannel socketChannel = SocketChannel.open();
-        socketChannel.configureBlocking(true);
-        SocketAddress sa = new InetSocketAddress(serverHost, serverPort);
-        socketChannel.connect(sa);
-
-        String BAD_KRB_MESSAGE = "Hello World!";
-        ByteBuffer writeBuffer = ByteBuffer.allocate(4 + BAD_KRB_MESSAGE.getBytes().length);
-        writeBuffer.putInt(BAD_KRB_MESSAGE.getBytes().length);
-        writeBuffer.put(BAD_KRB_MESSAGE.getBytes());
-        writeBuffer.flip();
-
-        socketChannel.write(writeBuffer);
-    }
-    
-    /**
-     * 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 {
-        kdcServer.stop();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/e89299f7/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcTest.java b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcTest.java
new file mode 100644
index 0000000..8861bc5
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcTest.java
@@ -0,0 +1,90 @@
+/**
+ *  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.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+public class SimpleKdcTest {
+
+    private String serverHost = "localhost";
+    private int serverPort = 0;
+
+    private KdcServer kdcServer;
+
+    @Before
+    public void setUp() throws Exception {
+        kdcServer = new KdcServer();
+        kdcServer.setKdcHost(serverHost);
+        serverPort = getServerPort();
+        kdcServer.setKdcTcpPort(serverPort);
+        kdcServer.init();
+        kdcServer.start();
+    }
+
+    @Test
+    public void testKdc() throws IOException, InterruptedException {
+        Thread.sleep(15);
+
+        SocketChannel socketChannel = SocketChannel.open();
+        socketChannel.configureBlocking(true);
+        SocketAddress sa = new InetSocketAddress(serverHost, serverPort);
+        socketChannel.connect(sa);
+
+        String BAD_KRB_MESSAGE = "Hello World!";
+        ByteBuffer writeBuffer = ByteBuffer.allocate(4 + BAD_KRB_MESSAGE.getBytes().length);
+        writeBuffer.putInt(BAD_KRB_MESSAGE.getBytes().length);
+        writeBuffer.put(BAD_KRB_MESSAGE.getBytes());
+        writeBuffer.flip();
+
+        socketChannel.write(writeBuffer);
+    }
+    
+    /**
+     * 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 {
+        kdcServer.stop();
+    }
+}
\ No newline at end of file


Mime
View raw message