001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2008 Sun Microsystems, Inc.
015 * Portions Copyright 2015 ForgeRock AS.
016 */
017package org.opends.server.protocols.internal;
018
019
020
021import java.net.InetAddress;
022import java.net.Socket;
023import javax.net.SocketFactory;
024
025
026
027/**
028 * This class provides an implementation of a
029 * {@code javax.net.SocketFactory} object that can be used to create
030 * internal LDAP sockets.  This socket factory can be used with some
031 * common LDAP SDKs (e.g., JNDI) in order to allow that SDK to be used
032 * to perform internal operations within OpenDS with minimal changes
033 * needed from what is required to perform external LDAP
034 * communication.
035 */
036@org.opends.server.types.PublicAPI(
037     stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
038     mayInstantiate=true,
039     mayExtend=false,
040     mayInvoke=true)
041public final class InternalLDAPSocketFactory
042       extends SocketFactory
043{
044  /**
045   * Creates a new instance of this internal LDAP socket factory.
046   */
047  public InternalLDAPSocketFactory()
048  {
049    // No implementation is required.
050  }
051
052
053
054  /**
055   * Retrieves the default socket factory that should be used.  Note
056   * that this method must be present for the implementation to work
057   * properly.  Even though the superclass declares the same static
058   * method and static methods are not generally overridden, that is
059   * not the case here because the method is invoked through
060   * reflection, and the superclass returns a bogus socket factory.
061   *
062   * @return  The default socket factory that should be used.
063   */
064  public static SocketFactory getDefault()
065  {
066    return new InternalLDAPSocketFactory();
067  }
068
069
070
071  /**
072   * Creates a new internal LDAP socket.  The provided arguments will
073   * be ignored, as they are not needed by this implementation.
074   *
075   * @param  host  The remote address to which the socket should be
076   *               connected.
077   * @param  port  The remote port to which the socket should be
078   *               connected.
079   *
080   * @return  The created internal LDAP socket.
081   */
082  @Override
083  public Socket createSocket(InetAddress host, int port)
084  {
085    return new InternalLDAPSocket();
086  }
087
088
089
090  /**
091   * Creates a new internal LDAP socket.  The provided arguments will
092   * be ignored, as they are not needed by this implementation.
093   *
094   * @param  host  The remote address to which the socket should be
095   *               connected.
096   * @param  port  The remote port to which the socket should be
097   *               connected.
098   *
099   * @return  The created internal LDAP socket.
100   */
101  @Override
102  public Socket createSocket(String host, int port)
103  {
104    return new InternalLDAPSocket();
105  }
106
107
108
109  /**
110   * Creates a new internal LDAP socket.  The provided arguments will
111   * be ignored, as they are not needed by this implementation.
112   *
113   * @param  host        The remote address to which the socket should
114   *                     be connected.
115   * @param  port        The remote port to which the socket should be
116   *                     connected.
117   * @param  clientHost  The local address to which the socket should
118   *                     be bound.
119   * @param  clientPort  The local port to which the socket should be
120   *                     bound.
121   *
122   * @return  The created internal LDAP socket.
123   */
124  @Override
125  public Socket createSocket(InetAddress host, int port,
126                             InetAddress clientHost, int clientPort)
127  {
128    return new InternalLDAPSocket();
129  }
130
131
132
133  /**
134   * Creates a new internal LDAP socket.  The provided arguments will
135   * be ignored, as they are not needed by this implementation.
136   *
137   * @param  host        The remote address to which the socket should
138   *                     be connected.
139   * @param  port        The remote port to which the socket should be
140   *                     connected.
141   * @param  clientHost  The local address to which the socket should
142   *                     be bound.
143   * @param  clientPort  The local port to which the socket should be
144   *                     bound.
145   *
146   * @return  The created internal LDAP socket.
147   */
148  @Override
149  public Socket createSocket(String host, int port,
150                             InetAddress clientHost, int clientPort)
151  {
152    return new InternalLDAPSocket();
153  }
154
155
156
157  /**
158   * Retrieves a string representation of this internal LDAP socket
159   * factory.
160   *
161   * @return  A string representation of this internal LDAP socket
162   *          factory.
163   */
164  @Override
165  public String toString()
166  {
167    return "InternalLDAPSocketFactory";
168  }
169}
170