001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.commons.net.ftp; 019 020 import java.io.IOException; 021 import java.net.InetAddress; 022 import java.net.Socket; 023 import java.net.UnknownHostException; 024 025 import javax.net.SocketFactory; 026 import javax.net.ssl.SSLContext; 027 028 /** 029 * 030 * Implementation of org.apache.commons.net.SocketFactory 031 * 032 * @since 2.0 033 */ 034 public class FTPSSocketFactory extends SocketFactory { 035 036 private final SSLContext context; 037 038 public FTPSSocketFactory(SSLContext context) { 039 this.context = context; 040 } 041 042 // Override the default implementation 043 @Override 044 public Socket createSocket() throws IOException{ 045 return this.context.getSocketFactory().createSocket(); 046 } 047 048 @Override 049 public Socket createSocket(String address, int port) throws UnknownHostException, IOException { 050 return this.context.getSocketFactory().createSocket(address, port); 051 } 052 053 @Override 054 public Socket createSocket(InetAddress address, int port) throws IOException { 055 return this.context.getSocketFactory().createSocket(address, port); 056 } 057 058 @Override 059 public Socket createSocket(String address, int port, InetAddress localAddress, int localPort) throws UnknownHostException, IOException { 060 return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort); 061 } 062 063 @Override 064 public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException { 065 return this.context.getSocketFactory().createSocket(address, port, localAddress, localPort); 066 } 067 068 069 // DEPRECATED METHODS - for API compatibility only - DO NOT USE 070 071 /** @deprecated (2.2) use {@link FTPSServerSocketFactory#createServerSocket(int) instead} */ 072 @Deprecated 073 public java.net.ServerSocket createServerSocket(int port) throws IOException { 074 return this.init(this.context.getServerSocketFactory().createServerSocket(port)); 075 } 076 077 /** @deprecated (2.2) use {@link FTPSServerSocketFactory#createServerSocket(int, int) instead} */ 078 @Deprecated 079 public java.net.ServerSocket createServerSocket(int port, int backlog) throws IOException { 080 return this.init(this.context.getServerSocketFactory().createServerSocket(port, backlog)); 081 } 082 083 /** @deprecated (2.2) use {@link FTPSServerSocketFactory#createServerSocket(int, int, InetAddress) instead} */ 084 @Deprecated 085 public java.net.ServerSocket createServerSocket(int port, int backlog, InetAddress ifAddress) throws IOException { 086 return this.init(this.context.getServerSocketFactory().createServerSocket(port, backlog, ifAddress)); 087 } 088 089 /** @deprecated (2.2) use {@link FTPSServerSocketFactory#init(java.net.ServerSocket)} */ 090 @SuppressWarnings("unused") 091 @Deprecated 092 public java.net.ServerSocket init(java.net.ServerSocket socket) throws IOException { 093 ((javax.net.ssl.SSLServerSocket) socket).setUseClientMode(true); 094 return socket; 095 } 096 097 }