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