diff options
author | Endi S. Dewata <edewata@redhat.com> | 2013-08-22 13:25:33 -0400 |
---|---|---|
committer | Endi S. Dewata <edewata@redhat.com> | 2013-08-24 01:40:08 -0400 |
commit | 510ace9989fc8d74be817b9bfe2bb7b895fb121d (patch) | |
tree | 4a06d1b9543ce763f795eed582fdab61fdbb83ab /base/java-tools/src/com/netscape/cmstools | |
parent | 99c3fc97f3f1c49ffef010896765b716e8359e50 (diff) | |
download | pki-510ace9989fc8d74be817b9bfe2bb7b895fb121d.tar.gz pki-510ace9989fc8d74be817b9bfe2bb7b895fb121d.tar.xz pki-510ace9989fc8d74be817b9bfe2bb7b895fb121d.zip |
Added TPS certificate resource.
New TPS services and clients have been added for TPS certificates. The
certificate database is currently implemented as in-memory database with
some sample data. Later it will be converted into LDAP database.
Ticket #652
Diffstat (limited to 'base/java-tools/src/com/netscape/cmstools')
4 files changed, 240 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java index 00f0131cb..8f740662c 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java @@ -23,6 +23,7 @@ import com.netscape.certsrv.tps.TPSClient; import com.netscape.cmstools.group.GroupCLI; import com.netscape.cmstools.logging.ActivityCLI; import com.netscape.cmstools.token.TokenCLI; +import com.netscape.cmstools.tps.cert.TPSCertCLI; import com.netscape.cmstools.user.UserCLI; /** @@ -38,6 +39,7 @@ public class TPSCLI extends SubsystemCLI { addModule(new ActivityCLI(this)); addModule(new GroupCLI(this)); addModule(new TokenCLI(this)); + addModule(new TPSCertCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertCLI.java new file mode 100644 index 000000000..4bb44368d --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertCLI.java @@ -0,0 +1,88 @@ +// --- 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.cert; + +import java.util.Arrays; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.tps.cert.TPSCertClient; +import com.netscape.certsrv.tps.cert.TPSCertData; +import com.netscape.cmstools.cli.CLI; + +/** + * @author Endi S. Dewata + */ +public class TPSCertCLI extends CLI { + + public TPSCertClient certClient; + + public TPSCertCLI(CLI parent) { + super("cert", "Certificate management commands", parent); + + addModule(new TPSCertFindCLI(this)); + addModule(new TPSCertShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + certClient = (TPSCertClient)parent.getClient("cert"); + + 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 printCert(TPSCertData cert) { + System.out.println(" Cert ID: " + cert.getID()); + if (cert.getSerialNumber() != null) System.out.println(" Serial Number: " + cert.getSerialNumber()); + if (cert.getSubject() != null) System.out.println(" Subject: " + cert.getSubject()); + if (cert.getTokenID() != null) System.out.println(" Token ID: " + cert.getTokenID()); + if (cert.getKeyType() != null) System.out.println(" Key Type: " + cert.getKeyType()); + if (cert.getStatus() != null) System.out.println(" Status: " + cert.getStatus()); + if (cert.getUserID() != null) System.out.println(" User ID: " + cert.getUserID()); + if (cert.getCreateTime() != null) System.out.println(" Create Time: " + cert.getCreateTime()); + if (cert.getModifyTime() != null) System.out.println(" Modify Time: " + cert.getModifyTime()); + + Link link = cert.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.java new file mode 100644 index 000000000..4d0827cb3 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertFindCLI.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.cert; + +import java.util.Collection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.tps.cert.TPSCertCollection; +import com.netscape.certsrv.tps.cert.TPSCertData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TPSCertFindCLI extends CLI { + + public TPSCertCLI certCLI; + + public TPSCertFindCLI(TPSCertCLI certCLI) { + super("find", "Find certificates", certCLI); + this.certCLI = certCLI; + } + + 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); + + TPSCertCollection result = certCLI.certClient.findCerts(start, size); + Collection<TPSCertData> certs = result.getEntries(); + + MainCLI.printMessage(certs.size() + " certificate(s) matched"); + + boolean first = true; + + for (TPSCertData certData : certs) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + TPSCertCLI.printCert(certData); + } + + MainCLI.printMessage("Number of entries returned " + certs.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.java new file mode 100644 index 000000000..b20e9a6cc --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/tps/cert/TPSCertShowCLI.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.cert; + +import com.netscape.certsrv.tps.cert.TPSCertData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class TPSCertShowCLI extends CLI { + + public TPSCertCLI certCLI; + + public TPSCertShowCLI(TPSCertCLI certCLI) { + super("show", "Show certificate", certCLI); + this.certCLI = certCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <Certificate ID>", options); + } + + public void execute(String[] args) throws Exception { + + if (args.length != 1) { + printHelp(); + System.exit(1); + } + + String certID = args[0]; + + TPSCertData certData = certCLI.certClient.getCert(certID); + + MainCLI.printMessage("Certificate \"" + certID + "\""); + + TPSCertCLI.printCert(certData); + } +} |