summaryrefslogtreecommitdiffstats
path: root/base/java-tools/src/com/netscape/cmstools/tps
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2013-08-27 14:38:07 -0400
committerEndi Sukma Dewata <edewata@redhat.com>2013-09-01 01:05:03 -0500
commit3be4905f70b05050b53995524c91ccb7a390e1e6 (patch)
tree58ee82727de131fed3187d61b092a9de07663f55 /base/java-tools/src/com/netscape/cmstools/tps
parent15e029e97aea4a23f065e6bc7fbfa16cdae8c02d (diff)
downloadpki-3be4905f70b05050b53995524c91ccb7a390e1e6.tar.gz
pki-3be4905f70b05050b53995524c91ccb7a390e1e6.tar.xz
pki-3be4905f70b05050b53995524c91ccb7a390e1e6.zip
Added TPS authenticator resource.
A skeleton for TPS authenticator services and the clients have been added. The service implementation will be added later. Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/tps')
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java107
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java108
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java94
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java107
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java53
-rw-r--r--base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java87
6 files changed, 556 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java
new file mode 100644
index 000000000..836f8bd85
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.authenticator;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorAddCLI extends CLI {
+
+ public AuthenticatorCLI authenticatorCLI;
+
+ public AuthenticatorAddCLI(AuthenticatorCLI authenticatorCLI) {
+ super("add", "Add authenticator", authenticatorCLI);
+ this.authenticatorCLI = authenticatorCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Authenticator ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "status", true, "Status: ENABLED, DISABLED.");
+ option.setArgName("status");
+ option.setRequired(true);
+ options.addOption(option);
+
+ option = new Option(null, "contents", true, "Input file containing authenticator attributes.");
+ 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 authenticatorID = cmdArgs[0];
+ String status = cmd.getOptionValue("status");
+ String contents = cmd.getOptionValue("contents");
+
+ AuthenticatorData authenticatorData = new AuthenticatorData();
+ authenticatorData.setID(authenticatorID);
+ authenticatorData.setStatus(status);
+
+ if (contents != null) {
+ try (BufferedReader in = new BufferedReader(new FileReader(contents));
+ StringWriter sw = new StringWriter();
+ PrintWriter out = new PrintWriter(sw, true)) {
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+
+ authenticatorData.setContents(sw.toString());
+ }
+ }
+
+ authenticatorData = authenticatorCLI.authenticatorClient.addAuthenticator(authenticatorData);
+
+ MainCLI.printMessage("Added authenticator \"" + authenticatorID + "\"");
+
+ AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java
new file mode 100644
index 000000000..198982a06
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java
@@ -0,0 +1,108 @@
+// --- 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.authenticator;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Arrays;
+
+import org.jboss.resteasy.plugins.providers.atom.Link;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorClient;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorInfo;
+import com.netscape.cmstools.cli.CLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorCLI extends CLI {
+
+ public AuthenticatorClient authenticatorClient;
+
+ public AuthenticatorCLI(CLI parent) {
+ super("authenticator", "Authenticator management commands", parent);
+
+ addModule(new AuthenticatorAddCLI(this));
+ addModule(new AuthenticatorFindCLI(this));
+ addModule(new AuthenticatorModifyCLI(this));
+ addModule(new AuthenticatorRemoveCLI(this));
+ addModule(new AuthenticatorShowCLI(this));
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ client = parent.getClient();
+ authenticatorClient = (AuthenticatorClient)parent.getClient("authenticator");
+
+ 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 printAuthenticatorInfo(AuthenticatorInfo authenticatorInfo) {
+ System.out.println(" Authenticator ID: " + authenticatorInfo.getID());
+ if (authenticatorInfo.getStatus() != null) System.out.println(" Status: " + authenticatorInfo.getStatus());
+
+ Link link = authenticatorInfo.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+
+ public static void printAuthenticatorData(AuthenticatorData authenticatorData) throws IOException {
+ System.out.println(" Authenticator ID: " + authenticatorData.getID());
+ if (authenticatorData.getStatus() != null) System.out.println(" Status: " + authenticatorData.getStatus());
+
+ System.out.println(" Contents:");
+ String contents = authenticatorData.getContents();
+ if (contents != null) {
+ BufferedReader in = new BufferedReader(new StringReader(contents));
+ String line;
+ while ((line = in.readLine()) != null) {
+ System.out.println(" " + line);
+ }
+ }
+
+ Link link = authenticatorData.getLink();
+ if (verbose && link != null) {
+ System.out.println(" Link: " + link.getHref());
+ }
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java
new file mode 100644
index 000000000..34c291fd1
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.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.authenticator;
+
+import java.util.Collection;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorCollection;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorInfo;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorFindCLI extends CLI {
+
+ public AuthenticatorCLI authenticatorCLI;
+
+ public AuthenticatorFindCLI(AuthenticatorCLI tokenCLI) {
+ super("find", "Find authenticators", tokenCLI);
+ this.authenticatorCLI = 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);
+
+ AuthenticatorCollection result = authenticatorCLI.authenticatorClient.findAuthenticators(start, size);
+ Collection<AuthenticatorInfo> authenticators = result.getEntries();
+
+ MainCLI.printMessage(authenticators.size() + " authenticator(s) matched");
+
+ boolean first = true;
+
+ for (AuthenticatorInfo authenticatorInfo : authenticators) {
+
+ if (first) {
+ first = false;
+ } else {
+ System.out.println();
+ }
+
+ AuthenticatorCLI.printAuthenticatorInfo(authenticatorInfo);
+ }
+
+ MainCLI.printMessage("Number of entries returned " + authenticators.size());
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java
new file mode 100644
index 000000000..c5fc01e07
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.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) 2013 Red Hat, Inc.
+// All rights reserved.
+// --- END COPYRIGHT BLOCK ---
+
+package com.netscape.cmstools.tps.authenticator;
+
+import java.io.BufferedReader;
+import java.io.FileReader;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.certsrv.tps.authenticator.AuthenticatorModification;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorModifyCLI extends CLI {
+
+ public AuthenticatorCLI authenticatorCLI;
+
+ public AuthenticatorModifyCLI(AuthenticatorCLI authenticatorCLI) {
+ super("mod", "Modify authenticator", authenticatorCLI);
+ this.authenticatorCLI = authenticatorCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Authenticator ID> [OPTIONS...]", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "status", true, "Status: ENABLED, DISABLED.");
+ option.setArgName("status");
+ options.addOption(option);
+
+ option = new Option(null, "contents", true, "Input file containing authenticator attributes.");
+ option.setArgName("file");
+ 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 authenticatorID = cmdArgs[0];
+ String status = cmd.getOptionValue("status");
+ String contents = cmd.getOptionValue("contents");
+
+ AuthenticatorModification authenticatorModification = new AuthenticatorModification();
+ authenticatorModification.setID(authenticatorID);
+ authenticatorModification.setStatus(status);
+
+ if (contents != null) {
+ // load contents from file
+ StringWriter sw = new StringWriter();
+ try (BufferedReader in = new BufferedReader(new FileReader(contents));
+ PrintWriter out = new PrintWriter(sw, true)) {
+
+ String line;
+ while ((line = in.readLine()) != null) {
+ out.println(line);
+ }
+
+ authenticatorModification.setContents(sw.toString());
+ }
+ }
+
+ AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.modifyAuthenticator(authenticatorID, authenticatorModification);
+
+ MainCLI.printMessage("Modified authenticator \"" + authenticatorID + "\"");
+
+ AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.java
new file mode 100644
index 000000000..6d565bc96
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorRemoveCLI.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.authenticator;
+
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorRemoveCLI extends CLI {
+
+ public AuthenticatorCLI authenticatorCLI;
+
+ public AuthenticatorRemoveCLI(AuthenticatorCLI authenticatorCLI) {
+ super("del", "Remove authenticator", authenticatorCLI);
+ this.authenticatorCLI = authenticatorCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Authenticator ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ if (args.length != 1) {
+ printHelp();
+ System.exit(1);
+ }
+
+ String authenticatorID = args[0];
+
+ authenticatorCLI.authenticatorClient.removeAuthenticator(authenticatorID);
+
+ MainCLI.printMessage("Deleted authenticator \"" + authenticatorID + "\"");
+ }
+}
diff --git a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
new file mode 100644
index 000000000..d4549aa0f
--- /dev/null
+++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java
@@ -0,0 +1,87 @@
+// --- 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.authenticator;
+
+import java.io.FileWriter;
+import java.io.PrintWriter;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+
+import com.netscape.certsrv.tps.authenticator.AuthenticatorData;
+import com.netscape.cmstools.cli.CLI;
+import com.netscape.cmstools.cli.MainCLI;
+
+/**
+ * @author Endi S. Dewata
+ */
+public class AuthenticatorShowCLI extends CLI {
+
+ public AuthenticatorCLI authenticatorCLI;
+
+ public AuthenticatorShowCLI(AuthenticatorCLI authenticatorCLI) {
+ super("show", "Show authenticator", authenticatorCLI);
+ this.authenticatorCLI = authenticatorCLI;
+ }
+
+ public void printHelp() {
+ formatter.printHelp(getFullName() + " <Authenticator ID>", options);
+ }
+
+ public void execute(String[] args) throws Exception {
+
+ Option option = new Option(null, "contents", true, "Output file to store authenticator attributes.");
+ option.setArgName("file");
+ 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 authenticatorID = args[0];
+ String file = cmd.getOptionValue("contents");
+
+ AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.getAuthenticator(authenticatorID);
+
+ MainCLI.printMessage("Authenticator \"" + authenticatorID + "\"");
+ AuthenticatorCLI.printAuthenticatorData(authenticatorData);
+
+ if (file != null) {
+ // store contents to file
+ PrintWriter out = new PrintWriter(new FileWriter(file));
+ String contents = authenticatorData.getContents();
+ if (contents != null) out.print(contents);
+ out.close();
+ }
+ }
+}