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 2006/07/23 13:20:22 UTC
svn commit: r424712 - in /james/server/trunk/src: conf/james-config.xml
java/org/apache/james/smtpserver/core/RoaminUsersHandler.java
test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java
Author: norman
Date: Sun Jul 23 04:20:21 2006
New Revision: 424712
URL: http://svn.apache.org/viewvc?rev=424712&view=rev
Log:
Allow to specify the expiretime in units.
Add junit test
Added:
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/smtpserver/core/RoaminUsersHandler.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=424712&r1=424711&r2=424712&view=diff
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Sun Jul 23 04:20:21 2006
@@ -923,8 +923,11 @@
<handler class="org.apache.james.smtpserver.core.filter.CoreFilterCmdHandlerLoader"></handler>
<!-- This connect handler can be used to enable RoaminUsers support (pop-before-smtp) -->
+ <!-- The expireTime is the time after which an ipAddress is handled as expired -->
<!--
- <handler class="org.apache.james.smtpserver.core.RoaminUsersHandler"></handler>
+ <handler class="org.apache.james.smtpserver.core.RoaminUsersHandler">
+ <expireTime> 1 hour </expireTime>
+ </handler>
-->
<!-- This command handler check against RBL-Lists -->
Modified: 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/RoaminUsersHandler.java?rev=424712&r1=424711&r2=424712&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/RoaminUsersHandler.java Sun Jul 23 04:20:21 2006
@@ -22,6 +22,7 @@
import org.apache.james.smtpserver.ConnectHandler;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.TimeConverter;
/**
* This ConnectHandler can be used to activate pop-before-smtp
@@ -40,17 +41,28 @@
Configuration config = arg0.getChild("expireTime", false);
if (config != null) {
- setExpireTime(config.getValueAsLong(RoaminUsersHelper.EXPIRE_TIME));
+ try {
+ setExpireTime(config.getValue(null));
+ } catch (NumberFormatException e) {
+ throw new ConfigurationException(
+ "Please configure a valid expireTime: "
+ + e.getMessage());
+ }
}
}
/**
* Set the time after which an ipAddresses should be handled as expired
*
- * @param expireTime The time in ms
+ * @param expireTime
+ * The time
*/
- public void setExpireTime(long expireTime) {
- this.expireTime = expireTime;
+ public void setExpireTime(String rawExpireTime) {
+ if (rawExpireTime != null) {
+ this.expireTime = TimeConverter.getMilliSeconds(rawExpireTime);
+ } else {
+ this.expireTime = RoaminUsersHelper.EXPIRE_TIME;
+ }
}
/**
@@ -59,7 +71,7 @@
public void onConnect(SMTPSession session) {
// some kind of random cleanup process
- if (Math.random() > 0.5) {
+ if (Math.random() > 0.8) {
RoaminUsersHelper.removeExpiredIP(expireTime);
}
Added: 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/RoaminUsersHandlerTest.java?rev=424712&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/smtpserver/RoaminUsersHandlerTest.java Sun Jul 23 04:20:21 2006
@@ -0,0 +1,223 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation. *
+ * All rights reserved. *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You *
+ * may obtain a copy of the License at: *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or *
+ * implied. See the License for the specific language governing *
+ * permissions and limitations under the License. *
+ ***********************************************************************/
+
+package org.apache.james.smtpserver;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+
+import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.james.smtpserver.core.RoaminUsersHandler;
+import org.apache.james.test.mock.avalon.MockLogger;
+import org.apache.james.util.RoaminUsersHelper;
+import org.apache.james.util.watchdog.Watchdog;
+import org.apache.mailet.Mail;
+
+import junit.framework.TestCase;
+
+public class RoaminUsersHandlerTest extends TestCase {
+
+ private SMTPSession mockedSession;
+
+ private void setupMockedSMTPSession() {
+ mockedSession = new SMTPSession() {
+ private boolean relayingAllowed = false;
+
+ public void abortMessage() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String clearResponseBuffer() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void endSession() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getCommandArgument() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getCommandName() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public SMTPHandlerConfigurationData getConfigurationData() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public HashMap getConnectionState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public InputStream getInputStream() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public Mail getMail() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public int getRcptCount() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getRemoteHost() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getRemoteIPAddress() {
+ return "192.168.200.1";
+ }
+
+ public StringBuffer getResponseBuffer() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getSessionID() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public HashMap getState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean getStopHandlerProcessing() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String getUser() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public Watchdog getWatchdog() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean isAuthRequired() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean isRelayingAllowed() {
+ return relayingAllowed;
+ }
+
+ public boolean isSessionEnded() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public String readCommandLine() throws IOException {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void resetConnectionState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void resetState() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void setMail(Mail mail) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void setRelayingAllowed(boolean relayingAllowed) {
+ this.relayingAllowed = relayingAllowed;
+ }
+
+ public void setStopHandlerProcessing(boolean b) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void setUser(String user) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public boolean useHeloEhloEnforcement() {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ public void writeResponse(String respString) {
+ throw new UnsupportedOperationException(
+ "Unimplemented mock service");
+ }
+
+ };
+ }
+
+ public void testAuthWorks() {
+
+ RoaminUsersHandler handler = new RoaminUsersHandler();
+
+ ContainerUtil.enableLogging(handler, new MockLogger());
+ setupMockedSMTPSession();
+ RoaminUsersHelper.addIPAddress("192.168.200.1");
+
+ assertFalse(mockedSession.isRelayingAllowed());
+ handler.onConnect(mockedSession);
+ assertTrue(mockedSession.isRelayingAllowed());
+ }
+
+ public void testIPGetRemoved() {
+ long sleepTime = 100;
+ RoaminUsersHandler handler = new RoaminUsersHandler();
+
+ ContainerUtil.enableLogging(handler, new MockLogger());
+ setupMockedSMTPSession();
+ RoaminUsersHelper.addIPAddress("192.168.200.1");
+ assertFalse(mockedSession.isRelayingAllowed());
+
+ try {
+ Thread.sleep(sleepTime);
+ RoaminUsersHelper.removeExpiredIP(10);
+ handler.onConnect(mockedSession);
+ assertFalse(mockedSession.isRelayingAllowed());
+
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org