OPENDJ-1654 LDAPOptions should be converted in a SchemaOptions style API
Use Options form forgerock util throughout and merge LDAPOptions and LDAPListenerOption into the classes to which they apply most.
32 files modified
2 files deleted
| | |
| | | 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 static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | |
| | | 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.controls.AuthorizationIdentityRequestControl; |
| | |
| | | import org.forgerock.opendj.ldap.requests.GSSAPISASLBindRequest; |
| | | import org.forgerock.opendj.ldap.requests.PlainSASLBindRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * A connection factory designed for use with command line tools. |
| | |
| | | e); |
| | | } |
| | | |
| | | LDAPOptions options = new LDAPOptions(); |
| | | Options options = Options.defaultOptions(); |
| | | |
| | | if (sslContext != null) { |
| | | options.setSSLContext(sslContext).setUseStartTLS(useStartTLSArg.isPresent()); |
| | | options.set(SSL_CONTEXT, sslContext) |
| | | .set(USE_STARTTLS, useStartTLSArg.isPresent()); |
| | | } |
| | | options.setConnectTimeout(getConnectTimeout(), TimeUnit.MILLISECONDS); |
| | | options.set(CONNECT_TIMEOUT_IN_MILLISECONDS, |
| | | TimeUnit.MILLISECONDS.toMillis(getConnectTimeout())); |
| | | connFactory = new LDAPConnectionFactory(hostNameArg.getValue(), port, options); |
| | | } |
| | | return connFactory; |
| | |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPConnectionFactory</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>%regex[LDAPConnectionFactory\(java\.net\.SocketAddress(, org\.forgerock\.opendj\.ldap\.LDAPOptions)?\)]</method> |
| | | <to>%regex[LDAPConnectionFactory\(java\.net\.InetSocketAddress(, org\.forgerock\.opendj\.ldap\.LDAPOptions)?\)]</to> |
| | | <justification>OPENDJ-1270: Changed constructors to only accept InetSocketAddresses instead of more generic SocketAddress</justification> |
| | | <method>%regex[LDAPConnectionFactory\(java\.lang\.String(.)*(org\.forgerock\.opendj\.ldap\.LDAPOptions)\)]</method> |
| | | <to>%regex[LDAPConnectionFactory\(java\.lang\.String(.)*(org\.forgerock\.util\.Options)\)]</to> |
| | | <justification>OPENDJ-1654: LDAPOptions should be converted in a SchemaOptions style API</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPListener</className> |
| | | <differenceType>7005</differenceType> |
| | | <method>%regex[LDAPListener\(java\.net\.SocketAddress, org\.forgerock\.opendj\.ldap\.ServerConnectionFactory(,\s*org\.forgerock\.opendj\.ldap\.LDAPListenerOptions)?\)]</method> |
| | | <to>%regex[LDAPListener\(java\.net\.InetSocketAddress,\s*org\.forgerock\.opendj\.ldap\.ServerConnectionFactory(,\s*org\.forgerock\.opendj\.ldap\.LDAPListenerOptions)?\)]</to> |
| | | <justification>OPENDJ-1270: Changed constructors to only accept InetSocketAddresses instead of more generic SocketAddress</justification> |
| | | <method>%regex[LDAPListener\((.*), org\.forgerock\.opendj\.ldap\.ServerConnectionFactory(,\s*org\.forgerock\.opendj\.ldap\.LDAPListenerOptions)?\)]</method> |
| | | <to>%regex[LDAPListener\((.*)\s*org\.forgerock\.opendj\.ldap\.ServerConnectionFactory(,\s*org\.forgerock\.util\.Options)?\)]</to> |
| | | <justification>OPENDJ-1654: LDAPOptions should be converted in a SchemaOptions style API</justification> |
| | | </difference> |
| | | |
| | | <difference> |
| | |
| | | <differenceType>8001</differenceType> |
| | | <justification>OPENDJ-1666 Update sdk to forgerock-util 2.0.0</justification> |
| | | </difference> |
| | | |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPListenerOptions</className> |
| | | <differenceType>8001</differenceType> |
| | | <justification>OPENDJ-1654: LDAPOptions should be converted in a SchemaOptions style API</justification> |
| | | </difference> |
| | | <difference> |
| | | <className>org/forgerock/opendj/ldap/LDAPOptions</className> |
| | | <differenceType>8001</differenceType> |
| | | <justification>OPENDJ-1654: LDAPOptions should be converted in a SchemaOptions style API</justification> |
| | | </difference> |
| | | </differences> |
| | |
| | | * |
| | | * CDDL HEADER END |
| | | * |
| | | * Copyright 2014 ForgeRock AS. |
| | | * Copyright 2014-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | | |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.Option; |
| | | |
| | | /** |
| | | * Common options for LDAP clients and listeners. |
| | | */ |
| | | abstract class CommonLDAPOptions<T extends CommonLDAPOptions<T>> { |
| | | /** Default values for options taken from Java properties. */ |
| | | private static final boolean DEFAULT_TCP_NO_DELAY; |
| | | private static final boolean DEFAULT_REUSE_ADDRESS; |
| | | private static final boolean DEFAULT_KEEPALIVE; |
| | | private static final int DEFAULT_LINGER; |
| | | static { |
| | | DEFAULT_LINGER = getIntProperty("org.forgerock.opendj.io.linger", -1); |
| | | DEFAULT_TCP_NO_DELAY = getBooleanProperty("org.forgerock.opendj.io.tcpNoDelay", true); |
| | | DEFAULT_REUSE_ADDRESS = getBooleanProperty("org.forgerock.opendj.io.reuseAddress", true); |
| | | DEFAULT_KEEPALIVE = getBooleanProperty("org.forgerock.opendj.io.keepAlive", true); |
| | | } |
| | | abstract class CommonLDAPOptions { |
| | | |
| | | static boolean getBooleanProperty(final String name, final boolean defaultValue) { |
| | | final String value = System.getProperty(name); |
| | |
| | | } |
| | | } |
| | | |
| | | private DecodeOptions decodeOptions; |
| | | private ClassLoader providerClassLoader; |
| | | private String transportProvider; |
| | | private boolean tcpNoDelay = DEFAULT_TCP_NO_DELAY; |
| | | private boolean keepAlive = DEFAULT_KEEPALIVE; |
| | | private boolean reuseAddress = DEFAULT_REUSE_ADDRESS; |
| | | private int linger = DEFAULT_LINGER; |
| | | |
| | | CommonLDAPOptions() { |
| | | this.decodeOptions = new DecodeOptions(); |
| | | } |
| | | |
| | | CommonLDAPOptions(final CommonLDAPOptions<?> options) { |
| | | this.decodeOptions = new DecodeOptions(options.decodeOptions); |
| | | this.providerClassLoader = options.providerClassLoader; |
| | | this.transportProvider = options.transportProvider; |
| | | this.linger = options.linger; |
| | | this.keepAlive = options.keepAlive; |
| | | this.reuseAddress = options.reuseAddress; |
| | | this.tcpNoDelay = options.tcpNoDelay; |
| | | } |
| | | |
| | | /** Sets the decoding options which will be used to control how requests and responses are decoded. */ |
| | | public static final Option<DecodeOptions> DECODE_OPTIONS = Option.withDefault(new DecodeOptions()); |
| | | /** |
| | | * Returns the decoding options which will be used to control how requests |
| | | * and responses are decoded. |
| | | * |
| | | * @return The decoding options which will be used to control how requests |
| | | * and responses are decoded (never {@code null}). |
| | | */ |
| | | public DecodeOptions getDecodeOptions() { |
| | | return decodeOptions; |
| | | } |
| | | |
| | | /** |
| | | * Returns the value of the {@link java.net.SocketOptions#SO_LINGER |
| | | * SO_LINGER} socket option for new connections. |
| | | * Specifies the class loader which will be used to load the {@link TransportProvider}. |
| | | * <p> |
| | | * The default setting is {@code -1} (disabled) and may be configured using |
| | | * the {@code org.forgerock.opendj.io.linger} property. |
| | | * |
| | | * @return The value of the {@link java.net.SocketOptions#SO_LINGER |
| | | * SO_LINGER} socket option for new connections, or -1 if linger |
| | | * should be disabled. |
| | | */ |
| | | public int getLinger() { |
| | | return linger; |
| | | } |
| | | |
| | | /** |
| | | * Returns the class loader which will be used to load the |
| | | * {@code TransportProvider}. |
| | | * <p> |
| | | * By default this method will return {@code null} indicating that the |
| | | * default class loader will be used. |
| | | * By default the default class loader will be used. |
| | | * <p> |
| | | * The transport provider is loaded using {@code java.util.ServiceLoader}, |
| | | * the JDK service-provider loading facility. The provider must be |
| | |
| | | * class loader from which the file was actually loaded. This method allows |
| | | * to provide a class loader to be used for loading the provider. |
| | | * |
| | | * @return The class loader which will be used when loading the transport |
| | | * provider, or {@code null} if the default class loader should be |
| | | * used. |
| | | */ |
| | | public ClassLoader getProviderClassLoader() { |
| | | return providerClassLoader; |
| | | } |
| | | |
| | | public static final Option<ClassLoader> PROVIDER_CLASS_LOADER = Option.of(ClassLoader.class, null); |
| | | /** |
| | | * Returns the name of the provider used for transport. |
| | | * Specifies the name of the provider to use for transport. |
| | | * <p> |
| | | * Transport providers implement {@code TransportProvider} interface. |
| | | * Transport providers implement {@link TransportProvider} interface. |
| | | * <p> |
| | | * The name should correspond to the name of an existing provider, as |
| | | * returned by {@code TransportProvider#getName()} method. |
| | | * |
| | | * @return The name of transport provider. The name is {@code null} if no |
| | | * specific provider has been selected. In that case, the first |
| | | * provider found will be used. |
| | | */ |
| | | public String getTransportProvider() { |
| | | return transportProvider; |
| | | } |
| | | |
| | | public static final Option<String> TRANSPORT_PROVIDER = Option.of(String.class, null); |
| | | /** |
| | | * Returns the value of the {@link java.net.SocketOptions#SO_KEEPALIVE |
| | | * SO_KEEPALIVE} socket option for new connections. |
| | | * Specifies the value of the {@link java.net.SocketOptions#TCP_NODELAY |
| | | * TCP_NODELAY} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.keepAlive} property. |
| | | * |
| | | * @return The value of the {@link java.net.SocketOptions#SO_KEEPALIVE |
| | | * SO_KEEPALIVE} socket option for new connections. |
| | | * {@code org.forgerock.opendj.io.tcpNoDelay} property. |
| | | */ |
| | | public boolean isKeepAlive() { |
| | | return keepAlive; |
| | | } |
| | | |
| | | public static final Option<Boolean> TCP_NO_DELAY = Option.withDefault( |
| | | getBooleanProperty("org.forgerock.opendj.io.tcpNoDelay", true)); |
| | | /** |
| | | * Returns the value of the {@link java.net.SocketOptions#SO_REUSEADDR |
| | | * Specifies the value of the {@link java.net.SocketOptions#SO_REUSEADDR |
| | | * SO_REUSEADDR} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.reuseAddress} property. |
| | | * |
| | | * @return The value of the {@link java.net.SocketOptions#SO_REUSEADDR |
| | | * SO_REUSEADDR} socket option for new connections. |
| | | */ |
| | | public boolean isReuseAddress() { |
| | | return reuseAddress; |
| | | } |
| | | |
| | | /** |
| | | * Returns the value of the {@link java.net.SocketOptions#TCP_NODELAY |
| | | * TCP_NODELAY} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.tcpNoDelay} property. |
| | | * |
| | | * @return The value of the {@link java.net.SocketOptions#TCP_NODELAY |
| | | * TCP_NODELAY} socket option for new connections. |
| | | */ |
| | | public boolean isTCPNoDelay() { |
| | | return tcpNoDelay; |
| | | } |
| | | |
| | | /** |
| | | * Sets the decoding options which will be used to control how requests and |
| | | * responses are decoded. |
| | | * |
| | | * @param decodeOptions |
| | | * The decoding options which will be used to control how |
| | | * requests and responses are decoded (never {@code null}). |
| | | * @return A reference to this set of options. |
| | | * @throws NullPointerException |
| | | * If {@code decodeOptions} was {@code null}. |
| | | */ |
| | | public T setDecodeOptions(final DecodeOptions decodeOptions) { |
| | | Reject.ifNull(decodeOptions); |
| | | this.decodeOptions = decodeOptions; |
| | | return getThis(); |
| | | } |
| | | |
| | | /** |
| | | * Specifies the value of the {@link java.net.SocketOptions#SO_KEEPALIVE |
| | | * SO_KEEPALIVE} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.keepAlive} property. |
| | | * |
| | | * @param keepAlive |
| | | * The value of the {@link java.net.SocketOptions#SO_KEEPALIVE |
| | | * SO_KEEPALIVE} socket option for new connections. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setKeepAlive(final boolean keepAlive) { |
| | | this.keepAlive = keepAlive; |
| | | return getThis(); |
| | | } |
| | | |
| | | public static final Option<Boolean> REUSE_ADDRESS = Option.withDefault( |
| | | getBooleanProperty("org.forgerock.opendj.io.reuseAddress", true)); |
| | | /** |
| | | * Specifies the value of the {@link java.net.SocketOptions#SO_LINGER |
| | | * SO_LINGER} socket option for new connections. |
| | |
| | | * should be disabled. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setLinger(final int linger) { |
| | | this.linger = linger; |
| | | return getThis(); |
| | | } |
| | | |
| | | public static final Option<Integer> LINGER = Option.withDefault( |
| | | getIntProperty("org.forgerock.opendj.io.linger", -1)); |
| | | /** |
| | | * Sets the class loader which will be used to load the |
| | | * {@code TransportProvider}. |
| | | * <p> |
| | | * The default class loader will be used if no class loader is set using |
| | | * this method. |
| | | * <p> |
| | | * The transport provider is loaded using {@code java.util.ServiceLoader}, |
| | | * the JDK service-provider loading facility. The provider must be |
| | | * accessible from the same class loader that was initially queried to |
| | | * locate the configuration file; note that this is not necessarily the |
| | | * class loader from which the file was actually loaded. This method allows |
| | | * to provide a class loader to be used for loading the provider. |
| | | * |
| | | * @param classLoader |
| | | * The class loader which will be used when loading the transport |
| | | * provider, or {@code null} if the default class loader should |
| | | * be used. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setProviderClassLoader(final ClassLoader classLoader) { |
| | | this.providerClassLoader = classLoader; |
| | | return getThis(); |
| | | } |
| | | |
| | | /** |
| | | * Specifies the value of the {@link java.net.SocketOptions#SO_REUSEADDR |
| | | * SO_REUSEADDR} socket option for new connections. |
| | | * Specifies the value of the {@link java.net.SocketOptions#SO_KEEPALIVE |
| | | * SO_KEEPALIVE} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.reuseAddress} property. |
| | | * {@code org.forgerock.opendj.io.keepAlive} property. |
| | | * |
| | | * @param reuseAddress |
| | | * The value of the {@link java.net.SocketOptions#SO_REUSEADDR |
| | | * SO_REUSEADDR} socket option for new connections. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setReuseAddress(final boolean reuseAddress) { |
| | | this.reuseAddress = reuseAddress; |
| | | return getThis(); |
| | | } |
| | | |
| | | /** |
| | | * Specifies the value of the {@link java.net.SocketOptions#TCP_NODELAY |
| | | * TCP_NODELAY} socket option for new connections. |
| | | * <p> |
| | | * The default setting is {@code true} and may be configured using the |
| | | * {@code org.forgerock.opendj.io.tcpNoDelay} property. |
| | | * |
| | | * @param tcpNoDelay |
| | | * The value of the {@link java.net.SocketOptions#TCP_NODELAY |
| | | * TCP_NODELAY} socket option for new connections. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setTCPNoDelay(final boolean tcpNoDelay) { |
| | | this.tcpNoDelay = tcpNoDelay; |
| | | return getThis(); |
| | | } |
| | | |
| | | /** |
| | | * Sets the name of the provider to use for transport. |
| | | * <p> |
| | | * Transport providers implement {@code TransportProvider} interface. |
| | | * <p> |
| | | * The name should correspond to the name of an existing provider, as |
| | | * returned by {@code TransportProvider#getName()} method. |
| | | * |
| | | * @param providerName |
| | | * The name of transport provider, or {@code null} if no specific |
| | | * provider is preferred. In that case, the first provider found |
| | | * will be used. |
| | | * @return A reference to this set of options. |
| | | */ |
| | | public T setTransportProvider(final String providerName) { |
| | | this.transportProvider = providerName; |
| | | return getThis(); |
| | | } |
| | | |
| | | abstract T getThis(); |
| | | public static final Option<Boolean> KEEPALIVE = Option.withDefault( |
| | | getBooleanProperty("org.forgerock.opendj.io.keepAlive", true)); |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.opendj.ldap.spi.TransportProvider; |
| | | import org.forgerock.util.Option; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * A factory class which can be used to obtain connections to an LDAP Directory |
| | | * Server. |
| | | */ |
| | | public final class LDAPConnectionFactory implements ConnectionFactory { |
| | | public final class LDAPConnectionFactory extends CommonLDAPOptions implements ConnectionFactory { |
| | | |
| | | /** |
| | | * Specifies the SSL context which will be used when initiating connections with the Directory Server. |
| | | * <p> |
| | | * By default no SSL context will be used, indicating that connections will not be secured. |
| | | * If an SSL context is set then connections will be secured using either SSL or StartTLS |
| | | * depending on {@link #USE_STARTTLS}. |
| | | */ |
| | | public static final Option<SSLContext> SSL_CONTEXT = Option.of(SSLContext.class, null); |
| | | /** |
| | | * Specifies whether SSL or StartTLS should be used for securing connections when an SSL context is specified. |
| | | * <p> |
| | | * By default SSL will be used in preference to StartTLS. |
| | | */ |
| | | public static final Option<Boolean> USE_STARTTLS = Option.withDefault(false); |
| | | /** |
| | | * Specifies the operation timeout in milliseconds. If a response is not |
| | | * received from the Directory Server within the timeout period, then the |
| | | * operation will be abandoned and a {@link TimeoutResultException} error |
| | | * result returned. A timeout setting of 0 disables operation timeout limits. |
| | | * <p> |
| | | * The default operation timeout is 0 (no timeout) and may be configured |
| | | * using the {@code org.forgerock.opendj.io.timeout} property. |
| | | */ |
| | | public static final Option<Long> TIMEOUT_IN_MILLISECONDS = Option.of(Long.class, |
| | | (long) getIntProperty("org.forgerock.opendj.io.timeout", 0)); |
| | | /** |
| | | * Specifies the connect timeout spcified in milliseconds. If a connection is not established |
| | | * within the timeout period, then a {@link TimeoutResultException} error result will be returned. |
| | | * <p> |
| | | * The default operation timeout is 10 seconds and may be configured using |
| | | * the {@code org.forgerock.opendj.io.connectTimeout} property. |
| | | * A timeout setting of 0 causes the OS connect timeout to be used. |
| | | */ |
| | | public static final Option<Long> CONNECT_TIMEOUT_IN_MILLISECONDS = Option.of(Long.class, |
| | | (long) getIntProperty("org.forgerock.opendj.io.connectTimeout", 10000)); |
| | | /** |
| | | * Specifies the cipher suites enabled for secure connections with the Directory Server. |
| | | * <p> |
| | | * The suites must be supported by the SSLContext specified by option {@link SSL_CONTEXT}. |
| | | * Only the suites listed in the parameter are enabled for use. |
| | | */ |
| | | public static final Option<List<String>> ENABLED_CIPHER_SUITES = Option.withDefault( |
| | | Collections.<String>emptyList()); |
| | | /** |
| | | * Specifies the protocol versions enabled for secure connections with the |
| | | * Directory Server. |
| | | * <p> |
| | | * The protocols must be supported by the SSLContext specified by option {@link SSL_CONTEXT}. |
| | | * Only the protocols listed in the parameter are enabled for use. |
| | | */ |
| | | public static final Option<List<String>> ENABLED_PROTOCOLS = |
| | | Option.withDefault(Collections.<String>emptyList()); |
| | | |
| | | /** |
| | | * We implement the factory using the pimpl idiom in order to avoid making |
| | | * too many implementation classes public. |
| | |
| | | * connections to the Directory Server at the provided host and port |
| | | * number. |
| | | * |
| | | * @param host |
| | | * The host name. |
| | | * @param port |
| | | * The port number. |
| | | * @throws NullPointerException |
| | | * If {@code host} was {@code null}. |
| | | * @param host The host name. |
| | | * @param port The port number. |
| | | * @throws NullPointerException If {@code host} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final String host, final int port) { |
| | | this(host, port, new LDAPOptions()); |
| | | this(host, port, Options.defaultOptions()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * connections to the Directory Server at the provided host and port |
| | | * number. |
| | | * |
| | | * @param host |
| | | * The host name. |
| | | * @param port |
| | | * The port number. |
| | | * @param options |
| | | * The LDAP options to use when creating connections. |
| | | * @throws NullPointerException |
| | | * If {@code host} or {@code options} was {@code null}. |
| | | * @param host The host name. |
| | | * @param port The port number. |
| | | * @param options The LDAP options to use when creating connections. |
| | | * @throws NullPointerException If {@code host} or {@code options} was {@code null}. |
| | | * @throws ProviderNotFoundException if no provider is available or if the |
| | | * provider requested using options is not found. |
| | | * provider requested using options is not found. |
| | | */ |
| | | public LDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | public LDAPConnectionFactory(final String host, final int port, final Options options) { |
| | | Reject.ifNull(host, options); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.provider = getProvider(TransportProvider.class, options.get(TRANSPORT_PROVIDER), |
| | | options.get(PROVIDER_CLASS_LOADER)); |
| | | this.impl = provider.getLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012-2014 ForgeRock AS. |
| | | * Portions copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.spi.LDAPListenerImpl; |
| | | import org.forgerock.opendj.ldap.spi.TransportProvider; |
| | | import org.forgerock.util.Option; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.Reject; |
| | | |
| | | /** |
| | |
| | | * } |
| | | * </pre> |
| | | */ |
| | | public final class LDAPListener implements Closeable { |
| | | public final class LDAPListener extends CommonLDAPOptions implements Closeable { |
| | | |
| | | /** |
| | | * Specifies the maximum queue length for incoming connections requests. If a |
| | | * connection request arrives when the queue is full, the connection is refused. |
| | | */ |
| | | public static final Option<Integer> BACKLOG = Option.withDefault(50); |
| | | /** |
| | | * Specifies the maximum request size in bytes for incoming LDAP requests. |
| | | * If an incoming request exceeds the limit then the connection will be aborted by the listener. |
| | | * Default value is 5MiB. |
| | | */ |
| | | public static final Option<Integer> MAX_REQUEST_SIZE_BYTES = Option.withDefault(5 * 1024 * 1024); |
| | | |
| | | /** |
| | | * We implement the factory using the pimpl idiom in order have |
| | |
| | | */ |
| | | public LDAPListener(final int port, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory) throws IOException { |
| | | this(port, factory, new LDAPListenerOptions()); |
| | | this(port, factory, Options.defaultOptions()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public LDAPListener(final int port, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options) throws IOException { |
| | | final Options options) throws IOException { |
| | | Reject.ifNull(factory, options); |
| | | final InetSocketAddress address = new InetSocketAddress(port); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.provider = getProvider(TransportProvider.class, options.get(TRANSPORT_PROVIDER), |
| | | options.get(PROVIDER_CLASS_LOADER)); |
| | | this.impl = provider.getLDAPListener(address, factory, options); |
| | | } |
| | | |
| | |
| | | */ |
| | | public LDAPListener(final InetSocketAddress address, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory) throws IOException { |
| | | this(address, factory, new LDAPListenerOptions()); |
| | | this(address, factory, Options.defaultOptions()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public LDAPListener(final InetSocketAddress address, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options) throws IOException { |
| | | final Options options) throws IOException { |
| | | Reject.ifNull(address, factory, options); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.provider = getProvider(TransportProvider.class, options.get(TRANSPORT_PROVIDER), |
| | | options.get(PROVIDER_CLASS_LOADER)); |
| | | this.impl = provider.getLDAPListener(address, factory, options); |
| | | } |
| | | |
| | |
| | | */ |
| | | public LDAPListener(final String host, final int port, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory) throws IOException { |
| | | this(host, port, factory, new LDAPListenerOptions()); |
| | | this(host, port, factory, Options.defaultOptions()); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public LDAPListener(final String host, final int port, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options) throws IOException { |
| | | final Options options) throws IOException { |
| | | Reject.ifNull(host, factory, options); |
| | | final InetSocketAddress address = new InetSocketAddress(host, port); |
| | | this.provider = getProvider(TransportProvider.class, options.getTransportProvider(), |
| | | options.getProviderClassLoader()); |
| | | this.provider = getProvider(TransportProvider.class, options.get(TRANSPORT_PROVIDER), |
| | | options.get(PROVIDER_CLASS_LOADER)); |
| | | this.impl = provider.getLDAPListener(address, factory, options); |
| | | } |
| | | |
| | |
| | | public String toString() { |
| | | return impl.toString(); |
| | | } |
| | | |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.spi; |
| | | |
| | |
| | | import java.net.InetSocketAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * Interface for transport providers, which provide implementation |
| | |
| | | * The LDAP options to use when creating connections. |
| | | * @return an implementation of {@code LDAPConnectionFactory} |
| | | */ |
| | | LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, LDAPOptions options); |
| | | LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, Options options); |
| | | |
| | | /** |
| | | * Returns an implementation of {@code LDAPListener}. |
| | |
| | | * address. |
| | | */ |
| | | LDAPListenerImpl getLDAPListener(InetSocketAddress address, |
| | | ServerConnectionFactory<LDAPClientContext, Integer> factory, LDAPListenerOptions options) |
| | | ServerConnectionFactory<LDAPClientContext, Integer> factory, Options options) |
| | | throws IOException; |
| | | |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.io; |
| | | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.DECODE_OPTIONS; |
| | | |
| | | import java.io.IOException; |
| | | |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | | import org.forgerock.opendj.ldap.DecodeException; |
| | | import org.forgerock.opendj.ldap.Entry; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LinkedHashMapEntry; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.util.Options; |
| | | import org.testng.annotations.DataProvider; |
| | | import org.testng.annotations.Test; |
| | | |
| | |
| | | ExtendedRequest<R> request) throws DecodeException, IOException { |
| | | CancelExtendedRequest cancelRequest = |
| | | CancelExtendedRequest.DECODER.decodeExtendedRequest(request, |
| | | new LDAPOptions().getDecodeOptions()); |
| | | Options.defaultOptions().get(DECODE_OPTIONS)); |
| | | assertThat(cancelRequest.getOID()).isEqualTo(oidCancel); |
| | | assertThat(cancelRequest.getRequestID()).isEqualTo(requestID); |
| | | } |
| | |
| | | |
| | | import com.forgerock.opendj.ldap.controls.AccountUsabilityRequestControl; |
| | | import com.forgerock.opendj.ldap.controls.AccountUsabilityResponseControl; |
| | | import org.forgerock.util.Options; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | |
| | | /** |
| | | * A simple ldap server that manages 1000 entries and used for running |
| | |
| | | return; |
| | | } |
| | | sslContext = new SSLContextBuilder().getSSLContext(); |
| | | listener = |
| | | new LDAPListener(findFreeSocketAddress(), getInstance(), |
| | | new LDAPListenerOptions().setBacklog(4096)); |
| | | listener = new LDAPListener(findFreeSocketAddress(), getInstance(), |
| | | Options.defaultOptions().set(BACKLOG, 4096)); |
| | | isRunning = true; |
| | | } |
| | | |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.spi; |
| | |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.Promise; |
| | | |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | |
| | | */ |
| | | public final class BasicLDAPConnectionFactory implements LDAPConnectionFactoryImpl { |
| | | |
| | | private final LDAPOptions options; |
| | | private final Options options; |
| | | private final String host; |
| | | private final int port; |
| | | |
| | | /** |
| | | * Creates a new LDAP connection factory which does nothing. |
| | | * |
| | | * @param host |
| | | * @param host |
| | | * The address of the Directory Server to connect to. |
| | | * @param port |
| | | * The port of the Directory Server to connect to. |
| | | * @param options |
| | | * The LDAP connection options to use when creating connections. |
| | | */ |
| | | public BasicLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | public BasicLDAPConnectionFactory(final String host, final int port, final Options options) { |
| | | this.host = host; |
| | | this.port = port; |
| | | this.options = new LDAPOptions(options); |
| | | this.options = Options.copyOf(options); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return getClass().getSimpleName() + "(" + host + ':' + port + ')'; |
| | | } |
| | | |
| | | LDAPOptions getLDAPOptions() { |
| | | Options getLDAPOptions() { |
| | | return options; |
| | | } |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap.spi; |
| | |
| | | import java.net.InetSocketAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * Basic LDAP listener implementation to use for tests only. |
| | |
| | | */ |
| | | public BasicLDAPListener(final InetSocketAddress address, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options) throws IOException { |
| | | final Options options) throws IOException { |
| | | this.connectionFactory = factory; |
| | | this.socketAddress = address; |
| | | } |
| | |
| | | // nothing to do |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public InetSocketAddress getSocketAddress() { |
| | | return socketAddress; |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.ldap.spi; |
| | | |
| | |
| | | import java.net.InetSocketAddress; |
| | | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * Provides an basic implementation of a transport provider doing nothing. |
| | |
| | | */ |
| | | public class BasicTransportProvider implements TransportProvider { |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, LDAPOptions options) { |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, Options options) { |
| | | return new BasicLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public LDAPListenerImpl getLDAPListener( |
| | | InetSocketAddress address, |
| | | ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | LDAPListenerOptions options) |
| | | InetSocketAddress address, ServerConnectionFactory<LDAPClientContext, Integer> factory, Options options) |
| | | throws IOException { |
| | | return new BasicLDAPListener(address, factory, options); |
| | | } |
| | |
| | | import org.forgerock.opendj.grizzly.GrizzlyLDAPConnectionFactory; |
| | | import org.forgerock.opendj.grizzly.GrizzlyLDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.opendj.ldap.spi.LDAPListenerImpl; |
| | | import org.forgerock.opendj.ldap.spi.TransportProvider; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * Grizzly transport provider implementation. |
| | |
| | | public class GrizzlyTransportProvider implements TransportProvider { |
| | | |
| | | @Override |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, LDAPOptions options) { |
| | | public LDAPConnectionFactoryImpl getLDAPConnectionFactory(String host, int port, Options options) { |
| | | return new GrizzlyLDAPConnectionFactory(host, port, options); |
| | | } |
| | | |
| | | @Override |
| | | public LDAPListenerImpl getLDAPListener(InetSocketAddress address, |
| | | ServerConnectionFactory<LDAPClientContext, Integer> factory, LDAPListenerOptions options) |
| | | ServerConnectionFactory<LDAPClientContext, Integer> factory, Options options) |
| | | throws IOException { |
| | | return new GrizzlyLDAPListener(address, factory, options); |
| | | } |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.CopyOnWriteArrayList; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.forgerock.opendj.ldap.spi.ExtendedResultLdapPromiseImpl; |
| | | import org.forgerock.opendj.ldap.spi.ResultLdapPromiseImpl; |
| | | import org.forgerock.opendj.ldap.spi.SearchResultLdapPromiseImpl; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.Reject; |
| | | import org.glassfish.grizzly.CompletionHandler; |
| | | import org.glassfish.grizzly.filterchain.Filter; |
| | |
| | | import org.glassfish.grizzly.ssl.SSLEngineConfigurator; |
| | | import org.glassfish.grizzly.ssl.SSLFilter; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.spi.LdapPromises.*; |
| | | |
| | |
| | | |
| | | @Override |
| | | public long handleTimeout(final long currentTime) { |
| | | final long timeout = factory.getLDAPOptions().getTimeout(TimeUnit.MILLISECONDS); |
| | | final long timeout = factory.getLDAPOptions().get(TIMEOUT_IN_MILLISECONDS); |
| | | if (timeout <= 0) { |
| | | return 0; |
| | | } |
| | |
| | | |
| | | @Override |
| | | public long getTimeout() { |
| | | return factory.getLDAPOptions().getTimeout(TimeUnit.MILLISECONDS); |
| | | return factory.getLDAPOptions().get(TIMEOUT_IN_MILLISECONDS); |
| | | } |
| | | |
| | | /** |
| | |
| | | return newMsgID; |
| | | } |
| | | |
| | | LDAPOptions getLDAPOptions() { |
| | | Options getLDAPOptions() { |
| | | return factory.getLDAPOptions(); |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2014 ForgeRock AS |
| | | * Portions Copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.List; |
| | | import java.util.concurrent.ExecutionException; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.TimeoutChecker; |
| | |
| | | import org.forgerock.opendj.ldap.requests.StartTLSExtendedRequest; |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.spi.LDAPConnectionFactoryImpl; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | |
| | | |
| | | import static org.forgerock.opendj.grizzly.DefaultTCPNIOTransport.*; |
| | | import static org.forgerock.opendj.grizzly.GrizzlyUtils.*; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.TimeoutChecker.*; |
| | | |
| | |
| | | final GrizzlyLDAPConnection connection = adaptConnection(result); |
| | | |
| | | // Plain connection. |
| | | if (options.getSSLContext() == null) { |
| | | if (options.get(SSL_CONTEXT) == null) { |
| | | thenOnResult(connection); |
| | | return; |
| | | } |
| | |
| | | return; |
| | | } |
| | | |
| | | if (options.useStartTLS()) { |
| | | List<String> protocols = options.get(ENABLED_PROTOCOLS); |
| | | List<String> suites = options.get(ENABLED_CIPHER_SUITES); |
| | | if (options.get(USE_STARTTLS)) { |
| | | // Chain StartTLS extended request. |
| | | final StartTLSExtendedRequest startTLS = |
| | | Requests.newStartTLSExtendedRequest(options.getSSLContext()); |
| | | startTLS.addEnabledCipherSuite(options.getEnabledCipherSuites().toArray( |
| | | new String[options.getEnabledCipherSuites().size()])); |
| | | startTLS.addEnabledProtocol(options.getEnabledProtocols().toArray( |
| | | new String[options.getEnabledProtocols().size()])); |
| | | Requests.newStartTLSExtendedRequest(options.get(SSL_CONTEXT)); |
| | | startTLS.addEnabledCipherSuite(suites.toArray(new String[suites.size()])); |
| | | startTLS.addEnabledProtocol(protocols.toArray(new String[protocols.size()])); |
| | | |
| | | connection.extendedRequestAsync(startTLS).thenOnResult(new ResultHandler<ExtendedResult>() { |
| | | @Override |
| | |
| | | } else { |
| | | // Install SSL/TLS layer. |
| | | try { |
| | | connection.startTLS(options.getSSLContext(), options.getEnabledProtocols(), |
| | | options.getEnabledCipherSuites(), new EmptyCompletionHandler<SSLEngine>() { |
| | | connection.startTLS(options.get(SSL_CONTEXT), protocols, suites, |
| | | new EmptyCompletionHandler<SSLEngine>() { |
| | | @Override |
| | | public void completed(final SSLEngine result) { |
| | | thenOnResult(connection); |
| | |
| | | |
| | | private GrizzlyLDAPConnection adaptConnection( |
| | | final org.glassfish.grizzly.Connection<?> connection) { |
| | | configureConnection(connection, options.isTCPNoDelay(), options.isKeepAlive(), options |
| | | .isReuseAddress(), options.getLinger(), logger); |
| | | configureConnection(connection, logger, options); |
| | | |
| | | final GrizzlyLDAPConnection ldapConnection = |
| | | new GrizzlyLDAPConnection(connection, GrizzlyLDAPConnectionFactory.this); |
| | |
| | | |
| | | @Override |
| | | public long getTimeout() { |
| | | return options.getConnectTimeout(TimeUnit.MILLISECONDS); |
| | | return options.get(CONNECT_TIMEOUT_IN_MILLISECONDS); |
| | | } |
| | | } |
| | | |
| | | private final LDAPClientFilter clientFilter; |
| | | private final FilterChain defaultFilterChain; |
| | | private final LDAPOptions options; |
| | | private final Options options; |
| | | private final String host; |
| | | private final int port; |
| | | |
| | |
| | | * Creates a new LDAP connection factory based on Grizzly which can be used |
| | | * to create connections to the Directory Server at the provided host and |
| | | * port address using provided connection options. |
| | | * |
| | | * @param host |
| | | * @param host |
| | | * The hostname of the Directory Server to connect to. |
| | | * @param port |
| | | * The port number of the Directory Server to connect to. |
| | | * @param options |
| | | * The LDAP connection options to use when creating connections. |
| | | */ |
| | | public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options) { |
| | | public GrizzlyLDAPConnectionFactory(final String host, final int port, final Options options) { |
| | | this(host, port, options, null); |
| | | } |
| | | |
| | |
| | | * to create connections to the Directory Server at the provided host and |
| | | * port address using provided connection options and provided TCP |
| | | * transport. |
| | | * |
| | | * @param host |
| | | * @param host |
| | | * The hostname of the Directory Server to connect to. |
| | | * @param port |
| | | * The port number of the Directory Server to connect to. |
| | | * @param options |
| | | * The LDAP connection options to use when creating connections. |
| | | * The LDAP connection options to use when creating connections. |
| | | * @param transport |
| | | * Grizzly TCP Transport NIO implementation to use for |
| | | * connections. If {@code null}, default transport will be used. |
| | | * Grizzly TCP Transport NIO implementation to use for |
| | | * connections. If {@code null}, default transport will be used. |
| | | */ |
| | | public GrizzlyLDAPConnectionFactory(final String host, final int port, final LDAPOptions options, |
| | | public GrizzlyLDAPConnectionFactory(final String host, final int port, final Options options, |
| | | TCPNIOTransport transport) { |
| | | this.transport = DEFAULT_TRANSPORT.acquireIfNull(transport); |
| | | this.host = host; |
| | | this.port = port; |
| | | this.options = new LDAPOptions(options); |
| | | this.clientFilter = new LDAPClientFilter(this.options.getDecodeOptions(), 0); |
| | | this.options = options; |
| | | this.clientFilter = new LDAPClientFilter(options.get(DECODE_OPTIONS), 0); |
| | | this.defaultFilterChain = |
| | | buildFilterChain(this.transport.get().getProcessor(), clientFilter); |
| | | } |
| | |
| | | return timeoutChecker.get(); |
| | | } |
| | | |
| | | LDAPOptions getLDAPOptions() { |
| | | Options getLDAPOptions() { |
| | | return options; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2011-2014 ForgeRock AS |
| | | * Portions copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import static org.forgerock.opendj.grizzly.DefaultTCPNIOTransport.DEFAULT_TRANSPORT; |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.InetSocketAddress; |
| | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.opendj.ldap.spi.LDAPListenerImpl; |
| | | import org.forgerock.util.Options; |
| | | import org.glassfish.grizzly.filterchain.FilterChain; |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOBindingHandler; |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection; |
| | |
| | | private final TCPNIOServerConnection serverConnection; |
| | | private final AtomicBoolean isClosed = new AtomicBoolean(); |
| | | private final InetSocketAddress socketAddress; |
| | | private final LDAPListenerOptions options; |
| | | private final Options options; |
| | | |
| | | /** |
| | | * Creates a new LDAP listener implementation which will listen for LDAP |
| | |
| | | */ |
| | | public GrizzlyLDAPListener(final InetSocketAddress address, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options) throws IOException { |
| | | final Options options) throws IOException { |
| | | this(address, factory, options, null); |
| | | } |
| | | |
| | |
| | | */ |
| | | public GrizzlyLDAPListener(final InetSocketAddress address, |
| | | final ServerConnectionFactory<LDAPClientContext, Integer> factory, |
| | | final LDAPListenerOptions options, TCPNIOTransport transport) throws IOException { |
| | | final Options options, TCPNIOTransport transport) throws IOException { |
| | | this.transport = DEFAULT_TRANSPORT.acquireIfNull(transport); |
| | | this.connectionFactory = factory; |
| | | this.options = new LDAPListenerOptions(options); |
| | | this.options = Options.copyOf(options); |
| | | final LDAPServerFilter serverFilter = |
| | | new LDAPServerFilter(this, this.options.getDecodeOptions(), this.options |
| | | .getMaxRequestSize()); |
| | | new LDAPServerFilter(this, options.get(DECODE_OPTIONS), options.get(MAX_REQUEST_SIZE_BYTES)); |
| | | final FilterChain ldapChain = |
| | | GrizzlyUtils.buildFilterChain(this.transport.get().getProcessor(), serverFilter); |
| | | final TCPNIOBindingHandler bindingHandler = |
| | | TCPNIOBindingHandler.builder(this.transport.get()).processor(ldapChain).build(); |
| | | this.serverConnection = bindingHandler.bind(address, options.getBacklog()); |
| | | this.serverConnection = bindingHandler.bind(address, options.get(BACKLOG)); |
| | | |
| | | /* |
| | | * Get the socket address now, ensuring that the host is the same as the |
| | |
| | | return connectionFactory; |
| | | } |
| | | |
| | | LDAPListenerOptions getLDAPListenerOptions() { |
| | | Options getLDAPListenerOptions() { |
| | | return options; |
| | | } |
| | | } |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | import org.forgerock.opendj.io.LDAPReader; |
| | | import org.forgerock.opendj.io.LDAPWriter; |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.util.Options; |
| | | import org.glassfish.grizzly.Connection; |
| | | import org.glassfish.grizzly.Processor; |
| | | import org.glassfish.grizzly.ThreadCache; |
| | |
| | | import org.glassfish.grizzly.nio.transport.TCPNIOConnection; |
| | | import org.glassfish.grizzly.ssl.SSLFilter; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | |
| | | /** |
| | | * Common utility methods. |
| | | */ |
| | |
| | | ThreadCache.putToCache(WRITER_INDEX, writer); |
| | | } |
| | | |
| | | static void configureConnection(final Connection<?> connection, final boolean tcpNoDelay, |
| | | final boolean keepAlive, final boolean reuseAddress, final int linger, |
| | | final LocalizedLogger logger) { |
| | | static void configureConnection(final Connection<?> connection, final LocalizedLogger logger, Options options) { |
| | | /* |
| | | * Test shows that its much faster with non block writes but risk |
| | | * running out of memory if the server is slow. |
| | |
| | | // Configure socket options. |
| | | final SocketChannel channel = (SocketChannel) ((TCPNIOConnection) connection).getChannel(); |
| | | final Socket socket = channel.socket(); |
| | | final boolean tcpNoDelay = options.get(TCP_NO_DELAY); |
| | | final boolean keepAlive = options.get(KEEPALIVE); |
| | | final boolean reuseAddress = options.get(REUSE_ADDRESS); |
| | | final int linger = options.get(LINGER); |
| | | try { |
| | | socket.setTcpNoDelay(tcpNoDelay); |
| | | } catch (final SocketException e) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2014 ForgeRock AS. |
| | | * Portions Copyright 2012-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | import org.glassfish.grizzly.filterchain.FilterChainContext; |
| | | import org.glassfish.grizzly.filterchain.NextAction; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.opendj.ldap.ResultCode.*; |
| | | import static org.forgerock.opendj.ldap.responses.Responses.*; |
| | | |
| | |
| | | private <R extends ExtendedResult> void handleExtendedResult0( |
| | | final GrizzlyLDAPConnection conn, final ExtendedResultLdapPromiseImpl<R> promise, |
| | | final ExtendedResult result) throws DecodeException { |
| | | final R decodedResponse = promise.decodeResult(result, conn.getLDAPOptions().getDecodeOptions()); |
| | | final R decodedResponse = promise.decodeResult(result, conn.getLDAPOptions().get(DECODE_OPTIONS)); |
| | | |
| | | if (result.getResultCode() == ResultCode.SUCCESS |
| | | && promise.getRequest() instanceof StartTLSExtendedRequest) { |
| | |
| | | import org.forgerock.opendj.ldap.DecodeOptions; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.LdapResultHandler; |
| | |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.Reject; |
| | | import org.glassfish.grizzly.Connection; |
| | | import org.glassfish.grizzly.Grizzly; |
| | |
| | | @Override |
| | | public NextAction handleAccept(final FilterChainContext ctx) throws IOException { |
| | | final Connection<?> connection = ctx.getConnection(); |
| | | LDAPListenerOptions options = listener.getLDAPListenerOptions(); |
| | | configureConnection(connection, options.isTCPNoDelay(), options.isKeepAlive(), options |
| | | .isReuseAddress(), options.getLinger(), logger); |
| | | Options options = listener.getLDAPListenerOptions(); |
| | | configureConnection(connection, logger, options); |
| | | try { |
| | | final ClientContextImpl clientContext = new ClientContextImpl(connection); |
| | | final ServerConnection<Integer> serverConn = |
| | |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | | import java.net.InetSocketAddress; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.concurrent.Callable; |
| | | import java.util.concurrent.CountDownLatch; |
| | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LDAPServer; |
| | | import org.forgerock.opendj.ldap.MockConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.opendj.ldap.schema.SchemaBuilder; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.forgerock.opendj.ldap.Connections.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.ENABLED_CIPHER_SUITES; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.forgerock.opendj.ldap.spi.LdapPromises.*; |
| | | import static org.mockito.Matchers.*; |
| | |
| | | // LDAPConnectionFactory with startTLS |
| | | SSLContext sslContext = |
| | | new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()).getSSLContext(); |
| | | LDAPOptions options = new LDAPOptions().setSSLContext(sslContext).setUseStartTLS(true) |
| | | .addEnabledCipherSuite( |
| | | new String[] { "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", |
| | | "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", |
| | | "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", |
| | | "SSL_DH_anon_WITH_DES_CBC_SHA", "SSL_DH_anon_WITH_RC4_128_MD5", |
| | | "TLS_DH_anon_WITH_AES_128_CBC_SHA", |
| | | "TLS_DH_anon_WITH_AES_256_CBC_SHA" }); |
| | | Options options = Options.defaultOptions().set(ENABLED_CIPHER_SUITES, |
| | | new ArrayList<String>(Arrays.asList( |
| | | "SSL_DH_anon_EXPORT_WITH_DES40_CBC_SHA", |
| | | "SSL_DH_anon_EXPORT_WITH_RC4_40_MD5", |
| | | "SSL_DH_anon_WITH_3DES_EDE_CBC_SHA", |
| | | "SSL_DH_anon_WITH_DES_CBC_SHA", |
| | | "SSL_DH_anon_WITH_RC4_128_MD5", |
| | | "TLS_DH_anon_WITH_AES_128_CBC_SHA", |
| | | "TLS_DH_anon_WITH_AES_256_CBC_SHA"))); |
| | | factories[5][0] = new LDAPConnectionFactory(serverAddress.getHostName(), serverAddress.getPort(), options); |
| | | |
| | | // startTLS + SASL confidentiality |
| | |
| | | import org.forgerock.opendj.ldap.ConnectionFactory; |
| | | import org.forgerock.opendj.ldap.Connections; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LdapPromise; |
| | | import org.forgerock.opendj.ldap.IntermediateResponseHandler; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.MockConnectionEventListener; |
| | | import org.forgerock.opendj.ldap.ProviderNotFoundException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.forgerock.opendj.ldap.requests.UnbindRequest; |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.NeverThrowsException; |
| | | import org.forgerock.util.promise.Promise; |
| | |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.forgerock.opendj.ldap.requests.Requests.*; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.mockito.Matchers.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | |
| | | private final AtomicReference<LDAPClientContext> context = new AtomicReference<>(); |
| | | private final LDAPListener server = createServer(); |
| | | private final InetSocketAddress socketAddress = server.getSocketAddress(); |
| | | private final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), new LDAPOptions().setTimeout(1, TimeUnit.MILLISECONDS)); |
| | | public final ConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), Options.defaultOptions().set(TIMEOUT_IN_MILLISECONDS, 1L)); |
| | | private final ConnectionFactory pool = Connections.newFixedConnectionPool(factory, 10); |
| | | private volatile ServerConnection<Integer> serverConnection; |
| | | |
| | |
| | | public void testClientSideConnectTimeout() throws Exception { |
| | | // Use an non-local unreachable network address. |
| | | final ConnectionFactory factory = new LDAPConnectionFactory("10.20.30.40", 1389, |
| | | new LDAPOptions().setConnectTimeout(1, TimeUnit.MILLISECONDS)); |
| | | Options.defaultOptions().set(CONNECT_TIMEOUT_IN_MILLISECONDS, 1L)); |
| | | try { |
| | | for (int i = 0; i < ITERATIONS; i++) { |
| | | final PromiseImpl<LdapException, NeverThrowsException> promise = PromiseImpl.create(); |
| | |
| | | @Test(expectedExceptions = { ProviderNotFoundException.class }, |
| | | expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*") |
| | | public void testCreateLDAPConnectionFactoryFailureProviderNotFound() throws Exception { |
| | | LDAPOptions options = new LDAPOptions().setTransportProvider("unknown"); |
| | | Options options = Options.defaultOptions().set(TRANSPORT_PROVIDER, "unknown"); |
| | | InetSocketAddress socketAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), options); |
| | |
| | | @Test |
| | | public void testCreateLDAPConnectionFactoryWithCustomClassLoader() throws Exception { |
| | | // test no exception is thrown, which means transport provider is correctly loaded |
| | | LDAPOptions options = new LDAPOptions().setProviderClassLoader(Thread.currentThread().getContextClassLoader()); |
| | | Options options = |
| | | Options.defaultOptions().set(PROVIDER_CLASS_LOADER, Thread.currentThread().getContextClassLoader()); |
| | | InetSocketAddress socketAddress = findFreeSocketAddress(); |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(socketAddress.getHostName(), |
| | | socketAddress.getPort(), options); |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013-2014 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.grizzly; |
| | |
| | | import static org.mockito.Mockito.verify; |
| | | import static org.mockito.Mockito.verifyZeroInteractions; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.TIMEOUT_IN_MILLISECONDS; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SdkTestCase; |
| | |
| | | import org.forgerock.opendj.ldap.controls.PersistentSearchRequestControl; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.mockito.ArgumentCaptor; |
| | | import org.testng.annotations.Test; |
| | |
| | | * triggering the timeout. |
| | | */ |
| | | LDAPConnectionFactory factory = new LDAPConnectionFactory(address.getHostName(), |
| | | address.getPort(), new LDAPOptions().setTimeout(100, TimeUnit.SECONDS)); |
| | | address.getPort(), Options.defaultOptions().set( |
| | | TIMEOUT_IN_MILLISECONDS, TimeUnit.SECONDS.toMillis((long) 100))); |
| | | GrizzlyLDAPConnection connection = (GrizzlyLDAPConnection) factory.getConnection(); |
| | | try { |
| | | SearchRequest request = |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2014 ForgeRock AS. |
| | | * Portions Copyright 2011-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ProviderNotFoundException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | |
| | | import org.forgerock.opendj.ldap.responses.ExtendedResult; |
| | | import org.forgerock.opendj.ldap.responses.Responses; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.PromiseImpl; |
| | | import org.testng.annotations.AfterClass; |
| | | import org.testng.annotations.BeforeClass; |
| | |
| | | import static org.fest.assertions.Assertions.*; |
| | | import static org.fest.assertions.Fail.*; |
| | | import static org.forgerock.opendj.ldap.LdapException.*; |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | import static org.forgerock.opendj.ldap.TestCaseUtils.*; |
| | | import static org.mockito.Mockito.*; |
| | | |
| | |
| | | @SuppressWarnings("unchecked") |
| | | @Test |
| | | public void testCreateLDAPListenerWithCustomClassLoader() throws Exception { |
| | | // test no exception is thrown, which means transport provider is |
| | | // correctly loaded |
| | | LDAPListenerOptions options = new LDAPListenerOptions(). |
| | | setProviderClassLoader(Thread.currentThread().getContextClassLoader()); |
| | | // test no exception is thrown, which means transport provider is correctly loaded |
| | | Options options = Options.defaultOptions().set(PROVIDER_CLASS_LOADER, |
| | | Thread.currentThread().getContextClassLoader()); |
| | | LDAPListener listener = new LDAPListener(findFreeSocketAddress(), |
| | | mock(ServerConnectionFactory.class), options); |
| | | listener.close(); |
| | |
| | | @Test(expectedExceptions = { ProviderNotFoundException.class }, |
| | | expectedExceptionsMessageRegExp = "^The requested provider 'unknown' .*") |
| | | public void testCreateLDAPListenerFailureProviderNotFound() throws Exception { |
| | | LDAPListenerOptions options = new LDAPListenerOptions().setTransportProvider("unknown"); |
| | | Options options = Options.defaultOptions().set(TRANSPORT_PROVIDER, "unknown"); |
| | | LDAPListener listener = new LDAPListener(findFreeSocketAddress(), mock(ServerConnectionFactory.class), options); |
| | | listener.close(); |
| | | } |
| | |
| | | final MockServerConnection serverConnection = new MockServerConnection(); |
| | | final MockServerConnectionFactory factory = |
| | | new MockServerConnectionFactory(serverConnection); |
| | | final LDAPListenerOptions options = new LDAPListenerOptions().setMaxRequestSize(2048); |
| | | final Options options = Options.defaultOptions().set(MAX_REQUEST_SIZE_BYTES, 2048); |
| | | final LDAPListener listener = new LDAPListener(findFreeSocketAddress(), factory, options); |
| | | |
| | | Connection connection = null; |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2013 ForgeRock AS. |
| | | * Copyright 2013-2015 ForgeRock AS. |
| | | */ |
| | | package org.forgerock.opendj.grizzly; |
| | | |
| | |
| | | import org.forgerock.opendj.io.LDAPReader; |
| | | import org.forgerock.opendj.io.LDAPReaderWriterTestCase; |
| | | import org.forgerock.opendj.io.LDAPWriter; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.util.Options; |
| | | import org.glassfish.grizzly.memory.HeapMemoryManager; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.DECODE_OPTIONS; |
| | | |
| | | /** |
| | | * Tests for LDAPWriter / LDAPReader classes using specific implementations of |
| | |
| | | |
| | | @Override |
| | | protected LDAPReader<? extends ASN1Reader> getLDAPReader() { |
| | | return GrizzlyUtils.createReader(new LDAPOptions().getDecodeOptions(), |
| | | 0, new HeapMemoryManager()); |
| | | return GrizzlyUtils.createReader(Options.defaultOptions().get(DECODE_OPTIONS), 0, new HeapMemoryManager()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ModificationType; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.TrustManagers; |
| | | import org.forgerock.opendj.ldap.requests.ModifyRequest; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.util.Options; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import java.nio.charset.Charset; |
| | |
| | | * For SSL the connection factory needs SSL context options. This |
| | | * implementation simply trusts all server certificates. |
| | | */ |
| | | private static LDAPOptions getTrustAllOptions() throws GeneralSecurityException { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | SSLContext sslContext = |
| | | new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()) |
| | | .getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | return lo; |
| | | private static Options getTrustAllOptions() throws GeneralSecurityException { |
| | | Options options = Options.defaultOptions(); |
| | | SSLContext sslContext = new SSLContextBuilder() |
| | | .setTrustManager(TrustManagers.trustAll()).getSSLContext(); |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | return options; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandlerFactory; |
| | | import org.forgerock.opendj.ldap.RoundRobinLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.opendj.ldap.requests.Requests; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * An LDAP load balancing proxy which forwards requests to one or more remote |
| | |
| | | |
| | | // --- JCite listener --- |
| | | // Create listener. |
| | | final LDAPListenerOptions options = new LDAPListenerOptions().setBacklog(4096); |
| | | final Options options = Options.defaultOptions().set(BACKLOG, 4096); |
| | | LDAPListener listener = null; |
| | | try { |
| | | listener = new LDAPListener(localAddress, localPort, connectionHandler, options); |
| | |
| | | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.Modification; |
| | | import org.forgerock.opendj.ldap.RequestContext; |
| | | import org.forgerock.opendj.ldap.RequestHandler; |
| | |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * This example is based on the {@link Proxy}. This example does no load |
| | |
| | | |
| | | @Override |
| | | public void handleSearch(final RequestContext requestContext, final SearchRequest request, |
| | | final IntermediateResponseHandler intermediateResponseHandler, final SearchResultHandler entryHandler, |
| | | final LdapResultHandler<Result> resultHandler) { |
| | | final IntermediateResponseHandler intermediateResponseHandler, |
| | | final SearchResultHandler entryHandler, final LdapResultHandler<Result> resultHandler) { |
| | | nextHandler.handleSearch(requestContext, rewrite(request), intermediateResponseHandler, |
| | | new SearchResultHandler() { |
| | | @Override |
| | |
| | | Connections.newServerConnectionFactory(proxyFactory); |
| | | |
| | | // Create listener. |
| | | final LDAPListenerOptions options = new LDAPListenerOptions().setBacklog(4096); |
| | | final Options options = Options.defaultOptions().set(BACKLOG, 4096); |
| | | LDAPListener listener = null; |
| | | try { |
| | | listener = new LDAPListener(localAddress, localPort, connectionHandler, options); |
| | |
| | | */ |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.USE_STARTTLS; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.SSL_CONTEXT; |
| | | |
| | | |
| | | import java.security.GeneralSecurityException; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | 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 org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * An example client application which performs SASL PLAIN authentication to a |
| | |
| | | * certificate that is not in the system trust store. To simplify this |
| | | * implementation trusts all server certificates. |
| | | */ |
| | | private static LDAPOptions getTrustAllOptions() throws GeneralSecurityException { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | private static Options getTrustAllOptions() throws GeneralSecurityException { |
| | | Options options = Options.defaultOptions(); |
| | | SSLContext sslContext = |
| | | new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()).getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | lo.setUseStartTLS(true); |
| | | return lo; |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | options.set(USE_STARTTLS, true); |
| | | return options; |
| | | } |
| | | |
| | | private static String host; |
| | |
| | | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPListener.BACKLOG; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | |
| | |
| | | import org.forgerock.opendj.ldap.KeyManagers; |
| | | import org.forgerock.opendj.ldap.LDAPClientContext; |
| | | import org.forgerock.opendj.ldap.LDAPListener; |
| | | import org.forgerock.opendj.ldap.LDAPListenerOptions; |
| | | import org.forgerock.opendj.ldap.MemoryBackend; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | |
| | | import org.forgerock.opendj.ldap.ServerConnectionFactory; |
| | | import org.forgerock.opendj.ldap.TrustManagers; |
| | | import org.forgerock.opendj.ldif.LDIFEntryReader; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * An LDAP directory server which exposes data contained in an LDIF file. This |
| | |
| | | // Create listener. |
| | | LDAPListener listener = null; |
| | | try { |
| | | final LDAPListenerOptions options = new LDAPListenerOptions().setBacklog(4096); |
| | | final Options options = Options.defaultOptions().set(BACKLOG, 4096); |
| | | |
| | | if (keyStoreFileName != null) { |
| | | // Configure SSL/TLS and enable it when connections are |
| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2011-2014 ForgeRock AS |
| | | * Copyright 2011-2015 ForgeRock AS |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.security.GeneralSecurityException; |
| | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.TrustManagers; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * An example client application which performs simple authentication to a |
| | |
| | | * @return SSL context options |
| | | * @throws GeneralSecurityException Could not load the trust store |
| | | */ |
| | | private static LDAPOptions getTrustOptions(final String hostname, |
| | | final String truststore, |
| | | final String storepass) |
| | | private static Options getTrustOptions(final String hostname, |
| | | final String truststore, |
| | | final String storepass) |
| | | throws GeneralSecurityException { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | Options options = Options.defaultOptions(); |
| | | |
| | | TrustManager trustManager = null; |
| | | try { |
| | |
| | | if (trustManager != null) { |
| | | SSLContext sslContext = new SSLContextBuilder() |
| | | .setTrustManager(trustManager).getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | } |
| | | |
| | | lo.setUseStartTLS(useStartTLS); |
| | | options.set(USE_STARTTLS, useStartTLS); |
| | | |
| | | return lo; |
| | | return options; |
| | | } |
| | | // --- JCite trust options --- |
| | | |
| | |
| | | * certificate that is not in the system trust store. To simplify this |
| | | * implementation trusts all server certificates. |
| | | */ |
| | | private static LDAPOptions getTrustAllOptions() throws GeneralSecurityException { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | private static Options getTrustAllOptions() throws GeneralSecurityException { |
| | | Options options = Options.defaultOptions(); |
| | | SSLContext sslContext = |
| | | new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()) |
| | | .getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | lo.setUseStartTLS(useStartTLS); |
| | | return lo; |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | options.set(USE_STARTTLS, useStartTLS); |
| | | return options; |
| | | } |
| | | // --- JCite trust all --- |
| | | |
| | |
| | | package org.forgerock.opendj.examples; |
| | | |
| | | import static org.forgerock.util.Utils.closeSilently; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.USE_STARTTLS; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.SSL_CONTEXT; |
| | | |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | |
| | | import org.forgerock.opendj.ldap.responses.BindResult; |
| | | import org.forgerock.opendj.ldap.responses.Result; |
| | | import org.forgerock.util.AsyncFunction; |
| | | import org.forgerock.util.Options; |
| | | import org.forgerock.util.promise.ExceptionHandler; |
| | | import org.forgerock.util.promise.Promise; |
| | | import org.forgerock.util.promise.ResultHandler; |
| | |
| | | * @param storepass Password for the trust store |
| | | * @return SSL context options if SSL or StartTLS is used. |
| | | */ |
| | | private static LDAPOptions getTrustOptions(final String hostname, |
| | | final String truststore, |
| | | final String storepass) { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | private static Options getTrustOptions(final String hostname, |
| | | final String truststore, |
| | | final String storepass) { |
| | | Options options = Options.defaultOptions(); |
| | | if (useSSL || useStartTLS) { |
| | | TrustManager trustManager = null; |
| | | try { |
| | |
| | | if (trustManager != null) { |
| | | SSLContext sslContext = new SSLContextBuilder() |
| | | .setTrustManager(trustManager).getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | } |
| | | } catch (Exception e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_CONNECT_ERROR.intValue()); |
| | | } |
| | | lo.setUseStartTLS(useStartTLS); |
| | | options.set(USE_STARTTLS, useStartTLS); |
| | | } |
| | | return lo; |
| | | return options; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return SSL context options to trust all certificates without checking. |
| | | */ |
| | | private static LDAPOptions getTrustAllOptions() { |
| | | LDAPOptions lo = new LDAPOptions(); |
| | | private static Options getTrustAllOptions() { |
| | | Options options = Options.defaultOptions(); |
| | | try { |
| | | SSLContext sslContext = |
| | | new SSLContextBuilder().setTrustManager(TrustManagers.trustAll()) |
| | | .getSSLContext(); |
| | | lo.setSSLContext(sslContext); |
| | | lo.setUseStartTLS(useStartTLS); |
| | | options.set(SSL_CONTEXT, sslContext); |
| | | options.set(USE_STARTTLS, useStartTLS); |
| | | } catch (GeneralSecurityException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_CONNECT_ERROR.intValue()); |
| | | } |
| | | return lo; |
| | | return options; |
| | | } |
| | | |
| | | private static String host; |
| | |
| | | import static org.forgerock.opendj.ldap.schema.CoreSchema.getEntryUUIDAttributeType; |
| | | import static org.forgerock.opendj.rest2ldap.ReadOnUpdatePolicy.CONTROLS; |
| | | import static org.forgerock.opendj.rest2ldap.Utils.ensureNotNull; |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.opendj.ldap.LDAPListener.*; |
| | | |
| | | import java.io.IOException; |
| | | import java.security.GeneralSecurityException; |
| | |
| | | import org.forgerock.opendj.ldap.FailoverLoadBalancingAlgorithm; |
| | | import org.forgerock.opendj.ldap.Filter; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.LinkedAttribute; |
| | | import org.forgerock.opendj.ldap.MultipleEntriesFoundException; |
| | |
| | | import org.forgerock.opendj.ldap.requests.SearchRequest; |
| | | import org.forgerock.opendj.ldap.schema.AttributeType; |
| | | import org.forgerock.opendj.ldap.schema.Schema; |
| | | import org.forgerock.util.Options; |
| | | |
| | | /** |
| | | * Provides core factory methods and builders for constructing LDAP resource |
| | |
| | | final ConnectionSecurity connectionSecurity = |
| | | configuration.get("connectionSecurity").defaultTo(ConnectionSecurity.NONE).asEnum( |
| | | ConnectionSecurity.class); |
| | | final LDAPOptions options = new LDAPOptions(); |
| | | options.setProviderClassLoader(providerClassLoader); |
| | | final Options options = Options.defaultOptions().set(PROVIDER_CLASS_LOADER, providerClassLoader); |
| | | if (connectionSecurity != ConnectionSecurity.NONE) { |
| | | try { |
| | | // Configure SSL. |
| | |
| | | password != null ? password.toCharArray() : null, type)); |
| | | break; |
| | | } |
| | | options.setSSLContext(builder.getSSLContext()); |
| | | options.setUseStartTLS(connectionSecurity == ConnectionSecurity.STARTTLS); |
| | | options.set(SSL_CONTEXT, builder.getSSLContext()); |
| | | options.set(USE_STARTTLS, |
| | | connectionSecurity == ConnectionSecurity.STARTTLS); |
| | | } catch (GeneralSecurityException | IOException e) { |
| | | // Rethrow as unchecked exception. |
| | | throw new IllegalArgumentException(e); |
| | |
| | | private static ConnectionFactory parseLDAPServers(final JsonValue config, |
| | | final BindRequest bindRequest, final int connectionPoolSize, |
| | | final int heartBeatIntervalSeconds, final int heartBeatTimeoutMilliSeconds, |
| | | final LDAPOptions options) { |
| | | final Options options) { |
| | | final List<ConnectionFactory> servers = new ArrayList<>(config.size()); |
| | | for (final JsonValue server : config) { |
| | | final String host = server.get("hostname").required().asString(); |
| | |
| | | import static com.forgerock.opendj.cli.ArgumentConstants.*; |
| | | import static com.forgerock.opendj.cli.CliMessages.*; |
| | | import static com.forgerock.opendj.cli.Utils.*; |
| | | |
| | | import static org.forgerock.opendj.ldap.LDAPConnectionFactory.*; |
| | | import static org.forgerock.util.Utils.*; |
| | | |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_ERROR_READING_SERVER_CONFIGURATION; |
| | | import static org.opends.messages.QuickSetupMessages.INFO_NOT_AVAILABLE_LABEL; |
| | |
| | | import org.forgerock.opendj.ldap.AuthorizationException; |
| | | import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.LDAPOptions; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SSLContextBuilder; |
| | | import org.forgerock.opendj.ldap.TrustManagers; |
| | | import org.forgerock.util.Options; |
| | | import org.opends.admin.ads.util.ApplicationTrustManager; |
| | | import org.opends.guitools.controlpanel.datamodel.BackendDescriptor; |
| | | import org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor; |
| | |
| | | |
| | | // This connection should always be secure. useSSL = true. |
| | | Connection connection = null; |
| | | final LDAPOptions options = new LDAPOptions(); |
| | | options.setConnectTimeout(ci.getConnectTimeout(), TimeUnit.MILLISECONDS); |
| | | final Options options = Options.defaultOptions(); |
| | | options.set(CONNECT_TIMEOUT_IN_MILLISECONDS, |
| | | TimeUnit.MILLISECONDS.toMillis((long) ci.getConnectTimeout())); |
| | | LDAPConnectionFactory factory = null; |
| | | while (true) |
| | | { |
| | |
| | | final SSLContextBuilder sslBuilder = new SSLContextBuilder(); |
| | | sslBuilder.setTrustManager(trustManager == null ? TrustManagers.trustAll() : trustManager); |
| | | sslBuilder.setKeyManager(keyManager); |
| | | options.setUseStartTLS(ci.useStartTLS()); |
| | | options.setSSLContext(sslBuilder.getSSLContext()); |
| | | options.set(USE_STARTTLS, ci.useStartTLS()); |
| | | options.set(SSL_CONTEXT, sslBuilder.getSSLContext()); |
| | | |
| | | factory = new LDAPConnectionFactory(hostName, portNumber, options); |
| | | connection = factory.getConnection(); |