| | |
| | | */ |
| | | package com.forgerock.opendj.cli; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.cli.CliConstants.DEFAULT_LDAP_PORT; |
| | | import static com.forgerock.opendj.cli.Utils.getHostNameForLdapUrl; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.KeyManagers; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.TrustManagers; |
| | |
| | | import org.forgerock.opendj.ldap.requests.PlainSASLBindRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | |
| | | import static java.util.concurrent.TimeUnit.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.Connections.*; |
| | | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | /** |
| | | * A connection factory designed for use with command line tools. |
| | | */ |
| | |
| | | /** The Logger. */ |
| | | static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | private static final long DEFAULT_TIMEOUT_SECONDS = 3; |
| | | |
| | | /** The 'hostName' global argument. */ |
| | | private final StringArgument hostNameArg; |
| | | private StringArgument hostNameArg; |
| | | |
| | | /** The 'port' global argument. */ |
| | | private final IntegerArgument portArg; |
| | | private IntegerArgument portArg; |
| | | |
| | | /** The 'bindDN' global argument. */ |
| | | private final StringArgument bindNameArg; |
| | | private StringArgument bindNameArg; |
| | | |
| | | /** The 'bindPasswordFile' global argument. */ |
| | | private final FileBasedArgument bindPasswordFileArg; |
| | | private FileBasedArgument bindPasswordFileArg; |
| | | |
| | | /** The 'password' value. */ |
| | | private char[] password; |
| | | |
| | | /** The 'bindPassword' global argument. */ |
| | | private final StringArgument bindPasswordArg; |
| | | private StringArgument bindPasswordArg; |
| | | |
| | | /** The 'connectTimeOut' global argument. */ |
| | | private final IntegerArgument connectTimeOut; |
| | | private IntegerArgument connectTimeOut; |
| | | |
| | | /** The 'trustAllArg' global argument. */ |
| | | private final BooleanArgument trustAllArg; |
| | | private BooleanArgument trustAllArg; |
| | | |
| | | /** The 'trustStore' global argument. */ |
| | | private final StringArgument trustStorePathArg; |
| | | private StringArgument trustStorePathArg; |
| | | |
| | | /** The 'trustStorePassword' global argument. */ |
| | | private final StringArgument trustStorePasswordArg; |
| | | private StringArgument trustStorePasswordArg; |
| | | |
| | | /** The 'trustStorePasswordFile' global argument. */ |
| | | private final FileBasedArgument trustStorePasswordFileArg; |
| | | private FileBasedArgument trustStorePasswordFileArg; |
| | | |
| | | /** The 'keyStore' global argument. */ |
| | | private final StringArgument keyStorePathArg; |
| | | private StringArgument keyStorePathArg; |
| | | |
| | | /** The 'keyStorePassword' global argument. */ |
| | | private final StringArgument keyStorePasswordArg; |
| | | private StringArgument keyStorePasswordArg; |
| | | |
| | | /** The 'keyStorePasswordFile' global argument. */ |
| | | private final FileBasedArgument keyStorePasswordFileArg; |
| | | private FileBasedArgument keyStorePasswordFileArg; |
| | | |
| | | /** The 'certNicknameArg' global argument. */ |
| | | private final StringArgument certNicknameArg; |
| | | private StringArgument certNicknameArg; |
| | | |
| | | /** The 'useSSLArg' global argument. */ |
| | | private final BooleanArgument useSSLArg; |
| | | private BooleanArgument useSSLArg; |
| | | |
| | | /** The 'useStartTLSArg' global argument. */ |
| | | private final BooleanArgument useStartTLSArg; |
| | | private BooleanArgument useStartTLSArg; |
| | | |
| | | /** Argument indicating a SASL option. */ |
| | | private final StringArgument saslOptionArg; |
| | | private StringArgument saslOptionArg; |
| | | |
| | | /** |
| | | * Whether to request that the server return the authorization ID in the |
| | |
| | | } |
| | | } |
| | | } catch (final Exception e) { |
| | | throw new ArgumentException(ERR_LDAP_CONN_CANNOT_INITIALIZE_SSL.get(e.toString()), e); |
| | | throw new ArgumentException(ERR_LDAP_CONN_CANNOT_INITIALIZE_SSL.get(e.toString()), |
| | | e); |
| | | } |
| | | |
| | | LDAPOptions options = new LDAPOptions(); |
| | |
| | | options.setSSLContext(sslContext).setUseStartTLS(useStartTLSArg.isPresent()); |
| | | } |
| | | options.setConnectTimeout(getConnectTimeout(), TimeUnit.MILLISECONDS); |
| | | connFactory = newLDAPConnectionFactory(hostNameArg.getValue(), port, options); |
| | | connFactory = new LDAPConnectionFactory(hostNameArg.getValue(), port, options); |
| | | } |
| | | return connFactory; |
| | | } |
| | |
| | | authenticatedConnFactory = getConnectionFactory(); |
| | | final BindRequest bindRequest = getBindRequest(); |
| | | if (bindRequest != null) { |
| | | app.setBindRequest(bindRequest); |
| | | authenticatedConnFactory = newLDAPConnectionFactory(hostNameArg.getValue(), port, |
| | | new LDAPOptions().setBindRequest(bindRequest).setTimeout(DEFAULT_TIMEOUT_SECONDS, SECONDS)); |
| | | authenticatedConnFactory = new AuthenticatedConnectionFactory(authenticatedConnFactory, bindRequest); |
| | | } |
| | | } |
| | | return authenticatedConnFactory; |