directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dran...@apache.org
Subject directory-kerberos git commit: Fixed an issue that authentication failure may cause KDC not to function any more due to exception not caught; Added negative tests; Some cleanup
Date Sun, 15 Mar 2015 07:41:34 GMT
Repository: directory-kerberos
Updated Branches:
  refs/heads/master 5f65a02f2 -> 17586b45a


Fixed an issue that authentication failure may cause KDC not to function any more due to exception
not caught; Added negative tests; Some cleanup


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

Branch: refs/heads/master
Commit: 17586b45ae7bc489b3bc58878a3112b174e393a2
Parents: 5f65a02
Author: Drankye <drankye@gmail.com>
Authored: Sun Mar 15 15:41:15 2015 +0800
Committer: Drankye <drankye@gmail.com>
Committed: Sun Mar 15 15:41:15 2015 +0800

----------------------------------------------------------------------
 .../kerby/kerberos/kerb/client/KrbClient.java   | 25 +++++++-----
 .../kerby/kerberos/kerb/server/KdcTest.java     | 43 +++++++++++++++++---
 .../kerby/kerberos/kerb/server/KdcHandler.java  | 15 +++++--
 .../kerby/event/BufferedEventHandler.java       |  6 +--
 .../java/org/apache/kerby/event/EventHub.java   |  3 +-
 .../org/apache/kerby/event/EventWaiter.java     |  6 ++-
 .../apache/kerby/event/WaitEventHandler.java    |  6 +--
 7 files changed, 72 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/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 201566e..d5d95a5 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
@@ -204,7 +204,8 @@ public class KrbClient {
      * @return
      * @throws KrbException
      */
-    public TgtTicket requestTgtTicket(String principal, KrbOptions options) throws KrbException
{
+    public TgtTicket requestTgtTicket(String principal,
+                                      KrbOptions options) throws KrbException {
         if (options == null) {
             options = new KrbOptions();
         }
@@ -243,8 +244,9 @@ public class KrbClient {
      * @return
      * @throws KrbException
      */
-    public TgtTicket requestTgtTicket(String principal, Certificate certificate,
-                                      PrivateKey privateKey, KrbOptions options) throws KrbException
{
+    public TgtTicket requestTgtTicket(
+            String principal, Certificate certificate, PrivateKey privateKey,
+            KrbOptions options) throws KrbException {
         if (options == null) {
             options = new KrbOptions();
         }
@@ -304,8 +306,9 @@ public class KrbClient {
      * @return
      * @throws KrbException
      */
-    public ServiceTicket requestServiceTicket(String clientPrincipal, String password,
-                                              String serverPrincipal, KrbOptions options)
throws KrbException {
+    public ServiceTicket requestServiceTicket(
+            String clientPrincipal, String password, String serverPrincipal,
+            KrbOptions options) throws KrbException {
         if (options == null) {
             options = new KrbOptions();
         }
@@ -323,8 +326,9 @@ public class KrbClient {
      * @return
      * @throws KrbException
      */
-    public ServiceTicket requestServiceTicket(String clientPrincipal, KerbToken token,
-                                              String serverPrincipal, KrbOptions options)
throws KrbException {
+    public ServiceTicket requestServiceTicket(
+            String clientPrincipal, KerbToken token, String serverPrincipal,
+            KrbOptions options) throws KrbException {
         if (options == null) {
             options = new KrbOptions();
         }
@@ -333,7 +337,8 @@ public class KrbClient {
         return requestServiceTicket(tgt, serverPrincipal, options);
     }
 
-    private TgtTicket requestTgtTicket(String clientPrincipal, AsRequest tgtTktReq) throws
KrbException {
+    private TgtTicket requestTgtTicket(String clientPrincipal,
+                                       AsRequest tgtTktReq) throws KrbException {
         tgtTktReq.setClientPrincipal(new PrincipalName(clientPrincipal));
         tgtTktReq.setTransport(transport);
 
@@ -356,7 +361,7 @@ public class KrbClient {
 
     private TgtTicket doRequestTgtTicket(AsRequest tgtTktReq) throws KrbException {
         eventHub.dispatch(KrbClientEvent.createTgtIntentEvent(tgtTktReq));
-        Event resultEvent = null;
+        Event resultEvent;
         try {
             resultEvent = eventWaiter.waitEvent(KrbClientEventType.TGT_RESULT,
                     context.getTimeout(), TimeUnit.SECONDS);
@@ -386,7 +391,7 @@ public class KrbClient {
         ticketReq.setTransport(transport);
 
         eventHub.dispatch(KrbClientEvent.createTktIntentEvent(ticketReq));
-        Event resultEvent = null;
+        Event resultEvent;
         try {
             resultEvent = eventWaiter.waitEvent(KrbClientEventType.TKT_RESULT,
                     context.getTimeout(), TimeUnit.SECONDS);

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/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 dff0f6f..e9166cf 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
@@ -21,6 +21,7 @@ package org.apache.kerby.kerberos.kerb.server;
 
 import org.apache.kerby.kerberos.kerb.spec.ticket.ServiceTicket;
 import org.apache.kerby.kerberos.kerb.spec.ticket.TgtTicket;
+import org.junit.Assert;
 import org.junit.Test;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -40,12 +41,42 @@ public abstract class KdcTest extends KdcTestBase {
         assertThat(kdcServer.isStarted()).isTrue();
 
         krbClnt.init();
-        TgtTicket tgt = krbClnt.requestTgtTicket(clientPrincipal,
-                password, null);
-        assertThat(tgt).isNotNull();
 
-        ServiceTicket tkt = krbClnt.requestServiceTicket(tgt,
-                serverPrincipal, null);
-        assertThat(tkt).isNotNull();
+        TgtTicket tgt;
+        ServiceTicket tkt;
+
+        // With good password
+        try {
+            tgt = krbClnt.requestTgtTicket(clientPrincipal, password, null);
+            assertThat(tgt).isNotNull();
+
+            tkt = krbClnt.requestServiceTicket(tgt, serverPrincipal, null);
+            assertThat(tkt).isNotNull();
+        } catch (Exception e) {
+            System.out.println("Exception occurred with good password");
+            e.printStackTrace();
+            Assert.fail();
+        }
+
+        // With bad password
+        try {
+            tgt = krbClnt.requestTgtTicket(clientPrincipal, "badpassword", null);
+        } catch (Exception e) {
+            System.out.println("Exception occurred with bad password");
+        }
+
+        // TODO: With good password again. This will fail, to be investigated.
+        /*
+        try {
+            tgt = krbClnt.requestTgtTicket(clientPrincipal, password, null);
+            assertThat(tgt).isNotNull();
+
+            tkt = krbClnt.requestServiceTicket(tgt, serverPrincipal, null);
+            assertThat(tkt).isNotNull();
+        } catch (Exception e) {
+            System.out.println("Exception occurred with good password again");
+            e.printStackTrace();
+            Assert.fail();
+        }*/
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/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
index 07de64d..a5f4b26 100644
--- 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
@@ -103,7 +103,8 @@ public class KdcHandler extends MessageHandler {
         KdcRequest kdcRequest = null;
 
         KrbMessageType messageType = krbRequest.getMsgType();
-        if (messageType == KrbMessageType.TGS_REQ || messageType == KrbMessageType.AS_REQ)
{
+        if (messageType == KrbMessageType.TGS_REQ || messageType
+                == KrbMessageType.AS_REQ) {
             KdcReq kdcReq = (KdcReq) krbRequest;
             String realm = getRequestRealm(kdcReq);
             if (realm == null || !kdcContexts.containsKey(realm)) {
@@ -123,10 +124,16 @@ public class KdcHandler extends MessageHandler {
         boolean isTcp = (transport instanceof TcpTransport);
         kdcRequest.isTcp(isTcp);
 
-        kdcRequest.process();
+        try {
+            kdcRequest.process();
 
-        KrbMessage krbResponse = kdcRequest.getReply();
-        KrbUtil.sendMessage(krbResponse, transport);
+            KrbMessage krbResponse = kdcRequest.getReply();
+            KrbUtil.sendMessage(krbResponse, transport);
+        } catch (Exception e) {
+            //TODO: log the error
+            System.out.println("Error occured while processing request:"
+                    + e.getMessage());
+        }
     }
 
     private void loadKdcRealms() {

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
b/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
index 39fca9f..d3c1401 100644
--- a/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/BufferedEventHandler.java
@@ -44,10 +44,6 @@ public abstract class BufferedEventHandler extends AbstractInternalEventHandler
 
     @Override
     protected void doHandle(Event event) throws Exception {
-        try {
-            eventQueue.put(event);
-        } catch (InterruptedException e) {
-            throw new RuntimeException(e);
-        }
+        eventQueue.put(event);
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
index 931455a..9f10c88 100644
--- a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventHub.java
@@ -142,7 +142,8 @@ public class EventHub implements Dispatcher {
             }
 
             @Override
-            public Event waitEvent(long timeout, TimeUnit timeUnit) throws TimeoutException
{
+            public Event waitEvent(long timeout,
+                                   TimeUnit timeUnit) throws TimeoutException {
                 return waitEventHandler.waitEvent(timeout, timeUnit);
             }
         };

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
index 5e6d7b1..5b41111 100644
--- a/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/EventWaiter.java
@@ -28,8 +28,10 @@ public interface EventWaiter {
 
     public abstract Event waitEvent();
 
-    public abstract Event waitEvent(EventType event, long timeout, TimeUnit timeUnit) throws
TimeoutException;
+    public abstract Event waitEvent(EventType event, long timeout,
+                                    TimeUnit timeUnit) throws TimeoutException;
 
-    public abstract Event waitEvent(long timeout, TimeUnit timeUnit) throws TimeoutException;
+    public abstract Event waitEvent(long timeout,
+                                    TimeUnit timeUnit) throws TimeoutException;
 
 }

http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/17586b45/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
----------------------------------------------------------------------
diff --git a/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java b/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
index 9edc230..da9c561 100644
--- a/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
+++ b/lib/kerby-event/src/main/java/org/apache/kerby/event/WaitEventHandler.java
@@ -90,15 +90,13 @@ public class WaitEventHandler extends BufferedEventHandler {
     }
 
     private Event checkEvent(EventType eventType) throws Exception {
-        Event event = null;
-
         while (true) {
             if (eventQueue.size() == 1) {
                 if (eventQueue.peek().getEventType() == eventType) {
                     return eventQueue.take();
                 }
             } else {
-                event = eventQueue.take();
+                Event event = eventQueue.take();
                 if (event.getEventType() == eventType) {
                     return event;
                 } else {
@@ -110,7 +108,7 @@ public class WaitEventHandler extends BufferedEventHandler {
 
     @Override
     public void start() {
-        executorService = Executors.newFixedThreadPool(2);
+        executorService = Executors.newFixedThreadPool(1);
     }
 
     @Override


Mime
View raw message