diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-09-24 10:10:02 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-01 19:25:51 -0400 |
commit | 565741cc9aa0e3f1e056c9c79dc1bec35bbbcc92 (patch) | |
tree | ffc9431f543c0ff652000fcbe9d735d37fce091a /base/java-tools/src/com/netscape/cmstools/tps | |
parent | e339952dfad45bc0ba1768a9386817eadd49b9dc (diff) | |
download | pki-565741cc9aa0e3f1e056c9c79dc1bec35bbbcc92.tar.gz pki-565741cc9aa0e3f1e056c9c79dc1bec35bbbcc92.tar.xz pki-565741cc9aa0e3f1e056c9c79dc1bec35bbbcc92.zip |
Added TPS authenticator service implementation.
The implementation of the TPS authenticator service has been modified to
use the configuration database to read and write the configuration file.
Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools/tps')
5 files changed, 53 insertions, 105 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 index 836f8bd85..59ec2f785 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorAddCLI.java @@ -43,17 +43,12 @@ public class AuthenticatorAddCLI extends CLI { } public void printHelp() { - formatter.printHelp(getFullName() + " <Authenticator ID> [OPTIONS...]", options); + formatter.printHelp(getFullName() + " [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 option = new Option(null, "input", true, "Input file containing authenticator properties."); option.setArgName("file"); option.setRequired(true); options.addOption(option); @@ -71,37 +66,31 @@ public class AuthenticatorAddCLI extends CLI { String[] cmdArgs = cmd.getArgs(); - if (cmdArgs.length != 1) { + if (cmdArgs.length != 0) { printHelp(); System.exit(1); } - String authenticatorID = cmdArgs[0]; - String status = cmd.getOptionValue("status"); - String contents = cmd.getOptionValue("contents"); + String input = cmd.getOptionValue("input"); - AuthenticatorData authenticatorData = new AuthenticatorData(); - authenticatorData.setID(authenticatorID); - authenticatorData.setStatus(status); + AuthenticatorData authenticatorData; - if (contents != null) { - try (BufferedReader in = new BufferedReader(new FileReader(contents)); - StringWriter sw = new StringWriter(); - PrintWriter out = new PrintWriter(sw, true)) { + try (BufferedReader in = new BufferedReader(new FileReader(input)); + StringWriter sw = new StringWriter(); + PrintWriter out = new PrintWriter(sw, true)) { - String line; - while ((line = in.readLine()) != null) { - out.println(line); - } - - authenticatorData.setContents(sw.toString()); + String line; + while ((line = in.readLine()) != null) { + out.println(line); } + + authenticatorData = AuthenticatorData.valueOf(sw.toString()); } authenticatorData = authenticatorCLI.authenticatorClient.addAuthenticator(authenticatorData); - MainCLI.printMessage("Added authenticator \"" + authenticatorID + "\""); + MainCLI.printMessage("Added authenticator \"" + authenticatorData.getID() + "\""); - AuthenticatorCLI.printAuthenticatorData(authenticatorData); + AuthenticatorCLI.printAuthenticatorData(authenticatorData, true); } } 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 index 198982a06..ebdf80890 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorCLI.java @@ -18,16 +18,13 @@ package com.netscape.cmstools.tps.authenticator; -import java.io.BufferedReader; import java.io.IOException; -import java.io.StringReader; -import java.util.Arrays; +import java.util.Map; 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; /** @@ -52,51 +49,19 @@ public class AuthenticatorCLI extends CLI { 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()); - } + super.execute(args); } - public static void printAuthenticatorData(AuthenticatorData authenticatorData) throws IOException { + public static void printAuthenticatorData(AuthenticatorData authenticatorData, boolean showProperties) 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); + if (showProperties) { + System.out.println(" Properties:"); + Map<String, String> properties = authenticatorData.getProperties(); + for (String name : properties.keySet()) { + String value = properties.get(name); + System.out.println(" " + name + ": " + value); } } 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 index 34c291fd1..2ff8288a0 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorFindCLI.java @@ -24,7 +24,7 @@ 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.certsrv.tps.authenticator.AuthenticatorData; import com.netscape.cmstools.cli.CLI; import com.netscape.cmstools.cli.MainCLI; @@ -35,9 +35,9 @@ public class AuthenticatorFindCLI extends CLI { public AuthenticatorCLI authenticatorCLI; - public AuthenticatorFindCLI(AuthenticatorCLI tokenCLI) { - super("find", "Find authenticators", tokenCLI); - this.authenticatorCLI = tokenCLI; + public AuthenticatorFindCLI(AuthenticatorCLI authenticatorCLI) { + super("find", "Find authenticators", authenticatorCLI); + this.authenticatorCLI = authenticatorCLI; } public void printHelp() { @@ -72,13 +72,13 @@ public class AuthenticatorFindCLI extends CLI { Integer size = s == null ? null : Integer.valueOf(s); AuthenticatorCollection result = authenticatorCLI.authenticatorClient.findAuthenticators(start, size); - Collection<AuthenticatorInfo> authenticators = result.getEntries(); + Collection<AuthenticatorData> authenticators = result.getEntries(); MainCLI.printMessage(authenticators.size() + " authenticator(s) matched"); boolean first = true; - for (AuthenticatorInfo authenticatorInfo : authenticators) { + for (AuthenticatorData authenticatorData : authenticators) { if (first) { first = false; @@ -86,7 +86,7 @@ public class AuthenticatorFindCLI extends CLI { System.out.println(); } - AuthenticatorCLI.printAuthenticatorInfo(authenticatorInfo); + AuthenticatorCLI.printAuthenticatorData(authenticatorData, false); } 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 index c5fc01e07..292e03f75 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorModifyCLI.java @@ -27,7 +27,6 @@ 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; @@ -53,7 +52,7 @@ public class AuthenticatorModifyCLI extends CLI { option.setArgName("status"); options.addOption(option); - option = new Option(null, "contents", true, "Input file containing authenticator attributes."); + option = new Option(null, "input", true, "Input file containing authenticator properties."); option.setArgName("file"); options.addOption(option); @@ -77,31 +76,26 @@ public class AuthenticatorModifyCLI extends CLI { String authenticatorID = cmdArgs[0]; String status = cmd.getOptionValue("status"); - String contents = cmd.getOptionValue("contents"); + String input = cmd.getOptionValue("input"); - AuthenticatorModification authenticatorModification = new AuthenticatorModification(); - authenticatorModification.setID(authenticatorID); - authenticatorModification.setStatus(status); + AuthenticatorData authenticatorData; - if (contents != null) { - // load contents from file + try (BufferedReader in = new BufferedReader(new FileReader(input)); StringWriter sw = new StringWriter(); - try (BufferedReader in = new BufferedReader(new FileReader(contents)); - PrintWriter out = new PrintWriter(sw, true)) { + PrintWriter out = new PrintWriter(sw, true)) { - String line; - while ((line = in.readLine()) != null) { - out.println(line); - } - - authenticatorModification.setContents(sw.toString()); + String line; + while ((line = in.readLine()) != null) { + out.println(line); } + + authenticatorData = AuthenticatorData.valueOf(sw.toString()); } - AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.modifyAuthenticator(authenticatorID, authenticatorModification); + authenticatorData = authenticatorCLI.authenticatorClient.updateAuthenticator(authenticatorID, authenticatorData); MainCLI.printMessage("Modified authenticator \"" + authenticatorID + "\""); - AuthenticatorCLI.printAuthenticatorData(authenticatorData); + AuthenticatorCLI.printAuthenticatorData(authenticatorData, true); } } 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 index d4549aa0f..af1290aa0 100644 --- a/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/tps/authenticator/AuthenticatorShowCLI.java @@ -46,7 +46,7 @@ public class AuthenticatorShowCLI extends CLI { public void execute(String[] args) throws Exception { - Option option = new Option(null, "contents", true, "Output file to store authenticator attributes."); + Option option = new Option(null, "output", true, "Output file to store authenticator properties."); option.setArgName("file"); options.addOption(option); @@ -69,19 +69,19 @@ public class AuthenticatorShowCLI extends CLI { } String authenticatorID = args[0]; - String file = cmd.getOptionValue("contents"); + String output = cmd.getOptionValue("output"); AuthenticatorData authenticatorData = authenticatorCLI.authenticatorClient.getAuthenticator(authenticatorID); - MainCLI.printMessage("Authenticator \"" + authenticatorID + "\""); - AuthenticatorCLI.printAuthenticatorData(authenticatorData); + if (output == null) { + MainCLI.printMessage("Authenticator \"" + authenticatorID + "\""); + AuthenticatorCLI.printAuthenticatorData(authenticatorData, true); - 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(); + } else { + try (PrintWriter out = new PrintWriter(new FileWriter(output))) { + out.println(authenticatorData); + } + MainCLI.printMessage("Stored authenticator \"" + authenticatorID + "\" into " + output); } } } |