diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java | 21 |
1 files changed, 9 insertions, 12 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 2b6b173b8..dcc60e25f 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/MainCLI.java @@ -230,12 +230,11 @@ public class MainCLI extends CLI { } public String[] loadPassword(String pwfile) throws Exception { + String[] tokenPassword = { null, null }; - BufferedReader br = null; String delimiter = "="; - try { - br = new BufferedReader(new FileReader(pwfile)); + try (BufferedReader br = new BufferedReader(new FileReader(pwfile))) { String line = br.readLine(); @@ -276,11 +275,6 @@ public class MainCLI extends CLI { // Set simple 'password' (do not trim leading/trailing whitespace) tokenPassword[1] = line; } - - } finally { - if (br != null) { - br.close(); - } } return tokenPassword; @@ -399,7 +393,7 @@ public class MainCLI extends CLI { config.setCertNickname(certNickname); if (certPasswordFile != null) { - // read client security database password from specified file + if (verbose) System.out.println("Loading NSS password from " + certPasswordFile); tokenPasswordPair = loadPassword(certPasswordFile); // XXX TBD set client security database token @@ -413,7 +407,7 @@ public class MainCLI extends CLI { config.setUsername(username); if (passwordFile != null) { - // read user password from specified file + if (verbose) System.out.println("Loading user password from " + passwordFile); tokenPasswordPair = loadPassword(passwordFile); // XXX TBD set user token @@ -494,15 +488,18 @@ public class MainCLI extends CLI { // If password is specified, use password to access security token if (config.getCertPassword() != null) { - if (verbose) System.out.println("Logging into security token"); + try { CryptoManager manager = CryptoManager.getInstance(); String tokenName = config.getTokenName(); - CryptoToken token = CryptoUtil.getKeyStorageToken(tokenName); + if (verbose) System.out.println("Getting " + (tokenName == null ? "internal" : tokenName) + " token"); + CryptoToken token = CryptoUtil.getKeyStorageToken(tokenName); manager.setThreadToken(token); + if (verbose) System.out.println("Logging into " + token.getName()); + Password password = new Password(config.getCertPassword().toCharArray()); token.login(password); |