You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2009/12/01 19:13:42 UTC

svn commit: r885854 - in /james/server/trunk: smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java

Author: norman
Date: Tue Dec  1 18:13:41 2009
New Revision: 885854

URL: http://svn.apache.org/viewvc?rev=885854&view=rev
Log:
Allow to cancel AUTH according to RFC (JAMES-939)

Modified:
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java?rev=885854&r1=885853&r2=885854&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java Tue Dec  1 18:13:41 2009
@@ -58,23 +58,37 @@
     implements CommandHandler, EhloExtension, ExtensibleHandler, MailParametersHook {
 
     private abstract class AbstractSMTPLineHandler implements LineHandler {
-        
+
         public void onLine(SMTPSession session, byte[] line) {
             try {
                 String l = new String(line, "US-ASCII");
-                SMTPResponse res = onCommand(session,l);
+                SMTPResponse res = handleCommand(session, l);
                 session.popLineHandler();
                 session.writeSMTPResponse(res);
             } catch (UnsupportedEncodingException e) {
-                // This should never happen, anyway return a error message and disconnect is prolly the best thing todo here
-                session.getLogger().error("Unable to parse line",e);
-                //end the session
+                // This should never happen, anyway return a error message and
+                // disconnect is prolly the best thing todo here
+                session.getLogger().error("Unable to parse line", e);
+                // end the session
                 SMTPResponse resp = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to parse line.");
                 resp.setEndSession(true);
                 session.writeSMTPResponse(resp);
             }
         }
 
+        private SMTPResponse handleCommand(SMTPSession session, String line) {
+            // See JAMES-939
+            
+            // According to RFC2554:
+            // "If the client wishes to cancel an authentication exchange, it issues a line with a single "*".
+            // If the server receives such an answer, it MUST reject the AUTH
+            // command by sending a 501 reply."
+            if (line.equals("*\r\n")) {
+                return new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SECURITY_AUTH) + " Authentication aborted");
+            }
+            return onCommand(session, line);
+        }
+
         protected abstract SMTPResponse onCommand(SMTPSession session, String l);
     }
 

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=885854&r1=885853&r2=885854&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java Tue Dec  1 18:13:41 2009
@@ -196,8 +196,10 @@
     protected void setUp() throws Exception {
         m_serviceManager = setUpServiceManager();
 
+        SimpleLog smtpLog = new SimpleLog("MockLog");
+        smtpLog.setLevel(SimpleLog.LOG_LEVEL_DEBUG);
         m_smtpServer = new SMTPServerProtocolHandlerFactory();
-        m_smtpServer.setLog(new SimpleLog("MockLog"));
+        m_smtpServer.setLog(smtpLog);
         m_smtpServer.setLoader(m_serviceManager);
         m_smtpServer.setDNSService(m_dnsServer);
         m_smtpServer.setMailetContext(mailetContext);
@@ -846,6 +848,31 @@
         smtpProtocol1.quit();
     }
 
+    public void testAuthCancel() throws Exception {
+        m_testConfiguration.setAuthorizedAddresses("127.0.0.1/8");
+        m_testConfiguration.setAuthorizingAnnounce();
+        finishSetUp(m_testConfiguration);
+
+        SMTPClient smtpProtocol = new SMTPClient();
+        smtpProtocol.connect("127.0.0.1", m_smtpListenerPort);
+
+        smtpProtocol.sendCommand("ehlo", InetAddress.getLocalHost().toString());
+
+        String sender ="test_user_smtp@localhost";
+      
+        smtpProtocol.sendCommand("AUTH PLAIN");
+
+        assertEquals("start auth.", 334, smtpProtocol.getReplyCode());
+
+        smtpProtocol.sendCommand("*");
+
+        assertEquals("cancel auth.", 501, smtpProtocol.getReplyCode());
+
+        smtpProtocol.quit();
+
+    }
+    
+    // Test for JAMES-939
     public void testAuth() throws Exception {
         m_testConfiguration.setAuthorizedAddresses("128.0.0.1/8");
         m_testConfiguration.setAuthorizingAnnounce();



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org