james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject svn commit: r992557 - in /james/server/trunk: mailets/src/main/java/org/apache/james/transport/mailets/ spoolmanager/src/main/java/org/apache/james/transport/mailets/ spring-deployment/src/main/config/james/ user-api/src/main/java/org/apache/james/api/...
Date Sat, 04 Sep 2010 08:03:54 GMT
Author: eric
Date: Sat Sep  4 08:03:53 2010
New Revision: 992557

URL: http://svn.apache.org/viewvc?rev=992557&view=rev
Log:
XMLVirtualUserTable and JDBCVirtualUserTable work symetric (+ code format + deprecate some mailets usage) (JAMES-745)

Modified:
    james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
    james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCVirtualUserTable.java
    james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/XMLVirtualUserTable.java
    james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
    james/server/trunk/spring-deployment/src/main/config/james/spoolmanager.xml
    james/server/trunk/spring-deployment/src/main/config/james/sqlResources.xml
    james/server/trunk/user-api/src/main/java/org/apache/james/api/vut/VirtualUserTable.java
    james/server/trunk/user-function/pom.xml
    james/server/trunk/user-function/src/main/java/org/apache/james/vut/JDBCVirtualUserTable.java
    james/server/trunk/user-function/src/main/java/org/apache/james/vut/XMLVirtualUserTable.java
    james/server/trunk/user-function/src/test/java/org/apache/james/vut/JDBCVirtualUserTableTest.java
    james/server/trunk/user-function/src/test/java/org/apache/james/vut/XMLVirtualUserTableTest.java
    james/server/trunk/user-function/src/test/resources/sqlResources.xml
    james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java
    james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableUtil.java
    james/server/trunk/user-library/src/test/java/org/apache/james/vut/AbstractVirtualUserTableTest.java

Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/AbstractVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -47,7 +47,10 @@ import org.apache.oro.text.regex.Malform
  * Provides an abstraction of common functionality needed for implementing
  * a Virtual User Table. Override the <code>mapRecipients</code> method to
  * map virtual recipients to real recipients.
+ * 
+ * @deprecated use the definitions in virtualusertable-store.xml instead
  */
+@Deprecated
 public abstract class AbstractVirtualUserTable extends GenericMailet
 {
     static private final String MARKER = "org.apache.james.transport.mailets.AbstractVirtualUserTable.mapped";

Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCVirtualUserTable.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/JDBCVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -89,7 +89,10 @@ import java.util.Map;
  *   &lt;table&gt;db://maildb/VirtualUserTable&lt;/table&gt;
  *   &lt;sqlquery&gt;sqlquery&lt;/sqlquery&gt;
  * &lt;/mailet&gt;
+ * 
+ * @deprecated use the definitions in virtualusertable-store.xml instead
  */
+@Deprecated
 public class JDBCVirtualUserTable extends AbstractVirtualUserTable
 {
     protected DataSource datasource;

Modified: james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/XMLVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/XMLVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/XMLVirtualUserTable.java (original)
+++ james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/XMLVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -56,7 +56,11 @@ import org.apache.mailet.MailAddress;
  * 2. user@*         - catchall mapping for user anywhere
  * 3. *@domain       - catchall mapping for anyone at domain
  * 4. null           - no valid mapping
+ * 
+ * @deprecated use the definitions in virtualusertable-store.xml instead
+ * 
  */
+@Deprecated
 public class XMLVirtualUserTable extends AbstractVirtualUserTable
 {
   /**

Modified: james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java (original)
+++ james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java Sat Sep  4 08:03:53 2010
@@ -48,7 +48,11 @@ import org.apache.mailet.MailAddress;
  * 
  * <usersRepository>LocalAdmins</usersRepository>: specific users repository
  * name. Default to empty. If empty does lookup the default userRepository.
+ * 
+ * @deprecated use org.apache.james.transport.mailets.VirtualUserTable
+ * 
  */
+@Deprecated
 public class UsersRepositoryAliasingForwarding extends AbstractVirtualUserTableMailet {
 
     /**

Modified: james/server/trunk/spring-deployment/src/main/config/james/spoolmanager.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spoolmanager.xml?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spoolmanager.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spoolmanager.xml Sat Sep  4 08:03:53 2010
@@ -33,7 +33,7 @@
          <!-- This mailet redirects mail for the user 'postmaster' at any local domain to -->
          <!-- the postmaster address specified for the server. The postmaster address -->
          <!-- is required by rfc822. Do not remove this mailet unless you are meeting -->
-         <!-- this requirement through other means (e.g. a XML/JDBCVirtualUserTable mailet) -->
+         <!-- this requirement through other means (e.g. a XML/JDBCVirtualUserTable defined in virtualusertable-store.xml) -->
          <mailet match="All" class="PostmasterAlias"/>
 
          <!-- Checks that the email Sender is associated with a valid domain. -->
@@ -180,6 +180,9 @@ Regards, Postmaster XXX.YYY
          -->
 
          <!--
+         
+         XMLVirtualUserTable is deprecated - Use the definitions in virtualusertable-store.xml
+         
          <mailet match="All" class="XMLVirtualUserTable">
             <!- 1:1 mapping ->
             <mapping>morgoth@middle-earth=sauron@mordor</mapping>
@@ -196,6 +199,7 @@ Regards, Postmaster XXX.YYY
                                   regex:(.*)-off@listserver:${1}-unsubscribe@listserver
             </mapping>
          </mailet>
+         
          -->
 
          <!-- Anti-spam processing -->
@@ -393,12 +397,11 @@ Regards, Postmaster XXX.YYY
          </mailet>
          -->
 
-
+         <!--  The VirtualUserTable will use the definitions found in virtualusertable-store.xml -->
          <mailet match="All" class="VirtualUserTable">
              <virtualusertable>DefaultVirtualUserTable</virtualusertable>
          </mailet>
 
-
          <!-- Is the recipient is for a local account, deliver it locally -->
          <mailet match="RecipientIsLocal" class="LocalDelivery"/>
 

Modified: james/server/trunk/spring-deployment/src/main/config/james/sqlResources.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/sqlResources.xml?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/sqlResources.xml (original)
+++ james/server/trunk/spring-deployment/src/main/config/james/sqlResources.xml Sat Sep  4 08:03:53 2010
@@ -897,9 +897,9 @@
 <sqlDefs name="org.apache.james.vut.JDBCVirtualUserTable">
 
     <!-- Statements used to check whether a particular message exists in this repository. -->
-    <sql name="selectMappings" db="derby">select VirtualUserTable.target_address,(VirtualUserTable."user" || '@' ||VirtualUserTable.domain) from VirtualUserTable, VirtualUserTable as VUTDomains where ((VirtualUserTable."user") like ? or (VirtualUserTable."user") like '\%' escape '\') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '\%' escape '\')) order by 2 desc</sql>
-    <sql name="selectMappings">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user like '\%') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '\%')) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1</sql>
-    <sql name="selectMappings" db="postgresql">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user like E'%') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like E'%')) order by (VirtualUserTable.user || '@' || VirtualUserTable.domain) desc limit 1</sql>
+    <sql name="selectMappings" db="derby">select VirtualUserTable.target_address,(VirtualUserTable."user" || '@' ||VirtualUserTable.domain) from VirtualUserTable, VirtualUserTable as VUTDomains where ((VirtualUserTable."user") like ? or (VirtualUserTable."user") = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by 2 desc</sql>
+    <sql name="selectMappings">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1</sql>
+    <sql name="selectMappings" db="postgresql">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by (VirtualUserTable.user || '@' || VirtualUserTable.domain) desc limit 1</sql>
     
     <sql name="selectUserDomainMapping" db="derby">select VirtualUserTable.target_address from VirtualUserTable where VirtualUserTable."user" = ? and VirtualUserTable.domain = ? </sql>
     <sql name="selectUserDomainMapping">select VirtualUserTable.target_address from VirtualUserTable where VirtualUserTable.user = ? and VirtualUserTable.domain = ? </sql>

Modified: james/server/trunk/user-api/src/main/java/org/apache/james/api/vut/VirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-api/src/main/java/org/apache/james/api/vut/VirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-api/src/main/java/org/apache/james/api/vut/VirtualUserTable.java (original)
+++ james/server/trunk/user-api/src/main/java/org/apache/james/api/vut/VirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -16,24 +16,19 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.api.vut;
 
 import java.util.Collection;
 
-
 /**
- * Interface which should be implemented of classes which map recipients
- *
+ * Interface which should be implemented of classes which map recipients.
  */
 public interface VirtualUserTable {
     
     /**
      * The component role used by components implementing this service
      */
-    public static final String ROLE = "org.apache.james.api.vut.VirtualUserTable";
+    public static final String ROLE = VirtualUserTable.class.getName();
     
     /**
      * The prefix which is used for error mappings
@@ -51,6 +46,11 @@ public interface VirtualUserTable {
     public static final String ALIASDOMAIN_PREFIX = "domain:";
     
     /**
+     * The wildcard used for alias domain mappings
+     */
+    public final static String WILDCARD = "*";
+
+    /**
      * Return the mapped MailAddress for the given address. Return null if no 
      * matched mapping was found
      * 
@@ -59,4 +59,5 @@ public interface VirtualUserTable {
      * @throws ErrorMappingException get thrown if an error mapping was found
      */
     public Collection<String> getMappings(String user, String domain) throws ErrorMappingException;
+
 }

Modified: james/server/trunk/user-function/pom.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/pom.xml?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/pom.xml (original)
+++ james/server/trunk/user-function/pom.xml Sat Sep  4 08:03:53 2010
@@ -59,13 +59,6 @@
             </goals>
           </execution>
         </executions>
-        <dependencies>
-          <dependency>
-          <groupId>org.apache.james</groupId>
-          <artifactId>james-server-user-api</artifactId>
-          <version>${pom.version}</version>
-        </dependency>
-    </dependencies>
       </plugin>
     </plugins>
   </build>

Modified: james/server/trunk/user-function/src/main/java/org/apache/james/vut/JDBCVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/src/main/java/org/apache/james/vut/JDBCVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/src/main/java/org/apache/james/vut/JDBCVirtualUserTable.java (original)
+++ james/server/trunk/user-function/src/main/java/org/apache/james/vut/JDBCVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -16,10 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
-
 package org.apache.james.vut;
 
 import java.io.InputStream;
@@ -55,11 +51,9 @@ public class JDBCVirtualUserTable extend
 
     private DataSourceSelector datasources = null;
     private DataSource dataSourceComponent = null;
-    private String tableName = "VirtualUserTable";
     private String dataSourceName = null;
     
-    private static String WILDCARD = "%";
-
+    private String tableName = "VirtualUserTable";
 
     /**
      * Contains all of the sql strings for this component.
@@ -73,12 +67,9 @@ public class JDBCVirtualUserTable extend
     
     private FileSystem fileSystem;
 
-    protected String datasourceName;
-    
-    
-    
-    public void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException {
-        String destination = arg0.getString("[@destinationURL]",null);
+    public void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException {
+        
+        String destination = conf.getString("[@destinationURL]",null);
     
         if (destination == null) {
             throw new ConfigurationException("destinationURL must configured");
@@ -107,17 +98,18 @@ public class JDBCVirtualUserTable extend
                 new StringBuffer(256)
                         .append("Malformed destinationURL - Must be of the format '")
                         .append("db://<data-source>'.  Was passed ")
-                        .append(arg0.getString("[@destinationURL]"));
+                        .append(conf.getString("[@destinationURL]"));
             throw new ConfigurationException(exceptionBuffer.toString());
         }
+        
         if (urlParams.size() >= 1) {
             dataSourceName = (String)urlParams.get(0);
         }
+        
         if (urlParams.size() >= 2) {
             tableName = (String)urlParams.get(1);
         }
 
-
         if (getLogger().isDebugEnabled()) {
             StringBuffer logBuffer =
                 new StringBuffer(128)
@@ -127,12 +119,13 @@ public class JDBCVirtualUserTable extend
             getLogger().debug(logBuffer.toString());
         }
     
-        sqlFileName = arg0.getString("sqlFile");
+        sqlFileName = conf.getString("sqlFile");
         
     }
 
     @PostConstruct
     public void init() throws Exception {
+        
         setDataSource(datasources.getDataSource(dataSourceName));
     
         StringBuffer logBuffer = null;
@@ -148,6 +141,7 @@ public class JDBCVirtualUserTable extend
             // Initialise the sql strings.
 
             InputStream sqlFile = null;
+            
             try {
                 sqlFile = fileSystem.getResource(sqlFileName);
             } catch (Exception e) {
@@ -178,9 +172,9 @@ public class JDBCVirtualUserTable extend
 
             // Check if the required table exists. If not, create it.
             DatabaseMetaData dbMetaData = conn.getMetaData();
+            
             // Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo.
             // Try UPPER, lower, and MixedCase, to see if the table is there.
-           
             if (!(theJDBCUtil.tableExists(dbMetaData, tableName))) {
             
                 // Users table doesn't exist - create it.
@@ -214,7 +208,6 @@ public class JDBCVirtualUserTable extend
         }
     };
     
-    
     public void setDataSource(DataSource dataSourceComponent) {
         this.dataSourceComponent = dataSourceComponent;
     }
@@ -281,16 +274,18 @@ public class JDBCVirtualUserTable extend
      * @see org.apache.james.impl.vut.AbstractVirtualUserTable#addMappingInternal(String, String, String)
      */
     public boolean addMappingInternal(String user, String domain, String regex) throws InvalidMappingException {
+
         String newUser = getUserString(user);
         String newDomain = getDomainString(domain);
         Collection<String> map =  getUserDomainMappings(newUser,newDomain);
 
         if (map != null && map.size() != 0) {
             map.add(regex);
-        
             return updateMapping(newUser,newDomain,VirtualUserTableUtil.CollectionToMapping(map));
         }
+    
         return addRawMapping(newUser,newDomain,regex);
+    
     }
     
     /**
@@ -517,5 +512,5 @@ public class JDBCVirtualUserTable extend
         }
         return null;
     }
+    
 }
-

Modified: james/server/trunk/user-function/src/main/java/org/apache/james/vut/XMLVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/src/main/java/org/apache/james/vut/XMLVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/src/main/java/org/apache/james/vut/XMLVirtualUserTable.java (original)
+++ james/server/trunk/user-function/src/main/java/org/apache/james/vut/XMLVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -16,12 +16,8 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.vut;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -33,19 +29,22 @@ import org.apache.commons.configuration.
 import org.apache.james.impl.vut.AbstractVirtualUserTable;
 import org.apache.james.impl.vut.VirtualUserTableUtil;
 
+/**
+ *
+ */
 public class XMLVirtualUserTable extends AbstractVirtualUserTable {
+    
     /**
      * Holds the configured mappings
      */
     private Map<String,String> mappings;
     
-    private final static String WILDCARD = "*";
-
     /**
      * @see org.apache.james.impl.vut.AbstractVirtualUserTable#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
      */
     @SuppressWarnings("unchecked")
     public void doConfigure(HierarchicalConfiguration arg0) throws ConfigurationException {
+
         List<String> mapConf = arg0.getList("mapping");
     
         mappings = new HashMap<String,String>();
@@ -58,9 +57,6 @@ public class XMLVirtualUserTable extends
             throw new ConfigurationException("No mapping configured");
         }
         
-        // Add domains of the mappings map to the domains List
-        Iterator<String> keys = mappings.keySet().iterator();
-        
     }
     
     /**
@@ -79,7 +75,6 @@ public class XMLVirtualUserTable extends
             return null;
         } else {
             return VirtualUserTableUtil.getTargetString(user, domain, mappings);
-    
         }
     }
 
@@ -114,7 +109,6 @@ public class XMLVirtualUserTable extends
         if ( mappings != null && mappings.size() > 0) {
             Map<String,Collection<String>> mappingsNew = new HashMap<String,Collection<String>>();
             Iterator<String> maps = mappings.keySet().iterator();
-                
             while (maps.hasNext()) {
                 String key = maps.next();
                 mappingsNew.put(key, VirtualUserTableUtil.mappingToCollection(mappings.get(key).toString()));
@@ -124,4 +118,5 @@ public class XMLVirtualUserTable extends
             return null;
         }
     }
+    
 }

Modified: james/server/trunk/user-function/src/test/java/org/apache/james/vut/JDBCVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/src/test/java/org/apache/james/vut/JDBCVirtualUserTableTest.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/src/test/java/org/apache/james/vut/JDBCVirtualUserTableTest.java (original)
+++ james/server/trunk/user-function/src/test/java/org/apache/james/vut/JDBCVirtualUserTableTest.java Sat Sep  4 08:03:53 2010
@@ -16,9 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.vut;
 
 import org.apache.commons.configuration.DefaultConfigurationBuilder;
@@ -31,9 +28,9 @@ import org.apache.james.test.util.Util;
 public class JDBCVirtualUserTableTest extends AbstractVirtualUserTableTest {
     
     /**
-     * @see org.apache.james.vut.AbstractVirtualUserTableTest#getVirtalUserTable()
+     * @see org.apache.james.vut.AbstractVirtualUserTableTest#getVirtualUserTable()
      */
-    protected AbstractVirtualUserTable getVirtalUserTable() throws Exception {
+    protected AbstractVirtualUserTable getVirtualUserTable() throws Exception {
         JDBCVirtualUserTable mr = new JDBCVirtualUserTable();
         mr.setLog(new SimpleLog("MockLog"));
         mr.setDataSourceSelector(Util.getDataSourceSelector());

Modified: james/server/trunk/user-function/src/test/java/org/apache/james/vut/XMLVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/src/test/java/org/apache/james/vut/XMLVirtualUserTableTest.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/src/test/java/org/apache/james/vut/XMLVirtualUserTableTest.java (original)
+++ james/server/trunk/user-function/src/test/java/org/apache/james/vut/XMLVirtualUserTableTest.java Sat Sep  4 08:03:53 2010
@@ -16,8 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
 package org.apache.james.vut;
 
 import java.util.ArrayList;
@@ -31,37 +29,28 @@ import org.apache.james.api.vut.manageme
 import org.apache.james.impl.vut.AbstractVirtualUserTable;
 import org.apache.james.impl.vut.VirtualUserTableUtil;
 
-
 public class XMLVirtualUserTableTest extends AbstractVirtualUserTableTest {
+
     private DefaultConfigurationBuilder defaultConfiguration = new DefaultConfigurationBuilder();
     
-    
     @Override
     protected void setUp() throws Exception {
         defaultConfiguration.setDelimiterParsingDisabled(true);
-        
         super.setUp();
     }
 
-
-
-    protected AbstractVirtualUserTable getVirtalUserTable() throws Exception {
+    protected AbstractVirtualUserTable getVirtualUserTable() throws Exception {
         XMLVirtualUserTable mr = new XMLVirtualUserTable();
         mr.setDNSService(setUpDNSServer());
         mr.setLog(new SimpleLog("MockLog"));
-       
         return mr;
     }
     
-    
-
     /**
      * @see org.apache.james.vut.AbstractVirtualUserTableTest#addMapping(java.lang.String, java.lang.String, java.lang.String, int)
      */
     protected boolean addMapping(String user, String domain, String mapping, int type) throws InvalidMappingException {
-        if (user == null) user = "*";
-        if (domain == null) domain = "*";
-        
+
         Collection<String> mappings = virtualUserTable.getUserDomainMappings(user, domain);
 
         if (mappings == null) {
@@ -81,7 +70,7 @@ public class XMLVirtualUserTableTest ext
         }
         
         if (mappings.size() > 0) { 
-            defaultConfiguration.addProperty("mapping",user + "@" + domain +"=" + VirtualUserTableUtil.CollectionToMapping(mappings));
+            defaultConfiguration.addProperty("mapping",user + "@" + domain + "=" + VirtualUserTableUtil.CollectionToMapping(mappings));
         }
     
         try {
@@ -93,21 +82,21 @@ public class XMLVirtualUserTableTest ext
                 return true;
             }
         }
+            
         return true;
+    
     }
 
     /**
      * @see org.apache.james.vut.AbstractVirtualUserTableTest#removeMapping(java.lang.String, java.lang.String, java.lang.String, int)
      */
     protected boolean removeMapping(String user, String domain, String mapping, int type) throws InvalidMappingException {       
-        if (user == null) user = "*";
-        if (domain == null) domain = "*";
-        
+
         Collection<String> mappings = virtualUserTable.getUserDomainMappings(user, domain);
         
         if (mappings == null) {
             return false;
-        }  
+        }
     
         removeMappingsFromConfig(user,domain, mappings);
     
@@ -134,10 +123,11 @@ public class XMLVirtualUserTableTest ext
                return true;
            }
         }
+            
         return true;
+
     }
     
-    
     @SuppressWarnings("unchecked")
     private void removeMappingsFromConfig(String user, String domain, Collection<String> mappings) {
         List<String> confs = defaultConfiguration.getList("mapping");
@@ -152,7 +142,6 @@ public class XMLVirtualUserTableTest ext
         }
         // clear old values
         defaultConfiguration.clear();
-        
         // add stored mappings
         for (int i = 0; i < stored.size(); i++) {
             defaultConfiguration.addProperty("mapping", stored.get(i));

Modified: james/server/trunk/user-function/src/test/resources/sqlResources.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/user-function/src/test/resources/sqlResources.xml?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-function/src/test/resources/sqlResources.xml (original)
+++ james/server/trunk/user-function/src/test/resources/sqlResources.xml Sat Sep  4 08:03:53 2010
@@ -442,217 +442,6 @@
     </sql>
 </sqlDefs>
 
-<!-- SQL statements to support the JDBCSpoolRepository class -->
-<!-- -->
-<!-- The JDBCSpoolRepository allows James to use a JDBC compliant database -->
-<!-- to hold messages that are on the spool. -->
-<sqlDefs name="org.apache.james.mailrepository.JDBCSpoolRepository">
-
-    <!-- Statements used to check whether a particular message exists in this repository. -->
-    <sql name="checkMessageExistsSQL">SELECT count(*) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to update a message stored in this repository. -->
-    <sql name="updateMessageSQL">UPDATE ${table} SET message_state = ?, error_message = ?, sender = ?, recipients = ?, remote_host = ?, remote_addr = ?, last_updated = ? WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to update the body of a message stored in this repository. -->
-    <sql name="updateMessageBodySQL">UPDATE ${table} SET message_body = ? WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to update the attributes of a message stored in this repository. -->
-    <sql name="updateMessageAttributesSQL">UPDATE ${table} SET message_attributes = ? WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to insert a message into this repository. -->
-    <sql name="insertMessageSQL">INSERT INTO ${table} (message_name,
-    repository_name, message_state, error_message, sender, recipients,
-    remote_host, remote_addr, last_updated, message_body,
-    message_attributes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)</sql>
-
-    <!-- Statements used to retrieve a message stored in this repository. -->
-    <sql name="retrieveMessageSQL">SELECT message_state, error_message, sender, recipients, remote_host, remote_addr, last_updated FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to retrieve the body of a message stored in this repository. -->
-    <sql name="retrieveMessageBodySQL">SELECT message_body FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to retrieve the attributes of a message stored in this repository. -->
-    <sql name="retrieveMessageAttributesSQL">SELECT message_attributes FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    
-    <!-- Statements used to retrieve the size of the body of a message stored in this repository. -->
-    <!-- NOTE: This statement is optional and need not be implemented for a particular database to be supported. -->
-    <sql name="retrieveMessageBodySizeSQL" db="mssql">SELECT datalength(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="mysql">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="hypersonic">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="hsqldb">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="postgresql">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="oracle">SELECT dbms_lob.getlength(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="db2">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-    <sql name="retrieveMessageBodySizeSQL" db="ingres">SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to delete a message stored in this repository. -->
-    <sql name="removeMessageSQL">DELETE FROM ${table} WHERE message_name = ? AND repository_name = ?</sql>
-
-    <!-- Statements used to list all messages stored in this repository. -->
-    <sql name="listMessagesSQL">SELECT message_name, message_state, last_updated, error_message FROM ${table} WHERE repository_name = ? ORDER BY last_updated ASC</sql>
-
-    <!-- Statements used to create the table associated with this class. -->
-    <sql name="createTable" db="hypersonic">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) NULL ,
-            sender varchar (255) NULL ,
-            recipients varchar NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body varchar NOT NULL ,
-            message_attributes varchar NULL ,
-            last_updated timestamp NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="hsqldb">
-        CREATE CACHED TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) NULL ,
-            sender varchar (255) NULL ,
-            recipients varchar NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body varchar NOT NULL ,
-            message_attributes varchar NULL ,
-            last_updated timestamp NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="mysql">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (100) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) NULL ,
-            sender varchar (255) NULL ,
-            recipients text NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body longblob NOT NULL ,
-            message_attributes longblob NULL ,
-            last_updated datetime NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="mssql">
-        CREATE TABLE [${table}] (
-            [message_name] [varchar] (200) NOT NULL,
-            [repository_name] [varchar] (255) NOT NULL,
-            [message_state] [varchar] (30) NOT NULL ,
-            [error_message] [varchar] (1000) NULL ,
-            [sender] [varchar] (255) NULL ,
-            [recipients] [text] NOT NULL ,
-            [remote_host] [varchar] (255) NOT NULL ,
-            [remote_addr] [varchar] (20) NOT NULL ,
-            [message_body] [image] NOT NULL ,
-            [message_attributes] [image] NULL ,
-            [last_updated] [datetime] NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="oracle">
-        CREATE TABLE ${table} (
-            message_name varchar2(200) NOT NULL ,
-            repository_name varchar2(255) NOT NULL ,
-            message_state varchar2(30) NOT NULL ,
-            error_message varchar2(200) NULL ,
-            sender varchar2(255) NULL ,
-            recipients varchar2(1000) NOT NULL ,
-            remote_host varchar2(255) NOT NULL ,
-            remote_addr varchar2(20) NOT NULL ,
-            message_body blob NOT NULL ,
-            message_attributes blob NULL ,
-            last_updated date NOT NULL ,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="postgresql">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) NULL ,
-            sender varchar (255) NULL ,
-            recipients text NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body bytea NOT NULL ,
-            message_attributes bytea NULL ,
-            last_updated timestamp NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="sapdb">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) NULL ,
-            sender varchar (255) NULL ,
-            recipients long NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body long byte NOT NULL ,
-            message_attributes long byte NULL ,
-            last_updated date NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="db2">
-        CREATE TABLE ${table} (
-            message_name varchar(200) NOT NULL ,
-            repository_name varchar(255) NOT NULL ,
-            message_state varchar(30) NOT NULL ,
-            error_message varchar(200) ,
-            sender varchar(255) ,
-            recipients varchar(1000) NOT NULL ,
-            remote_host varchar(100) NOT NULL ,
-            remote_addr varchar(20) NOT NULL ,
-            message_body blob NOT NULL ,
-            message_attributes blob ,
-            last_updated timestamp NOT NULL ,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-    <sql name="createTable" db="ingres">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) ,
-            sender varchar (255) ,
-            recipients LONG VARCHAR NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body LONG BYTE NOT NULL ,
-            message_attributes LONG BYTE ,
-            last_updated DATE NOT NULL
-        )
-    </sql>
-    <sql name="createTable" db="derby">
-        CREATE TABLE ${table} (
-            message_name varchar (200) NOT NULL,
-            repository_name varchar (255) NOT NULL,
-            message_state varchar (30) NOT NULL ,
-            error_message varchar (200) ,
-            sender varchar (255) ,
-            recipients long varchar NOT NULL ,
-            remote_host varchar (255) NOT NULL ,
-            remote_addr varchar (20) NOT NULL ,
-            message_body blob NOT NULL ,
-            message_attributes blob ,
-            last_updated timestamp NOT NULL,
-            PRIMARY KEY (repository_name, message_name)
-        )
-    </sql>
-</sqlDefs>
 
 <!-- SQL statements to support the BayesianAnalysis and the BayesianAnalysisFeeder mailets -->
 <!-- -->
@@ -900,6 +689,86 @@
 
 </sqlDefs>
 
+<sqlDefs name="NetworkWhiteList">
+
+    <sql name="networkWhiteListTableName">networkWhitelist</sql>
+
+    <!-- Statements used to retrieve a single entry. -->
+    <sql name="selectNetwork">SELECT network FROM networkWhitelist where (localUser=? AND localHost=?)</sql>
+
+    <!-- Statements used to create the "whitelist" table. -->
+    <sql name="createNetworkWhiteListTable" db="hypersonic">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL,
+            PRIMARY KEY (localUser, localHost)
+        )    </sql>
+    <sql name="createNetworkWhiteListTable" db="hsqldb">
+        CREATE CACHED TABLE ${table} (
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )    </sql>
+    <sql name="createNetworkWhiteListTable" db="mysql">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) character set latin1 NOT NULL,
+            network varchar (255) NOT NULL
+        ) TYPE=InnoDB
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="mssql">
+        CREATE TABLE [networkWhitelist] (
+            [localUser] [varchar] (64) NOT NULL,
+            [localHost] [varchar] (255) NOT NULL,
+            [network] [varchar] (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="oracle">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="postgresql">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="sapdb">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="db2">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="ingres">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+    <sql name="createNetworkWhiteListTable" db="derby">
+        CREATE TABLE networkWhitelist (
+            localUser varchar (64) NOT NULL,
+            localHost varchar (255) NOT NULL,
+            network varchar (255) NOT NULL
+        )
+    </sql>
+
+</sqlDefs>
 <!-- SQL statements to support the GreyList Handler-->
 <!-- -->
 <sqlDefs name="GreyList">
@@ -1028,8 +897,9 @@
 <sqlDefs name="org.apache.james.vut.JDBCVirtualUserTable">
 
     <!-- Statements used to check whether a particular message exists in this repository. -->
-    <sql name="selectMappings" db="derby">select VirtualUserTable.target_address,(VirtualUserTable."user" || '@' ||VirtualUserTable.domain) from VirtualUserTable, VirtualUserTable as VUTDomains where ((VirtualUserTable."user") like ? or (VirtualUserTable."user") like '\%' escape '\') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '\%' escape '\')) order by 2 desc</sql>
-    <sql name="selectMappings">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user like '\%') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '\%')) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1</sql>
+    <sql name="selectMappings" db="derby">select VirtualUserTable.target_address,(VirtualUserTable."user" || '@' ||VirtualUserTable.domain) from VirtualUserTable, VirtualUserTable as VUTDomains where ((VirtualUserTable."user") like ? or (VirtualUserTable."user") = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by 2 desc</sql>
+    <sql name="selectMappings">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1</sql>
+    <sql name="selectMappings" db="postgresql">select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user = '*') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain = '*')) order by (VirtualUserTable.user || '@' || VirtualUserTable.domain) desc limit 1</sql>
     
     <sql name="selectUserDomainMapping" db="derby">select VirtualUserTable.target_address from VirtualUserTable where VirtualUserTable."user" = ? and VirtualUserTable.domain = ? </sql>
     <sql name="selectUserDomainMapping">select VirtualUserTable.target_address from VirtualUserTable where VirtualUserTable.user = ? and VirtualUserTable.domain = ? </sql>

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java (original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/AbstractVirtualUserTable.java Sat Sep  4 08:03:53 2010
@@ -16,9 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.impl.vut;
 
 import java.net.InetAddress;
@@ -27,7 +24,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.logging.Logger;
 
@@ -60,7 +56,9 @@ public abstract class AbstractVirtualUse
        
     // TODO: Should we use true or false as default ?
     private boolean recursive = true;
+
     private HierarchicalConfiguration config;
+    
     private Log logger;
 
     @Resource(name="dnsserver")
@@ -82,16 +80,13 @@ public abstract class AbstractVirtualUse
         this.logger = logger;
     }
     
-    
     protected void doConfigure(HierarchicalConfiguration conf) throws ConfigurationException {
-        
     }
     
     public void setRecursiveMapping(boolean recursive) {
         this.recursive = recursive;
     }
     
-    
     /**
      * Set the mappingLimit
      * 
@@ -110,8 +105,7 @@ public abstract class AbstractVirtualUse
         return getMappings(user,domain,mappingLimit);
     }
     
-
-    public Collection<String> getMappings(String user,String domain,int mappingLimit) throws ErrorMappingException {
+    public Collection<String> getMappings(String user, String domain, int mappingLimit) throws ErrorMappingException {
 
         // We have to much mappings throw ErrorMappingException to avoid infinity loop
         if (mappingLimit == 0) throw new ErrorMappingException("554 Too many mappings to process");
@@ -186,8 +180,11 @@ public abstract class AbstractVirtualUse
                     }
                 } 
             }
+        
             return mappings;
+        
         }
+        
         return null;
     }
     
@@ -274,6 +271,7 @@ public abstract class AbstractVirtualUse
      * @see org.apache.james.api.vut.management.VirtualUserTableManagement#addMapping(java.lang.String, java.lang.String, java.lang.String)
      */
     public synchronized boolean addMapping(String user, String domain, String mapping) throws InvalidMappingException {
+
         String map = mapping.toLowerCase();
         
         if (map.startsWith(VirtualUserTable.ERROR_PREFIX)) {
@@ -286,12 +284,14 @@ public abstract class AbstractVirtualUse
         } else {
             return addAddressMapping(user,domain,map);
         }
+        
     }
     
     /**
      * @see org.apache.james.api.vut.management.VirtualUserTableManagement#removeMapping(java.lang.String, java.lang.String, java.lang.String)
      */
     public synchronized boolean removeMapping(String user, String domain, String mapping) throws InvalidMappingException {
+
         String map = mapping.toLowerCase();
     
         if (map.startsWith(VirtualUserTable.ERROR_PREFIX)) {
@@ -304,6 +304,7 @@ public abstract class AbstractVirtualUse
         } else {
             return removeAddressMapping(user,domain,map);
         }
+        
     }
     
     /**
@@ -321,38 +322,15 @@ public abstract class AbstractVirtualUse
     }
     
     
-   private boolean checkMapping(String user,String domain, String mapping) {
+    private boolean checkMapping(String user,String domain, String mapping) {
        Collection<String> mappings = getUserDomainMappings(user,domain);
        if (mappings != null && mappings.contains(mapping)) {
            return false;
        } else {
            return true;
        }
-   }
-
- 
-    /**
-     * Return a List which holds all ipAddress of the domains in the given List
-     * 
-     * @param domains List of domains
-     * @return domainIP List of ipaddress for domains
-     */
-    private static List<String> getDomainsIP(List<String> domains,DNSService dns,Log log) {
-        List<String> domainIP = new ArrayList<String>();
-        if (domains.size() > 0 ) {
-            for (int i = 0; i < domains.size(); i++) {
-                List<String> domList = getDomainIP(domains.get(i).toString(),dns,log);
-                
-                for(int i2 = 0; i2 < domList.size();i2++) {
-                    if(domainIP.contains(domList.get(i2)) == false) {
-                        domainIP.add(domList.get(i2));
-                    }
-                }
-            }
-        }
-        return domainIP;    
     }
-    
+
     /**
      * @see #getDomainsIP(List, DNSService, Logger)
      */
@@ -402,8 +380,9 @@ public abstract class AbstractVirtualUse
      * @param domain the domain
      * @return the mappings
      */
-    private String mapAddress(String user,String domain) {
-       String mappings = mapAddressInternal(user, domain);
+    private String mapAddress(String user, String domain) {
+
+        String mappings = mapAddressInternal(user, domain);
 
         // check if we need to sort
         // TODO: Maybe we should just return the aliasdomain mapping
@@ -486,4 +465,5 @@ public abstract class AbstractVirtualUse
      *    <code>MailAddress</code>es to <code>String</code>s.
      */
     protected abstract String mapAddressInternal(String user, String domain);
+    
 }

Modified: james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableUtil.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableUtil.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableUtil.java (original)
+++ james/server/trunk/user-library/src/main/java/org/apache/james/impl/vut/VirtualUserTableUtil.java Sat Sep  4 08:03:53 2010
@@ -16,9 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
-
-
 package org.apache.james.impl.vut;
 
 import java.util.ArrayList;
@@ -44,8 +41,8 @@ public class VirtualUserTableUtil {
 
     private VirtualUserTableUtil() {}
     
-
-    public static String QUERY = "select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user like '\\%') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '\\%' and VUTDomains.domain like ?)) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1";
+    // @deprecated QUERY is deprecated - SQL queries are now located in sqlResources.xml
+    public static String QUERY = "select VirtualUserTable.target_address from VirtualUserTable, VirtualUserTable as VUTDomains where (VirtualUserTable.user like ? or VirtualUserTable.user like '\\%') and (VirtualUserTable.domain like ? or (VirtualUserTable.domain like '%*%' and VUTDomains.domain like ?)) order by concat(VirtualUserTable.user,'@',VirtualUserTable.domain) desc limit 1";
     
     /**
      * Processes regex virtual user mapping
@@ -58,7 +55,7 @@ public class VirtualUserTableUtil {
      * @param targetString a String specifying the mapping
      * @throws MalformedPatternException 
      */
-     public static String regexMap( MailAddress address, String targetString) throws MalformedPatternException {
+    public static String regexMap( MailAddress address, String targetString) throws MalformedPatternException {
         String result = null;
         int identifierLength = VirtualUserTable.REGEX_PREFIX.length();
 
@@ -85,16 +82,16 @@ public class VirtualUserTableUtil {
             result = XMLResources.replaceParameters(targetString.substring(msgPos + 1), parameters);
         }    
         return result;
-    }
+     }
      
-     /**
-      * Returns the real recipient given a virtual username and domain.
-      * 
-      * @param user the virtual user
-      * @param domain the virtual domain
-      * @return the real recipient address, or <code>null</code> if no mapping exists
-      */
-     public static String getTargetString(String user, String domain, Map mappings) {
+    /**
+     * Returns the real recipient given a virtual username and domain.
+     * 
+     * @param user the virtual user
+     * @param domain the virtual domain
+     * @return the real recipient address, or <code>null</code> if no mapping exists
+     */
+    public static String getTargetString(String user, String domain, Map mappings) {
          StringBuffer buf;
          String target;
          
@@ -162,7 +159,7 @@ public class VirtualUserTableUtil {
      */
      public static Collection<String> getMappings(String rawMapping) {
         return mappingToCollection(rawMapping);
-    }
+     }
      
      /**
       * Convert a raw mapping String to a Collection
@@ -180,9 +177,8 @@ public class VirtualUserTableUtil {
              map.add(raw);
          }
          return map;
-    }
+     }
      
-
      /**
       * Convert a Collection which holds mappings to a raw mapping String
       * 
@@ -203,4 +199,5 @@ public class VirtualUserTableUtil {
          }  
          return mapping.toString();  
     }
+     
 }

Modified: james/server/trunk/user-library/src/test/java/org/apache/james/vut/AbstractVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/user-library/src/test/java/org/apache/james/vut/AbstractVirtualUserTableTest.java?rev=992557&r1=992556&r2=992557&view=diff
==============================================================================
--- james/server/trunk/user-library/src/test/java/org/apache/james/vut/AbstractVirtualUserTableTest.java (original)
+++ james/server/trunk/user-library/src/test/java/org/apache/james/vut/AbstractVirtualUserTableTest.java Sat Sep  4 08:03:53 2010
@@ -16,7 +16,6 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.vut;
 
 import java.net.InetAddress;
@@ -25,6 +24,8 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.Map;
 
+import junit.framework.TestCase;
+
 import org.apache.james.api.dnsservice.DNSService;
 import org.apache.james.api.dnsservice.TemporaryResolutionException;
 import org.apache.james.api.vut.ErrorMappingException;
@@ -33,35 +34,35 @@ import org.apache.james.api.vut.manageme
 import org.apache.james.impl.vut.AbstractVirtualUserTable;
 import org.apache.james.lifecycle.LifecycleUtil;
 
-import junit.framework.TestCase;
-
 public abstract class AbstractVirtualUserTableTest extends TestCase {
 
     protected AbstractVirtualUserTable virtualUserTable;
+    
     protected final static int REGEX_TYPE = 0;
     protected final static int ERROR_TYPE = 1;
     protected final static int ADDRESS_TYPE = 2;
     protected final static int ALIASDOMAIN_TYPE = 3;
-    
+
     protected void setUp() throws Exception {
-        virtualUserTable = getVirtalUserTable();
+        virtualUserTable = getVirtualUserTable();
     }
-    
+
     protected void tearDown() throws Exception {
-        Map<String,Collection<String>> mappings = virtualUserTable.getAllMappings();
         
+        Map<String,Collection<String>> mappings = virtualUserTable.getAllMappings();
+
         if (mappings != null) {
             Iterator<String> mappingsIt = virtualUserTable.getAllMappings().keySet().iterator();
-    
-    
+
+
             while(mappingsIt.hasNext()) {
                 String key = mappingsIt.next().toString();
                 String args[] = key.split("@");
-        
+
                 Collection<String> map = mappings.get(key);
-        
+
                 Iterator<String> mapIt = map.iterator();
-        
+
                 while (mapIt.hasNext()) {
                     try {
                         removeMapping(args[0], args[1], mapIt.next().toString());
@@ -71,9 +72,11 @@ public abstract class AbstractVirtualUse
                 }
             }
         }
+        
         LifecycleUtil.dispose(virtualUserTable);
-    }
     
+    }
+
     private void removeMapping(String user, String domain, String rawMapping) throws InvalidMappingException {
         if (rawMapping.startsWith(VirtualUserTable.ERROR_PREFIX)) {
             removeMapping(user, domain, rawMapping.substring(VirtualUserTable.ERROR_PREFIX.length()), ERROR_TYPE);
@@ -85,73 +88,70 @@ public abstract class AbstractVirtualUse
             removeMapping(user, domain, rawMapping, ADDRESS_TYPE);
         }
     }
-    
-    protected abstract AbstractVirtualUserTable getVirtalUserTable() throws Exception;
-    
+
+    protected abstract AbstractVirtualUserTable getVirtualUserTable() throws Exception;
+
     protected abstract boolean addMapping(String user , String domain, String mapping,int type)throws InvalidMappingException;
-    
+
     protected abstract boolean removeMapping(String user, String domain, String mapping, int type) throws InvalidMappingException;
-    
- 
+
     protected DNSService setUpDNSServer() {
+        
         DNSService dns = new DNSService() {
             public String getHostName(InetAddress inet) {
                 return "test";
             }
-            
             public InetAddress[] getAllByName(String name) throws UnknownHostException {
                 return new InetAddress[] { InetAddress.getByName("127.0.0.1")};        
             }
-            
             public InetAddress getLocalHost() throws UnknownHostException {
                 return InetAddress.getLocalHost();
             }
-
-            
             @SuppressWarnings("unchecked")
             public Collection findMXRecords(String hostname)
-                    throws TemporaryResolutionException {
+            throws TemporaryResolutionException {
                 throw new UnsupportedOperationException("Should never be called");
             }
-
             @SuppressWarnings("unchecked")
             public Collection findTXTRecords(String hostname) {
                 throw new UnsupportedOperationException("Should never be called");
             }
-
             public InetAddress getByName(String host)
-                    throws UnknownHostException {
+            throws UnknownHostException {
                 throw new UnsupportedOperationException("Should never be called");
             }
-
             @SuppressWarnings("unchecked")
             public Iterator getSMTPHostAddresses(String domainName)
-                    throws TemporaryResolutionException {
+            throws TemporaryResolutionException {
                 throw new UnsupportedOperationException("Should never be called");
             }
         };
+        
         return dns;
-    }
     
+    }
+
     public void testStoreAndRetrieveRegexMapping() throws ErrorMappingException {
+        
         String user = "test";
         String domain = "localhost";
         String regex = "(.*):{$1}@localhost";
         String regex2 = "(.+):{$1}@test"; 
         String invalidRegex = ".*):";
         boolean catched = false;
-        try {
         
+        try {
+
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-        
+
             assertTrue("Added virtual mapping", addMapping(user, domain, regex, REGEX_TYPE));
             assertTrue("Added virtual mapping", addMapping(user, domain, regex2, REGEX_TYPE));
 
             assertEquals("Two mappings",virtualUserTable.getMappings(user, domain).size(), 2);           
             assertEquals("One mappingline",virtualUserTable.getAllMappings().size(),1);
-           
+
             assertTrue("remove virtual mapping", removeMapping(user, domain, regex, REGEX_TYPE));
-        
+
             try {
                 assertTrue("Added virtual mapping", virtualUserTable.addRegexMapping(user, domain, invalidRegex));
             } catch (InvalidMappingException e) {
@@ -161,34 +161,35 @@ public abstract class AbstractVirtualUse
 
             assertTrue("remove virtual mapping", removeMapping(user, domain, regex2, REGEX_TYPE));
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-            
+
             assertNull("No mappings",virtualUserTable.getAllMappings());
-            
+
         } catch (InvalidMappingException e) {
             fail("Storing failed");
         }
-    
+
     }
-    
+
 
     public void testStoreAndRetrieveAddressMapping() throws ErrorMappingException {
+        
         String user = "test";
         String domain = "localhost";
         String address = "test@localhost2";
         String address2 = "test@james";
-        
+
         try {
-        
+
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-        
+
             assertTrue("Added virtual mapping", addMapping(user, domain, address, ADDRESS_TYPE));
             assertTrue("Added virtual mapping", addMapping(user, domain, address2, ADDRESS_TYPE));
 
             assertEquals("Two mappings",virtualUserTable.getMappings(user, domain).size(),2);
             assertEquals("One mappingline",virtualUserTable.getAllMappings().size(),1);
-        
+
             assertTrue("remove virtual mapping", removeMapping(user, domain, address, ADDRESS_TYPE));
-        
+
             /* TEMPORARILY REMOVE JDBC specific test 
             String invalidAddress= ".*@localhost2:";
             boolean catched = false;
@@ -200,30 +201,31 @@ public abstract class AbstractVirtualUse
                 } 
                 assertTrue("Invalid Mapping throw exception" , catched);
             }         
-            */
-            
+             */
+
             assertTrue("remove virtual mapping", removeMapping(user, domain, address2, ADDRESS_TYPE));
-            
+
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
             assertNull("No mappings",virtualUserTable.getAllMappings());
-            
+
         } catch (InvalidMappingException e) {
             fail("Storing failed");
         }
-        
-    
+
+
     }
 
-    public void testStoreAndRetrieveErrorMapping() throws ErrorMappingException { 
+    public void testStoreAndRetrieveErrorMapping() throws ErrorMappingException {
+        
         String user = "test";
         String domain = "localhost";
         String error = "bounce!";
         boolean catched = false;
-        
+
         try {
-        
+
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-        
+
             assertTrue("Added virtual mapping", addMapping(user, domain, error, ERROR_TYPE));
             assertEquals("One mappingline",virtualUserTable.getAllMappings().size(),1);
 
@@ -237,44 +239,44 @@ public abstract class AbstractVirtualUse
             assertTrue("remove virtual mapping", removeMapping(user, domain, error, ERROR_TYPE));
             assertNull("No mapping",virtualUserTable.getMappings(user, domain));
             assertNull("No mappings",virtualUserTable.getAllMappings());
-            
+
         } catch (InvalidMappingException e) {
-             fail("Storing failed");
+            fail("Storing failed");
         }
 
     }
-    
-    public void testStoreAndRetrieveWildCardAddressMapping() throws ErrorMappingException {        
+
+    public void testStoreAndRetrieveWildCardAddressMapping() throws ErrorMappingException {
+
         String user = "test";
         String user2 = "test2";
         String domain = "localhost";
         String address = "test@localhost2";
         String address2 = "test@james";
 
+        try {
 
-       try {
-                 
-            assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-        
-            assertTrue("Added virtual mapping", addMapping(null, domain, address, ADDRESS_TYPE));
+            assertNull("No mapping", virtualUserTable.getMappings(user, domain));
+
+            assertTrue("Added virtual mapping", addMapping(VirtualUserTable.WILDCARD, domain, address, ADDRESS_TYPE));
             assertTrue("Added virtual mapping", addMapping(user, domain, address2, ADDRESS_TYPE));
 
-          
-            assertTrue("One mappings",virtualUserTable.getMappings(user, domain).size() == 1);
-            assertTrue("One mappings",virtualUserTable.getMappings(user2, domain).size() == 1);
-           
+            assertTrue("One mappings", virtualUserTable.getMappings(user, domain).size() == 1);
+            assertTrue("One mappings", virtualUserTable.getMappings(user2, domain).size() == 1);
+
             assertTrue("remove virtual mapping", removeMapping(user, domain, address2, ADDRESS_TYPE));
-            assertTrue("remove virtual mapping", removeMapping(null, domain, address, ADDRESS_TYPE));
-            assertNull("No mapping",virtualUserTable.getMappings(user, domain));
-            assertNull("No mapping",virtualUserTable.getMappings(user2, domain));
-      
+            assertTrue("remove virtual mapping", removeMapping(VirtualUserTable.WILDCARD, domain, address, ADDRESS_TYPE));
+            assertNull("No mapping", virtualUserTable.getMappings(user, domain));
+            assertNull("No mapping", virtualUserTable.getMappings(user2, domain));
+
         } catch (InvalidMappingException e) {
-           fail("Storing failed");
+            fail("Storing failed");
         }
-    
+
     }
-    
+
     public void testRecursiveMapping() throws ErrorMappingException {
+        
         String user1 = "user1";
         String user2 = "user2";
         String user3 = "user3";
@@ -282,12 +284,12 @@ public abstract class AbstractVirtualUse
         String domain2 = "domain2";
         String domain3 = "domain3";
         boolean exception1 = false;
-    
+
         virtualUserTable.setRecursiveMapping(true);
-       
+
         try {
             assertNull("No mappings",virtualUserTable.getAllMappings());
-     
+
             assertTrue("Add mapping", addMapping(user1, domain1, user2 + "@" + domain2, ADDRESS_TYPE));
             assertTrue("Add mapping", addMapping(user2, domain2, user3 + "@" + domain3, ADDRESS_TYPE));
             assertEquals("Recursive mapped", virtualUserTable.getMappings(user1, domain1).iterator().next(),user3 + "@" + domain3);
@@ -299,38 +301,42 @@ public abstract class AbstractVirtualUse
                 exception1 = true;
             }
             assertTrue("Exception thrown on to many mappings", exception1);
-            
+
             // disable recursive mapping
             virtualUserTable.setRecursiveMapping(false);
             assertEquals("Not recursive mapped", virtualUserTable.getMappings(user1, domain1).iterator().next(),user2 + "@" + domain2);
-            
+
         } catch (InvalidMappingException e) {
             fail("Storing failed");
         }
     }
-   
-    
+
+
     public void testAliasDomainMapping() throws ErrorMappingException {
+        
         String domain = "realdomain";
         String aliasDomain = "aliasdomain";
         String user = "user";
         String user2 = "user2";
-    
+
         assertNull("No mappings",virtualUserTable.getAllMappings());
-        try {
-            assertTrue("Add mapping",addMapping(null, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE));
-            assertTrue("Add aliasDomain mapping", addMapping(null, aliasDomain, domain, ALIASDOMAIN_TYPE));
         
+        try {
+            
+            assertTrue("Add mapping",addMapping(VirtualUserTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE));
+            assertTrue("Add aliasDomain mapping", addMapping(VirtualUserTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE));
+
             Iterator<String> mappings = virtualUserTable.getMappings(user, aliasDomain).iterator();
             assertEquals("Domain mapped as first ", mappings.next(), user + "@" + domain);
             assertEquals("Address mapped as second ", mappings.next(), user2 + "@" + domain);
-            
-            assertTrue("Remove mapping", removeMapping(null, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE));
-            assertTrue("Remove aliasDomain mapping", removeMapping(null, aliasDomain, domain, ALIASDOMAIN_TYPE));
-        
+
+            assertTrue("Remove mapping", removeMapping(VirtualUserTable.WILDCARD, aliasDomain, user2 + "@" + domain, ADDRESS_TYPE));
+            assertTrue("Remove aliasDomain mapping", removeMapping(VirtualUserTable.WILDCARD, aliasDomain, domain, ALIASDOMAIN_TYPE));
+
         } catch (InvalidMappingException e) {
             fail("Storing failed");
         }
+
     }
-    
+
 }



---------------------------------------------------------------------
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