Remove duplicate code
authorNiklas Gustavsson <ngn@apache.org>
Tue, 1 May 2012 21:45:04 +0000 (21:45 +0000)
committerNiklas Gustavsson <ngn@apache.org>
Tue, 1 May 2012 21:45:04 +0000 (21:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/mina/ftpserver/trunk@1332847 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/ftpserver/command/impl/AUTH.java

index acc8827..06e030c 100644 (file)
@@ -21,6 +21,8 @@ package org.apache.ftpserver.command.impl;
 
 import java.io.IOException;
 import java.security.GeneralSecurityException;
+import java.util.Arrays;
+import java.util.List;
 
 import org.apache.ftpserver.command.AbstractCommand;
 import org.apache.ftpserver.ftplet.FtpException;
@@ -48,6 +50,8 @@ public class AUTH extends AbstractCommand {
 
     private final Logger LOG = LoggerFactory.getLogger(AUTH.class);
 
+    private static final List<String> VALID_AUTH_TYPES = Arrays.asList("SSL", "TLS");
+
     /**
      * Execute command
      */
@@ -95,22 +99,11 @@ public class AUTH extends AbstractCommand {
 
         // check parameter
         String authType = request.getArgument().toUpperCase();
-        if (authType.equals("SSL")) {
-            try {
-                secureSession(session, "SSL");
-                session.write(LocalizedFtpReply.translate(session, request, context,
-                        234, "AUTH.SSL", null));
-            } catch (FtpException ex) {
-                throw ex;
-            } catch (Exception ex) {
-                LOG.warn("AUTH.execute()", ex);
-                throw new FtpException("AUTH.execute()", ex);
-            }
-        } else if (authType.equals("TLS")) {
+        if (VALID_AUTH_TYPES.contains(authType)) {
             try {
-                secureSession(session, "TLS");
+                secureSession(session, authType);
                 session.write(LocalizedFtpReply.translate(session, request, context,
-                        234, "AUTH.TLS", null));
+                        234, "AUTH." + authType, null));
             } catch (FtpException ex) {
                 throw ex;
             } catch (Exception ex) {