directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject [02/10] directory-kerby git commit: DIRKRB-399 Enable SimpleKdcServer#stop to delete krb5.conf created by init method. Contributed by Yaning.
Date Thu, 20 Aug 2015 02:38:11 GMT
DIRKRB-399 Enable SimpleKdcServer#stop to delete krb5.conf created by init method. Contributed
by Yaning.


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

Branch: refs/heads/pkinit-support
Commit: 7d4ca519901a0658b84d6e6269d470469beeee71
Parents: e8f1a2d
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Wed Aug 12 14:48:52 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Wed Aug 12 14:48:52 2015 +0800

----------------------------------------------------------------------
 .../kerberos/kerb/server/KdcServerTest.java     | 73 +++++++++++++++++++
 .../kerberos/kerb/server/SimpleKdcTest.java     | 73 -------------------
 .../kerby/kerberos/kerb/client/Krb5Conf.java    |  9 ++-
 .../kerberos/kerb/server/SimpleKdcServer.java   | 13 +++-
 .../kerberos/kerb/SimpleKdcServerTest.java      | 75 ++++++++++++++++++++
 5 files changed, 168 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d4ca519/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcServerTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcServerTest.java
b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcServerTest.java
new file mode 100644
index 0000000..3918ae7
--- /dev/null
+++ b/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/KdcServerTest.java
@@ -0,0 +1,73 @@
+/**
+ *  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.util.NetworkUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+public class KdcServerTest {
+    private String serverHost = "localhost";
+    private int serverPort = -1;
+
+    private KdcServer kdcServer;
+
+    @Before
+    public void setUp() throws Exception {
+        kdcServer = new KdcServer();
+        kdcServer.setKdcHost(serverHost);
+        kdcServer.setAllowUdp(false);
+        kdcServer.setAllowTcp(true);
+        serverPort = NetworkUtil.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 badKrbMessage = "Hello World!";
+        ByteBuffer writeBuffer = ByteBuffer.allocate(4 + badKrbMessage.getBytes().length);
+        writeBuffer.putInt(badKrbMessage.getBytes().length);
+        writeBuffer.put(badKrbMessage.getBytes());
+        writeBuffer.flip();
+
+        socketChannel.write(writeBuffer);
+    }
+
+    @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/7d4ca519/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
deleted file mode 100644
index 8f15ede..0000000
--- a/kerby-kerb/kerb-server/src/test/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcTest.java
+++ /dev/null
@@ -1,73 +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.util.NetworkUtil;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.IOException;
-import java.net.InetSocketAddress;
-import java.net.SocketAddress;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-public class SimpleKdcTest {
-    private String serverHost = "localhost";
-    private int serverPort = -1;
-
-    private KdcServer kdcServer;
-
-    @Before
-    public void setUp() throws Exception {
-        kdcServer = new KdcServer();
-        kdcServer.setKdcHost(serverHost);
-        kdcServer.setAllowUdp(false);
-        kdcServer.setAllowTcp(true);
-        serverPort = NetworkUtil.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 badKrbMessage = "Hello World!";
-        ByteBuffer writeBuffer = ByteBuffer.allocate(4 + badKrbMessage.getBytes().length);
-        writeBuffer.putInt(badKrbMessage.getBytes().length);
-        writeBuffer.put(badKrbMessage.getBytes());
-        writeBuffer.flip();
-
-        socketChannel.write(writeBuffer);
-    }
-
-    @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/7d4ca519/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/Krb5Conf.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/Krb5Conf.java
b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/Krb5Conf.java
index 028fae7..dc47652 100644
--- a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/Krb5Conf.java
+++ b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/client/Krb5Conf.java
@@ -34,6 +34,7 @@ public class Krb5Conf {
     public static final String KRB5_CONF = "java.security.krb5.conf";
     private static final String KRB5_CONF_FILE = "krb5.conf";
     private SimpleKdcServer kdcServer;
+    private File confFile;
 
     public Krb5Conf(SimpleKdcServer kdcServer) {
         this.kdcServer = kdcServer;
@@ -71,9 +72,15 @@ public class Krb5Conf {
         int udpLimit = setting.allowUdp() ? 4096 : 1;
         content = content.replaceAll("_UDP_LIMIT_", String.valueOf(udpLimit));
 
-        File confFile = new File(kdcServer.getWorkDir(), KRB5_CONF_FILE);
+        this.confFile = new File(kdcServer.getWorkDir(), KRB5_CONF_FILE);
         IOUtil.writeFile(content, confFile);
 
         return confFile;
     }
+
+    public void deleteKrb5conf() throws IOException {
+        if (!this.confFile.delete()) {
+            throw new IOException();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d4ca519/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
index f3b19b5..9da97ea 100644
--- a/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
+++ b/kerby-kerb/kerb-simplekdc/src/main/java/org/apache/kerby/kerberos/kerb/server/SimpleKdcServer.java
@@ -35,6 +35,7 @@ import java.io.IOException;
 public class SimpleKdcServer extends KdcServer {
     private final KrbClient krbClnt;
     private Kadmin kadmin;
+    private Krb5Conf krb5Conf;
 
     private File workDir;
 
@@ -126,7 +127,7 @@ public class SimpleKdcServer extends KdcServer {
         kadmin.createBuiltinPrincipals();
 
         try {
-            Krb5Conf krb5Conf = new Krb5Conf(this);
+            krb5Conf = new Krb5Conf(this);
             krb5Conf.initKrb5conf();
         } catch (IOException e) {
             throw new KrbException("Failed to make krb5.conf", e);
@@ -241,4 +242,14 @@ public class SimpleKdcServer extends KdcServer {
     public void exportPrincipal(String principal, File keytabFile) throws KrbException {
         kadmin.exportKeytab(keytabFile, principal);
     }
+
+    @Override
+    public void stop() throws KrbException {
+        super.stop();
+        try {
+            krb5Conf.deleteKrb5conf();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/7d4ca519/kerby-kerb/kerb-simplekdc/src/main/test/org/apache/kerby/kerberos/kerb/SimpleKdcServerTest.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-simplekdc/src/main/test/org/apache/kerby/kerberos/kerb/SimpleKdcServerTest.java
b/kerby-kerb/kerb-simplekdc/src/main/test/org/apache/kerby/kerberos/kerb/SimpleKdcServerTest.java
new file mode 100644
index 0000000..cb26513
--- /dev/null
+++ b/kerby-kerb/kerb-simplekdc/src/main/test/org/apache/kerby/kerberos/kerb/SimpleKdcServerTest.java
@@ -0,0 +1,75 @@
+/**
+ *  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;
+
+import org.apache.kerby.kerberos.kerb.server.KdcServer;
+import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer;
+import org.apache.kerby.util.NetworkUtil;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+public class SimpleKdcServerTest {
+    private String serverHost = "localhost";
+    private int serverPort = -1;
+
+    private KdcServer kdcServer;
+
+    @Before
+    public void setUp() throws Exception {
+        kdcServer = new SimpleKdcServer();
+        kdcServer.setKdcHost(serverHost);
+        kdcServer.setAllowUdp(false);
+        kdcServer.setAllowTcp(true);
+        serverPort = NetworkUtil.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 badKrbMessage = "Hello World!";
+        ByteBuffer writeBuffer = ByteBuffer.allocate(4 + badKrbMessage.getBytes().length);
+        writeBuffer.putInt(badKrbMessage.getBytes().length);
+        writeBuffer.put(badKrbMessage.getBytes());
+        writeBuffer.flip();
+
+        socketChannel.write(writeBuffer);
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        kdcServer.stop();
+    }
+}


Mime
View raw message