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: Refactored kadmin tool
Date Tue, 23 Jun 2015 02:34:26 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 390e21c8f -> dadf393f8


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ListPrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ListPrincipalCommand.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ListPrincipalCommand.java
new file mode 100644
index 0000000..a9433b7
--- /dev/null
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ListPrincipalCommand.java
@@ -0,0 +1,52 @@
+/**
+ *  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.kadmin.command;
+
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.Kadmin;
+
+import java.util.List;
+
+public class ListPrincipalCommand extends KadminCommand {
+
+    public ListPrincipalCommand(Kadmin kadmin) {
+        super(kadmin);
+    }
+
+    @Override
+    public void execute(String input) {
+        String[] commands = input.split(" ");
+        List<String> principalNames = null;
+
+
+        if (commands.length == 1) {
+            try {
+                principalNames = getKadmin().listPrincipal();
+            } catch (KrbException e) {
+                System.err.print("Fail to list principal!" + e.getMessage());
+            }
+        }
+        System.out.println("Principals are listed:");
+
+        for (String principalName : principalNames) {
+            System.out.println(principalName);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
new file mode 100644
index 0000000..86c19e3
--- /dev/null
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/ModifyPrincipalCommand.java
@@ -0,0 +1,100 @@
+/**
+ *  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.kadmin.command;
+
+import org.apache.kerby.KOptionType;
+import org.apache.kerby.KOptions;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.Kadmin;
+import org.apache.kerby.kerberos.kerb.admin.KadminOption;
+import org.apache.kerby.kerberos.tool.kadmin.ToolUtil;
+
+public class ModifyPrincipalCommand extends KadminCommand {
+    private static final String USAGE = "Usage: modify_principal [options] principal\n" +
+        "\toptions are:\n" +
+        "\t\t[-expire dd/MM/yy:HH:mm:ss]\n" +
+        "\t\t[-disabled true/false]\n" +
+        "\t\t[-locked true/false]\n" +
+        "\tExample:\n" +
+        "\t\tmodify_principal -expire 23/04/15:01:01:01 -disabled false -locked true test@EXAMPLE.COM";
+
+    private KOptions kOptions;
+    private String principal;
+
+    public ModifyPrincipalCommand(Kadmin kadmin) {
+        super(kadmin);
+    }
+
+    @Override
+    public void execute(String input) {
+        String[] commands = input.split(" ");
+        if (commands.length < 2) {
+            ToolUtil.printUsage("missing operand!", USAGE);
+            return;
+        }
+        parseOptions(commands);
+
+        try {
+            getKadmin().modifyPrincipal(principal, kOptions);
+            System.out.println("Principal \"" + principal + "\" modified.");
+        } catch (KrbException e) {
+            System.err.println("Principal \"" + principal + "\" fail to modify. " + e.getCause());
+        }
+    }
+
+    private void parseOptions(String[] commands) {
+        KadminOption kOption;
+        String opt, error, param;
+        int i = 1;
+        while (i < commands.length) {
+            error = null;
+            opt = commands[i++];
+            if (opt.startsWith("-")) {
+                kOption = KadminOption.fromName(opt);
+                if (kOption == KadminOption.NONE) {
+                    error = "Invalid option:" + opt;
+                    break;
+                }
+            } else {
+                principal = opt;
+                kOption = KadminOption.NONE;
+            }
+
+            if (kOption.getType() != KOptionType.NOV) { // require a parameter
+                param = null;
+                if (i < commands.length) {
+                    param = commands[i++];
+                }
+                if (param != null) {
+                    KOptions.parseSetValue(kOption, param);
+                } else {
+                    error = "Option " + opt + " require a parameter";
+                }
+            }
+            if (error != null) {
+                ToolUtil.printUsage(error, USAGE);
+            }
+            kOptions.add(kOption);
+        }
+        if(principal == null) {
+            ToolUtil.printUsage("missing principal name!", USAGE);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
new file mode 100644
index 0000000..07952a5
--- /dev/null
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/command/RenamePrincipalCommand.java
@@ -0,0 +1,80 @@
+/**
+ *  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.kadmin.command;
+
+import org.apache.kerby.KOptions;
+import org.apache.kerby.kerberos.kerb.KrbException;
+import org.apache.kerby.kerberos.kerb.admin.Kadmin;
+import org.apache.kerby.kerberos.kerb.admin.KadminOption;
+import org.apache.kerby.kerberos.tool.kadmin.ToolUtil;
+
+
+public class RenamePrincipalCommand extends KadminCommand {
+    private static final String USAGE = "Usage: rename_principal [-force] old_principal new_principal\n";
+
+    private KOptions kOptions;
+    private String oldPrincipalName;
+    private String newPrincipalName;
+
+    public RenamePrincipalCommand(Kadmin kadmin) {
+        super(kadmin);
+    }
+
+    @Override
+    public void execute(String input) {
+        String[] commands = input.split("\\s+");
+        if (commands.length < 3 || commands.length > 4) {
+            System.err.println(USAGE);
+            return;
+        }
+
+        kOptions = ToolUtil.parseOptions(commands, 1, commands.length - 3);
+        if(kOptions==null) {
+            System.err.println(USAGE);
+            return;
+        }
+        oldPrincipalName = commands[commands.length - 2];
+        newPrincipalName = commands[commands.length - 1];
+
+        if (kOptions.contains(KadminOption.FORCE)) {
+            renamePrincipal(getKadmin());
+        } else {
+            String prompt = "Are you sure want to rename the principal? (yes/no, YES/NO, y/n, Y/N) ";
+            String reply = ToolUtil.getReplay(prompt);
+            if (reply.equals("yes") || reply.equals("YES") || reply.equals("y") || reply.equals("Y")) {
+                renamePrincipal(getKadmin());
+            } else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) {
+                System.out.println("Principal \"" + oldPrincipalName + "\"  not renamed." );
+            } else {
+                System.err.println("Unknown response, fail to rename the principal.");
+            }
+        }
+    }
+
+    public void renamePrincipal(Kadmin kadmin) {
+        try {
+            kadmin.renamePrincipal(oldPrincipalName, newPrincipalName);
+            System.out.println("Principal \"" + oldPrincipalName + "\" renamed to \"" +
+                newPrincipalName + "\".");
+        } catch (KrbException e) {
+            System.err.println("Principal rename failed! Exception happened. " + e.getCause());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
deleted file mode 100644
index 063dbf6..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/AddPrincipalExecutor.java
+++ /dev/null
@@ -1,142 +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.kadmin.executor;
-
-import org.apache.kerby.KOptions;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-import org.apache.kerby.kerberos.kerb.server.KdcConfig;
-import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
-
-import java.io.Console;
-import java.util.Arrays;
-import java.util.Scanner;
-
-public class AddPrincipalExecutor implements KadminCommandExecutor{
-    private static final String USAGE = "Usage: add_principal [options] principal\n" +
-            "\toptions are:\n" +
-            "\t\t[-randkey|-nokey] [-x db_princ_args]* [-expire expdate] [-pwexpire pwexpdate] [-maxlife maxtixlife]\n" +
-            "\t\t[-kvno kvno] [-policy policy] [-clearpolicy]\n" +
-            "\t\t[-pw password] [-maxrenewlife maxrenewlife]\n" +
-            "\t\t[-e keysaltlist]\n" +
-            "\t\t[{+|-}attribute]\n" +
-            "\tattributes are:\n" +
-            "\t\tallow_postdated allow_forwardable allow_tgs_req allow_renewable\n" +
-            "\t\tallow_proxiable allow_dup_skey allow_tix requires_preauth\n" +
-            "\t\trequires_hwauth needchange allow_svr password_changing_service\n" +
-            "\t\tok_as_delegate ok_to_auth_as_delegate no_auth_data_required\n" +
-            "\n" +
-            "\twhere,\n" +
-            "\t[-x db_princ_args]* - any number of database specific arguments.\n" +
-            "\t\t\tLook at each database documentation for supported arguments.\n" +
-            "\tExample:\n" +
-            "\t\tadd_principal -expire 23/04/15:01:01:01 -kvno 1 -pw mypassword test@EXAMPLE.COM";
-
-    private KdcConfig kdcConfig;
-    private Config backendConfig;
-    private KOptions kOptions;
-
-    public AddPrincipalExecutor(KdcConfig kdcConfig, Config backendConfig) {
-        this.kdcConfig = kdcConfig;
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split("\\s+");
-        if (commands.length < 2) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        kOptions = KadminTool.parseOptions(commands, 1, commands.length - 2);
-        if(kOptions == null) {
-            System.err.println(USAGE);
-            return;
-        }
-        String principal = commands[commands.length - 1];
-        String password;
-        if(kOptions.contains(KadminOption.PW)) {
-            password = kOptions.getStringOption(KadminOption.PW);
-        } else {
-            password = getPassword(principal);
-        }
-
-        if (password == null) {
-            return;
-        }
-
-        Kadmin kadmin = new Kadmin(kdcConfig, backendConfig);
-
-        try {
-            kadmin.addPrincipal(principal, password, kOptions);
-            System.out.println("Principal \"" + principal + "\" created.");
-        } catch (KrbException e) {
-            System.err.println("Fail to add principal \"" + principal + "\"." + e.getCause());
-        }
-    }
-
-    /**
-     * Get password for the input principal from console
-     */
-    private String getPassword(String principal) {
-        String passwordOnce;
-        String passwordTwice;
-
-        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.");
-            Scanner scanner = new Scanner(System.in);
-            passwordOnce = getPassword(scanner,
-                    "Enter password for principal \"" + principal + "\":");
-            passwordTwice = getPassword(scanner,
-                    "Re-enter password for principal \"" + principal + "\":");
-
-        } else {
-            passwordOnce = getPassword(console,
-                    "Enter password for principal \"" + principal + "\":");
-            passwordTwice = getPassword(console,
-                    "Re-enter password for principal \"" + principal + "\":");
-        }
-
-        if (!passwordOnce.equals(passwordTwice)) {
-            System.err.println("add_principal: Password mismatch while reading password for \"" + principal + "\".");
-            return null;
-        }
-        return passwordOnce;
-    }
-
-    private String getPassword(Scanner scanner, String prompt) {
-        System.out.println(prompt);
-        return scanner.nextLine().trim();
-    }
-
-    private String getPassword(Console console, String prompt) {
-        console.printf(prompt);
-        char[] passwordChars = console.readPassword();
-        String password = new String(passwordChars).trim();
-        Arrays.fill(passwordChars, ' ');
-        return password;
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ChangePasswordExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ChangePasswordExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ChangePasswordExecutor.java
deleted file mode 100644
index 3c8ca4e..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ChangePasswordExecutor.java
+++ /dev/null
@@ -1,140 +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.kadmin.executor;
-
-import org.apache.kerby.KOptions;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-import org.apache.kerby.kerberos.kerb.server.KdcConfig;
-import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
-
-import java.io.Console;
-import java.util.Arrays;
-import java.util.Scanner;
-
-public class ChangePasswordExecutor implements KadminCommandExecutor{
-    private static final String USAGE = "Usage: change_password [-randkey] " +
-            "[-keepold] [-e keysaltlist] [-pw password] principal";
-
-    private KdcConfig kdcConfig;
-    private Config backendConfig;
-    private KOptions kOptions;
-    private Kadmin kadmin;
-
-    public ChangePasswordExecutor(KdcConfig kdcCfg, Config backendCfg) {
-        this.kdcConfig=kdcCfg;
-        this.backendConfig = backendCfg;
-        this.kadmin = new Kadmin(kdcConfig, backendConfig);
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split("\\s");
-        String principal = commands[commands.length -1];
-        String password;
-
-        if (commands.length <= 1) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        if (commands.length == 2) {//only principal is given
-            password = getPassword(principal);
-            if(password == null) {
-                System.out.println("Did not get new password successfully. Please try again");
-                return;
-            }
-            try {
-                kadmin.updatePassword(principal, password);
-                System.out.println("Update password success.");
-            } catch (KrbException e) {
-                System.err.println("Fail to update password. " + e.getCause());
-            }
-        } else if (commands.length > 2) {
-            kOptions = KadminTool.parseOptions(commands, 1, commands.length - 2);
-            if (kOptions == null) {
-                System.err.println(USAGE);
-                return;
-            }
-            if (kOptions.contains(KadminOption.PW)){
-                password = kOptions.getStringOption(KadminOption.PW);
-                try {
-                    kadmin.updatePassword(principal, password);
-                    System.out.println("Update password success.");
-                } catch (KrbException e) {
-                    System.err.println("Fail to update password. " + e.getCause());
-                }
-            } else if( kOptions.contains(KadminOption.RANDKEY)){
-                try {
-                    kadmin.updateKey(principal);
-                } catch (KrbException e) {
-                    System.err.println("Fail to update key. " + e.getCause());
-                }
-            }
-        }
-    }
-
-    /**
-     * Get password from console
-     */
-    private String getPassword(String principal) {
-        String passwordOnce;
-        String passwordTwice;
-
-        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.");
-            Scanner scanner = new Scanner(System.in);
-            passwordOnce = getPassword(scanner,
-                    "Please enter new password  \"" + principal + "\":");
-            passwordTwice = getPassword(scanner,
-                    "Please re-enter password  =\"" + principal + "\":");
-
-        } else {
-            passwordOnce = getPassword(console,
-                    "Please enter new password \"" + principal + "\":");
-            passwordTwice = getPassword(console,
-                    "Please re-enter password \"" + principal + "\":");
-        }
-
-        if (!passwordOnce.equals(passwordTwice)) {
-            System.err.println("change_password: Password mismatch while reading password for \"" + principal + "\".");
-            return null;
-        }
-        return passwordOnce;
-    }
-
-    private String getPassword(Scanner scanner, String prompt) {
-        System.out.println(prompt);
-        return scanner.nextLine().trim();
-    }
-
-    private String getPassword(Console console, String prompt) {
-        console.printf(prompt);
-        char[] passwordChars = console.readPassword();
-        String password = new String(passwordChars).trim();
-        Arrays.fill(passwordChars, ' ');
-        return password;
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/DeletePrincipalExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/DeletePrincipalExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/DeletePrincipalExecutor.java
deleted file mode 100644
index 1bd6bf1..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/DeletePrincipalExecutor.java
+++ /dev/null
@@ -1,105 +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.kadmin.executor;
-
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-
-import java.io.Console;
-import java.util.Scanner;
-
-public class DeletePrincipalExecutor implements KadminCommandExecutor{
-
-    private static final String USAGE = "Usage: delete_principal [options] principal\n" +
-            "This command prompts for deletion, unless the -force option is given.\n" +
-            "\toptions are:\n" +
-            "\t\t[-force]" + " no prompts for deletion.";
-
-    private Config backendConfig;
-    private Boolean force = false;
-
-    public DeletePrincipalExecutor(Config backendConfig) {
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split(" ");
-        if (commands.length < 2) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        parseOptions(commands);
-        String principal = commands[commands.length - 1];
-
-        Kadmin kadmin = new Kadmin(backendConfig);
-        if (force) {
-            deletePrincipal(kadmin, principal);
-        } else {
-            String reply;
-            Console console = System.console();
-            String prompt = "Are you sure want to delete the principal? (yes/no, YES/NO, y/n, Y/N) ";
-            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.");
-                Scanner scanner = new Scanner(System.in);
-                reply = getReply(scanner, prompt);
-            } else {
-                reply = getReply(console, prompt);
-            }
-            if (reply.equals("yes") || reply.equals("YES") || reply.equals("y") || reply.equals("Y")) {
-                deletePrincipal(kadmin, principal);
-            } else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) {
-                System.out.println("Pincipal \"" + principal + "\"  not deleted." );
-            } else {
-                System.err.println("Unknow request, fail to delete the principal.");
-            }
-        }
-    }
-
-    private void deletePrincipal(Kadmin kadmin, String principal) {
-        try {
-            kadmin.deletePrincipal(principal);
-            System.out.println("Principal \"" + principal + "\" deleted.");
-        } catch (KrbException e) {
-            System.err.println("Fail to delete principal \"" + principal + "\" ." + e.getCause());
-        }
-    }
-
-    private String getReply(Scanner scanner, String prompt) {
-        System.out.println(prompt);
-        return scanner.nextLine().trim();
-    }
-
-    private String getReply(Console console, String prompt) {
-        console.printf(prompt);
-        String line = console.readLine();
-        return line;
-    }
-
-    private void parseOptions(String[] commands) {
-        if (commands[1].equals("-force")) {
-            force = true;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/GetPrincipalExcutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/GetPrincipalExcutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/GetPrincipalExcutor.java
deleted file mode 100644
index 08057b3..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/GetPrincipalExcutor.java
+++ /dev/null
@@ -1,79 +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.kadmin.executor;
-
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.identity.KrbIdentity;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionKey;
-import org.apache.kerby.kerberos.kerb.spec.base.EncryptionType;
-
-import java.util.Map;
-
-public class GetPrincipalExcutor implements KadminCommandExecutor {
-    private static final String USAGE = "Usage: getprinc principalName\n" +
-            "such as, getprinc hello@TEST.COM";
-    private Config backendConfig;
-
-    public GetPrincipalExcutor(Config backendConfig) {
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split(" ");
-
-        if (commands.length != 2) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        String princName = commands[commands.length - 1];
-        Kadmin kadmin = new Kadmin(backendConfig);
-        KrbIdentity identity = null;
-        try {
-            identity = kadmin.getPrincipal(princName);
-        } catch (KrbException e) {
-            System.err.println("Fail to get principal: " + princName + ". " + e.getCause());
-        }
-
-        if (identity == null) {
-            System.err.println(princName + " doesn't exist\n");
-            System.err.println(USAGE);
-            return;
-        }
-
-        Map<EncryptionType, EncryptionKey> key = identity.getKeys();
-
-        System.out.println(
-                "Principal: " + identity.getPrincipalName() + "\n" +
-                "Expiration data: " + identity.getExpireTime() + "\n" +
-                "Created time: " + identity.getCreatedTime() + "\n" +
-                "KDC flags: " + identity.getKdcFlags() + "\n" +
-                "Key version: " + identity.getKeyVersion() + "\n" +
-                "Number of keys: " + key.size()
-        );
-
-        for (EncryptionType keyType : key.keySet()) {
-            System.out.println("key: " + keyType);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KadminCommandExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KadminCommandExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KadminCommandExecutor.java
deleted file mode 100644
index 996c9f3..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KadminCommandExecutor.java
+++ /dev/null
@@ -1,28 +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.kadmin.executor;
-
-public interface KadminCommandExecutor {
-
-    /**
-     * Execute the kadmin command.
-     */
-    void execute(String input);
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabAddExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabAddExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabAddExecutor.java
deleted file mode 100644
index 59a102e..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabAddExecutor.java
+++ /dev/null
@@ -1,84 +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.kadmin.executor;
-
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-
-import java.io.File;
-
-public class KeytabAddExecutor implements KadminCommandExecutor{
-    private static final String USAGE =
-            "Usage: ktadd [-k[eytab] keytab] [-q] [-e keysaltlist] [-norandkey] [principal | -glob princ-exp] [...]";
-
-    private static final String DEFAULT_KEYTAB_FILE_LOCATION = "/etc/krb5.keytab";
-
-    private Config backendConfig;
-
-    public KeytabAddExecutor(Config backendConfig) {
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split(" ");
-
-        String principal = null;
-        String keytabFileLocation = null;
-
-        //Since commands[0] is ktadd, the initial index is 1.
-        int index = 1;
-        while (index < commands.length) {
-            String command = commands[index];
-            if (command.equals("-k")) {
-                index++;
-                if (index >= commands.length) {
-                    System.err.println(USAGE);
-                    return;
-                }
-                keytabFileLocation = commands[index].trim();
-
-            } else if (!command.startsWith("-")){
-                principal = command;
-            }
-            index++;
-        }
-
-        if (keytabFileLocation == null) {
-            keytabFileLocation = DEFAULT_KEYTAB_FILE_LOCATION;
-        }
-        File keytabFile = new File(keytabFileLocation);
-
-        if (principal == null || !keytabFile.exists()) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        Kadmin kadmin = new Kadmin(backendConfig);
-        try {
-        StringBuffer result = kadmin.addEntryToKeytab(keytabFile, principal);
-            System.out.println(result.toString());
-        } catch (KrbException e) {
-            System.err.println("Principal \"" + principal + "\" fail to add entry to keytab." +
-                e.getCause());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabRemoveExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabRemoveExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabRemoveExecutor.java
deleted file mode 100644
index ffde039..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/KeytabRemoveExecutor.java
+++ /dev/null
@@ -1,94 +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.kadmin.executor;
-
-import org.apache.kerby.KOptions;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
-
-import java.io.File;
-
-public class KeytabRemoveExecutor implements KadminCommandExecutor{
-    private static final String USAGE =
-            "Usage: ktremove [-k[eytab] keytab] [-q] principal [kvno | all | old]";
-
-    private static final String DEFAULT_KEYTAB_FILE_LOCATION = "/etc/krb5.keytab";
-
-    private Config backendConfig;
-
-    public KeytabRemoveExecutor(Config backendConfig) {
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split("\\s+");
-        if (commands.length < 2 || commands.length > 6) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        String principal = null;
-        String keytabFileLocation = null;
-        String rangeSuffix = null;
-        int lastIndex ;
-
-        if (commands[commands.length - 1].matches("^all|old|-?\\d+$")) {
-            if (commands.length < 3) {
-                System.err.println(USAGE);
-                return;
-            }
-            lastIndex = commands.length - 3;
-            principal = commands[commands.length - 2];
-            rangeSuffix = commands[commands.length - 1];
-        } else {
-            lastIndex = commands.length - 2;
-            principal = commands[commands.length - 1];
-        }
-        KOptions kOptions = KadminTool.parseOptions(commands, 1, lastIndex);
-
-        if (principal == null || kOptions == null ||
-                kOptions.contains(KadminOption.K) && kOptions.contains(KadminOption.KEYTAB)) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        keytabFileLocation = kOptions.contains(KadminOption.K)?
-                kOptions.getStringOption(KadminOption.K):kOptions.getStringOption(KadminOption.KEYTAB);
-
-        if (keytabFileLocation == null) {
-            keytabFileLocation = DEFAULT_KEYTAB_FILE_LOCATION;
-        }
-        File keytabFile = new File(keytabFileLocation);
-
-        Kadmin kadmin = new Kadmin(backendConfig);
-        try {
-            StringBuilder result = kadmin.removeEntryFromKeytab(keytabFile, principal, rangeSuffix);
-            result.append("\tFile:" + keytabFileLocation);
-            System.out.println(result.toString());
-        } catch (KrbException e) {
-            System.err.println("Principal \"" + principal + "\" fail to remove entry from keytab." +
-                e.getMessage());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
deleted file mode 100644
index ec5abe3..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ListPrincipalExcutor.java
+++ /dev/null
@@ -1,55 +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.kadmin.executor;
-
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-
-import java.util.List;
-
-public class ListPrincipalExcutor implements KadminCommandExecutor {
-    private Config backenConfig;
-
-    public ListPrincipalExcutor(Config backenConfig) {
-        this.backenConfig = backenConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split(" ");
-        List<String> principalNames = null;
-
-
-        if (commands.length == 1) {
-            Kadmin kadmin = new Kadmin(backenConfig);
-            try {
-                principalNames = kadmin.listPrincipal();
-            } catch (KrbException e) {
-                System.err.print("Fail to list principal!" + e.getMessage());
-            }
-        }
-        System.out.println("Principals are listed:");
-
-        for (String principalName : principalNames) {
-            System.out.println(principalName);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ModifyPrincipalExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ModifyPrincipalExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ModifyPrincipalExecutor.java
deleted file mode 100644
index 3a581f6..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/ModifyPrincipalExecutor.java
+++ /dev/null
@@ -1,107 +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.kadmin.executor;
-
-import org.apache.kerby.KOptionType;
-import org.apache.kerby.KOptions;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.server.KdcConfig;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
-
-public class ModifyPrincipalExecutor implements KadminCommandExecutor {
-    private static final String USAGE = "Usage: modify_principal [options] principal\n" +
-        "\toptions are:\n" +
-        "\t\t[-expire dd/MM/yy:HH:mm:ss]\n" +
-        "\t\t[-disabled true/false]\n" +
-        "\t\t[-locked true/false]\n" +
-        "\tExample:\n" +
-        "\t\tmodify_principal -expire 23/04/15:01:01:01 -disabled false -locked true test@EXAMPLE.COM";
-
-    private Config backendConfig;
-    private KOptions kOptions;
-    private String principal;
-    private KdcConfig kdcConfig; //NOPMD
-
-    public ModifyPrincipalExecutor(KdcConfig kdcConfig, Config backendConfig) {
-        this.backendConfig = backendConfig;
-        this.kdcConfig = kdcConfig;
-        kOptions = new KOptions();
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split(" ");
-        if (commands.length < 2) {
-            KadminTool.printUsage("missing operand!", USAGE);
-            return;
-        }
-        parseOptions(commands);
-        Kadmin kadmin = new Kadmin(kdcConfig, backendConfig);
-
-        try {
-            kadmin.modifyPrincipal(principal, kOptions);
-            System.out.println("Principal \"" + principal + "\" modified.");
-        } catch (KrbException e) {
-            System.err.println("Principal \"" + principal + "\" fail to modify. " + e.getCause());
-        }
-    }
-
-    private void parseOptions(String[] commands) {
-        KadminOption kOption;
-        String opt, error, param;
-        int i = 1;
-        while (i < commands.length) {
-            error = null;
-            opt = commands[i++];
-            if (opt.startsWith("-")) {
-                kOption = KadminOption.fromName(opt);
-                if (kOption == KadminOption.NONE) {
-                    error = "Invalid option:" + opt;
-                    break;
-                }
-            } else {
-                principal = opt;
-                kOption = KadminOption.NONE;
-            }
-
-            if (kOption.getType() != KOptionType.NOV) { // require a parameter
-                param = null;
-                if (i < commands.length) {
-                    param = commands[i++];
-                }
-                if (param != null) {
-                    KOptions.parseSetValue(kOption, param);
-                } else {
-                    error = "Option " + opt + " require a parameter";
-                }
-            }
-            if (error != null) {
-                KadminTool.printUsage(error, USAGE);
-            }
-            kOptions.add(kOption);
-        }
-        if(principal == null) {
-            KadminTool.printUsage("missing principal name!", USAGE);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/RenamePrincipalExecutor.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/RenamePrincipalExecutor.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/RenamePrincipalExecutor.java
deleted file mode 100644
index 300a70c..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/executor/RenamePrincipalExecutor.java
+++ /dev/null
@@ -1,83 +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.kadmin.executor;
-
-import org.apache.kerby.KOptions;
-import org.apache.kerby.config.Config;
-import org.apache.kerby.kerberos.kerb.KrbException;
-import org.apache.kerby.kerberos.kerb.admin.Kadmin;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-import org.apache.kerby.kerberos.tool.kadmin.tool.KadminTool;
-
-
-public class RenamePrincipalExecutor implements KadminCommandExecutor{
-    private static final String USAGE = "Usage: rename_principal [-force] old_principal new_principal\n";
-
-    private KOptions kOptions;
-    private Config backendConfig;
-    private String oldPrincipalName;
-    private String newPrincipalName;
-
-    public RenamePrincipalExecutor(Config backendConfig) {
-        this.backendConfig = backendConfig;
-    }
-
-    @Override
-    public void execute(String input) {
-        String[] commands = input.split("\\s+");
-        if (commands.length < 3 || commands.length > 4) {
-            System.err.println(USAGE);
-            return;
-        }
-
-        kOptions = KadminTool.parseOptions(commands, 1, commands.length - 3);
-        if(kOptions==null) {
-            System.err.println(USAGE);
-            return;
-        }
-        oldPrincipalName = commands[commands.length - 2];
-        newPrincipalName = commands[commands.length - 1];
-
-        Kadmin kadmin = new Kadmin(backendConfig);
-        if (kOptions.contains(KadminOption.FORCE)) {
-            renamePrincipal(kadmin);
-        } else {
-            String prompt = "Are you sure want to rename the principal? (yes/no, YES/NO, y/n, Y/N) ";
-            String reply = KadminTool.getReplay(prompt);
-            if (reply.equals("yes") || reply.equals("YES") || reply.equals("y") || reply.equals("Y")) {
-                renamePrincipal(kadmin);
-            } else if (reply.equals("no") || reply.equals("NO") || reply.equals("n") || reply.equals("N")) {
-                System.out.println("Principal \"" + oldPrincipalName + "\"  not renamed." );
-            } else {
-                System.err.println("Unknown response, fail to rename the principal.");
-            }
-        }
-    }
-
-    public void renamePrincipal(Kadmin kadmin) {
-        try {
-            kadmin.renamePrincipal(oldPrincipalName, newPrincipalName);
-            System.out.println("Principal \"" + oldPrincipalName + "\" renamed to \"" +
-                newPrincipalName + "\".");
-        } catch (KrbException e) {
-            System.err.println("Principal rename failed! Exception happened. " + e.getCause());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/dadf393f/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/tool/KadminTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/tool/KadminTool.java b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/tool/KadminTool.java
deleted file mode 100644
index 72eb70a..0000000
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/tool/KadminTool.java
+++ /dev/null
@@ -1,84 +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.kadmin.tool;
-
-import org.apache.kerby.KOptionType;
-import org.apache.kerby.KOptions;
-import org.apache.kerby.kerberos.kerb.admin.KadminOption;
-
-import java.util.Scanner;
-
-public class KadminTool {
-
-    public static void printUsage(String error, String USAGE) {
-        System.err.println(error + "\n");
-        System.err.println(USAGE);
-    }
-
-    public static KOptions parseOptions(String[] commands, int beginIndex, int endIndex) {
-        KadminOption kOption;
-        String opt, error, param;
-
-        if(beginIndex < 0) {
-            System.out.println("Invalid function parameter(s).");
-            return null;
-        }
-
-        KOptions kOptions = new KOptions();
-        int i = beginIndex;
-        while (i <= endIndex) {
-            error = null;
-            opt = commands[i++];
-            if (opt.startsWith("-")) {
-                kOption = KadminOption.fromName(opt);
-                if (kOption == KadminOption.NONE) {
-                    error = "Invalid option:" + opt;
-                }
-            } else {
-                kOption = KadminOption.NONE;
-                error = "Invalid parameter:" + opt + " , it does not belong to any option.";
-            }
-
-            if (kOption.getType() != KOptionType.NOV) { // require a parameter
-                param = null;
-                if (i <= endIndex) {
-                    param = commands[i++];
-                }
-                if (param != null) {
-                    kOptions.parseSetValue(kOption, param);
-                } else {
-                    error = "Option " + opt + " require a parameter";
-                }
-            }
-            if (error != null) {
-                System.out.println(error);
-                return null;
-            }
-            kOptions.add(kOption);
-        }
-        return kOptions;
-    }
-
-    public static String getReplay(String prompt) {
-        Scanner scanner = new Scanner(System.in);
-        System.out.println(prompt);
-        return scanner.nextLine().trim();
-    }
-}


Mime
View raw message