You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by ng...@apache.org on 2008/08/17 21:52:49 UTC

svn commit: r686637 [8/16] - in /mina/ftpserver/trunk: core/src/main/java/org/apache/ftpserver/ core/src/main/java/org/apache/ftpserver/command/ core/src/main/java/org/apache/ftpserver/config/spring/ core/src/main/java/org/apache/ftpserver/filesystem/ ...

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/ListArgumentParser.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/ListArgumentParser.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/ListArgumentParser.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/ListArgumentParser.java Sun Aug 17 12:52:42 2008
@@ -15,93 +15,96 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */ 
+ */
 package org.apache.ftpserver.listing;
 
 import java.util.StringTokenizer;
 
 /**
  * Parses a list argument (e.g. for LIST or NLST) into a {@link ListArgument}
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class ListArgumentParser {
-    
+
     /**
      * Parse the argument
-     * @param argument The argument string
+     * 
+     * @param argument
+     *            The argument string
      * @return The parsed argument
-     * @throws IllegalArgumentException If the argument string is incorrectly formated
+     * @throws IllegalArgumentException
+     *             If the argument string is incorrectly formated
      */
     public static ListArgument parse(String argument) {
         String file = "./";
         String options = "";
         String pattern = "*";
-        
+
         // find options and file name (may have regular expression)
-        if(argument != null) {
+        if (argument != null) {
             argument = argument.trim();
             StringBuffer optionsSb = new StringBuffer(4);
             StringBuffer fileSb = new StringBuffer(16);
             StringTokenizer st = new StringTokenizer(argument, " ", true);
-            while(st.hasMoreTokens()) {
+            while (st.hasMoreTokens()) {
                 String token = st.nextToken();
-                
-                if(fileSb.length() != 0) {
+
+                if (fileSb.length() != 0) {
                     // file name started - append to file name buffer
                     fileSb.append(token);
-                }
-                else if(token.equals(" ")) {
+                } else if (token.equals(" ")) {
                     // delimiter and file not started - ignore
                     continue;
-                } 
-                else if(token.charAt(0) == '-') {
-                    // token and file name not started - append to options buffer
+                } else if (token.charAt(0) == '-') {
+                    // token and file name not started - append to options
+                    // buffer
                     if (token.length() > 1) {
                         optionsSb.append(token.substring(1));
                     }
-                }
-                else {
+                } else {
                     // filename - append to the filename buffer
                     fileSb.append(token);
                 }
             }
-            
-            if(fileSb.length() != 0) {
+
+            if (fileSb.length() != 0) {
                 file = fileSb.toString();
             }
             options = optionsSb.toString();
         }
-        
+
         int slashIndex = file.lastIndexOf('/');
-        if(slashIndex == -1) {
-            if(containsPattern(file)) {
+        if (slashIndex == -1) {
+            if (containsPattern(file)) {
                 pattern = file;
                 file = "./";
             }
-        } else if( slashIndex != (file.length() -1) ) {
-            String after = file.substring(slashIndex+1);
-            
-            if(containsPattern(after)) {
-                pattern = file.substring(slashIndex+1);
-                file = file.substring(0, slashIndex+1);
-            }            
-            
-            if(containsPattern(file)) {
-                throw new IllegalArgumentException("Directory path can not contain regular expression");
+        } else if (slashIndex != (file.length() - 1)) {
+            String after = file.substring(slashIndex + 1);
+
+            if (containsPattern(after)) {
+                pattern = file.substring(slashIndex + 1);
+                file = file.substring(0, slashIndex + 1);
+            }
+
+            if (containsPattern(file)) {
+                throw new IllegalArgumentException(
+                        "Directory path can not contain regular expression");
             }
         }
 
-        if( "*".equals(pattern) || "".equals(pattern) ) {
+        if ("*".equals(pattern) || "".equals(pattern)) {
             pattern = null;
         }
-        
-        
+
         return new ListArgument(file, pattern, options.toCharArray());
     }
 
     private static boolean containsPattern(String file) {
-        return file.indexOf('*') > -1 || 
-               file.indexOf('?') > -1 ||
-               file.indexOf('[') > -1;
+        return file.indexOf('*') > -1 || file.indexOf('?') > -1
+                || file.indexOf('[') > -1;
 
     }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/MLSTFileFormater.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/MLSTFileFormater.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/MLSTFileFormater.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/MLSTFileFormater.java Sun Aug 17 12:52:42 2008
@@ -23,70 +23,69 @@
 
 /**
  * Formats files according to the MLST specification
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class MLSTFileFormater implements FileFormater {
 
-    private static final String[] DEFAULT_TYPES = new String[] {"Size", "Modify", "Type"};
+    private static final String[] DEFAULT_TYPES = new String[] { "Size",
+            "Modify", "Type" };
+
+    private final static char[] NEWLINE = { '\r', '\n' };
 
-    private final static char[] NEWLINE  = {'\r', '\n'};
-    
     private String[] selectedTypes = DEFAULT_TYPES;
-    
+
     /**
-     * @param selectedTypes The types to show in the formated file
+     * @param selectedTypes
+     *            The types to show in the formated file
      */
     public MLSTFileFormater(String[] selectedTypes) {
-        if(selectedTypes != null) {
+        if (selectedTypes != null) {
             this.selectedTypes = selectedTypes.clone();
         }
     }
-    
+
     /**
      * @see FileFormater#format(FileObject)
      */
     public String format(FileObject file) {
         StringBuffer sb = new StringBuffer();
-        
-        for(int i=0; i<selectedTypes.length; ++i) {
+
+        for (int i = 0; i < selectedTypes.length; ++i) {
             String type = selectedTypes[i];
-            if(type.equalsIgnoreCase("size")) {
+            if (type.equalsIgnoreCase("size")) {
                 sb.append("Size=");
                 sb.append(String.valueOf(file.getSize()));
                 sb.append(';');
-            }
-            else if(type.equalsIgnoreCase("modify")) {
-                String timeStr = DateUtils.getFtpDate( file.getLastModified() );
+            } else if (type.equalsIgnoreCase("modify")) {
+                String timeStr = DateUtils.getFtpDate(file.getLastModified());
                 sb.append("Modify=");
                 sb.append(timeStr);
                 sb.append(';');
-            }
-            else if(type.equalsIgnoreCase("type")) {
-                if(file.isFile()) {
+            } else if (type.equalsIgnoreCase("type")) {
+                if (file.isFile()) {
                     sb.append("Type=file;");
-                }
-                else if(file.isDirectory()) {
+                } else if (file.isDirectory()) {
                     sb.append("Type=dir;");
                 }
-            }
-            else if(type.equalsIgnoreCase("perm")) {
+            } else if (type.equalsIgnoreCase("perm")) {
                 sb.append("Perm=");
-                if(file.hasReadPermission()) {
-                    if(file.isFile()) {
+                if (file.hasReadPermission()) {
+                    if (file.isFile()) {
                         sb.append('r');
-                    }
-                    else if(file.isDirectory()) {
+                    } else if (file.isDirectory()) {
                         sb.append('e');
                         sb.append('l');
                     }
                 }
-                if(file.hasWritePermission()) {
-                    if(file.isFile()) {
+                if (file.hasWritePermission()) {
+                    if (file.isFile()) {
                         sb.append('a');
                         sb.append('d');
                         sb.append('f');
                         sb.append('w');
-                    }
-                    else if(file.isDirectory()) {
+                    } else if (file.isDirectory()) {
                         sb.append('f');
                         sb.append('p');
                         sb.append('c');
@@ -98,7 +97,7 @@
         }
         sb.append(' ');
         sb.append(file.getShortName());
-        
+
         sb.append(NEWLINE);
 
         return sb.toString();

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/NLSTFileFormater.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/NLSTFileFormater.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/NLSTFileFormater.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/NLSTFileFormater.java Sun Aug 17 12:52:42 2008
@@ -22,11 +22,14 @@
 
 /**
  * Formats files according to the NLST specification
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class NLSTFileFormater implements FileFormater {
 
-    private final static char[] NEWLINE  = {'\r', '\n'};
-    
+    private final static char[] NEWLINE = { '\r', '\n' };
+
     /**
      * @see FileFormater#format(FileObject)
      */

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/RegexFileFilter.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/RegexFileFilter.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/RegexFileFilter.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/RegexFileFilter.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */ 
+ */
 package org.apache.ftpserver.listing;
 
 import org.apache.ftpserver.ftplet.FileObject;
@@ -23,15 +23,21 @@
 
 /**
  * Selects files which short name matches a regular expression
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class RegexFileFilter implements FileFilter {
 
     private RegularExpr regex;
+
     private FileFilter wrappedFilter;
-    
+
     /**
      * Constructor with a regular expression
-     * @param regex The regular expression to select by
+     * 
+     * @param regex
+     *            The regular expression to select by
      */
     public RegexFileFilter(String regex) {
         this.regex = new RegularExpr(regex);
@@ -39,23 +45,26 @@
 
     /**
      * Constructor with a wrapped filter, allows for chaining filters
-     * @param regex The regular expression to select by
-     * @param wrappedFilter The {@link FileFilter} to wrap
+     * 
+     * @param regex
+     *            The regular expression to select by
+     * @param wrappedFilter
+     *            The {@link FileFilter} to wrap
      */
     public RegexFileFilter(String regex, FileFilter wrappedFilter) {
         this(regex);
-        
+
         this.wrappedFilter = wrappedFilter;
     }
-    
+
     /**
      * @see FileFilter#accept(FileObject)
      */
     public boolean accept(FileObject file) {
-        if(wrappedFilter != null && !wrappedFilter.accept(file)) {
+        if (wrappedFilter != null && !wrappedFilter.accept(file)) {
             return false;
         }
-        
+
         return regex.isMatch(file.getShortName());
     }
 

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/VisibleFileFilter.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/VisibleFileFilter.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/VisibleFileFilter.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/listing/VisibleFileFilter.java Sun Aug 17 12:52:42 2008
@@ -15,18 +15,21 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */ 
+ */
 package org.apache.ftpserver.listing;
 
 import org.apache.ftpserver.ftplet.FileObject;
 
 /**
  * Selects files that are visible
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class VisibleFileFilter implements FileFilter {
 
     private FileFilter wrappedFilter;
-    
+
     /**
      * Default constructor
      */
@@ -36,20 +39,22 @@
 
     /**
      * Constructor with a wrapped filter, allows for chaining filters
-     * @param wrappedFilter The {@link FileFilter} to wrap
+     * 
+     * @param wrappedFilter
+     *            The {@link FileFilter} to wrap
      */
     public VisibleFileFilter(FileFilter wrappedFilter) {
         this.wrappedFilter = wrappedFilter;
     }
-    
+
     /**
      * @see FileFilter#accept(FileObject)
      */
     public boolean accept(FileObject file) {
-        if(wrappedFilter != null && !wrappedFilter.accept(file)) {
+        if (wrappedFilter != null && !wrappedFilter.accept(file)) {
             return false;
         }
-        
+
         return !file.isHidden();
     }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/CommandLine.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.main;
 
@@ -24,11 +24,13 @@
 import org.springframework.core.io.FileSystemResource;
 
 /**
- * This class is the starting point for the FtpServer when it is started
- * using the command line mode.
+ * This class is the starting point for the FtpServer when it is started using
+ * the command line mode.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
-public 
-class CommandLine {
+public class CommandLine {
 
     /**
      * The purpose of this class is to allow the final user to start the
@@ -41,9 +43,10 @@
     /**
      * This method is the FtpServer starting point when running by using the
      * command line mode.
-     *
-     * @param args The first element of this array must specify the kind of
-     *             configuration to be used to start the server.
+     * 
+     * @param args
+     *            The first element of this array must specify the kind of
+     *            configuration to be used to start the server.
      */
     public static void main(String args[]) {
 
@@ -51,7 +54,7 @@
 
             // get configuration
             FtpServer server = getConfiguration(args);
-            if(server == null) {
+            if (server == null) {
                 return;
             }
 
@@ -61,8 +64,7 @@
 
             // add shutdown hook if possible
             addShutdownHook(server);
-        }
-        catch(Exception ex) {
+        } catch (Exception ex) {
             ex.printStackTrace();
         }
     }
@@ -89,12 +91,16 @@
      * Print the usage message.
      */
     private static void usage() {
-        System.err.println("Usage: java org.apache.ftpserver.main.CommandLine [OPTION] [CONFIGFILE]");
-        System.err.println("Starts FtpServer using the default configuration of the ");
+        System.err
+                .println("Usage: java org.apache.ftpserver.main.CommandLine [OPTION] [CONFIGFILE]");
+        System.err
+                .println("Starts FtpServer using the default configuration of the ");
         System.err.println("configuration file if provided.");
         System.err.println("");
-        System.err.println("      --default              use the default configuration, ");
-        System.err.println("                             also used if no command line argument is given ");
+        System.err
+                .println("      --default              use the default configuration, ");
+        System.err
+                .println("                             also used if no command line argument is given ");
         System.err.println("  -?, --help                 print this message");
     }
 
@@ -104,43 +110,48 @@
     private static FtpServer getConfiguration(String[] args) throws Exception {
 
         FtpServer server = null;
-        if(args.length == 0) {
+        if (args.length == 0) {
             System.out.println("Using default configuration");
             server = new FtpServer();
-        } else if( (args.length == 1) && args[0].equals("-default") ) {
+        } else if ((args.length == 1) && args[0].equals("-default")) {
             // supported for backwards compatibility, but not documented
-            System.out.println("The -default switch is deprecated, please use --default instead");
+            System.out
+                    .println("The -default switch is deprecated, please use --default instead");
             System.out.println("Using default configuration");
             server = new FtpServer();
-        } else if( (args.length == 1) && args[0].equals("--default") ) {
+        } else if ((args.length == 1) && args[0].equals("--default")) {
             System.out.println("Using default configuration");
             server = new FtpServer();
-        } else if( (args.length == 1) && args[0].equals("--help") ) {
+        } else if ((args.length == 1) && args[0].equals("--help")) {
             usage();
-        } else if( (args.length == 1) && args[0].equals("-?") ) {
+        } else if ((args.length == 1) && args[0].equals("-?")) {
             usage();
-        } else if( args.length == 1 ) {
-            System.out.println("Using XML configuration file " + args[0] + "...");
-            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(args[0]));
-            if(bf.containsBean("server")) {
+        } else if (args.length == 1) {
+            System.out.println("Using XML configuration file " + args[0]
+                    + "...");
+            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(
+                    args[0]));
+            if (bf.containsBean("server")) {
                 server = (FtpServer) bf.getBean("server");
             } else {
                 String[] beanNames = bf.getBeanNamesForType(FtpServer.class);
-                if(beanNames.length == 1) {
+                if (beanNames.length == 1) {
                     server = (FtpServer) bf.getBean(beanNames[0]);
-                } else if(beanNames.length > 1) {
-                    System.out.println("Using the first server defined in the configuration, named " + beanNames[0]);
+                } else if (beanNames.length > 1) {
+                    System.out
+                            .println("Using the first server defined in the configuration, named "
+                                    + beanNames[0]);
                     server = (FtpServer) bf.getBean(beanNames[0]);
                 } else {
-                    System.err.println("XML configuration does not contain a server configuration");
+                    System.err
+                            .println("XML configuration does not contain a server configuration");
                 }
-                
+
             }
-        }
-        else {
+        } else {
             usage();
         }
-        
+
         return server;
     }
 }
\ No newline at end of file

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/main/Daemon.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.main;
 
@@ -27,48 +27,52 @@
 import org.springframework.core.io.FileSystemResource;
 
 /**
- * Invokes FtpServer as a daemon, running in the background. 
- * Used for example for the Windows service.
+ * Invokes FtpServer as a daemon, running in the background. Used for example
+ * for the Windows service.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class Daemon {
 
     private static final Logger LOG = LoggerFactory.getLogger(Daemon.class);
-    
+
     private static FtpServer server;
+
     private static Object lock = new Object();
-    
+
     public static void main(String[] args) throws Exception {
-        try{
-            if(server == null) {
+        try {
+            if (server == null) {
                 // get configuration
                 FtpServer server = getConfiguration(args);
-                if(server == null) {
+                if (server == null) {
                     LOG.error("No configuration provided");
                     throw new FtpException("No configuration provided");
                 }
             }
-            
+
             String command = "start";
-            
-            if(args != null && args.length > 0) {
+
+            if (args != null && args.length > 0) {
                 command = args[0];
             }
-            
-            if(command.equals("start")) {
+
+            if (command.equals("start")) {
                 LOG.info("Starting FTP server daemon");
                 server.start();
-                
+
                 synchronized (lock) {
                     lock.wait();
                 }
-            } else if(command.equals("stop")) {
+            } else if (command.equals("stop")) {
                 synchronized (lock) {
                     lock.notify();
                 }
                 LOG.info("Stopping FTP server daemon");
                 server.stop();
             }
-        } catch(Throwable t) {
+        } catch (Throwable t) {
             LOG.error("Daemon error", t);
         }
     }
@@ -77,40 +81,44 @@
      * Get the configuration object.
      */
     private static FtpServer getConfiguration(String[] args) throws Exception {
-    
+
         FtpServer server = null;
-        if(args == null || args.length < 2) {
+        if (args == null || args.length < 2) {
             LOG.info("Using default configuration....");
             server = new FtpServer();
-        } else if( (args.length == 2) && args[1].equals("-default") ) {
+        } else if ((args.length == 2) && args[1].equals("-default")) {
             // supported for backwards compatibility, but not documented
-            System.out.println("The -default switch is deprecated, please use --default instead");
+            System.out
+                    .println("The -default switch is deprecated, please use --default instead");
             LOG.info("Using default configuration....");
             server = new FtpServer();
-        } else if( (args.length == 2) && args[1].equals("--default") ) {
+        } else if ((args.length == 2) && args[1].equals("--default")) {
             LOG.info("Using default configuration....");
             server = new FtpServer();
-        }
-        else if( args.length == 2 ) {
+        } else if (args.length == 2) {
             LOG.info("Using xml configuration file " + args[1] + "...");
-            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(args[1]));
-            if(bf.containsBean("server")) {
+            XmlBeanFactory bf = new XmlBeanFactory(new FileSystemResource(
+                    args[1]));
+            if (bf.containsBean("server")) {
                 server = (FtpServer) bf.getBean("server");
             } else {
                 String[] beanNames = bf.getBeanNamesForType(FtpServer.class);
-                if(beanNames.length == 1) {
+                if (beanNames.length == 1) {
                     server = (FtpServer) bf.getBean(beanNames[0]);
-                } else if(beanNames.length > 1) {
-                    System.out.println("Using the first server defined in the configuration, named " + beanNames[0]);
+                } else if (beanNames.length > 1) {
+                    System.out
+                            .println("Using the first server defined in the configuration, named "
+                                    + beanNames[0]);
                     server = (FtpServer) bf.getBean(beanNames[0]);
                 } else {
-                    System.err.println("XML configuration does not contain a server configuration");
+                    System.err
+                            .println("XML configuration does not contain a server configuration");
                 }
             }
         } else {
             throw new FtpException("Invalid configuration option");
         }
-        
+
         return server;
     }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/message/MessageResourceImpl.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/message/MessageResourceImpl.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/message/MessageResourceImpl.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/message/MessageResourceImpl.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.message;
 
@@ -37,64 +37,69 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
- * Class to get ftp server reply messages. This supports i18n.
- * Basic message search path is: 
+ * Class to get ftp server reply messages. This supports i18n. Basic message
+ * search path is:
  * 
  * Custom Language Specific Messages -> Default Language Specific Messages ->
  * Custom Common Messages -> Default Common Messages -> null (not found)
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
-public 
-class MessageResourceImpl implements MessageResource {
+public class MessageResourceImpl implements MessageResource {
+
+    private final Logger LOG = LoggerFactory
+            .getLogger(MessageResourceImpl.class);
 
-    private final Logger LOG = LoggerFactory.getLogger(MessageResourceImpl.class);
-    
     private final static String RESOURCE_PATH = "org/apache/ftpserver/message/";
-    
+
     private String[] languages;
+
     private Map<String, PropertiesPair> messages;
+
     private File customMessageDirectory;
 
     private boolean isConfigured = false;
 
     private static class PropertiesPair {
         public Properties defaultProperties = new Properties();
+
         public Properties customProperties = new Properties();
-    } 
-    
+    }
+
     public String[] getLanguages() {
-        if(languages != null) {
+        if (languages != null) {
             return languages.clone();
         } else {
             return null;
         }
-	}
+    }
+
+    public void setLanguages(String[] languages) {
+        if (languages != null) {
+            this.languages = languages.clone();
+        } else {
+            this.languages = null;
+        }
+    }
+
+    public File getCustomMessageDirectory() {
+        return customMessageDirectory;
+    }
 
-	public void setLanguages(String[] languages) {
-	    if(languages != null) {
-	        this.languages = languages.clone();
-	    } else {
-	        this.languages = null;
-	    }
-	}
-
-	public File getCustomMessageDirectory() {
-		return customMessageDirectory;
-	}
-
-	public void setCustomMessageDirectory(File customMessageDirectory) {
-		this.customMessageDirectory = customMessageDirectory;
-	}
+    public void setCustomMessageDirectory(File customMessageDirectory) {
+        this.customMessageDirectory = customMessageDirectory;
+    }
 
-	/**
+    /**
      * Configure - load properties file.
      */
     public void configure() {
         // populate different properties
         messages = new HashMap<String, PropertiesPair>();
-        if(languages != null) {
-            for(String language : languages) {
+        if (languages != null) {
+            for (String language : languages) {
                 PropertiesPair pair = createPropertiesPair(language);
                 messages.put(language, pair);
             }
@@ -102,204 +107,201 @@
         PropertiesPair pair = createPropertiesPair(null);
         messages.put(null, pair);
     }
-    
+
     /**
      * Lazy init the user manager
      */
     private void lazyInit() {
-        if(!isConfigured ) {
+        if (!isConfigured) {
             configure();
         }
     }
-    
+
     /**
-     * Create Properties pair object. It stores the default 
-     * and the custom messages.
+     * Create Properties pair object. It stores the default and the custom
+     * messages.
      */
     private PropertiesPair createPropertiesPair(String lang) {
         PropertiesPair pair = new PropertiesPair();
-        
+
         // load default resource
         String defaultResourceName;
-        if(lang == null) {
+        if (lang == null) {
             defaultResourceName = RESOURCE_PATH + "FtpStatus.properties";
-        }
-        else {
-            defaultResourceName = RESOURCE_PATH + "FtpStatus_" + lang + ".properties";
+        } else {
+            defaultResourceName = RESOURCE_PATH + "FtpStatus_" + lang
+                    + ".properties";
         }
         InputStream in = null;
         try {
-            in = getClass().getClassLoader().getResourceAsStream(defaultResourceName);
-            if(in != null) {
+            in = getClass().getClassLoader().getResourceAsStream(
+                    defaultResourceName);
+            if (in != null) {
                 pair.defaultProperties.load(in);
             }
-        }
-        catch(Exception ex) {
+        } catch (Exception ex) {
             LOG.warn("MessageResourceImpl.createPropertiesPair()", ex);
-            throw new FtpServerConfigurationException("MessageResourceImpl.createPropertiesPair()", ex);
-        }
-        finally {
+            throw new FtpServerConfigurationException(
+                    "MessageResourceImpl.createPropertiesPair()", ex);
+        } finally {
             IoUtils.close(in);
         }
-        
+
         // load custom resource
         File resourceFile = null;
-        if(lang == null) {
+        if (lang == null) {
             resourceFile = new File(customMessageDirectory, "FtpStatus.gen");
-        }
-        else {
-            resourceFile = new File(customMessageDirectory, "FtpStatus_" + lang + ".gen");
+        } else {
+            resourceFile = new File(customMessageDirectory, "FtpStatus_" + lang
+                    + ".gen");
         }
         in = null;
         try {
-            if(resourceFile.exists()) {
+            if (resourceFile.exists()) {
                 in = new FileInputStream(resourceFile);
                 pair.customProperties.load(in);
             }
-        }
-        catch(Exception ex) {
+        } catch (Exception ex) {
             LOG.warn("MessageResourceImpl.createPropertiesPair()", ex);
-            throw new FtpServerConfigurationException("MessageResourceImpl.createPropertiesPair()", ex);
-        }
-        finally {
+            throw new FtpServerConfigurationException(
+                    "MessageResourceImpl.createPropertiesPair()", ex);
+        } finally {
             IoUtils.close(in);
         }
-        
+
         return pair;
     }
-    
+
     /**
      * Get all the available languages.
      */
     public String[] getAvailableLanguages() {
-        if(languages == null) {
+        if (languages == null) {
             return null;
-        } else {         
+        } else {
             return (String[]) languages.clone();
         }
     }
-    
+
     /**
      * Get the message. If the message not found, it will return null.
      */
     public String getMessage(int code, String subId, String language) {
         lazyInit();
-        
+
         // find the message key
         String key = String.valueOf(code);
-        if(subId != null) {
+        if (subId != null) {
             key = key + '.' + subId;
         }
-        
+
         // get language specific value
         String value = null;
         PropertiesPair pair = null;
-        if(language != null) {
+        if (language != null) {
             language = language.toLowerCase();
             pair = messages.get(language);
-            if(pair != null) {
+            if (pair != null) {
                 value = pair.customProperties.getProperty(key);
-                if(value == null) {
+                if (value == null) {
                     value = pair.defaultProperties.getProperty(key);
                 }
             }
         }
-        
+
         // if not available get the default value
-        if(value == null) {
+        if (value == null) {
             pair = messages.get(null);
-            if(pair != null) {
+            if (pair != null) {
                 value = pair.customProperties.getProperty(key);
-                if(value == null) {
+                if (value == null) {
                     value = pair.defaultProperties.getProperty(key);
                 }
             }
         }
-        
+
         return value;
     }
-    
+
     /**
      * Get all messages.
      */
     public Properties getMessages(String language) {
         lazyInit();
-        
+
         Properties messages = new Properties();
-        
-        // load properties sequentially 
+
+        // load properties sequentially
         // (default,custom,default language,custom language)
         PropertiesPair pair = this.messages.get(null);
-        if(pair != null) {
+        if (pair != null) {
             messages.putAll(pair.defaultProperties);
             messages.putAll(pair.customProperties);
         }
-        if(language != null) {
+        if (language != null) {
             language = language.toLowerCase();
             pair = this.messages.get(language);
-            if(pair != null) {
+            if (pair != null) {
                 messages.putAll(pair.defaultProperties);
                 messages.putAll(pair.customProperties);
             }
         }
         return messages;
     }
-    
+
     /**
      * Save properties in file.
      */
     public void save(Properties prop, String language) throws FtpException {
         lazyInit();
-        
+
         // null properties - nothing to save
-        if(prop == null) {
+        if (prop == null) {
             return;
         }
-        
+
         // empty properties - nothing to save
-        if(prop.isEmpty()) {
+        if (prop.isEmpty()) {
             return;
         }
-        
+
         // get custom resource file name
         File resourceFile = null;
-        if(language == null) {
+        if (language == null) {
             resourceFile = new File(customMessageDirectory, "FtpStatus.gen");
-        }
-        else {
+        } else {
             language = language.toLowerCase();
-            resourceFile = new File(customMessageDirectory, "FtpStatus_" + language + ".gen");
+            resourceFile = new File(customMessageDirectory, "FtpStatus_"
+                    + language + ".gen");
         }
-        
+
         // save resource file
         OutputStream out = null;
         try {
             out = new FileOutputStream(resourceFile);
             prop.store(out, "Custom Messages");
-        }
-        catch(IOException ex) {
+        } catch (IOException ex) {
             LOG.error("MessageResourceImpl.save()", ex);
             throw new FtpException("MessageResourceImpl.save()", ex);
-        }
-        finally {
+        } finally {
             IoUtils.close(out);
         }
-        
+
         // assign new messages
         PropertiesPair pair = messages.get(language);
-        if(pair == null) {
+        if (pair == null) {
             pair = new PropertiesPair();
             messages.put(language, pair);
         }
         pair.customProperties = prop;
     }
-    
+
     /**
      * Dispose component - clear all maps.
      */
     public void dispose() {
         Iterator<String> it = messages.keySet().iterator();
-        while(it.hasNext()) {
+        while (it.hasNext()) {
             String language = it.next();
             PropertiesPair pair = messages.get(language);
             pair.customProperties.clear();

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/AliasKeyManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/AliasKeyManager.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/AliasKeyManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/AliasKeyManager.java Sun Aug 17 12:52:42 2008
@@ -24,155 +24,158 @@
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.X509KeyManager;
 
-
 /**
  * X509KeyManager which allows selection of a specific keypair and certificate
  * chain (identified by their keystore alias name) to be used by the server to
  * authenticate itself to SSL clients.
  * 
- * This class is only used on Java 1.4 systems, on Java 1.5 and newer 
- * the @see {@link ExtendedAliasKeyManager} is used instead
+ * This class is only used on Java 1.4 systems, on Java 1.5 and newer the @see
+ * {@link ExtendedAliasKeyManager} is used instead
  * 
  * Based of org.apache.tomcat.util.net.jsse.JSSEKeyManager.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public final class AliasKeyManager implements X509KeyManager {
 
-	private X509KeyManager delegate;
-	private String serverKeyAlias;
+    private X509KeyManager delegate;
+
+    private String serverKeyAlias;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param mgr
-	 *            The X509KeyManager used as a delegate
-	 * @param keyStore
-	 * @param serverKeyAlias
-	 *            The alias name of the server's keypair and supporting
-	 *            certificate chain
-	 * @param keyAlias
-	 */
-	public AliasKeyManager(KeyManager mgr, String keyAlias) {
-		this.delegate = (X509KeyManager)mgr;
-		this.serverKeyAlias = keyAlias;
-	}
-
-	/**
-	 * Choose an alias to authenticate the client side of a secure socket, given
-	 * the public key type and the list of certificate issuer authorities
-	 * recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name(s), ordered with the
-	 *            most-preferred key type first
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use
-	 * 
-	 * @return The alias name for the desired key, or null if there are no
-	 *         matches
-	 */
-	public String chooseClientAlias(String[] keyType, Principal[] issuers,
-			Socket socket) {
-		return delegate.chooseClientAlias(keyType, issuers, socket);
-	}
-
-	/**
-	 * Returns this key manager's server key alias that was provided in the
-	 * constructor.
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used (ignored)
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use (ignored)
-	 * 
-	 * @return Alias name for the desired key
-	 */
-	public String chooseServerAlias(String keyType, Principal[] issuers,
-			Socket socket) {
-		if (serverKeyAlias != null) {
-			PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
-			if (key != null) {
-				if (key.getAlgorithm().equals(keyType)) {
-					return serverKeyAlias;
-				} else {
-					return null;
-				}
-			} else {
-				return null;
-			}
-		} else {
-			return delegate.chooseServerAlias(keyType, issuers, socket);
-		}
-	}
-
-	/**
-	 * Returns the certificate chain associated with the given alias.
-	 * 
-	 * @param alias
-	 *            The alias name
-	 * 
-	 * @return Certificate chain (ordered with the user's certificate first and
-	 *         the root certificate authority last), or null if the alias can't
-	 *         be found
-	 */
-	public X509Certificate[] getCertificateChain(String alias) {
-		return delegate.getCertificateChain(alias);
-	}
-
-	/**
-	 * Get the matching aliases for authenticating the client side of a secure
-	 * socket, given the public key type and the list of certificate issuer
-	 * authorities recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * 
-	 * @return Array of the matching alias names, or null if there were no
-	 *         matches
-	 */
-	public String[] getClientAliases(String keyType, Principal[] issuers) {
-		return delegate.getClientAliases(keyType, issuers);
-	}
-
-	/**
-	 * Get the matching aliases for authenticating the server side of a secure
-	 * socket, given the public key type and the list of certificate issuer
-	 * authorities recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * 
-	 * @return Array of the matching alias names, or null if there were no
-	 *         matches
-	 */
-	public String[] getServerAliases(String keyType, Principal[] issuers) {
-		return delegate.getServerAliases(keyType, issuers);
-	}
-
-	/**
-	 * Returns the key associated with the given alias.
-	 * 
-	 * @param alias
-	 *            The alias name
-	 * 
-	 * @return The requested key, or null if the alias can't be found
-	 */
-	public PrivateKey getPrivateKey(String alias) {
-		return delegate.getPrivateKey(alias);
-	}
+    /**
+     * Constructor.
+     * 
+     * @param mgr
+     *            The X509KeyManager used as a delegate
+     * @param keyStore
+     * @param serverKeyAlias
+     *            The alias name of the server's keypair and supporting
+     *            certificate chain
+     * @param keyAlias
+     */
+    public AliasKeyManager(KeyManager mgr, String keyAlias) {
+        this.delegate = (X509KeyManager) mgr;
+        this.serverKeyAlias = keyAlias;
+    }
+
+    /**
+     * Choose an alias to authenticate the client side of a secure socket, given
+     * the public key type and the list of certificate issuer authorities
+     * recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name(s), ordered with the
+     *            most-preferred key type first
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use
+     * 
+     * @return The alias name for the desired key, or null if there are no
+     *         matches
+     */
+    public String chooseClientAlias(String[] keyType, Principal[] issuers,
+            Socket socket) {
+        return delegate.chooseClientAlias(keyType, issuers, socket);
+    }
+
+    /**
+     * Returns this key manager's server key alias that was provided in the
+     * constructor.
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used (ignored)
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use (ignored)
+     * 
+     * @return Alias name for the desired key
+     */
+    public String chooseServerAlias(String keyType, Principal[] issuers,
+            Socket socket) {
+        if (serverKeyAlias != null) {
+            PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
+            if (key != null) {
+                if (key.getAlgorithm().equals(keyType)) {
+                    return serverKeyAlias;
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        } else {
+            return delegate.chooseServerAlias(keyType, issuers, socket);
+        }
+    }
+
+    /**
+     * Returns the certificate chain associated with the given alias.
+     * 
+     * @param alias
+     *            The alias name
+     * 
+     * @return Certificate chain (ordered with the user's certificate first and
+     *         the root certificate authority last), or null if the alias can't
+     *         be found
+     */
+    public X509Certificate[] getCertificateChain(String alias) {
+        return delegate.getCertificateChain(alias);
+    }
+
+    /**
+     * Get the matching aliases for authenticating the client side of a secure
+     * socket, given the public key type and the list of certificate issuer
+     * authorities recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * 
+     * @return Array of the matching alias names, or null if there were no
+     *         matches
+     */
+    public String[] getClientAliases(String keyType, Principal[] issuers) {
+        return delegate.getClientAliases(keyType, issuers);
+    }
+
+    /**
+     * Get the matching aliases for authenticating the server side of a secure
+     * socket, given the public key type and the list of certificate issuer
+     * authorities recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * 
+     * @return Array of the matching alias names, or null if there were no
+     *         matches
+     */
+    public String[] getServerAliases(String keyType, Principal[] issuers) {
+        return delegate.getServerAliases(keyType, issuers);
+    }
+
+    /**
+     * Returns the key associated with the given alias.
+     * 
+     * @param alias
+     *            The alias name
+     * 
+     * @return The requested key, or null if the alias can't be found
+     */
+    public PrivateKey getPrivateKey(String alias) {
+        return delegate.getPrivateKey(alias);
+    }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ClientAuth.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ClientAuth.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ClientAuth.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ClientAuth.java Sun Aug 17 12:52:42 2008
@@ -17,21 +17,24 @@
 package org.apache.ftpserver.ssl;
 
 /**
- * Enumeration of possible levels of client
- * authentication during an SSL session.
+ * Enumeration of possible levels of client authentication during an SSL
+ * session.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public enum ClientAuth {
-	
-	/**
-	 * Client authentication is required
-	 */
+
+    /**
+     * Client authentication is required
+     */
     NEED,
-    
+
     /**
-     * Client authentication is requested but not required 
+     * Client authentication is requested but not required
      */
     WANT,
-    
+
     /**
      * Client authentication is not performed
      */

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/DefaultSslConfiguration.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/DefaultSslConfiguration.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/DefaultSslConfiguration.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/DefaultSslConfiguration.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.ssl;
 
@@ -38,55 +38,72 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 /**
- * Used to configure the SSL settings for the control channel
- * or the data channel.
+ * Used to configure the SSL settings for the control channel or the data
+ * channel.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public class DefaultSslConfiguration implements SslConfiguration {
-    
-    private final Logger LOG = LoggerFactory.getLogger(DefaultSslConfiguration.class);
-    
+
+    private final Logger LOG = LoggerFactory
+            .getLogger(DefaultSslConfiguration.class);
+
     private File keystoreFile = new File("./res/.keystore");
+
     private String keystorePass;
+
     private String keystoreType = KeyStore.getDefaultType();
+
     private String keystoreAlgorithm = "SunX509";
 
     private File trustStoreFile;
+
     private String trustStorePass;
+
     private String trustStoreType = KeyStore.getDefaultType();
+
     private String trustStoreAlgorithm = "SunX509";
-    
+
     private String sslProtocol = "TLS";
+
     private ClientAuth clientAuthReqd = ClientAuth.NONE;
+
     private String keyPass;
+
     private String keyAlias;
 
     private KeyManagerFactory keyManagerFactory;
+
     private TrustManagerFactory trustManagerFactory;
-    
+
     private HashMap<String, SSLContext> sslContextMap = new HashMap<String, SSLContext>();
 
     private String[] enabledCipherSuites;
-    
+
     /**
      * The key store file used by this configuration
+     * 
      * @return The key store file
      */
     public File getKeystoreFile() {
         return keystoreFile;
     }
-    
+
     /**
      * Set the key store file to be used by this configuration
-     * @param keyStoreFile A path to an existing key store file
+     * 
+     * @param keyStoreFile
+     *            A path to an existing key store file
      */
     public void setKeystoreFile(File keyStoreFile) {
         this.keystoreFile = keyStoreFile;
     }
-    
+
     /**
      * The password used to load the key store
+     * 
      * @return The password
      */
     public String getKeystorePassword() {
@@ -94,8 +111,10 @@
     }
 
     /**
-     * Set the password used to load the key store 
-     * @param keystorePass The password
+     * Set the password used to load the key store
+     * 
+     * @param keystorePass
+     *            The password
      */
     public void setKeystorePassword(String keystorePass) {
         this.keystorePass = keystorePass;
@@ -103,43 +122,47 @@
 
     /**
      * The key store type, defaults to @see {@link KeyStore#getDefaultType()}
+     * 
      * @return The key store type
      */
     public String getKeystoreType() {
         return keystoreType;
     }
-    
+
     /**
      * Set the key store type
-     * @param keystoreType The key store type
+     * 
+     * @param keystoreType
+     *            The key store type
      */
     public void setKeystoreType(String keystoreType) {
         this.keystoreType = keystoreType;
     }
-    
+
     /**
-     * The algorithm used to open the key store. 
-     * 	 Defaults to "SunX509"
+     * The algorithm used to open the key store. Defaults to "SunX509"
+     * 
      * @return The key store algorithm
      */
     public String getKeystoreAlgorithm() {
         return keystoreAlgorithm;
     }
-    
+
     /**
-     * Override the key store algorithm used to
-     *   open the key store
-     * @param keystoreAlgorithm The key store algorithm
+     * Override the key store algorithm used to open the key store
+     * 
+     * @param keystoreAlgorithm
+     *            The key store algorithm
      */
     public void setKeystoreAlgorithm(String keystoreAlgorithm) {
         this.keystoreAlgorithm = keystoreAlgorithm;
-    
+
     }
-    
+
     /**
-     * The SSL protocol used for this channel. 
-     *   Supported values are "SSL" and "TLS". 
-     *   Defaults to "TLS".
+     * The SSL protocol used for this channel. Supported values are "SSL" and
+     * "TLS". Defaults to "TLS".
+     * 
      * @return The SSL protocol
      */
     public String getSslProtocol() {
@@ -147,57 +170,64 @@
     }
 
     /**
-     * Set the SSL protocol used for this channel. 
-     *   Supported values are "SSL" and "TLS".
-     *   Defaults to "TLS". 
-     * @param sslProtocol The SSL protocol
+     * Set the SSL protocol used for this channel. Supported values are "SSL"
+     * and "TLS". Defaults to "TLS".
+     * 
+     * @param sslProtocol
+     *            The SSL protocol
      */
     public void setSslProtocol(String sslProtocol) {
         this.sslProtocol = sslProtocol;
     }
-    
+
     /**
-     * Set what client authentication level to use, supported
-     * values are "yes" or "true" for required authentication, 
-     * "want" for wanted authentication and "false" or "none" 
-     * for no authentication. Defaults to "none".
-     * @param clientAuthReqd The desired authentication level
+     * Set what client authentication level to use, supported values are "yes"
+     * or "true" for required authentication, "want" for wanted authentication
+     * and "false" or "none" for no authentication. Defaults to "none".
+     * 
+     * @param clientAuthReqd
+     *            The desired authentication level
      */
     public void setClientAuthentication(String clientAuthReqd) {
-        if("true".equalsIgnoreCase(clientAuthReqd) 
+        if ("true".equalsIgnoreCase(clientAuthReqd)
                 || "yes".equalsIgnoreCase(clientAuthReqd)
-                || "need".equalsIgnoreCase(clientAuthReqd) ) {
+                || "need".equalsIgnoreCase(clientAuthReqd)) {
             this.clientAuthReqd = ClientAuth.NEED;
-        } else if("want".equalsIgnoreCase(clientAuthReqd)) {
+        } else if ("want".equalsIgnoreCase(clientAuthReqd)) {
             this.clientAuthReqd = ClientAuth.WANT;
         } else {
             this.clientAuthReqd = ClientAuth.NONE;
         }
     }
-    
+
     /**
      * The password used to load the key
+     * 
      * @return The password
      */
     public String getKeyPassword() {
         return keyPass;
     }
-    
+
     /**
-     * Set the password used to load the key 
-     * @param keyPass The password
+     * Set the password used to load the key
+     * 
+     * @param keyPass
+     *            The password
      */
     public void setKeyPassword(String keyPass) {
         this.keyPass = keyPass;
     }
-    
+
     public File getTruststoreFile() {
         return trustStoreFile;
     }
-    
+
     /**
-     * Set the password used to load the trust store 
-     * @param trustStoreFile The password
+     * Set the password used to load the trust store
+     * 
+     * @param trustStoreFile
+     *            The password
      */
     public void setTruststoreFile(File trustStoreFile) {
         this.trustStoreFile = trustStoreFile;
@@ -205,6 +235,7 @@
 
     /**
      * The password used to load the trust store
+     * 
      * @return The password
      */
     public String getTruststorePassword() {
@@ -212,15 +243,18 @@
     }
 
     /**
-     * Set the password used to load the trust store 
-     * @param trustStorePass The password
+     * Set the password used to load the trust store
+     * 
+     * @param trustStorePass
+     *            The password
      */
     public void setTruststorePassword(String trustStorePass) {
         this.trustStorePass = trustStorePass;
     }
-    
+
     /**
      * The trust store type, defaults to @see {@link KeyStore#getDefaultType()}
+     * 
      * @return The trust store type
      */
     public String getTruststoreType() {
@@ -229,134 +263,149 @@
 
     /**
      * Set the trust store type
-     * @param keystoreType The trust store type
-     */    
+     * 
+     * @param keystoreType
+     *            The trust store type
+     */
     public void setTruststoreType(String trustStoreType) {
         this.trustStoreType = trustStoreType;
     }
-    
+
     /**
-     * The algorithm used to open the trust store. 
-     * 	 Defaults to "SunX509"
+     * The algorithm used to open the trust store. Defaults to "SunX509"
+     * 
      * @return The trust store algorithm
      */
     public String getTruststoreAlgorithm() {
         return trustStoreAlgorithm;
     }
-    
+
     /**
-     * Override the trust store algorithm used to
-     *   open the trust store
-     * @param trustStoreAlgorithm The trust store algorithm
+     * Override the trust store algorithm used to open the trust store
+     * 
+     * @param trustStoreAlgorithm
+     *            The trust store algorithm
      */
     public void setTruststoreAlgorithm(String trustStoreAlgorithm) {
         this.trustStoreAlgorithm = trustStoreAlgorithm;
-    
+
     }
 
-    private KeyStore loadStore(File storeFile, String storeType, String storePass) throws IOException, GeneralSecurityException {
+    private KeyStore loadStore(File storeFile, String storeType,
+            String storePass) throws IOException, GeneralSecurityException {
         FileInputStream fin = null;
         try {
             fin = new FileInputStream(storeFile);
             KeyStore store = KeyStore.getInstance(storeType);
             store.load(fin, storePass.toCharArray());
-            
+
             return store;
-        }
-        finally {
+        } finally {
             IoUtils.close(fin);
         }
     }
-    
+
     /**
-     * Configure secure server related properties. 
+     * Configure secure server related properties.
      */
     public synchronized void init() {
-        
+
         try {
             // initialize keystore
-            LOG.debug("Loading key store from \"{}\", using the key store type \"{}\"", keystoreFile.getAbsolutePath(), keystoreType);
-            KeyStore keyStore = loadStore(keystoreFile, keystoreType, keystorePass);
-            
+            LOG
+                    .debug(
+                            "Loading key store from \"{}\", using the key store type \"{}\"",
+                            keystoreFile.getAbsolutePath(), keystoreType);
+            KeyStore keyStore = loadStore(keystoreFile, keystoreType,
+                    keystorePass);
+
             KeyStore trustStore;
-            if(trustStoreFile != null) {
-                LOG.debug("Loading trust store from \"{}\", using the key store type \"{}\"", trustStoreFile.getAbsolutePath(), trustStoreType);
-                trustStore = loadStore(trustStoreFile, trustStoreType, trustStorePass);
+            if (trustStoreFile != null) {
+                LOG
+                        .debug(
+                                "Loading trust store from \"{}\", using the key store type \"{}\"",
+                                trustStoreFile.getAbsolutePath(),
+                                trustStoreType);
+                trustStore = loadStore(trustStoreFile, trustStoreType,
+                        trustStorePass);
             } else {
                 trustStore = keyStore;
             }
-            
-            
+
             String keyPassToUse;
-            if(keyPass == null) {
+            if (keyPass == null) {
                 keyPassToUse = keystorePass;
             } else {
                 keyPassToUse = keyPass;
             }
             // initialize key manager factory
-            keyManagerFactory = KeyManagerFactory.getInstance(keystoreAlgorithm);
+            keyManagerFactory = KeyManagerFactory
+                    .getInstance(keystoreAlgorithm);
             keyManagerFactory.init(keyStore, keyPassToUse.toCharArray());
-            
+
             // initialize trust manager factory
-            trustManagerFactory = TrustManagerFactory.getInstance(trustStoreAlgorithm);
+            trustManagerFactory = TrustManagerFactory
+                    .getInstance(trustStoreAlgorithm);
             trustManagerFactory.init(trustStore);
-        }
-        catch(Exception ex) {
+        } catch (Exception ex) {
             LOG.error("DefaultSsl.configure()", ex);
-            throw new FtpServerConfigurationException("DefaultSsl.configure()", ex);
+            throw new FtpServerConfigurationException("DefaultSsl.configure()",
+                    ex);
         }
     }
-    
+
     private synchronized void lazyInit() {
-        if(keyManagerFactory == null) {
+        if (keyManagerFactory == null) {
             init();
         }
     }
-    
+
     /**
      * @see SslConfiguration#getSSLContext(String)
      */
-    public synchronized SSLContext getSSLContext(String protocol) throws GeneralSecurityException {
+    public synchronized SSLContext getSSLContext(String protocol)
+            throws GeneralSecurityException {
         lazyInit();
-        
+
         // null value check
-        if(protocol == null) {
+        if (protocol == null) {
             protocol = sslProtocol;
         }
-        
+
         // if already stored - return it
         SSLContext ctx = sslContextMap.get(protocol);
-        if(ctx != null) {
+        if (ctx != null) {
             return ctx;
         }
-        
+
         // create SSLContext
         ctx = SSLContext.getInstance(protocol);
-        
+
         KeyManager[] keyManagers = keyManagerFactory.getKeyManagers();
 
-        // wrap key managers to allow us to control their behavior (FTPSERVER-93)
+        // wrap key managers to allow us to control their behavior
+        // (FTPSERVER-93)
         for (int i = 0; i < keyManagers.length; i++) {
-          if(ClassUtils.extendsClass(keyManagers[i].getClass(), "javax.net.ssl.X509ExtendedKeyManager")) {
-        	  keyManagers[i] = new ExtendedAliasKeyManager(keyManagers[i], keyAlias);
-          } else if(keyManagers[i] instanceof X509KeyManager) {
-        	  keyManagers[i] = new AliasKeyManager(keyManagers[i], keyAlias);
-          }
-        } 
-        
+            if (ClassUtils.extendsClass(keyManagers[i].getClass(),
+                    "javax.net.ssl.X509ExtendedKeyManager")) {
+                keyManagers[i] = new ExtendedAliasKeyManager(keyManagers[i],
+                        keyAlias);
+            } else if (keyManagers[i] instanceof X509KeyManager) {
+                keyManagers[i] = new AliasKeyManager(keyManagers[i], keyAlias);
+            }
+        }
+
         // create SSLContext
         ctx = SSLContext.getInstance(protocol);
-        
-        ctx.init(keyManagers, 
-                 trustManagerFactory.getTrustManagers(), 
-                 null);
+
+        ctx.init(keyManagers, trustManagerFactory.getTrustManagers(), null);
 
         // store it in map
         sslContextMap.put(protocol, ctx);
-        
+
         return ctx;
     }
-    
+
     /**
      * @see SslConfiguration#getClientAuth()
      */
@@ -375,21 +424,21 @@
      * @see SslConfiguration#getEnabledCipherSuites()
      */
     public String[] getEnabledCipherSuites() {
-        if(enabledCipherSuites != null) {
+        if (enabledCipherSuites != null) {
             return enabledCipherSuites.clone();
         } else {
             return null;
         }
     }
-    
+
     /**
-     * Set the allowed cipher suites, note that
-     *   the exact list of supported cipher suites
-     *   differs between JRE implementations.
+     * Set the allowed cipher suites, note that the exact list of supported
+     * cipher suites differs between JRE implementations.
+     * 
      * @param enabledCipherSuites
      */
     public void setEnabledCipherSuites(String[] enabledCipherSuites) {
-        if(enabledCipherSuites != null) {
+        if (enabledCipherSuites != null) {
             this.enabledCipherSuites = enabledCipherSuites.clone();
         } else {
             this.enabledCipherSuites = null;
@@ -398,6 +447,7 @@
 
     /**
      * Get the server key alias to be used for SSL communication
+     * 
      * @return The alias, or null if none is set
      */
     public String getKeyAlias() {
@@ -405,11 +455,13 @@
     }
 
     /**
-     * Set the alias for the key to be used for SSL communication.
-     * If the specified key store contains multiple keys, this 
-     * alias can be set to select a specific key.
-     * @param keyAlias The alias to use, or null if JSSE should
-     *          be allowed to choose the key.
+     * Set the alias for the key to be used for SSL communication. If the
+     * specified key store contains multiple keys, this alias can be set to
+     * select a specific key.
+     * 
+     * @param keyAlias
+     *            The alias to use, or null if JSSE should be allowed to choose
+     *            the key.
      */
     public void setKeyAlias(String keyAlias) {
         this.keyAlias = keyAlias;

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ExtendedAliasKeyManager.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ExtendedAliasKeyManager.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ExtendedAliasKeyManager.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/ExtendedAliasKeyManager.java Sun Aug 17 12:52:42 2008
@@ -25,208 +25,212 @@
 import javax.net.ssl.SSLEngine;
 import javax.net.ssl.X509ExtendedKeyManager;
 
-
 /**
  * X509KeyManager which allows selection of a specific keypair and certificate
  * chain (identified by their keystore alias name) to be used by the server to
  * authenticate itself to SSL clients.
  * 
  * Based of org.apache.tomcat.util.net.jsse.JSSEKeyManager.
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public final class ExtendedAliasKeyManager extends X509ExtendedKeyManager {
 
-	private X509ExtendedKeyManager delegate;
-	private String serverKeyAlias;
+    private X509ExtendedKeyManager delegate;
+
+    private String serverKeyAlias;
 
-	/**
-	 * Constructor.
-	 * 
-	 * @param mgr
-	 *            The X509KeyManager used as a delegate
-	 * @param keyStore
-	 * @param serverKeyAlias
-	 *            The alias name of the server's keypair and supporting
-	 *            certificate chain
-	 * @param keyAlias
-	 */
-	public ExtendedAliasKeyManager(KeyManager mgr, String keyAlias) {
-		this.delegate = (X509ExtendedKeyManager)mgr;
-		this.serverKeyAlias = keyAlias;
-	}
-
-	/**
-	 * Choose an alias to authenticate the client side of a secure socket, given
-	 * the public key type and the list of certificate issuer authorities
-	 * recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name(s), ordered with the
-	 *            most-preferred key type first
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use
-	 * 
-	 * @return The alias name for the desired key, or null if there are no
-	 *         matches
-	 */
-	public String chooseClientAlias(String[] keyType, Principal[] issuers,
-			Socket socket) {
-		return delegate.chooseClientAlias(keyType, issuers, socket);
-	}
-
-	/**
-	 * Returns this key manager's server key alias that was provided in the
-	 * constructor if matching the key type.
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used (ignored)
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use (ignored)
-	 * 
-	 * @return Alias name for the desired key
-	 */
-	public String chooseServerAlias(String keyType, Principal[] issuers,
-			Socket socket) {
-		if (serverKeyAlias != null) {
-			PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
-			if (key != null) {
-				if (key.getAlgorithm().equals(keyType)) {
-					return serverKeyAlias;
-				} else {
-					return null;
-				}
-			} else {
-				return null;
-			}
-		} else {
-			return delegate.chooseServerAlias(keyType, issuers, socket);
-		}
-	}
-
-	/**
-	 * Returns the certificate chain associated with the given alias.
-	 * 
-	 * @param alias
-	 *            The alias name
-	 * 
-	 * @return Certificate chain (ordered with the user's certificate first and
-	 *         the root certificate authority last), or null if the alias can't
-	 *         be found
-	 */
-	public X509Certificate[] getCertificateChain(String alias) {
-		return delegate.getCertificateChain(alias);
-	}
-
-	/**
-	 * Get the matching aliases for authenticating the client side of a secure
-	 * socket, given the public key type and the list of certificate issuer
-	 * authorities recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * 
-	 * @return Array of the matching alias names, or null if there were no
-	 *         matches
-	 */
-	public String[] getClientAliases(String keyType, Principal[] issuers) {
-		return delegate.getClientAliases(keyType, issuers);
-	}
-
-	/**
-	 * Get the matching aliases for authenticating the server side of a secure
-	 * socket, given the public key type and the list of certificate issuer
-	 * authorities recognized by the peer (if any).
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used
-	 * 
-	 * @return Array of the matching alias names, or null if there were no
-	 *         matches
-	 */
-	public String[] getServerAliases(String keyType, Principal[] issuers) {
-		return delegate.getServerAliases(keyType, issuers);
-	}
-
-	/**
-	 * Returns the key associated with the given alias.
-	 * 
-	 * @param alias
-	 *            The alias name
-	 * 
-	 * @return The requested key, or null if the alias can't be found
-	 */
-	public PrivateKey getPrivateKey(String alias) {
-		return delegate.getPrivateKey(alias);
-	}
-
-	/**
-	 * Choose an alias to authenticate the client side of a secure socket, given
-	 * the public key type and the list of certificate issuer authorities
-	 * recognized by the peer (if any).
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used (ignored)
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use (ignored)
-	 * @return The alias name for the desired key, or null if there are no
-	 *         matches          
-	 */
-	public String chooseEngineClientAlias(String[] keyType,
-			Principal[] issuers, SSLEngine engine) {
-		return delegate.chooseEngineClientAlias(keyType, issuers, engine);
-	}
-
-	/**
-	 * Returns this key manager's server key alias that was provided in the
-	 * constructor if matching the key type.
-	 * 
-	 * @param keyType
-	 *            The key algorithm type name
-	 * @param issuers
-	 *            The list of acceptable CA issuer subject names, or null if it
-	 *            does not matter which issuers are used (ignored)
-	 * @param socket
-	 *            The socket to be used for this connection. This parameter can
-	 *            be null, in which case this method will return the most
-	 *            generic alias to use (ignored)
-	 * 
-	 * @return Alias name for the desired key
-	 */
-	public String chooseEngineServerAlias(String keyType, Principal[] issuers,
-			SSLEngine engine) {
-
-		if (serverKeyAlias != null) {
-			PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
-			if (key != null) {
-				if (key.getAlgorithm().equals(keyType)) {
-					return serverKeyAlias;
-				} else {
-					return null;
-				}
-			} else {
-				return null;
-			}
-		} else {
-			return delegate.chooseEngineServerAlias(keyType, issuers, engine);
-		}
-	}
+    /**
+     * Constructor.
+     * 
+     * @param mgr
+     *            The X509KeyManager used as a delegate
+     * @param keyStore
+     * @param serverKeyAlias
+     *            The alias name of the server's keypair and supporting
+     *            certificate chain
+     * @param keyAlias
+     */
+    public ExtendedAliasKeyManager(KeyManager mgr, String keyAlias) {
+        this.delegate = (X509ExtendedKeyManager) mgr;
+        this.serverKeyAlias = keyAlias;
+    }
+
+    /**
+     * Choose an alias to authenticate the client side of a secure socket, given
+     * the public key type and the list of certificate issuer authorities
+     * recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name(s), ordered with the
+     *            most-preferred key type first
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use
+     * 
+     * @return The alias name for the desired key, or null if there are no
+     *         matches
+     */
+    public String chooseClientAlias(String[] keyType, Principal[] issuers,
+            Socket socket) {
+        return delegate.chooseClientAlias(keyType, issuers, socket);
+    }
+
+    /**
+     * Returns this key manager's server key alias that was provided in the
+     * constructor if matching the key type.
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used (ignored)
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use (ignored)
+     * 
+     * @return Alias name for the desired key
+     */
+    public String chooseServerAlias(String keyType, Principal[] issuers,
+            Socket socket) {
+        if (serverKeyAlias != null) {
+            PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
+            if (key != null) {
+                if (key.getAlgorithm().equals(keyType)) {
+                    return serverKeyAlias;
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        } else {
+            return delegate.chooseServerAlias(keyType, issuers, socket);
+        }
+    }
+
+    /**
+     * Returns the certificate chain associated with the given alias.
+     * 
+     * @param alias
+     *            The alias name
+     * 
+     * @return Certificate chain (ordered with the user's certificate first and
+     *         the root certificate authority last), or null if the alias can't
+     *         be found
+     */
+    public X509Certificate[] getCertificateChain(String alias) {
+        return delegate.getCertificateChain(alias);
+    }
+
+    /**
+     * Get the matching aliases for authenticating the client side of a secure
+     * socket, given the public key type and the list of certificate issuer
+     * authorities recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * 
+     * @return Array of the matching alias names, or null if there were no
+     *         matches
+     */
+    public String[] getClientAliases(String keyType, Principal[] issuers) {
+        return delegate.getClientAliases(keyType, issuers);
+    }
+
+    /**
+     * Get the matching aliases for authenticating the server side of a secure
+     * socket, given the public key type and the list of certificate issuer
+     * authorities recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used
+     * 
+     * @return Array of the matching alias names, or null if there were no
+     *         matches
+     */
+    public String[] getServerAliases(String keyType, Principal[] issuers) {
+        return delegate.getServerAliases(keyType, issuers);
+    }
+
+    /**
+     * Returns the key associated with the given alias.
+     * 
+     * @param alias
+     *            The alias name
+     * 
+     * @return The requested key, or null if the alias can't be found
+     */
+    public PrivateKey getPrivateKey(String alias) {
+        return delegate.getPrivateKey(alias);
+    }
+
+    /**
+     * Choose an alias to authenticate the client side of a secure socket, given
+     * the public key type and the list of certificate issuer authorities
+     * recognized by the peer (if any).
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used (ignored)
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use (ignored)
+     * @return The alias name for the desired key, or null if there are no
+     *         matches
+     */
+    public String chooseEngineClientAlias(String[] keyType,
+            Principal[] issuers, SSLEngine engine) {
+        return delegate.chooseEngineClientAlias(keyType, issuers, engine);
+    }
+
+    /**
+     * Returns this key manager's server key alias that was provided in the
+     * constructor if matching the key type.
+     * 
+     * @param keyType
+     *            The key algorithm type name
+     * @param issuers
+     *            The list of acceptable CA issuer subject names, or null if it
+     *            does not matter which issuers are used (ignored)
+     * @param socket
+     *            The socket to be used for this connection. This parameter can
+     *            be null, in which case this method will return the most
+     *            generic alias to use (ignored)
+     * 
+     * @return Alias name for the desired key
+     */
+    public String chooseEngineServerAlias(String keyType, Principal[] issuers,
+            SSLEngine engine) {
+
+        if (serverKeyAlias != null) {
+            PrivateKey key = delegate.getPrivateKey(serverKeyAlias);
+            if (key != null) {
+                if (key.getAlgorithm().equals(keyType)) {
+                    return serverKeyAlias;
+                } else {
+                    return null;
+                }
+            } else {
+                return null;
+            }
+        } else {
+            return delegate.chooseEngineServerAlias(keyType, issuers, engine);
+        }
+    }
 }

Modified: mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/SslConfiguration.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/SslConfiguration.java?rev=686637&r1=686636&r2=686637&view=diff
==============================================================================
--- mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/SslConfiguration.java (original)
+++ mina/ftpserver/trunk/core/src/main/java/org/apache/ftpserver/ssl/SslConfiguration.java Sun Aug 17 12:52:42 2008
@@ -15,7 +15,7 @@
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.
- */  
+ */
 
 package org.apache.ftpserver.ssl;
 
@@ -23,40 +23,49 @@
 
 import javax.net.ssl.SSLContext;
 
-
 /**
  * SSL configuration
+ *
+ * @author The Apache MINA Project (dev@mina.apache.org)
+ * @version $Rev$, $Date$
  */
 public interface SslConfiguration {
-    
-	/**
-	 * Return the SSL context for this configuration
-	 * @return The {@link SSLContext}
-	 * @throws GeneralSecurityException
-	 */
+
+    /**
+     * Return the SSL context for this configuration
+     * 
+     * @return The {@link SSLContext}
+     * @throws GeneralSecurityException
+     */
     SSLContext getSSLContext() throws GeneralSecurityException;
-    
-	/**
-	 * Return the SSL context for this configuration given the specified protocol
-     * @param protocol The protocol, SSL or TLS must be supported
+
+    /**
+     * Return the SSL context for this configuration given the specified
+     * protocol
+     * 
+     * @param protocol
+     *            The protocol, SSL or TLS must be supported
      * @return The {@link SSLContext}
      * @throws GeneralSecurityException
      */
     SSLContext getSSLContext(String protocol) throws GeneralSecurityException;
-    
+
     /**
      * Returns the cipher suites that should be enabled for this connection.
      * Must return null if the default (as decided by the JVM) cipher suites
      * should be used.
+     * 
      * @return An array of cipher suites, or null.
      */
     String[] getEnabledCipherSuites();
-    
+
     /**
      * Return the required client authentication setting
-     * @return {@link ClientAuth#NEED} if client authentication is required, 
-     * 		{@link ClientAuth#WANT} is client authentication is wanted or
-     * 		{@link ClientAuth#NONE} if no client authentication is the be performed  
+     * 
+     * @return {@link ClientAuth#NEED} if client authentication is required,
+     *         {@link ClientAuth#WANT} is client authentication is wanted or
+     *         {@link ClientAuth#NONE} if no client authentication is the be
+     *         performed
      */
     ClientAuth getClientAuth();
 }