incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/socketfactory FtpSocketFactory.java SSLFtpSocketFactory.java
Date Wed, 07 Sep 2005 05:02:22 GMT
rana_b      2005/09/06 22:02:22

  Added:       src/java/org/apache/ftpserver/socketfactory
                        FtpSocketFactory.java SSLFtpSocketFactory.java
  Log:
  Refactored - removed avalon entirely
  
  Revision  Changes    Path
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/socketfactory/FtpSocketFactory.java
  
  Index: FtpSocketFactory.java
  ===================================================================
  // $Id: FtpSocketFactory.java,v 1.1 2005/09/07 05:02:21 rana_b Exp $
  /*
   * Copyright 2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.ftpserver.socketfactory;
  
  import org.apache.ftpserver.ftplet.Configuration;
  import org.apache.ftpserver.ftplet.FtpException;
  import org.apache.ftpserver.ftplet.Logger;
  import org.apache.ftpserver.interfaces.ISocketFactory;
  import org.apache.ftpserver.interfaces.ISsl;
  
  import java.net.InetAddress;
  import java.net.ServerSocket;
  
  
  /**
   * It creates standard FTP server socket.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class FtpSocketFactory implements ISocketFactory {
      
      private Logger m_logger;
      
      private InetAddress m_serverAddress;
      private int m_port;
      private ISsl m_ssl;
      
      /**
       * Set logger
       */
      public void setLogger(Logger logger) {
          m_logger = logger;
      }
      
      /**
       * Configure the server
       */
      public void configure(Configuration conf) throws FtpException {
          try {
              
              // get server address
              String serverAddress = conf.getString("address", null);
              if(serverAddress != null) {
                  m_serverAddress = InetAddress.getByName(serverAddress);
              }
              
              // get server port
              m_port = conf.getInt("port", 21);
              
              // get certificate
              Configuration sslConf = conf.getConfiguration("ssl", null);
              if(sslConf != null) {
                  m_ssl = (ISsl)Class.forName("org.apache.ftpserver.ssl.Ssl").newInstance();
                  m_ssl.configure(sslConf);
              }
          }
          catch(FtpException ex) {
              throw ex;
          }
          catch(Exception ex) {
              m_logger.error("FtpSocketFactory.configure()", ex);
              throw new FtpException("FtpSocketFactory.configure()", ex);
          }
      }
      
      /**
       * Create server socket.
       */
      public ServerSocket createServerSocket() throws Exception {     
          ServerSocket ssocket = null;
          if(m_serverAddress == null) {
              ssocket = new ServerSocket(m_port, 100);
          }
          else {
              new ServerSocket(m_port, 100, m_serverAddress);
          }
          return ssocket;
      }
              
      /**
       * Get server address.
       */
      public InetAddress getServerAddress() {
          return m_serverAddress;
      }
      
      /**
       * Get port number.
       */
      public int getPort() {
          return m_port;
      }
          
      /**
       * Get SSL component.
       */
      public ISsl getSSL() {
          return m_ssl;
      }
      
      /**
       * Release all resources.
       */
      public void dispose() {
      } 
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/socketfactory/SSLFtpSocketFactory.java
  
  Index: SSLFtpSocketFactory.java
  ===================================================================
  // $Id: SSLFtpSocketFactory.java,v 1.1 2005/09/07 05:02:21 rana_b Exp $
  /*
   * Copyright 2004 The Apache Software Foundation
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.ftpserver.socketfactory;
  
  import org.apache.ftpserver.ftplet.Configuration;
  import org.apache.ftpserver.ftplet.FtpException;
  
  import java.net.InetAddress;
  import java.net.ServerSocket;
  
  
  /**
   * It is used in case of implicit SSL connection.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class SSLFtpSocketFactory extends FtpSocketFactory {        
      
      /**
       * Configure secure server related properties. 
       */
      public void configure(Configuration conf) throws FtpException {
          super.configure(conf);
          if(getSSL() == null) {
              throw new FtpException("SSL component not configured.");
          }
      }
      
      /**
       * Create secure server socket.
       */
      public ServerSocket createServerSocket() throws Exception {
          InetAddress addr = getServerAddress();
          int port = getPort();
          return getSSL().createServerSocket(addr, port);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message