diff options
| author | Endi Sukma Dewata <edewata@redhat.com> | 2013-04-23 11:37:03 -0400 |
|---|---|---|
| committer | Endi Sukma Dewata <edewata@redhat.com> | 2013-04-25 23:17:31 -0400 |
| commit | 7a89bc5ac029066e4ec6d35d1cc953f046a9d36f (patch) | |
| tree | 0568e637df7c1ce57b5c0512bc7c356aa5e0dab6 /base/java-tools | |
| parent | 7ca438db07efb122bc93efd0471be7a2be34b663 (diff) | |
| download | pki-7a89bc5ac029066e4ec6d35d1cc953f046a9d36f.tar.gz pki-7a89bc5ac029066e4ec6d35d1cc953f046a9d36f.tar.xz pki-7a89bc5ac029066e4ec6d35d1cc953f046a9d36f.zip | |
Refactored code to import CA certificate.
The code to import CA certificate has been moved from PKIConnection
into PKIClient to allow reuse.
The Client classes have been modified such that it uses a shared
PKIClient object instead of PKIConnection.
The return codes in CertFindCLI has been fixed to be more consistent
with other commands.
Ticket #491
Diffstat (limited to 'base/java-tools')
7 files changed, 33 insertions, 19 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java index 02f973910..8abe6f22a 100644 --- a/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cert/CertCLI.java @@ -81,7 +81,7 @@ public class CertCLI extends CLI { public void execute(String[] args) throws Exception { - client = new CertClient(parent.connection); + client = new CertClient(parent.client); if (args.length == 0) { printHelp(); diff --git a/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java b/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java index 5415da574..590d79598 100644 --- a/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cert/CertFindCLI.java @@ -63,12 +63,12 @@ public class CertFindCLI extends CLI { } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); printHelp(); - System.exit(-1); + System.exit(1); } if (cmd.hasOption("help")) { printHelp(); - System.exit(-1); + System.exit(1); } String fileName = null; @@ -78,20 +78,24 @@ public class CertFindCLI extends CLI { if (fileName == null || fileName.length() < 1) { System.err.println("Error: No file name specified."); printHelp(); - System.exit(-1); + System.exit(1); } } + if (fileName != null) { FileReader reader = null; try { reader = new FileReader(fileName); searchData = CertSearchRequest.valueOf(reader); + } catch (FileNotFoundException e) { System.err.println("Error: " + e.getMessage()); - System.exit(-1); + System.exit(1); + } catch (JAXBException e) { System.err.println("Error: " + e.getMessage()); - System.exit(-1); + System.exit(1); + } finally { if (reader != null) try { @@ -100,10 +104,12 @@ public class CertFindCLI extends CLI { e.printStackTrace(); } } + } else { searchData = new CertSearchRequest(); searchData.setSerialNumberRangeInUse(true); } + String s = cmd.getOptionValue("start"); Integer start = s == null ? null : Integer.valueOf(s); @@ -111,18 +117,21 @@ public class CertFindCLI extends CLI { Integer size = s == null ? null : Integer.valueOf(s); addSearchAttribute(cmd, searchData); + CertDataInfos certs = null; try { certs = parent.client.findCerts(searchData, start, size); } catch (PKIException e) { System.err.println("Error: Cannot list certificates. " + e.getMessage()); - System.exit(-1); + System.exit(1); } + if (certs.getCertInfos() == null || certs.getCertInfos().isEmpty()) { - MainCLI.printMessage("No matches found."); - System.exit(-1); + MainCLI.printMessage("No certificates found"); + System.exit(0); // valid result } - MainCLI.printMessage(certs.getCertInfos().size() + " certificate(s) matched"); + + MainCLI.printMessage(certs.getCertInfos().size() + " certificate(s) found"); boolean first = true; 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 aa4327fe6..1510cc7af 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java @@ -37,6 +37,7 @@ import org.mozilla.jss.util.Password; import com.netscape.certsrv.account.AccountClient; import com.netscape.certsrv.client.ClientConfig; +import com.netscape.certsrv.client.PKIClient; import com.netscape.certsrv.client.PKIConnection; import com.netscape.cmstools.cert.CertCLI; import com.netscape.cmstools.group.GroupCLI; @@ -55,6 +56,7 @@ public class MainCLI extends CLI { public Collection<Integer> rejectedCertStatuses; public Collection<Integer> ignoredCertStatuses; + public PKIClient client; public PKIConnection connection; public AccountClient accountClient; @@ -223,8 +225,11 @@ public class MainCLI extends CLI { } public void connect() throws Exception { - connection = new PKIConnection(config); - connection.setVerbose(verbose); + + client = new PKIClient(config); + client.setVerbose(verbose); + + connection = client.getConnection(); connection.setRejectedCertStatuses(rejectedCertStatuses); connection.setIgnoredCertStatuses(ignoredCertStatuses); @@ -234,7 +239,7 @@ public class MainCLI extends CLI { connection.setOutput(file); } - accountClient = new AccountClient(connection); + accountClient = new AccountClient(client); } public void execute(String[] args) throws Exception { @@ -355,8 +360,8 @@ public class MainCLI extends CLI { try { connect(); - // login - if (config.getCertDatabase() != null || config.getUsername() != null) { + // login if username or nickname is specified + if (config.getUsername() != null || config.getCertNickname() != null) { accountClient.login(); loggedIn = true; } diff --git a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java index 75eeffd97..bd8cec773 100644 --- a/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/group/GroupCLI.java @@ -75,7 +75,7 @@ public class GroupCLI extends CLI { public void execute(String[] args) throws Exception { - client = new GroupClient(parent.connection); + client = new GroupClient(parent.client); if (args.length == 0) { printHelp(); diff --git a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java index f3922d5da..0d2396243 100644 --- a/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/key/KeyCLI.java @@ -67,7 +67,7 @@ public class KeyCLI extends CLI { public void execute(String[] args) throws Exception { - keyClient = new KeyClient(parent.connection); + keyClient = new KeyClient(parent.client); if (args.length == 0) { printHelp(); diff --git a/base/java-tools/src/com/netscape/cmstools/system/KRAConnectorCLI.java b/base/java-tools/src/com/netscape/cmstools/system/KRAConnectorCLI.java index d59d7445a..03db762d4 100644 --- a/base/java-tools/src/com/netscape/cmstools/system/KRAConnectorCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/system/KRAConnectorCLI.java @@ -62,7 +62,7 @@ public class KRAConnectorCLI extends CLI { public void execute(String[] args) throws Exception { - client = new KRAConnectorClient(parent.connection); + client = new KRAConnectorClient(parent.client); if (args.length == 0) { printHelp(); diff --git a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java index 84dd6bae5..2343d1989 100644 --- a/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/user/UserCLI.java @@ -81,7 +81,7 @@ public class UserCLI extends CLI { public void execute(String[] args) throws Exception { - client = new UserClient(parent.connection); + client = new UserClient(parent.client); if (args.length == 0) { printHelp(); |
