summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/cli
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-07-22 15:28:50 -0400
committerEndi S. Dewata <edewata@redhat.com>2013-08-13 10:38:12 -0400
commit74f60e95a9fd5984f81aeda492e157d1c9b6dedd (patch)
tree18b086682bb02da702ae985a75e9f94de6b1794e /base/java-tools/src/com/netscape/cmstools/cli
parent23cce978aedc948723a3cce211b4e743b0e7c444 (diff)
downloadpki-74f60e95a9fd5984f81aeda492e157d1c9b6dedd.tar.gz
pki-74f60e95a9fd5984f81aeda492e157d1c9b6dedd.tar.xz
pki-74f60e95a9fd5984f81aeda492e157d1c9b6dedd.zip
Added skeleton for token services.
A skeleton for token service and the clients has been added. Currently it's storing the database in memory. The actual implementation using LDAP database will be added after the TPS configuration code is ready. Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/cli')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/CLI.java15
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java4
-rw-r--r--base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java109
3 files changed, 127 insertions, 1 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CLI.java b/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
index a1fc4f7f9..40ac517af 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/CLI.java
@@ -37,6 +37,8 @@ public class CLI {
public static CommandLineParser parser = new PosixParser();
public static HelpFormatter formatter = new HelpFormatter();
+ public CLI parent;
+
public String name;
public String description;
@@ -44,8 +46,13 @@ public class CLI {
public Map<String, CLI> modules = new LinkedHashMap<String, CLI>();
public CLI(String name, String description) {
+ this(name, description, null);
+ }
+
+ public CLI(String name, String description, CLI parent) {
this.name = name;
this.description = description;
+ this.parent = parent;
}
public String getName() {
@@ -56,6 +63,14 @@ public class CLI {
this.name = name;
}
+ public String getFullName() {
+ if (parent == null) {
+ return name;
+ } else {
+ return parent.getName() + "-" + name;
+ }
+ }
+
public String getDescription() {
return description;
}
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
index 1c6411d79..257f0bcfb 100644
--- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
+++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java
@@ -76,6 +76,7 @@ public class MainCLI extends CLI {
addModule(new KRAConnectorCLI(this));
addModule(new ProfileCLI(this));
addModule(new SecurityDomainCLI(this));
+ addModule(new TPSCLI(this));
addModule(new UserCLI(this));
}
@@ -343,9 +344,10 @@ public class MainCLI extends CLI {
}
// get command module
+ if (verbose) System.out.println("Module: " + moduleName);
module = getModule(moduleName);
if (module == null)
- throw new Error("Invalid command \"" + command + "\".");
+ throw new Error("Invalid module \"" + moduleName + "\".");
// prepare module arguments
if (moduleCommand != null) {
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
new file mode 100644
index 000000000..4dd7e208c
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java
@@ -0,0 +1,109 @@
+// --- BEGIN COPYRIGHT BLOCK ---
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this program; if not, write to the Free Software Foundation, Inc.,
+// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+//
+// (C) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.cli;
+
+import org.apache.commons.lang.StringUtils;
+
+import com.netscape.certsrv.tps.TPSClient;
+import com.netscape.cmstools.token.TokenCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TPSCLI extends CLI {
+
+ public MainCLI mainCLI;
+ public TPSClient tpsClient;
+
+ public TPSCLI(MainCLI mainCLI) {
+ super("tps", "TPS management commands", mainCLI);
+ this.mainCLI = mainCLI;
+
+ addModule(new TokenCLI(this));
+ }
+
+ public void printHelp() {
+
+ System.out.println("Commands:");
+
+ int leftPadding = 1;
+ int rightPadding = 25;
+
+ for (CLI module : modules.values()) {
+ String label = name + "-" + module.getName();
+
+ int padding = rightPadding - leftPadding - label.length();
+ if (padding < 1)
+ padding = 1;
+
+ System.out.print(StringUtils.repeat(" ", leftPadding));
+ System.out.print(label);
+ System.out.print(StringUtils.repeat(" ", padding));
+ System.out.println(module.getDescription());
+ }
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ tpsClient = new TPSClient(mainCLI.client);
+
+ if (args.length == 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String command = args[0];
+ String moduleName;
+ String moduleCommand;
+
+ // If a command contains a '-' sign it will be
+ // split into module name and module command.
+ // Otherwise it's a single command.
+ int i = command.indexOf('-');
+ if (i >= 0) { // <module name>-<module command>
+ moduleName = command.substring(0, i);
+ moduleCommand = command.substring(i+1);
+
+ } else { // <command>
+ moduleName = command;
+ moduleCommand = null;
+ }
+
+ // get command module
+ if (verbose) System.out.println("Module: " + moduleName);
+ CLI module = getModule(moduleName);
+ if (module == null) {
+ throw new Error("Invalid module \"" + moduleName + "\".");
+ }
+
+ // prepare module arguments
+ String[] moduleArgs;
+ if (moduleCommand != null) {
+ moduleArgs = new String[args.length];
+ moduleArgs[0] = moduleCommand;
+ System.arraycopy(args, 1, moduleArgs, 1, args.length-1);
+
+ } else {
+ moduleArgs = new String[args.length-1];
+ System.arraycopy(args, 1, moduleArgs, 0, args.length-1);
+ }
+
+ module.execute(moduleArgs);
+ }
+}