directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject directory-kerby git commit: DIRKRB-693/DIRKRB-695 - Switching to use JLine for the Kadmin tool
Date Mon, 12 Feb 2018 10:35:25 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/trunk a21e49f17 -> f90dc5aca


DIRKRB-693/DIRKRB-695 - Switching to use JLine for the Kadmin tool


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

Branch: refs/heads/trunk
Commit: f90dc5acae6f1ccabce265a033a457e24d163933
Parents: a21e49f
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Mon Feb 12 10:34:50 2018 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Mon Feb 12 10:34:50 2018 +0000

----------------------------------------------------------------------
 kerby-dist/kdc-dist/LICENSE                     |  5 +++
 kerby-dist/kdc-dist/licenses/LICENSE.jline.txt  | 35 ++++++++++++++++++++
 kerby-tool/kdc-tool/pom.xml                     |  5 +++
 .../kerby/kerberos/tool/kadmin/KadminTool.java  | 34 +++++++++++++------
 pom.xml                                         |  1 +
 5 files changed, 70 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f90dc5ac/kerby-dist/kdc-dist/LICENSE
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/LICENSE b/kerby-dist/kdc-dist/LICENSE
index aa7b845..a5f4f98 100644
--- a/kerby-dist/kdc-dist/LICENSE
+++ b/kerby-dist/kdc-dist/LICENSE
@@ -210,3 +210,8 @@ This project bundles the SLF4J library (MIT license):
 
 See licenses/LICENSE-slf4j.txt
 
+===============================================================================
+This project bundles the JLine library (BSD license):
+
+See licenses/LICENSE.jline.txt
+

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f90dc5ac/kerby-dist/kdc-dist/licenses/LICENSE.jline.txt
----------------------------------------------------------------------
diff --git a/kerby-dist/kdc-dist/licenses/LICENSE.jline.txt b/kerby-dist/kdc-dist/licenses/LICENSE.jline.txt
new file mode 100644
index 0000000..4ebd976
--- /dev/null
+++ b/kerby-dist/kdc-dist/licenses/LICENSE.jline.txt
@@ -0,0 +1,35 @@
+Copyright (c) 2002-2017, the original author or authors.
+All rights reserved.
+
+http://www.opensource.org/licenses/bsd-license.php
+
+Redistribution and use in source and binary forms, with or
+without modification, are permitted provided that the following
+conditions are met:
+
+Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright
+notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with
+the distribution.
+
+Neither the name of JLine nor the names of its contributors
+may be used to endorse or promote products derived from this
+software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
+BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+OF THE POSSIBILITY OF SUCH DAMAGE.
+

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f90dc5ac/kerby-tool/kdc-tool/pom.xml
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/pom.xml b/kerby-tool/kdc-tool/pom.xml
index c997982..69ab83d 100644
--- a/kerby-tool/kdc-tool/pom.xml
+++ b/kerby-tool/kdc-tool/pom.xml
@@ -56,6 +56,11 @@
         <artifactId>kerb-admin-server</artifactId>
         <version>${project.version}</version>
       </dependency>
+      <dependency>
+        <groupId>org.jline</groupId>
+        <artifactId>jline</artifactId>
+        <version>${jline.version}</version>
+      </dependency>
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f90dc5ac/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
----------------------------------------------------------------------
diff --git a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
index bc3b2e1..82f49b9 100644
--- a/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
+++ b/kerby-tool/kdc-tool/src/main/java/org/apache/kerby/kerberos/tool/kadmin/KadminTool.java
@@ -36,6 +36,14 @@ import org.apache.kerby.kerberos.tool.kadmin.command.ModifyPrincipalCommand;
 import org.apache.kerby.kerberos.tool.kadmin.command.RenamePrincipalCommand;
 import org.apache.kerby.kerberos.tool.kadmin.command.AddPrincipalsCommand;
 import org.apache.kerby.util.OSUtil;
+import org.jline.reader.Completer;
+import org.jline.reader.EndOfFileException;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.UserInterruptException;
+import org.jline.reader.impl.completer.StringsCompleter;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +51,6 @@ import javax.security.auth.login.LoginException;
 import java.io.File;
 import java.io.IOException;
 import java.util.Map;
-import java.util.Scanner;
 
 /**
  * Ref. MIT kadmin command tool usage.
@@ -185,7 +192,7 @@ public class KadminTool {
         return confDir;
     }
 
-    public static void main(String[] args) throws KrbException {
+    public static void main(String[] args) throws KrbException, IOException {
 
         if (args.length < 2) {
             System.err.println(USAGE);
@@ -249,16 +256,23 @@ public class KadminTool {
             String query = kOptions.getStringOption(KadminOption.QUERY);
             execute(kadmin, query);
         } else {
-            System.out.print(PROMPT + ": ");
 
-            try (Scanner scanner = new Scanner(System.in, "UTF-8")) {
-                String input = scanner.nextLine();
+            Completer completer = new StringsCompleter("add_principal", "batch_anks", "ktadd",
"ktremove",
+                                                       "delete_principal", "modify_principal",
"rename_principal",
+                                                       "change_password", "list_principals",
"get_principal");
 
-                while (!(input.equals("quit") || input.equals("exit")
-                        || input.equals("q"))) {
-                    execute(kadmin, input);
-                    System.out.print(PROMPT + ": ");
-                    input = scanner.nextLine();
+            Terminal terminal = TerminalBuilder.terminal();
+            LineReader lineReader = LineReaderBuilder.builder().completer(completer).terminal(terminal).build();
+
+            while (true) {
+                try {
+                    String line = lineReader.readLine(PROMPT + ": ");
+                    if ("quit".equals(line) || "exit".equals(line) || "q".equals(line)) {
+                        break;
+                    }
+                    execute(kadmin, line);
+                } catch (UserInterruptException | EndOfFileException ex) {
+                    break;
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/f90dc5ac/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 89b8c79..9029972 100644
--- a/pom.xml
+++ b/pom.xml
@@ -59,6 +59,7 @@
     <findbugs.version>3.0.4</findbugs.version>
     <buildtools.dir>${basedir}/build-tools</buildtools.dir>
     <skipTests>false</skipTests>
+    <jline.version>3.6.0</jline.version>
     <maven-javadoc-plugin.version>2.10.4</maven-javadoc-plugin.version>
     <maven-jxr-plugin.version>2.5</maven-jxr-plugin.version>
     <mockito.version>2.7.22</mockito.version>


Mime
View raw message