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 rd...@apache.org on 2009/09/17 16:04:32 UTC

svn commit: r816200 - in /james/server/trunk/smtpserver-function/src: main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java

Author: rdonkin
Date: Thu Sep 17 14:04:32 2009
New Revision: 816200

URL: http://svn.apache.org/viewvc?rev=816200&view=rev
Log:
JAMES-919 Inject virtual user store https://issues.apache.org/jira/browse/JAMES-919

Modified:
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java?rev=816200&r1=816199&r2=816200&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java Thu Sep 17 14:04:32 2009
@@ -28,9 +28,6 @@
 
 import javax.annotation.Resource;
 
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.Serviceable;
 import org.apache.commons.configuration.Configuration;
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.logging.Log;
@@ -57,7 +54,7 @@
 /**
  * Handler which reject invalid recipients
  */
-public class ValidRcptHandler implements LogEnabled, RcptHook, Configurable, Serviceable {
+public class ValidRcptHandler implements LogEnabled, RcptHook, Configurable {
     
 
     /** This log is the fall back shared by all instances */
@@ -68,6 +65,16 @@
     
     private UsersRepository users;
     
+    private VirtualUserTableStore tableStore;
+
+    private Collection<String> recipients = new ArrayList<String>();
+    private Collection<String> domains = new ArrayList<String>();
+    private Collection<Pattern> regex = new ArrayList<Pattern>();
+    private boolean vut = true;
+    private VirtualUserTable table;
+    private String tableName = null;
+
+    
     /**
      * Gets the users repository.
      * @return the users
@@ -83,23 +90,24 @@
     @Resource(name="localusersrepository")
     public final void setUsers(UsersRepository users) {
         this.users = users;
-    }
-    
-    private Collection<String> recipients = new ArrayList<String>();
-    private Collection<String> domains = new ArrayList<String>();
-    private Collection<Pattern> regex = new ArrayList<Pattern>();
-    private boolean vut = true;
-    private VirtualUserTable table;
-    private String tableName = null;
+    }    
     
     /**
-     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     * Gets the virtual user table store.
+     * @return the tableStore
      */
-    public void service(ServiceManager arg0) throws ServiceException {
-        if (tableName == null || tableName.equals("")) {
-            tableName =  VirtualUserTableStore.DEFAULT_TABLE;
-        }
-        table = ((VirtualUserTableStore) arg0.lookup(VirtualUserTableStore.ROLE)).getTable(tableName);
+    public final VirtualUserTableStore getTableStore() {
+        return tableStore;
+    }
+
+    /**
+     * Sets the virtual user table store.
+     * @param tableStore the tableStore to set
+     */
+    @Resource(name="virtualusertable-store")
+    public final void setTableStore(VirtualUserTableStore tableStore) {
+        this.tableStore = tableStore;
+        loadTable();
     }
     
     /**
@@ -136,7 +144,7 @@
     /**
      * Set the domains for which every rcpt will be accepted. 
      * 
-     * @param dom The valid domains. Commaseperated list
+     * @param dom The valid domains. Comma seperated list
      */
     public void setValidDomains(Collection<String> doms) {
     	Iterator<String> domsIt = doms.iterator();
@@ -174,6 +182,16 @@
 
     public void setTableName(String tableName) {
     	this.tableName = tableName;
+        loadTable();
+    }
+
+    private void loadTable() {
+        if (this.tableName == null || this.tableName.equals("")) {
+            this.tableName =  VirtualUserTableStore.DEFAULT_TABLE;
+        }
+        if (tableStore != null) {
+            table = tableStore.getTable(this.tableName);
+        }
     }
     
     /**

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=816200&r1=816199&r2=816200&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java Thu Sep 17 14:04:32 2009
@@ -61,6 +61,7 @@
         users.addUser(VALID_USER,"xxx");
         handler = new ValidRcptHandler();
         handler.setUsers(users);
+        handler.setTableStore(setUpVirtualUserTableStore());
     }
 
     private SMTPSession setupMockedSMTPSession(final SMTPConfiguration conf, final MailAddress rcpt, final boolean relayingAllowed) {
@@ -79,12 +80,6 @@
         return session;
     }
     
-    private MockServiceManager setUpServiceManager() throws Exception {
-        serviceMan = new MockServiceManager();
-        serviceMan.put(VirtualUserTableStore.ROLE, setUpVirtualUserTableStore());
-        return serviceMan;
-    }
-    
     private VirtualUserTableStore setUpVirtualUserTableStore() {
         final VirtualUserTable table = new VirtualUserTable() {
  
@@ -153,7 +148,6 @@
     }
     
     public void testRejectInvalidUser() throws Exception {
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -164,7 +158,6 @@
     }
     
     public void testNotRejectInvalidUserRelay() throws Exception {
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,true);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -175,7 +168,6 @@
     }
     
     public void testNotRejectValidUser() throws Exception {
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(VALID_USER + "@localhost");
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -189,7 +181,6 @@
         String recipient = "recip@domain";
         ArrayList<String> list = new ArrayList<String>();
         list.add(recipient);
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(recipient);
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -206,7 +197,6 @@
         String recipient = "recip@" + domain;
         ArrayList<String> list = new ArrayList<String>();
         list.add(domain);
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(recipient);
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -223,7 +213,6 @@
         String recipient = "recip@" + domain;
         ArrayList<String> list = new ArrayList<String>();
         list.add("reci.*");
-        ContainerUtil.service(handler, setUpServiceManager());
         MailAddress mailAddress = new MailAddress(recipient);
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
         ContainerUtil.enableLogging(handler,new MockLogger());
@@ -237,8 +226,6 @@
     
     public void testInvalidRegex() throws Exception{
         boolean exception = false;
-        ContainerUtil.service(handler, setUpServiceManager());
-        ContainerUtil.enableLogging(handler,new MockLogger());
         
         ArrayList<String> list = new ArrayList<String>();
         list.add("(.*");
@@ -255,9 +242,6 @@
         MailAddress mailAddress = new MailAddress(USER1 + "@localhost");
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
     
-        ContainerUtil.service(handler, setUpServiceManager());
-        ContainerUtil.enableLogging(handler,new MockLogger());
-
         int rCode = handler.doRcpt(session, null, mailAddress).getResult();
         
         assertEquals("Not rejected",rCode,HookReturnCode.DECLINED);
@@ -267,9 +251,6 @@
         MailAddress mailAddress = new MailAddress(USER2 + "@localhost");
         SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
 
-        ContainerUtil.service(handler, setUpServiceManager());
-        ContainerUtil.enableLogging(handler,new MockLogger());
-
         int rCode = handler.doRcpt(session, null,mailAddress).getResult();
     
         assertNull("Valid Error mapping",session.getState().get("VALID_USER"));



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