directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ha...@apache.org
Subject [1/2] directory-kerby git commit: DIRKRB-182 Implementing the framework of kadmin
Date Fri, 20 Mar 2015 03:58:25 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/master 4cbe950b7 -> 44de66463


DIRKRB-182 Implementing the framework of kadmin


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

Branch: refs/heads/master
Commit: d8295c4bea74422a523269e4b824c5b41fdfb0a5
Parents: 07cdbac
Author: hazel <linchen7@foxmail.com>
Authored: Fri Mar 20 11:58:05 2015 +0800
Committer: hazel <linchen7@foxmail.com>
Committed: Fri Mar 20 11:58:05 2015 +0800

----------------------------------------------------------------------
 kdc-tool/kadmin-tool/pom.xml                    |  46 +++++++
 .../kerby/kerberos/tool/kadmin/Kadmin.java      | 134 +++++++++++++++++++
 .../kadmin/executor/KadminCommandExecutor.java  |  28 ++++
 kdc-tool/pom.xml                                |   1 +
 4 files changed, 209 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d8295c4b/kdc-tool/kadmin-tool/pom.xml
----------------------------------------------------------------------
diff --git a/kdc-tool/kadmin-tool/pom.xml b/kdc-tool/kadmin-tool/pom.xml
new file mode 100644
index 0000000..4ad8dd6
--- /dev/null
+++ b/kdc-tool/kadmin-tool/pom.xml
@@ -0,0 +1,46 @@
+<?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>kadmin</artifactId>
+    <name>Kadmin</name>
+    <description>Kerby KDC kadmin 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-identity</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.kerby</groupId>
+        <artifactId>kerb-server</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+    </dependencies>
+
+</project>

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d8295c4b/kdc-tool/kadmin-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
----------------------------------------------------------------------
diff --git a/kdc-tool/kadmin-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
b/kdc-tool/kadmin-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
new file mode 100644
index 0000000..e5b5c97
--- /dev/null
+++ b/kdc-tool/kadmin-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/Kadmin.java
@@ -0,0 +1,134 @@
+/**
+ *  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;
+
+import org.apache.kerby.config.Conf;
+import org.apache.kerby.kerberos.kerb.server.KdcConfig;
+import org.apache.kerby.kerberos.tool.kadmin.executor.KadminCommandExecutor;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Scanner;
+
+public class Kadmin {
+    private static final String PROMPT = Kadmin.class.getSimpleName() + ".local";
+    private static final String REQUEST_LIST = "Available " + PROMPT + " requests:\n" +
+            "\n" +
+            "add_principal, addprinc, ank\n" +
+            "                         Add principal\n" +
+            "delete_principal, delprinc\n" +
+            "                         Delete principal\n" +
+            "modify_principal, modprinc\n" +
+            "                         Modify principal\n" +
+            "rename_principal, renprinc\n" +
+            "                         Rename principal\n" +
+            "change_password, cpw     Change password\n" +
+            "get_principal, getprinc  Get principal\n" +
+            "list_principals, listprincs, get_principals, getprincs\n" +
+            "                         List principals\n" +
+            "add_policy, addpol       Add policy\n" +
+            "modify_policy, modpol    Modify policy\n" +
+            "delete_policy, delpol    Delete policy\n" +
+            "get_policy, getpol       Get policy\n" +
+            "list_policies, listpols, get_policies, getpols\n" +
+            "                         List policies\n" +
+            "get_privs, getprivs      Get privileges\n" +
+            "ktadd, xst               Add entry(s) to a keytab\n" +
+            "ktremove, ktrem          Remove entry(s) from a keytab\n" +
+            "lock                     Lock database exclusively (use with extreme caution!)\n"
+
+            "unlock                   Release exclusive database lock\n" +
+            "purgekeys                Purge previously retained old keys from a principal\n"
+
+            "get_strings, getstrs     Show string attributes on a principal\n" +
+            "set_string, setstr       Set a string attribute on a principal\n" +
+            "del_string, delstr       Delete a string attribute on a principal\n" +
+            "list_requests, lr, ?     List available requests.\n" +
+            "quit, exit, q            Exit program.";
+
+    private static KdcConfig kdcConfig;
+    private static Conf backendConfig;
+
+    private static void execute(String command) {
+        if (command.equals("list_requests") ||
+                command.equals("lr") ||
+                command.equals("?")) {
+            System.out.println(REQUEST_LIST);
+            return;
+        }
+
+        KadminCommandExecutor executor = null;
+        //TODO execute commands.
+
+        if (executor == null) {
+            System.out.println("Unknown request \"" + command + "\". Type \"?\" for a request
list.");
+            return;
+        }
+        executor.execute(command);
+    }
+
+    private static void initConfig(String[] args) {
+        File confDir;
+        if (args.length == 0) {
+            confDir = new File("/etc/kerby/");// for Linux. TODO: fix for Win etc.
+        } else {
+            confDir = new File(args[0]);
+        }
+
+        if (confDir.exists()) {
+            File kdcConfFile = new File(confDir, "kdc.conf");
+            if (kdcConfFile.exists()) {
+                kdcConfig = new KdcConfig();
+                try {
+                    kdcConfig.addIniConfig(kdcConfFile);
+                } catch (IOException e) {
+                    System.err.println("Can not load the kdc configuration file " + kdcConfFile.getAbsolutePath());
+                    e.printStackTrace();
+                }
+            }
+
+            File backendConfigFile = new File(confDir, "backend.conf");
+            if (backendConfigFile.exists()) {
+                backendConfig = new Conf();
+                try {
+                    backendConfig.addIniConfig(backendConfigFile);
+                } catch (IOException e) {
+                    System.err.println("Can not load the backend configuration file " + backendConfigFile.getAbsolutePath());
+                    e.printStackTrace();
+                }
+            }
+        } else {
+            throw new RuntimeException("Can not find configuration directory");
+        }
+    }
+
+    public static void main(String[] args) {
+        initConfig(args);
+        System.out.print(PROMPT + ": ");
+        Scanner scanner = new Scanner(System.in);
+        String input = scanner.nextLine();
+
+        while (!(input.equals("quit") ||
+                input.equals("exit") ||
+                input.equals("q"))) {
+            execute(input);
+            System.out.print(PROMPT + ": ");
+            input = scanner.nextLine();
+        }
+    }
+}

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

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/d8295c4b/kdc-tool/pom.xml
----------------------------------------------------------------------
diff --git a/kdc-tool/pom.xml b/kdc-tool/pom.xml
index 8c486d4..cc9948a 100644
--- a/kdc-tool/pom.xml
+++ b/kdc-tool/pom.xml
@@ -29,6 +29,7 @@
   <modules>
     <module>client-tool</module>
     <module>token-tool</module>
+    <module>kadmin-tool</module>
   </modules>
 
 </project>


Mime
View raw message