james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r425355 - in /james/server/trunk/src: conf/ java/org/apache/james/pop3server/ java/org/apache/james/smtpserver/core/ java/org/apache/james/util/ test/org/apache/james/pop3server/ test/org/apache/james/smtpserver/
Date Tue, 25 Jul 2006 09:58:50 GMT
Author: norman
Date: Tue Jul 25 02:58:49 2006
New Revision: 425355

URL: http://svn.apache.org/viewvc?rev=425355&view=rev
Log:
Rename RoaminUsersHandler to POP3BeforeSMTPHandler.
Fix a synchronize

Added:
    james/server/trunk/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java
      - copied, changed from r424766, james/server/trunk/src/java/org/apache/james/smtpserver/core/RoaminUsersHandler.java
    james/server/trunk/src/java/org/apache/james/util/POP3BeforeSMTPHelper.java
      - copied, changed from r424769, james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java
    james/server/trunk/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java
      - copied, changed from r424766, james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java
Removed:
    james/server/trunk/src/java/org/apache/james/smtpserver/core/RoaminUsersHandler.java
    james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java
    james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java
Modified:
    james/server/trunk/src/conf/james-config.xml
    james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java
    james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java

Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?rev=425355&r1=425354&r2=425355&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Tue Jul 25 02:58:49 2006
@@ -922,10 +922,11 @@
             <!-- Load the core filter command handlers-->
             <handler class="org.apache.james.smtpserver.core.filter.CoreFilterCmdHandlerLoader"></handler>
       
 
-            <!-- This connect handler can be used to enable RoaminUsers support (pop-before-smtp)
-->
+            <!-- This connect handler can be used to enable POP3 before SMTP support -->
+            <!-- Plz note that only the ip get stored to indentify an authenticated client
-->
             <!-- The expireTime is the time after which an ipAddress is handled as expired
-->
             <!--
-            <handler class="org.apache.james.smtpserver.core.RoaminUsersHandler">
+            <handler class="org.apache.james.smtpserver.core.POP3BeforeSMTPHandler">
             <expireTime> 1 hour </expireTime>
             </handler>
             -->

Modified: james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java?rev=425355&r1=425354&r2=425355&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/pop3server/PassCmdHandler.java Tue Jul 25
02:58:49 2006
@@ -19,7 +19,7 @@
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
 import org.apache.james.services.MailRepository;
-import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.POP3BeforeSMTPHelper;
 
 /**
   * Handles PASS command
@@ -54,7 +54,7 @@
                     session.stat();
                     
                     // Store the ipAddress to use it later for pop before smtp 
-                    RoaminUsersHelper.addIPAddress(session.getRemoteIPAddress());
+                    POP3BeforeSMTPHelper.addIPAddress(session.getRemoteIPAddress());
                     
                     StringBuffer responseBuffer =
                         new StringBuffer(64)

Copied: james/server/trunk/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java
(from r424766, james/server/trunk/src/java/org/apache/james/smtpserver/core/RoaminUsersHandler.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java?p2=james/server/trunk/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java&p1=james/server/trunk/src/java/org/apache/james/smtpserver/core/RoaminUsersHandler.java&r1=424766&r2=425355&rev=425355&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/smtpserver/core/RoaminUsersHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/smtpserver/core/POP3BeforeSMTPHandler.java
Tue Jul 25 02:58:49 2006
@@ -21,18 +21,18 @@
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.james.smtpserver.ConnectHandler;
 import org.apache.james.smtpserver.SMTPSession;
-import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.POP3BeforeSMTPHelper;
 import org.apache.james.util.TimeConverter;
 
 /**
  * This ConnectHandler can be used to activate pop-before-smtp
  */
-public class RoaminUsersHandler implements ConnectHandler, Configurable {
+public class POP3BeforeSMTPHandler implements ConnectHandler, Configurable {
 
     /**
      * The time after which ipAddresses should be handled as expired
      */
-    private long expireTime = RoaminUsersHelper.EXPIRE_TIME;
+    private long expireTime = POP3BeforeSMTPHelper.EXPIRE_TIME;
 
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(Configuration)
@@ -70,12 +70,12 @@
 
         // some kind of random cleanup process
         if (Math.random() > 0.99) {
-            RoaminUsersHelper.removeExpiredIP(expireTime);
+            POP3BeforeSMTPHelper.removeExpiredIP(expireTime);
         }
 
         // Check if the ip is allowed to relay
         if (!session.isRelayingAllowed()
-                && RoaminUsersHelper.isAuthorized(session.getRemoteIPAddress()))
{
+                && POP3BeforeSMTPHelper.isAuthorized(session.getRemoteIPAddress()))
{
             session.setRelayingAllowed(true);
         }
     }

Copied: james/server/trunk/src/java/org/apache/james/util/POP3BeforeSMTPHelper.java (from
r424769, james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/POP3BeforeSMTPHelper.java?p2=james/server/trunk/src/java/org/apache/james/util/POP3BeforeSMTPHelper.java&p1=james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java&r1=424769&r2=425355&rev=425355&view=diff
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/RoaminUsersHelper.java (original)
+++ james/server/trunk/src/java/org/apache/james/util/POP3BeforeSMTPHelper.java Tue Jul 25
02:58:49 2006
@@ -17,7 +17,6 @@
 package org.apache.james.util;
 
 import java.util.Collections;
-import java.util.ConcurrentModificationException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -26,9 +25,9 @@
  * Helper class which is used to store ipAddresses and timestamps for pop before
  * smtp support.
  */
-public class RoaminUsersHelper {
+public class POP3BeforeSMTPHelper {
 
-    private RoaminUsersHelper() {
+    private POP3BeforeSMTPHelper() {
     }
 
     /**
@@ -59,10 +58,7 @@
      *            The ipAddress
      */
     public static void addIPAddress(String ipAddress) {
-        try {
-            ipMap.put(ipAddress, Long.toString(System.currentTimeMillis()));
-        } catch (ConcurrentModificationException e) {
-        }
+        ipMap.put(ipAddress, Long.toString(System.currentTimeMillis()));
     }
 
     /**
@@ -81,18 +77,21 @@
      *            handled as expired
      */
     public static void removeExpiredIP(long clearTime) {
-        Iterator storedIP = ipMap.keySet().iterator();
-        long currTime = System.currentTimeMillis();
+        synchronized (ipMap) {
+            Iterator storedIP = ipMap.keySet().iterator();
+            long currTime = System.currentTimeMillis();
+
+            while (storedIP.hasNext()) {
+                String key = storedIP.next().toString();
+                long storedTime = Long.parseLong((String) ipMap.get(key));
+
+                // remove the ip from the map when it is expired
+                if ((currTime - clearTime) > storedTime) {
+                    // remove the entry from the iterator first to get sure that we not get

+                    // a ConcurrentModificationException
+                    storedIP.remove();
 
-        while (storedIP.hasNext()) {
-            String key = storedIP.next().toString();
-            long storedTime = Long.parseLong((String) ipMap.get(key));
-
-            // remove the ip from the map when it is expired
-            if ((currTime - clearTime) > storedTime) {
-                try {
                     ipMap.remove(key);
-                } catch (ConcurrentModificationException e) {
                 }
             }
         }

Modified: james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java?rev=425355&r1=425354&r2=425355&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/pop3server/POP3ServerTest.java Tue Jul 25
02:58:49 2006
@@ -35,7 +35,7 @@
 import org.apache.james.test.mock.james.MockMailServer;
 import org.apache.james.test.util.Util;
 import org.apache.james.userrepository.MockUsersRepository;
-import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.POP3BeforeSMTPHelper;
 import org.apache.james.util.connection.SimpleConnectionManager;
 import org.apache.mailet.MailAddress;
 
@@ -303,7 +303,7 @@
 
         m_pop3Protocol.login("foo", pass);
         assertEquals(1, m_pop3Protocol.getState());
-        assertTrue(RoaminUsersHelper.isAuthorized("127.0.0.1"));
+        assertTrue(POP3BeforeSMTPHelper.isAuthorized("127.0.0.1"));
     }
 
 }

Copied: james/server/trunk/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java
(from r424766, james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java)
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java?p2=james/server/trunk/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java&p1=james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java&r1=424766&r2=425355&rev=425355&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/POP3BeforeSMTPHandlerTest.java
Tue Jul 25 02:58:49 2006
@@ -22,15 +22,15 @@
 import java.util.HashMap;
 
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.smtpserver.core.RoaminUsersHandler;
+import org.apache.james.smtpserver.core.POP3BeforeSMTPHandler;
 import org.apache.james.test.mock.avalon.MockLogger;
-import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.POP3BeforeSMTPHelper;
 import org.apache.james.util.watchdog.Watchdog;
 import org.apache.mailet.Mail;
 
 import junit.framework.TestCase;
 
-public class RoaminUsersHandlerTest extends TestCase {
+public class POP3BeforeSMTPHandlerTest extends TestCase {
 
     private SMTPSession mockedSession;
 
@@ -190,11 +190,11 @@
 
     public void testAuthWorks() {
 
-        RoaminUsersHandler handler = new RoaminUsersHandler();
+        POP3BeforeSMTPHandler handler = new POP3BeforeSMTPHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         setupMockedSMTPSession();
-        RoaminUsersHelper.addIPAddress("192.168.200.1");
+        POP3BeforeSMTPHelper.addIPAddress("192.168.200.1");
 
         assertFalse(mockedSession.isRelayingAllowed());
         handler.onConnect(mockedSession);
@@ -203,16 +203,16 @@
 
     public void testIPGetRemoved() {
         long sleepTime = 100;
-        RoaminUsersHandler handler = new RoaminUsersHandler();
+        POP3BeforeSMTPHandler handler = new POP3BeforeSMTPHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         setupMockedSMTPSession();
-        RoaminUsersHelper.addIPAddress("192.168.200.1");
+        POP3BeforeSMTPHelper.addIPAddress("192.168.200.1");
         assertFalse(mockedSession.isRelayingAllowed());
 
         try {
             Thread.sleep(sleepTime);
-            RoaminUsersHelper.removeExpiredIP(10);
+            POP3BeforeSMTPHelper.removeExpiredIP(10);
             handler.onConnect(mockedSession);
             assertFalse(mockedSession.isRelayingAllowed());
 
@@ -223,7 +223,7 @@
     
     public void testThrowExceptionOnIllegalExpireTime() {
         boolean exception = false;
-        RoaminUsersHandler handler = new RoaminUsersHandler();
+        POP3BeforeSMTPHandler handler = new POP3BeforeSMTPHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         setupMockedSMTPSession();     
@@ -238,7 +238,7 @@
     
     public void testValidExpireTime() {
         boolean exception = false;
-        RoaminUsersHandler handler = new RoaminUsersHandler();
+        POP3BeforeSMTPHandler handler = new POP3BeforeSMTPHandler();
 
         ContainerUtil.enableLogging(handler, new MockLogger());
         setupMockedSMTPSession();     



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


Mime
View raw message