summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-08-26 13:21:58 -0400
committerEndi Sukma Dewata <edewata@redhat.com>2013-09-01 01:04:48 -0500
commita847bcb7c71836f7c0498163e31238f118740339 (patch)
tree9701c88ce01db56118585ade51013837f0496b7c /base/java-tools/src/com/netscape/cmstools/tps
parentbc2df101c9fbd0f9468573de0a0dbe14ca16dc92 (diff)
downloadpki-a847bcb7c71836f7c0498163e31238f118740339.tar.gz
pki-a847bcb7c71836f7c0498163e31238f118740339.tar.xz
pki-a847bcb7c71836f7c0498163e31238f118740339.zip
Reorganized TPS classes.
The TPS classes have been reorganized as follows: * common: com.netscape.certsrv.tps * CLI: com.netscape.cmstools.tps * server: org.dogtagpki.server.tps TPSConnection and TPSMessage were moved from server package into common package. The build script and configuration files have been modified accordingly.
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/tps')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java81
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java90
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java94
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java81
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java53
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java56
6 files changed, 455 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
new file mode 100644
index 000000000..0d495ddc7
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenAddCLI.java
@@ -0,0 +1,81 @@
+// --- 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.tps.token;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.token.TokenData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenAddCLI extends CLI {
+
+ public TokenCLI tokenCLI;
+
+ public TokenAddCLI(TokenCLI tokenCLI) {
+ super("add", "Add token", tokenCLI);
+ this.tokenCLI = tokenCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Token ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "user", true, "User ID");
+ option.setArgName("User ID");
+ 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 tokenID = cmdArgs[0];
+
+ TokenData tokenData = new TokenData();
+ tokenData.setID(tokenID);
+ tokenData.setUserID(cmd.getOptionValue("user"));
+
+ tokenData = tokenCLI.tokenClient.addToken(tokenData);
+
+ MainCLI.printMessage("Added token \"" + tokenID + "\"");
+
+ TokenCLI.printToken(tokenData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java
new file mode 100644
index 000000000..16c2b213b
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenCLI.java
@@ -0,0 +1,90 @@
+// --- 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.tps.token;
+
+import java.util.Arrays;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.tps.token.TokenClient;
+import com.netscape.certsrv.tps.token.TokenData;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenCLI extends CLI {
+
+ public TokenClient tokenClient;
+
+ public TokenCLI(CLI parent) {
+ super("token", "Token management commands", parent);
+
+ addModule(new TokenAddCLI(this));
+ addModule(new TokenFindCLI(this));
+ addModule(new TokenModifyCLI(this));
+ addModule(new TokenRemoveCLI(this));
+ addModule(new TokenShowCLI(this));
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ client = parent.getClient();
+ tokenClient = (TokenClient)parent.getClient("token");
+
+ 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 printToken(TokenData token) {
+ System.out.println(" Token ID: " + token.getID());
+ if (token.getUserID() != null) System.out.println(" User ID: " + token.getUserID());
+ if (token.getStatus() != null) System.out.println(" Status: " + token.getStatus());
+ if (token.getReason() != null) System.out.println(" Reason: " + token.getReason());
+ if (token.getAppletID() != null) System.out.println(" Applet ID: " + token.getAppletID());
+ if (token.getKeyInfo() != null) System.out.println(" Key Info: " + token.getKeyInfo());
+ if (token.getCreateTimestamp() != null) System.out.println(" Date Created: " + token.getCreateTimestamp());
+ if (token.getModifyTimestamp() != null) System.out.println(" Date Modified: " + token.getModifyTimestamp());
+
+ Link link = token.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
new file mode 100644
index 000000000..3ade40bb9
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenFindCLI.java
@@ -0,0 +1,94 @@
+// --- 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.tps.token;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.token.TokenCollection;
+import com.netscape.certsrv.tps.token.TokenData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenFindCLI extends CLI {
+
+ public TokenCLI tokenCLI;
+
+ public TokenFindCLI(TokenCLI tokenCLI) {
+ super("find", "Find tokens", tokenCLI);
+ this.tokenCLI = tokenCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " [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 s = cmd.getOptionValue("start");
+ Integer start = s == null ? null : Integer.valueOf(s);
+
+ s = cmd.getOptionValue("size");
+ Integer size = s == null ? null : Integer.valueOf(s);
+
+ TokenCollection result = tokenCLI.tokenClient.findTokens(start, size);
+ Collection<TokenData> tokens = result.getEntries();
+
+ MainCLI.printMessage(tokens.size() + " token(s) matched");
+
+ boolean first = true;
+
+ for (TokenData tokenData : tokens) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ TokenCLI.printToken(tokenData);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + tokens.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java
new file mode 100644
index 000000000..28559e163
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenModifyCLI.java
@@ -0,0 +1,81 @@
+// --- 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.tps.token;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.token.TokenData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenModifyCLI extends CLI {
+
+ public TokenCLI tokenCLI;
+
+ public TokenModifyCLI(TokenCLI tokenCLI) {
+ super("mod", "Modify token", tokenCLI);
+ this.tokenCLI = tokenCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Token ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "user", true, "User ID");
+ option.setArgName("User ID");
+ 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 tokenID = cmdArgs[0];
+
+ TokenData tokenData = new TokenData();
+ tokenData.setID(tokenID);
+ tokenData.setUserID(cmd.getOptionValue("user"));
+
+ tokenData = tokenCLI.tokenClient.updateToken(tokenID, tokenData);
+
+ MainCLI.printMessage("Modified token \"" + tokenID + "\"");
+
+ TokenCLI.printToken(tokenData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.java
new file mode 100644
index 000000000..f522991cb
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenRemoveCLI.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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.token;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenRemoveCLI extends CLI {
+
+ public TokenCLI tokenCLI;
+
+ public TokenRemoveCLI(TokenCLI tokenCLI) {
+ super("del", "Remove token", tokenCLI);
+ this.tokenCLI = tokenCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Token ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String tokenID = args[0];
+
+ tokenCLI.tokenClient.removeToken(tokenID);
+
+ MainCLI.printMessage("Deleted token \"" + tokenID + "\"");
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.java
new file mode 100644
index 000000000..14190ef01
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/token/TokenShowCLI.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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.token;
+
+import com.netscape.certsrv.tps.token.TokenData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class TokenShowCLI extends CLI {
+
+ public TokenCLI tokenCLI;
+
+ public TokenShowCLI(TokenCLI tokenCLI) {
+ super("show", "Show token", tokenCLI);
+ this.tokenCLI = tokenCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Token ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String tokenID = args[0];
+
+ TokenData tokenData = tokenCLI.tokenClient.getToken(tokenID);
+
+ MainCLI.printMessage("Token \"" + tokenID + "\"");
+
+ TokenCLI.printToken(tokenData);
+ }
+}