summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/user
diff options
context:
space:
mode:
authorEndi Sukma Dewata <edewata@redhat.com>2012-08-18 02:30:44 -0500
committerEndi Sukma Dewata <edewata@redhat.com>2012-08-29 23:42:53 -0500
commit60835ed008586f85a22737d0161cb026f2dbffec (patch)
tree363e447f38aa7bfe9835955e7f1f7345228c14ff /base/java-tools/src/com/netscape/cmstools/user
parent88176c5c8caf146a1a408dc3a7f6b23e1a8e63b7 (diff)
downloadpki-60835ed008586f85a22737d0161cb026f2dbffec.tar.gz
pki-60835ed008586f85a22737d0161cb026f2dbffec.tar.xz
pki-60835ed008586f85a22737d0161cb026f2dbffec.zip
Moved REST CLI into pki-tools.
The pki-client.jar has been split and merged into pki-certsrv.jar and pki-tools.jar. The REST client classes are now packaged in com.netscape.certsrv.<component> packages. The REST CLI classes are now packaged in com.netscape.cmstools.<component> packages. The "pki" script has been moved into pki-tools RPM package. Ticket #215
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/user')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java106
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java97
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserCLI.java163
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java98
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java104
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java107
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java53
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java61
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java56
-rw-r--r--base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java96
10 files changed, 941 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java
new file mode 100644
index 000000000..3db8fe533
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserAddCLI.java
@@ -0,0 +1,106 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserAddCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserAddCLI(UserCLI parent) {
+ super("add", "Add user");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "fullName", true, "Full name");
+ option.setArgName("fullName");
+ option.setRequired(true);
+ options.addOption(option);
+
+ option = new Option(null, "email", true, "Email");
+ option.setArgName("email");
+ options.addOption(option);
+
+ option = new Option(null, "password", true, "Password");
+ option.setArgName("password");
+ options.addOption(option);
+
+ option = new Option(null, "phone", true, "Phone");
+ option.setArgName("phone");
+ options.addOption(option);
+
+ option = new Option(null, "type", true, "Type");
+ option.setArgName("type");
+ options.addOption(option);
+
+ option = new Option(null, "state", true, "State");
+ option.setArgName("state");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userId = cmdArgs[0];
+
+ UserData userData = new UserData();
+ userData.setID(userId);
+ userData.setFullName(cmd.getOptionValue("fullName"));
+ userData.setEmail(cmd.getOptionValue("email"));
+ userData.setPassword(cmd.getOptionValue("password"));
+ userData.setPhone(cmd.getOptionValue("phone"));
+ userData.setType(cmd.getOptionValue("type"));
+ userData.setState(cmd.getOptionValue("state"));
+
+ userData = parent.client.addUser(userData);
+
+ MainCLI.printMessage("Added user \"" + userId + "\"");
+
+ UserCLI.printUser(userData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java
new file mode 100644
index 000000000..7bec2ff19
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserAddCertCLI.java
@@ -0,0 +1,97 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.io.File;
+import java.util.Scanner;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserCertData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserAddCertCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserAddCertCLI(UserCLI parent) {
+ super("add-cert", "Add user cert");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "input", true, "Input file");
+ option.setArgName("file");
+ option.setRequired(true);
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userId = cmdArgs[0];
+ String file = cmd.getOptionValue("input");
+
+ // get cert from file
+ if (verbose) {
+ System.out.println("Reading cert from "+file+".");
+ }
+ String encoded = new Scanner(new File(file)).useDelimiter("\\A").next();
+ if (verbose) {
+ System.out.println(encoded);
+ }
+
+ UserCertData userCertData = new UserCertData();
+ userCertData.setEncoded(encoded);
+
+ if (verbose) {
+ System.out.println(userCertData);
+ }
+
+ userCertData = parent.client.addUserCert(userId, userCertData);
+
+ MainCLI.printMessage("Added certificate \"" + userCertData.getID() + "\"");
+
+ UserCLI.printCert(userCertData, false, false);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
new file mode 100644
index 000000000..301754a22
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java
@@ -0,0 +1,163 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.util.Arrays;
+
+import org.apache.commons.lang.StringUtils;
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.user.UserCertData;
+import com.netscape.certsrv.user.UserClient;
+import com.netscape.certsrv.user.UserData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserCLI extends CLI {
+
+ public MainCLI parent;
+ public UserClient client;
+
+ public UserCLI(MainCLI parent) {
+ super("user", "User management commands");
+ this.parent = parent;
+
+ addModule(new UserFindCLI(this));
+ addModule(new UserShowCLI(this));
+ addModule(new UserAddCLI(this));
+ addModule(new UserModifyCLI(this));
+ addModule(new UserRemoveCLI(this));
+
+ addModule(new UserFindCertCLI(this));
+ addModule(new UserShowCertCLI(this));
+ addModule(new UserAddCertCLI(this));
+ addModule(new UserRemoveCertCLI(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 {
+
+ client = new UserClient(parent.config);
+ client.setVerbose(verbose);
+
+ if (args.length == 0) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String command = args[0];
+ String[] commandArgs = Arrays.copyOfRange(args, 1, args.length);
+
+ if (command == null) {
+ printHelp();
+ System.exit(1);
+ }
+
+ CLI module = getModule(command);
+ if (module != null) {
+ module.execute(commandArgs);
+
+ } else {
+ System.err.println("Error: Invalid command \"" + command + "\"");
+ printHelp();
+ System.exit(1);
+ }
+ }
+
+ public static void printUser(UserData userData) {
+ System.out.println(" User ID: " + userData.getID());
+
+ String fullName = userData.getFullName();
+ if (!StringUtils.isEmpty(fullName))
+ System.out.println(" Full name: " + fullName);
+
+ String email = userData.getEmail();
+ if (!StringUtils.isEmpty(email))
+ System.out.println(" Email: " + email);
+
+ String phone = userData.getPhone();
+ if (!StringUtils.isEmpty(phone))
+ System.out.println(" Phone: " + phone);
+
+ String type = userData.getType();
+ if (!StringUtils.isEmpty(type))
+ System.out.println(" Type: " + type);
+
+ String state = userData.getState();
+ if (!StringUtils.isEmpty(state))
+ System.out.println(" State: " + state);
+
+ Link link = userData.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+
+ public static void printCert(
+ UserCertData userCertData,
+ boolean showPrettyPrint,
+ boolean showEncoded) {
+
+ System.out.println(" Cert ID: " + userCertData.getID());
+ System.out.println(" Version: " + userCertData.getVersion());
+ System.out.println(" Serial Number: " + userCertData.getSerialNumber().toHexString());
+ System.out.println(" Issuer: " + userCertData.getIssuerDN());
+ System.out.println(" Subject: " + userCertData.getSubjectDN());
+
+ Link link = userCertData.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+
+ String prettyPrint = userCertData.getPrettyPrint();
+ if (showPrettyPrint && prettyPrint != null) {
+ System.out.println();
+ System.out.println(prettyPrint);
+ }
+
+ String encoded = userCertData.getEncoded();
+ if (showEncoded && encoded != null) {
+ System.out.println();
+ System.out.println(encoded);
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java
new file mode 100644
index 000000000..a5b96d1c3
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserFindCLI.java
@@ -0,0 +1,98 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserCollection;
+import com.netscape.certsrv.user.UserData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserFindCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserFindCLI(UserCLI parent) {
+ super("find", "Find users");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " [FILTER] [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();;
+ String filter = cmdArgs.length > 0 ? cmdArgs[0] : null;
+
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ UserCollection response = parent.client.findUsers(filter, start, size);
+
+ Collection<UserData> entries = response.getUsers();
+
+ MainCLI.printMessage(entries.size() + " user(s) matched");
+
+ boolean first = true;
+
+ for (UserData userData : entries) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ UserCLI.printUser(userData);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + entries.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java
new file mode 100644
index 000000000..08f687933
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserFindCertCLI.java
@@ -0,0 +1,104 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserCertCollection;
+import com.netscape.certsrv.user.UserCertData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserFindCertCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserFindCertCLI(UserCLI parent) {
+ super("find-cert", "Find user certs");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "start", true, "Page start");
+ option.setArgName("start");
+ options.addOption(option);
+
+ option = new Option(null, "size", true, "Page size");
+ option.setArgName("size");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userID = cmdArgs[0];
+
+ String s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ UserCertCollection response = parent.client.findUserCerts(userID, start, size);
+
+ Collection<UserCertData> entries = response.getCerts();
+
+ MainCLI.printMessage(entries.size() + " user cert(s) matched");
+
+ boolean first = true;
+
+ for (UserCertData userCertData : entries) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ UserCLI.printCert(userCertData, false, false);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + entries.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java
new file mode 100644
index 000000000..706224ef9
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserModifyCLI.java
@@ -0,0 +1,107 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserModifyCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserModifyCLI(UserCLI parent) {
+ super("mod", "Modify user");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "fullName", true, "Full name");
+ option.setArgName("fullName");
+ options.addOption(option);
+
+ option = new Option(null, "email", true, "Email");
+ option.setArgName("email");
+ options.addOption(option);
+
+ option = new Option(null, "password", true, "Password");
+ option.setArgName("password");
+ options.addOption(option);
+
+ option = new Option(null, "phone", true, "Phone");
+ option.setArgName("phone");
+ options.addOption(option);
+
+ // type cannot be modified
+ // option = new Option(null, "type", true, "Type");
+ // option.setArgName("type");
+ // options.addOption(option);
+
+ option = new Option(null, "state", true, "State");
+ option.setArgName("state");
+ options.addOption(option);
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userId = cmdArgs[0];
+
+ UserData userData = new UserData();
+ userData.setID(userId);
+ userData.setFullName(cmd.getOptionValue("fullName"));
+ userData.setEmail(cmd.getOptionValue("email"));
+ userData.setPassword(cmd.getOptionValue("password"));
+ userData.setPhone(cmd.getOptionValue("phone"));
+ // type cannot be modified
+ // userData.setType(cmd.getOptionValue("type"));
+ userData.setState(cmd.getOptionValue("state"));
+
+ userData = parent.client.modifyUser(userId, userData);
+
+ MainCLI.printMessage("Modified user \"" + userId + "\"");
+
+ UserCLI.printUser(userData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java
new file mode 100644
index 000000000..6bafba8a4
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCLI.java
@@ -0,0 +1,53 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserRemoveCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserRemoveCLI(UserCLI parent) {
+ super("del", "Remove user");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userID = args[0];
+
+ parent.client.removeUser(userID);
+
+ MainCLI.printMessage("Deleted user \"" + userID + "\"");
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java
new file mode 100644
index 000000000..203e48f52
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserRemoveCertCLI.java
@@ -0,0 +1,61 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.net.URLEncoder;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserRemoveCertCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserRemoveCertCLI(UserCLI parent) {
+ super("remove-cert", "Remove user cert");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> <Cert ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 2) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userID = args[0];
+ String certID = args[1];
+
+ if (verbose) {
+ System.out.println("Removing cert "+certID+" from user "+userID+".");
+ }
+
+ parent.client.removeUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
+
+ MainCLI.printMessage("Deleted certificate \"" + certID + "\"");
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java
new file mode 100644
index 000000000..679b67791
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserShowCLI.java
@@ -0,0 +1,56 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import com.netscape.certsrv.user.UserData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserShowCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserShowCLI(UserCLI parent) {
+ super("show", "Show user");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userId = args[0];
+
+ UserData userData = parent.client.getUser(userId);
+
+ MainCLI.printMessage("User \"" + userId + "\"");
+
+ UserCLI.printUser(userData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java
new file mode 100644
index 000000000..f30c72327
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/user/UserShowCertCLI.java
@@ -0,0 +1,96 @@
+// --- 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) 2012 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.user;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+import java.net.URLEncoder;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.user.UserCertData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class UserShowCertCLI extends CLI {
+
+ public UserCLI parent;
+
+ public UserShowCertCLI(UserCLI parent) {
+ super("show-cert", "Show user cert");
+ this.parent = parent;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(parent.name + "-" + name + " <User ID> <Cert ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "output", true, "Output file");
+ option.setArgName("file");
+ options.addOption(option);
+
+ options.addOption(null, "pretty", false, "Pretty print");
+ options.addOption(null, "encoded", false, "Base-64 encoded");
+
+ CommandLine cmd = null;
+
+ try {
+ cmd = parser.parse(options, args);
+
+ } catch (Exception e) {
+ System.err.println("Error: " + e.getMessage());
+ printHelp();
+ System.exit(1);
+ }
+
+ boolean showPrettyPrint = cmd.hasOption("pretty");
+ boolean showEncoded = cmd.hasOption("encoded");
+
+ String[] cmdArgs = cmd.getArgs();
+
+ if (cmdArgs.length != 2) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String userID = cmdArgs[0];
+ String certID = cmdArgs[1];
+ String file = cmd.getOptionValue("output");
+
+ UserCertData userCertData = parent.client.getUserCert(userID, URLEncoder.encode(certID, "UTF-8"));
+
+ String encoded = userCertData.getEncoded();
+ if (encoded != null && file != null) {
+ // store cert to file
+ PrintWriter out = new PrintWriter(new FileWriter(file));
+ out.print(encoded);
+ out.close();
+ }
+
+ MainCLI.printMessage("Certificate \"" + userCertData.getID() + "\"");
+
+ UserCLI.printCert(userCertData, showPrettyPrint, showEncoded);
+ }
+}