You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2015/03/16 00:07:40 UTC
directory-kerberos git commit: Renamed kinit module
Repository: directory-kerberos
Updated Branches:
refs/heads/master 17586b45a -> 2e13e938a
Renamed kinit module
Project: http://git-wip-us.apache.org/repos/asf/directory-kerberos/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerberos/commit/2e13e938
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerberos/tree/2e13e938
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerberos/diff/2e13e938
Branch: refs/heads/master
Commit: 2e13e938acb016681e06afe93edd8011d0a4d3b4
Parents: 17586b4
Author: Drankye <dr...@gmail.com>
Authored: Mon Mar 16 07:07:06 2015 +0800
Committer: Drankye <dr...@gmail.com>
Committed: Mon Mar 16 07:07:06 2015 +0800
----------------------------------------------------------------------
kdc-tool/client-tool/pom.xml | 49 +++++
.../org/apache/kerby/kerberos/tool/Kinit.java | 215 +++++++++++++++++++
.../kerby/kerberos/tool/TestKdcServer.java | 106 +++++++++
kdc-tool/kinit/pom.xml | 49 -----
.../org/apache/kerby/kerberos/tool/Kinit.java | 214 ------------------
.../kerby/kerberos/tool/TestKdcServer.java | 106 ---------
6 files changed, 370 insertions(+), 369 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/client-tool/pom.xml
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/pom.xml b/kdc-tool/client-tool/pom.xml
new file mode 100644
index 0000000..2c49764
--- /dev/null
+++ b/kdc-tool/client-tool/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed 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. See accompanying LICENSE file.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kdc-tool</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>kinit</artifactId>
+ <name>Kinit</name>
+ <description>Kerby KDC kinit tool</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerby-config</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerb-client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.kerby</groupId>
+ <artifactId>kerb-server</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
new file mode 100644
index 0000000..134eb6b
--- /dev/null
+++ b/kdc-tool/client-tool/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
@@ -0,0 +1,215 @@
+/**
+ * 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.tool;
+
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.client.KrbClient;
+import org.apache.kerby.kerberos.kerb.client.KrbConfig;
+
+import java.io.Console;
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Scanner;
+
+/**
+ * kinit like tool
+ */
+public class Kinit {
+
+ private static final String COMMON_USAGE = "Usage: " +
+ Kinit.class.getSimpleName() + " [-l lifetime] [-f | -F] principal\n" +
+ "\n" +
+ " options:\t-l lifetime\n" +
+ "\t-f forwardable\n" +
+ "\t-F not forwardable";
+
+ private void printUsage(String cmd) {
+ if ("-l".equals(cmd)) {
+ System.err.println("Usage: " + Kinit.class.getSimpleName() + " -l lifetime principal");
+ } else if ("-f".equals(cmd)) {
+ System.err.println("Usage: " + Kinit.class.getSimpleName() + " -f principal");
+ } else if ("-F".equals(cmd)) {
+ System.err.println("Usage: " + Kinit.class.getSimpleName() + " -F principal");
+ } else {
+ System.err.println(COMMON_USAGE);
+ }
+ }
+
+ /**
+ * args[0] is the configuration directory written in script.
+ * args[length - 1] is principal
+ */
+ private int execute(String[] args) {
+ if (args.length < 2 || args.length > 4) {
+ printUsage("");
+ return -1;
+ }
+
+ //no options
+ if (args.length == 2) {
+ return requestTicket(args, 1);
+ }
+
+ int exitCode = -1;
+ int i = 1;
+ String cmd = args[i];
+
+ //
+ // verify that we have enough option parameters
+ //
+ if ("-l".equals(cmd)) {
+ if (args.length != 4) {
+ printUsage(cmd);
+ return exitCode;
+ }
+ } else if ("-f".equals(cmd)) {
+ if (args.length != 3) {
+ printUsage(cmd);
+ return exitCode;
+ }
+ } else if ("-F".equals(cmd)) {
+ if (args.length != 3) {
+ printUsage(cmd);
+ return exitCode;
+ }
+ }
+
+ //
+ //execute the command
+ //
+ if ("-l".equals(cmd)) {
+ exitCode = ticketWithLifetime(args, i);
+ } else if ("-f".equals(cmd)) {
+ exitCode = ticketForwardable(args, i);
+ } else if ("-F".equals(cmd)) {
+ exitCode = ticketNonForwardable(args, i);
+ }
+
+ return exitCode;
+ }
+
+ /**
+ * Init the KrbClient
+ */
+ private KrbClient createClient(String confDirString) {
+ KrbConfig krbConfig = new KrbConfig();
+ Conf conf = krbConfig.getConf();
+
+ try {
+ File confDir = new File(confDirString);
+ File[] files = confDir.listFiles();
+ if (files == null) {
+ throw new IOException("There are no file in configuration directory: " + confDirString);
+ }
+
+ for (File file : files) {
+ conf.addIniConfig(file);
+ }
+ } catch (IOException e) {
+ System.err.println("Something wrong with krb configuration.");
+ e.printStackTrace();
+ }
+
+ KrbClient krbClient = new KrbClient(krbConfig);
+ krbClient.init();
+ return krbClient;
+ }
+
+ /**
+ * Get password for the input principal from console
+ */
+ private String getPassword(String principal) {
+ Console console = System.console();
+ if (console == null) {
+ System.out.println("Couldn't get Console instance, maybe you're running this from within an IDE. Use scanner to read password.");
+ System.out.println("Password for " + principal + ":");
+ Scanner scanner = new Scanner(System.in);
+ return scanner.nextLine().trim();
+ }
+ console.printf("Password for " + principal + ":");
+ char[] passwordChars = console.readPassword();
+ String password = new String(passwordChars).trim();
+ Arrays.fill(passwordChars, ' ');
+ return password;
+ }
+
+ private int requestTicket(String[] args, int i) {
+ String principal = args[i];
+ KrbClient client = createClient(args[0]);
+ String password = getPassword(principal);
+
+ try {
+ client.requestTgtTicket(principal, password, null);
+ return 0;
+ } catch (KrbException e) {
+ System.err.println("Something error.");
+ return -1;
+ }
+ }
+
+ private int ticketWithLifetime(String[] args, int i) {
+ String lifetime = args[i];
+ String principal = args[i];
+ KrbClient client = createClient(args[0]);
+ String password = getPassword(principal);
+ try {
+ //TODO
+ return 0;
+ } catch (Exception e) {
+ System.err.println("Something error.");
+ return -1;
+ }
+ }
+
+ private int ticketForwardable(String[] args, int i) {
+ String principal = args[i];
+ KrbClient client = createClient(args[0]);
+ String password = getPassword(principal);
+ try {
+ //TODO
+ return 0;
+ } catch (Exception e) {
+ System.err.println("Something error.");
+ return -1;
+ }
+ }
+
+ private int ticketNonForwardable(String[] args, int i) {
+ String principal = args[i];
+ KrbClient client = createClient(args[0]);
+ String password = getPassword(principal);
+ try {
+ //TODO
+ return 0;
+ } catch (Exception e) {
+ System.err.println("Something error.");
+ return -1;
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ Kinit kinit = new Kinit();
+ int exitCode = kinit.execute(args);
+ System.exit(exitCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/client-tool/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
----------------------------------------------------------------------
diff --git a/kdc-tool/client-tool/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java b/kdc-tool/client-tool/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
new file mode 100644
index 0000000..c37e7eb
--- /dev/null
+++ b/kdc-tool/client-tool/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
@@ -0,0 +1,106 @@
+/**
+ * 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.tool;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
+import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
+import org.apache.kerby.kerberos.kerb.server.KdcConfigKey;
+import org.apache.kerby.kerberos.kerb.server.KdcServer;
+import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
+import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
+
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+
+/**
+ * A standalone kdc server with some default value for test.
+ */
+public class TestKdcServer extends SimpleKdcServer {
+
+ public static final String ORG_DOMAIN = KdcConfigKey.KDC_DOMAIN.getPropertyKey();
+ public static final String KDC_REALM = KdcConfigKey.KDC_REALM.getPropertyKey();
+ public static final String KDC_HOST = KdcConfigKey.KDC_HOST.getPropertyKey();
+ public static final String KDC_TCP_PORT = KdcConfigKey.KDC_TCP_PORT.getPropertyKey();
+
+ private static final Properties DEFAULT_CONFIG = new Properties();
+ static {
+ DEFAULT_CONFIG.setProperty(KDC_HOST, "localhost");
+ DEFAULT_CONFIG.setProperty(KDC_TCP_PORT, "8015");
+ DEFAULT_CONFIG.setProperty(ORG_DOMAIN, "test.com");
+ DEFAULT_CONFIG.setProperty(KDC_REALM, "TEST.COM");
+ }
+
+ public static Properties createConf() {
+ return (Properties) DEFAULT_CONFIG.clone();
+ }
+
+ @Override
+ public void init() {
+ super.init();
+
+ getKdcConfig().getConf().addPropertiesConfig(createConf());
+
+ createPrincipals("krbtgt", "test-service/localhost");
+
+ createPrincipal("client@TEST.COM", "123456");
+ }
+
+ public static void main(String[] args) {
+ KdcServer server = new TestKdcServer();
+ server.init();
+ server.start();
+ System.out.println("Kdc Server(for test) Started.");
+ }
+
+ public String getKdcRealm() {
+ return getKdcConfig().getKdcRealm();
+ }
+
+ public synchronized void createPrincipal(String principal, String password) {
+ KrbIdentity identity = new KrbIdentity(principal);
+ List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
+ List<EncryptionKey> encKeys = null;
+ try {
+ encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
+ } catch (KrbException e) {
+ throw new RuntimeException("Failed to generate encryption keys", e);
+ }
+ identity.addKeys(encKeys);
+ getIdentityService().addIdentity(identity);
+ }
+
+ public void createPrincipals(String ... principals) {
+ String passwd;
+ for (String principal : principals) {
+ passwd = UUID.randomUUID().toString();
+ createPrincipal(fixPrincipal(principal), passwd);
+ }
+ }
+
+ private String fixPrincipal(String principal) {
+ if (! principal.contains("@")) {
+ principal += "@" + getKdcRealm();
+ }
+ return principal;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/kinit/pom.xml
----------------------------------------------------------------------
diff --git a/kdc-tool/kinit/pom.xml b/kdc-tool/kinit/pom.xml
deleted file mode 100644
index 2c49764..0000000
--- a/kdc-tool/kinit/pom.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed 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. See accompanying LICENSE file.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kdc-tool</artifactId>
- <version>1.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>kinit</artifactId>
- <name>Kinit</name>
- <description>Kerby KDC kinit tool</description>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerby-config</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerb-client</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.kerby</groupId>
- <artifactId>kerb-server</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/kinit/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
----------------------------------------------------------------------
diff --git a/kdc-tool/kinit/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java b/kdc-tool/kinit/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
deleted file mode 100644
index e4c0d7c..0000000
--- a/kdc-tool/kinit/src/main/java/org/apache/kerby/kerberos/tool/Kinit.java
+++ /dev/null
@@ -1,214 +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.tool;
-
-import org.apache.kerby.config.Conf;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.client.KrbClient;
-import org.apache.kerby.kerberos.kerb.client.KrbConfig;
-
-import java.io.Console;
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Scanner;
-
-/**
- * kinit like tool
- */
-public class Kinit {
-
- private static final String COMMON_USAGE = "Usage: " + Kinit.class.getSimpleName() + " [-l lifetime] [-f | -F] principal\n" +
- "\n" +
- " options:\t-l lifetime\n" +
- "\t-f forwardable\n" +
- "\t-F not forwardable";
-
- private void printUsage(String cmd) {
- if ("-l".equals(cmd)) {
- System.err.println("Usage: " + Kinit.class.getSimpleName() + " -l lifetime principal");
- } else if ("-f".equals(cmd)) {
- System.err.println("Usage: " + Kinit.class.getSimpleName() + " -f principal");
- } else if ("-F".equals(cmd)) {
- System.err.println("Usage: " + Kinit.class.getSimpleName() + " -F principal");
- } else {
- System.err.println(COMMON_USAGE);
- }
- }
-
- /**
- * args[0] is the configuration directory written in script.
- * args[length - 1] is principal
- */
- private int execute(String[] args) {
- if (args.length < 2 || args.length > 4) {
- printUsage("");
- return -1;
- }
-
- //no options
- if (args.length == 2) {
- return requestTicket(args, 1);
- }
-
- int exitCode = -1;
- int i = 1;
- String cmd = args[i];
-
- //
- // verify that we have enough option parameters
- //
- if ("-l".equals(cmd)) {
- if (args.length != 4) {
- printUsage(cmd);
- return exitCode;
- }
- } else if ("-f".equals(cmd)) {
- if (args.length != 3) {
- printUsage(cmd);
- return exitCode;
- }
- } else if ("-F".equals(cmd)) {
- if (args.length != 3) {
- printUsage(cmd);
- return exitCode;
- }
- }
-
- //
- //execute the command
- //
- if ("-l".equals(cmd)) {
- exitCode = ticketWithLifetime(args, i);
- } else if ("-f".equals(cmd)) {
- exitCode = ticketForwardable(args, i);
- } else if ("-F".equals(cmd)) {
- exitCode = ticketNonForwardable(args, i);
- }
-
- return exitCode;
- }
-
- /**
- * Init the KrbClient
- */
- private KrbClient createClient(String confDirString) {
- KrbConfig krbConfig = new KrbConfig();
- Conf conf = krbConfig.getConf();
-
- try {
- File confDir = new File(confDirString);
- File[] files = confDir.listFiles();
- if (files == null) {
- throw new IOException("There are no file in configuration directory: " + confDirString);
- }
-
- for (File file : files) {
- conf.addIniConfig(file);
- }
- } catch (IOException e) {
- System.err.println("Something wrong with krb configuration.");
- e.printStackTrace();
- }
-
- KrbClient krbClient = new KrbClient(krbConfig);
- krbClient.init();
- return krbClient;
- }
-
- /**
- * Get password for the input principal from console
- */
- private String getPassword(String principal) {
- Console console = System.console();
- if (console == null) {
- System.out.println("Couldn't get Console instance, maybe you're running this from within an IDE. Use scanner to read password.");
- System.out.println("Password for " + principal + ":");
- Scanner scanner = new Scanner(System.in);
- return scanner.nextLine().trim();
- }
- console.printf("Password for " + principal + ":");
- char[] passwordChars = console.readPassword();
- String password = new String(passwordChars).trim();
- Arrays.fill(passwordChars, ' ');
- return password;
- }
-
- private int requestTicket(String[] args, int i) {
- String principal = args[i];
- KrbClient client = createClient(args[0]);
- String password = getPassword(principal);
-
- try {
- client.requestTgtTicket(principal, password, null);
- return 0;
- } catch (KrbException e) {
- System.err.println("Something error.");
- return -1;
- }
- }
-
- private int ticketWithLifetime(String[] args, int i) {
- String lifetime = args[i];
- String principal = args[i];
- KrbClient client = createClient(args[0]);
- String password = getPassword(principal);
- try {
- //TODO
- return 0;
- } catch (Exception e) {
- System.err.println("Something error.");
- return -1;
- }
- }
-
- private int ticketForwardable(String[] args, int i) {
- String principal = args[i];
- KrbClient client = createClient(args[0]);
- String password = getPassword(principal);
- try {
- //TODO
- return 0;
- } catch (Exception e) {
- System.err.println("Something error.");
- return -1;
- }
- }
-
- private int ticketNonForwardable(String[] args, int i) {
- String principal = args[i];
- KrbClient client = createClient(args[0]);
- String password = getPassword(principal);
- try {
- //TODO
- return 0;
- } catch (Exception e) {
- System.err.println("Something error.");
- return -1;
- }
- }
-
- public static void main(String[] args) throws Exception {
- Kinit kinit = new Kinit();
- int exitCode = kinit.execute(args);
- System.exit(exitCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerberos/blob/2e13e938/kdc-tool/kinit/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
----------------------------------------------------------------------
diff --git a/kdc-tool/kinit/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java b/kdc-tool/kinit/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
deleted file mode 100644
index c37e7eb..0000000
--- a/kdc-tool/kinit/src/test/java/org/apache/kerby/kerberos/tool/TestKdcServer.java
+++ /dev/null
@@ -1,106 +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.tool;
-
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.common.EncryptionUtil;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.server.KdcConfigKey;
-import org.apache.kerby.kerberos.kerb.server.KdcServer;
-import org.apache.kerby.kerberos.kerb.server.SimpleKdcServer;
-import org.apache.kerby.kerberos.kerb.spec.common.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.common.EncryptionType;
-
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-
-/**
- * A standalone kdc server with some default value for test.
- */
-public class TestKdcServer extends SimpleKdcServer {
-
- public static final String ORG_DOMAIN = KdcConfigKey.KDC_DOMAIN.getPropertyKey();
- public static final String KDC_REALM = KdcConfigKey.KDC_REALM.getPropertyKey();
- public static final String KDC_HOST = KdcConfigKey.KDC_HOST.getPropertyKey();
- public static final String KDC_TCP_PORT = KdcConfigKey.KDC_TCP_PORT.getPropertyKey();
-
- private static final Properties DEFAULT_CONFIG = new Properties();
- static {
- DEFAULT_CONFIG.setProperty(KDC_HOST, "localhost");
- DEFAULT_CONFIG.setProperty(KDC_TCP_PORT, "8015");
- DEFAULT_CONFIG.setProperty(ORG_DOMAIN, "test.com");
- DEFAULT_CONFIG.setProperty(KDC_REALM, "TEST.COM");
- }
-
- public static Properties createConf() {
- return (Properties) DEFAULT_CONFIG.clone();
- }
-
- @Override
- public void init() {
- super.init();
-
- getKdcConfig().getConf().addPropertiesConfig(createConf());
-
- createPrincipals("krbtgt", "test-service/localhost");
-
- createPrincipal("client@TEST.COM", "123456");
- }
-
- public static void main(String[] args) {
- KdcServer server = new TestKdcServer();
- server.init();
- server.start();
- System.out.println("Kdc Server(for test) Started.");
- }
-
- public String getKdcRealm() {
- return getKdcConfig().getKdcRealm();
- }
-
- public synchronized void createPrincipal(String principal, String password) {
- KrbIdentity identity = new KrbIdentity(principal);
- List<EncryptionType> encTypes = getKdcConfig().getEncryptionTypes();
- List<EncryptionKey> encKeys = null;
- try {
- encKeys = EncryptionUtil.generateKeys(fixPrincipal(principal), password, encTypes);
- } catch (KrbException e) {
- throw new RuntimeException("Failed to generate encryption keys", e);
- }
- identity.addKeys(encKeys);
- getIdentityService().addIdentity(identity);
- }
-
- public void createPrincipals(String ... principals) {
- String passwd;
- for (String principal : principals) {
- passwd = UUID.randomUUID().toString();
- createPrincipal(fixPrincipal(principal), passwd);
- }
- }
-
- private String fixPrincipal(String principal) {
- if (! principal.contains("@")) {
- principal += "@" + getKdcRealm();
- }
- return principal;
- }
-}
\ No newline at end of file