| | |
| | | |
| | | private Message heading = INFO_LDAP_CONN_HEADING_CONNECTION_PARAMETERS.get(); |
| | | |
| | | // A copy of the secureArgList for convenience. |
| | | private SecureConnectionCliArgs copySecureArgsList = null; |
| | | |
| | | // The command builder that we can return with the connection information. |
| | | private CommandBuilder commandBuilder; |
| | | |
| | | /** |
| | | * Enumeration description protocols for interactive CLI choices. |
| | | */ |
| | |
| | | SecureConnectionCliArgs secureArgs) { |
| | | this.app = app; |
| | | this.secureArgsList = secureArgs; |
| | | this.commandBuilder = new CommandBuilder(null); |
| | | copySecureArgsList = new SecureConnectionCliArgs(); |
| | | try |
| | | { |
| | | copySecureArgsList.createGlobalArguments(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | // This is a bug: we should always be able to create the global arguments |
| | | // no need to localize this one. |
| | | throw new RuntimeException("Unexpected error: "+t, t); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | public void run(boolean canUseSSL, boolean canUseStartTLS) |
| | | throws ArgumentException |
| | | { |
| | | // Reset everything |
| | | commandBuilder.clearArguments(); |
| | | copySecureArgsList.createGlobalArguments(); |
| | | boolean secureConnection = (canUseSSL || canUseStartTLS) && |
| | | ( |
| | | secureArgsList.useSSLArg.isPresent() |
| | |
| | | } |
| | | } |
| | | |
| | | copySecureArgsList.hostNameArg.clearValues(); |
| | | copySecureArgsList.hostNameArg.addValue(hostName); |
| | | commandBuilder.addArgument(copySecureArgsList.hostNameArg); |
| | | |
| | | useSSL = secureArgsList.useSSL(); |
| | | useStartTLS = secureArgsList.useStartTLS(); |
| | | boolean connectionTypeIsSet = |
| | |
| | | } |
| | | } |
| | | |
| | | if (useSSL) |
| | | { |
| | | commandBuilder.addArgument(copySecureArgsList.useSSLArg); |
| | | } |
| | | else if (useStartTLS) |
| | | { |
| | | commandBuilder.addArgument(copySecureArgsList.useStartTLSArg); |
| | | } |
| | | |
| | | if ((useSSL || useStartTLS) && (trustManager == null)) |
| | | { |
| | | initializeTrustManager(); |
| | |
| | | } |
| | | } |
| | | |
| | | copySecureArgsList.portArg.clearValues(); |
| | | copySecureArgsList.portArg.addValue(String.valueOf(portNumber)); |
| | | commandBuilder.addArgument(copySecureArgsList.portArg); |
| | | |
| | | // Get the LDAP bind credentials. |
| | | bindDN = secureArgsList.bindDnArg.getValue(); |
| | | adminUID = secureArgsList.adminUidArg.getValue(); |
| | |
| | | .unableToReadConnectionParameters(e); |
| | | } |
| | | } |
| | | if (useAdmin) |
| | | { |
| | | copySecureArgsList.adminUidArg.clearValues(); |
| | | copySecureArgsList.adminUidArg.addValue(getAdministratorUID()); |
| | | commandBuilder.addArgument(copySecureArgsList.adminUidArg); |
| | | } |
| | | else |
| | | { |
| | | copySecureArgsList.bindDnArg.clearValues(); |
| | | copySecureArgsList.bindDnArg.addValue(getBindDN()); |
| | | commandBuilder.addArgument(copySecureArgsList.bindDnArg); |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | throw ArgumentExceptionFactory.missingBindPassword(bindDN); |
| | | } |
| | | } |
| | | copySecureArgsList.bindPasswordFileArg.clearValues(); |
| | | copySecureArgsList.bindPasswordFileArg.getNameToValueMap().putAll( |
| | | secureArgsList.bindPasswordFileArg.getNameToValueMap()); |
| | | commandBuilder.addArgument(secureArgsList.bindPasswordFileArg); |
| | | } |
| | | else if (bindPassword == null || bindPassword.equals("-")) |
| | | { |
| | |
| | | .unableToReadConnectionParameters(e); |
| | | } |
| | | } |
| | | copySecureArgsList.bindPasswordArg.clearValues(); |
| | | copySecureArgsList.bindPasswordArg.addValue(bindPassword); |
| | | commandBuilder.addObfuscatedArgument( |
| | | copySecureArgsList.bindPasswordArg); |
| | | } |
| | | } |
| | | |
| | |
| | | private ApplicationTrustManager getTrustManagerInternal() |
| | | throws ArgumentException |
| | | { |
| | | // Remove these arguments since this method might be called several times. |
| | | commandBuilder.removeArgument(copySecureArgsList.trustAllArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.trustStorePathArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.trustStorePasswordArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.trustStorePasswordFileArg); |
| | | |
| | | // If we have the trustALL flag, don't do anything |
| | | // just return null |
| | | if (secureArgsList.trustAllArg.isPresent()) |
| | | { |
| | | commandBuilder.addArgument(copySecureArgsList.trustAllArg); |
| | | return null; |
| | | } |
| | | |
| | |
| | | { |
| | | if (result.getValue().equals(TrustMethod.TRUSTALL.getChoice())) |
| | | { |
| | | commandBuilder.addArgument(copySecureArgsList.trustAllArg); |
| | | // If we have the trustALL flag, don't do anything |
| | | // just return null |
| | | return null; |
| | |
| | | // The certificate will be displayed to the user |
| | | askForTrustStore = false; |
| | | trustStoreInMemory = true; |
| | | |
| | | // There is no direct equivalent for this option, so propose the |
| | | // trust all option as command-line argument. |
| | | commandBuilder.addArgument(copySecureArgsList.trustAllArg); |
| | | } |
| | | else |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // If we not trust all server certificates, we have to get info |
| | | // If we do not trust all server certificates, we have to get info |
| | | // about truststore. First get the truststore path. |
| | | truststorePath = secureArgsList.trustStorePathArg.getValue(); |
| | | |
| | | if (app.isInteractive() && !secureArgsList.trustStorePathArg.isPresent() |
| | | && askForTrustStore) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | if (truststorePath != null) |
| | | { |
| | | copySecureArgsList.trustStorePathArg.clearValues(); |
| | | copySecureArgsList.trustStorePathArg.addValue(truststorePath); |
| | | commandBuilder.addArgument(copySecureArgsList.trustStorePathArg); |
| | | } |
| | | |
| | | // Then the truststore password. |
| | | // As the most common case is to have no password for truststore, |
| | | // we don't ask it in the interactive mode. |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | // We've got all the information to get the truststore manager |
| | | try |
| | | { |
| | |
| | | { |
| | | truststore.load(null, null); |
| | | } |
| | | |
| | | if (secureArgsList.trustStorePasswordFileArg.isPresent()) |
| | | { |
| | | copySecureArgsList.trustStorePasswordFileArg.clearValues(); |
| | | copySecureArgsList.trustStorePasswordFileArg.getNameToValueMap().putAll( |
| | | secureArgsList.trustStorePasswordFileArg.getNameToValueMap()); |
| | | commandBuilder.addArgument( |
| | | copySecureArgsList.trustStorePasswordFileArg); |
| | | } |
| | | else |
| | | { |
| | | copySecureArgsList.trustStorePasswordArg.clearValues(); |
| | | copySecureArgsList.trustStorePasswordArg.addValue(truststorePassword); |
| | | commandBuilder.addObfuscatedArgument( |
| | | copySecureArgsList.trustStorePasswordArg); |
| | | } |
| | | |
| | | return new ApplicationTrustManager(truststore); |
| | | } |
| | | catch (Exception e) |
| | |
| | | private KeyManager getKeyManagerInternal() |
| | | throws ArgumentException |
| | | { |
| | | // Remove these arguments since this method might be called several times. |
| | | commandBuilder.removeArgument(copySecureArgsList.certNicknameArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.keyStorePathArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.keyStorePasswordArg); |
| | | commandBuilder.removeArgument(copySecureArgsList.keyStorePasswordFileArg); |
| | | |
| | | // Do we need client side authentication ? |
| | | // If one of the client side authentication args is set, we assume |
| | | // that we |
| | |
| | | } |
| | | } |
| | | |
| | | if (keystorePath != null) |
| | | { |
| | | copySecureArgsList.keyStorePathArg.clearValues(); |
| | | copySecureArgsList.keyStorePathArg.addValue(keystorePath); |
| | | commandBuilder.addArgument(copySecureArgsList.keyStorePathArg); |
| | | } |
| | | |
| | | |
| | | // Then the keystore password. |
| | | keystorePassword = secureArgsList.keyStorePasswordArg.getValue(); |
| | | |
| | |
| | | ApplicationKeyManager akm = new ApplicationKeyManager(keystore, |
| | | keystorePassword.toCharArray()); |
| | | |
| | | |
| | | if (secureArgsList.keyStorePasswordFileArg.isPresent()) |
| | | { |
| | | copySecureArgsList.keyStorePasswordFileArg.clearValues(); |
| | | copySecureArgsList.keyStorePasswordFileArg.getNameToValueMap().putAll( |
| | | secureArgsList.keyStorePasswordFileArg.getNameToValueMap()); |
| | | commandBuilder.addArgument( |
| | | copySecureArgsList.keyStorePasswordFileArg); |
| | | } |
| | | else |
| | | { |
| | | copySecureArgsList.keyStorePasswordArg.clearValues(); |
| | | copySecureArgsList.keyStorePasswordArg.addValue(keystorePassword); |
| | | commandBuilder.addObfuscatedArgument( |
| | | copySecureArgsList.keyStorePasswordArg); |
| | | } |
| | | |
| | | if (certifNickname != null) |
| | | { |
| | | copySecureArgsList.certNicknameArg.clearValues(); |
| | | copySecureArgsList.certNicknameArg.addValue(certifNickname); |
| | | } |
| | | |
| | | if (certifNickname != null) |
| | | { |
| | | return new SelectableCertificateKeyManager(akm, certifNickname); |
| | |
| | | } |
| | | |
| | | /** |
| | | * Populates an a set of LDAP options with state from this interaction. |
| | | * Populates a set of LDAP options with state from this interaction. |
| | | * |
| | | * @param options existing set of options; may be null in which case this |
| | | * method will create a new set of <code>LDAPConnectionOptions</code> |
| | |
| | | } |
| | | |
| | | /** |
| | | * Returns the command builder with the equivalent arguments on the |
| | | * non-interactive mode. |
| | | * @return the command builder with the equivalent arguments on the |
| | | * non-interactive mode. |
| | | */ |
| | | public CommandBuilder getCommandBuilder() |
| | | { |
| | | return commandBuilder; |
| | | } |
| | | |
| | | /** |
| | | * Displays the heading if it was not displayed before. |
| | | * |
| | | */ |