diff options
author | Endi Sukma Dewata <edewata@redhat.com> | 2012-10-08 14:50:26 -0500 |
---|---|---|
committer | Endi Sukma Dewata <edewata@redhat.com> | 2012-10-22 17:12:20 -0500 |
commit | 1723a2ecd9d4d741ecd6d292712eeaea9d19bde9 (patch) | |
tree | f9812748c4d5c8895a8da7be352983eb792ed000 /base/java-tools | |
parent | 1c45197227a0d54b525d4b40f66aa96aeb4f2e6a (diff) | |
download | pki-1723a2ecd9d4d741ecd6d292712eeaea9d19bde9.tar.gz pki-1723a2ecd9d4d741ecd6d292712eeaea9d19bde9.tar.xz pki-1723a2ecd9d4d741ecd6d292712eeaea9d19bde9.zip |
Added REST account service.
A REST account service has been added to allow client to login
to establish a session and to logout to destroy the session. This
way multiple operations can be executed using the same session
without having to re-authenticate.
Ticket #357
Diffstat (limited to 'base/java-tools')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java | 34 |
1 files changed, 29 insertions, 5 deletions
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 6f1c4909f..d7cb293a7 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java @@ -30,6 +30,7 @@ import org.mozilla.jss.crypto.CryptoToken; import org.mozilla.jss.util.IncorrectPasswordException; import org.mozilla.jss.util.Password; +import com.netscape.certsrv.account.AccountClient; import com.netscape.certsrv.client.ClientConfig; import com.netscape.certsrv.client.PKIConnection; import com.netscape.cmstools.cert.CertCLI; @@ -45,6 +46,7 @@ public class MainCLI extends CLI { public ClientConfig config = new ClientConfig(); public PKIConnection connection; + public AccountClient accountClient; public MainCLI() throws Exception { super("pki", "PKI command-line interface"); @@ -167,6 +169,8 @@ public class MainCLI extends CLI { public void connect() throws Exception { connection = new PKIConnection(config); connection.setVerbose(verbose); + + accountClient = new AccountClient(connection); } public void execute(String[] args) throws Exception { @@ -253,13 +257,12 @@ public class MainCLI extends CLI { return; } - // execute module command - try { - if (verbose) System.out.println("Server URI: "+config.getServerURI()); + if (verbose) System.out.println("Server URI: "+config.getServerURI()); - // initialize certificate database if specified - if (config.getCertDatabase() != null) { + // initialize certificate database if specified + if (config.getCertDatabase() != null) { + try { if (verbose) System.out.println("Certificate database: "+config.getCertDatabase()); CryptoManager.initialize(config.getCertDatabase()); @@ -274,10 +277,28 @@ public class MainCLI extends CLI { throw new Error("Incorrect certificate database password.", e); } } + + } catch (Throwable t) { + if (verbose) { + t.printStackTrace(System.err); + } else { + System.err.println(t.getClass().getSimpleName()+": "+t.getMessage()); + } + System.exit(1); } + } + // execute command + boolean loggedIn = false; + try { connect(); + // login + if (config.getCertDatabase() != null || config.getUsername() != null) { + accountClient.login(); + loggedIn = true; + } + // execute module command module.execute(moduleArgs); @@ -288,6 +309,9 @@ public class MainCLI extends CLI { System.err.println(t.getClass().getSimpleName()+": "+t.getMessage()); } System.exit(1); + + } finally { + if (loggedIn) accountClient.logout(); } } |