diff options
author | Endi S. Dewata <edewata@redhat.com> | 2017-01-17 15:20:28 +0100 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2017-02-24 19:18:07 +0100 |
commit | d7c22171b84b7d8f7a068be42b07a53c8092eb48 (patch) | |
tree | eff8f5bdf220c545e5794c36640432c50c34c742 /base/java-tools/src | |
parent | 91d639dbf5336d075c3d37daf4112a6444bd951e (diff) | |
download | pki-d7c22171b84b7d8f7a068be42b07a53c8092eb48.tar.gz pki-d7c22171b84b7d8f7a068be42b07a53c8092eb48.tar.xz pki-d7c22171b84b7d8f7a068be42b07a53c8092eb48.zip |
Added access banner for PKI CLI.
The PKI CLI has been modified to retrieve access banner from
the server and ask for user confirmation at the beginning of the
program. An --ignore-banner option was added to allow bypassing
the banner for automation.
https://fedorahosted.org/pki/ticket/2582
Diffstat (limited to 'base/java-tools/src')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/cli/CLIException.java | 46 | ||||
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java | 37 |
2 files changed, 83 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CLIException.java b/base/java-tools/src/com/netscape/cmstools/cli/CLIException.java new file mode 100644 index 000000000..f36d259a1 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/cli/CLIException.java @@ -0,0 +1,46 @@ +// --- 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) 2017 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.cli; + +public class CLIException extends Exception { + + private static final long serialVersionUID = 1L; + + int code; + + public CLIException() { + } + + public CLIException(int code) { + this.code = code; + } + + public CLIException(String message) { + super(message); + } + + public CLIException(String message, int code) { + super(message); + this.code = code; + } + + public int getCode() { + return code; + } +} 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 c5f20711a..0a9ddf0a6 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java @@ -38,6 +38,8 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.UnrecognizedOptionException; import org.apache.commons.lang.StringUtils; +import org.dogtagpki.common.Info; +import org.dogtagpki.common.InfoClient; import org.mozilla.jss.CryptoManager; import org.mozilla.jss.CryptoManager.NotInitializedException; import org.mozilla.jss.crypto.CryptoToken; @@ -81,6 +83,7 @@ public class MainCLI extends CLI { public Collection<Integer> rejectedCertStatuses = new HashSet<Integer>(); public Collection<Integer> ignoredCertStatuses = new HashSet<Integer>(); + public boolean ignoreBanner; public File certDatabase; String output; @@ -213,6 +216,9 @@ public class MainCLI extends CLI { option.setArgName("list"); options.addOption(option); + option = new Option(null, "ignore-banner", false, "Ignore access banner"); + options.addOption(option); + option = new Option(null, "message-format", true, "Message format: xml (default), json"); option.setArgName("format"); options.addOption(option); @@ -432,6 +438,8 @@ public class MainCLI extends CLI { list = cmd.getOptionValue("ignore-cert-status"); convertCertStatusList(list, ignoredCertStatuses); + ignoreBanner = cmd.hasOption("ignore-banner"); + this.certDatabase = new File(config.getCertDatabase()); if (verbose) System.out.println("Client security database: "+this.certDatabase.getAbsolutePath()); @@ -503,6 +511,28 @@ public class MainCLI extends CLI { PKIConnection connection = client.getConnection(); connection.setOutput(file); } + + if (!ignoreBanner) { + + InfoClient infoClient = new InfoClient(client); + Info info = infoClient.getInfo(); + String banner = info.getBanner(); + + if (banner != null) { + + System.out.println(banner.trim()); + System.out.println(); + System.out.print("Do you want to proceed (y/N)? "); + System.out.flush(); + + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String line = reader.readLine().trim(); + + if (!line.equalsIgnoreCase("Y")) { + throw new CLIException(); + } + } + } } public void execute(String[] args) throws Exception { @@ -578,6 +608,13 @@ public class MainCLI extends CLI { MainCLI cli = new MainCLI(); cli.execute(args); + } catch (CLIException e) { + String message = e.getMessage(); + if (message != null) { + System.err.println(message); + } + System.exit(e.getCode()); + } catch (Throwable t) { handleException(t); System.exit(-1); |