james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r489065 - in /james/server/trunk/src: conf/ java/org/apache/james/core/ java/org/apache/james/management/ java/org/apache/james/services/ java/org/apache/james/util/ java/org/apache/james/vut/ test/org/apache/james/test/mock/james/ test/org...
Date Wed, 20 Dec 2006 12:18:45 GMT
Author: norman
Date: Wed Dec 20 04:18:43 2006
New Revision: 489065

URL: http://svn.apache.org/viewvc?view=rev&rev=489065
Log:
Make it possible to add an aliasdomain to james. See JAMES-740
Throw ConfigurationException if an invalid mappingLimit was set.
Some code cleanup.

Modified:
    james/server/trunk/src/conf/james-config.xml
    james/server/trunk/src/java/org/apache/james/core/DefaultVirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/management/VirtualUserTableManagement.java
    james/server/trunk/src/java/org/apache/james/services/VirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
    james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagementService.java
    james/server/trunk/src/java/org/apache/james/util/VirtualUserTableUtil.java
    james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java
    james/server/trunk/src/test/org/apache/james/test/mock/james/MockVirtualUserTableManagementImpl.java
    james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java
    james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java
    james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java

Modified: james/server/trunk/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-config.xml?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Wed Dec 20 04:18:43 2006
@@ -1504,10 +1504,19 @@
    
    <!-- The VirtualUserTable Store block -->
    <virtualusertable-store>
-   
+      <!-- Configure VirtualUserTable stores here. -->
+      <!-- -->
+      <!-- If set recursiveMapping false only the first mapping will get processed. -->
+      <!-- Default true. -->
+      <!-- By setting the mappingLimit you can specify how much mapping will get processed
-->
+      <!-- before a bounce will send. This avoid infinity loops. Default 10.  -->
+      
       <!-- The DefaultVirtualUserTable  for storing James' VirtualUserTable mappings.
-->
       <!--
       <table name="DefaultVirtualUserTable" class="org.apache.james.vut.XMLVirtualUserTable">
+         <recursiveMapping> true </recursiveMapping>
+         <mappingLimit> 10 </mappingLimit>
+         
          <mapping> some@domain=someuser </mapping>
       </table>
       -->
@@ -1521,6 +1530,8 @@
       <!-- The DefaultVirtualUserTable  for storing James' VirtualUserTable mappings.
-->
       <!-- TEMPORARY DEFAULT: db using Derby  -->
       <table name="DefaultVirtualUserTable" class="org.apache.james.vut.JDBCVirtualUserTable"
destinationURL="db://maildb/VirtualUserTable">
+         <recursiveMapping> true </recursiveMapping>
+         <mappingLimit> 10 </mappingLimit>
          <sqlFile>file://conf/sqlResources.xml</sqlFile>
       </table>
    </virtualusertable-store>

Modified: james/server/trunk/src/java/org/apache/james/core/DefaultVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/DefaultVirtualUserTable.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/DefaultVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/DefaultVirtualUserTable.java Wed Dec
20 04:18:43 2006
@@ -135,4 +135,18 @@
     public Map getAllMappings() {
         return vut.getAllMappings();
     }
+
+    /**
+     * @see org.apache.james.services.VirtualUserTableManagement#addAliasDomain(java.lang.String,
java.lang.String)
+     */
+    public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException
{
+        return vut.addAliasDomainMapping(aliasDomain, realDomain);
+    }
+
+    /**
+     * @see org.apache.james.services.VirtualUserTableManagement#removeAliasDomain(java.lang.String,
java.lang.String)
+     */
+    public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws
InvalidMappingException {
+        return vut.removeAliasDomainMapping(aliasDomain, realDomain);
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/management/VirtualUserTableManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/VirtualUserTableManagement.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/VirtualUserTableManagement.java
(original)
+++ james/server/trunk/src/java/org/apache/james/management/VirtualUserTableManagement.java
Wed Dec 20 04:18:43 2006
@@ -189,4 +189,26 @@
     public Map getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException{
         return getTable(virtualUserTable).getAllMappings();
     }
+
+    /**
+     * @see org.apache.james.services.VirtualUserTableManagementService#addAliasDomainMapping(java.lang.String,
java.lang.String, java.lang.String)
+     */
+    public boolean addAliasDomainMapping(String virtualUserTable, String aliasDomain, String
realDomain) throws VirtualUserTableManagementException {
+        try {
+            return getTable(virtualUserTable).addAliasDomainMapping(aliasDomain, realDomain);
+        } catch (InvalidMappingException e) {
+            throw new VirtualUserTableManagementException(e);
+        }
+    }
+
+    /**
+     * @see org.apache.james.services.VirtualUserTableManagementService#removeAliasDomainMapping(java.lang.String,
java.lang.String, java.lang.String)
+     */
+    public boolean removeAliasDomainMapping(String virtualUserTable, String aliasDomain,
String realDomain) throws VirtualUserTableManagementException {
+        try {
+            return getTable(virtualUserTable).removeAliasDomainMapping(aliasDomain, realDomain);
+        } catch (InvalidMappingException e) {
+            throw new VirtualUserTableManagementException(e);
+        }
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/services/VirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/VirtualUserTable.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/VirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/services/VirtualUserTable.java Wed Dec 20
04:18:43 2006
@@ -42,9 +42,14 @@
     public static final String ERROR_PREFIX = "error:";
     
     /**
-     * The prefix which is used for regex prefix
+     * The prefix which is used for regex mappings
      */
     public static final String REGEX_PREFIX = "regex:";
+    
+    /**
+     * The prefix which is used for alias domain mappings
+     */
+    public static final String ALIASDOMAIN_PREFIX = "domain:";
     
     /**
      * Return the mapped MailAddress for the given address. Return null if no 

Modified: james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
(original)
+++ james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagement.java
Wed Dec 20 04:18:43 2006
@@ -140,4 +140,24 @@
      * @return Map which holds all mappings
      */
     public Map getAllMappings();
+    
+    /**
+     * Add aliasDomain mapping
+     * 
+     * @param aliasDomain the aliasdomain which should be mapped to the realDomain
+     * @param realDomain the realDomain
+     * @return true if successfilly
+     * @throws InvalidMappingException
+     */
+    public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException;
+    
+    /**
+     * Remove aliasDomain mapping
+     * 
+     * @param aliasDomain the aliasdomain which should be mapped to the realDomain
+     * @param realDomain the realDomain
+     * @return true if successfilly
+     * @throws InvalidMappingException
+     */
+    public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws
InvalidMappingException;
 }

Modified: james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagementService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagementService.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagementService.java
(original)
+++ james/server/trunk/src/java/org/apache/james/services/VirtualUserTableManagementService.java
Wed Dec 20 04:18:43 2006
@@ -150,4 +150,26 @@
      * @throws VirtualUserTableManagementException 
      */
     public Map getAllMappings(String virtualUserTable) throws VirtualUserTableManagementException;
+    
+    /**
+     * Add aliasDomain mapping
+     * 
+     * @param virtualUserTable The virtualUserTable 
+     * @param aliasDomain the aliasdomain which should be mapped to the realDomain
+     * @param realDomain the realDomain
+     * @return true if successfilly
+     * @throws InvalidMappingException
+     */
+    public boolean addAliasDomainMapping(String virtualUserTable, String aliasDomain, String
realDomain) throws VirtualUserTableManagementException;
+    
+    /**
+     * Remove aliasDomain mapping
+     * 
+     * @param virtualUserTable The virtualUserTable 
+     * @param aliasDomain the aliasdomain which should be mapped to the realDomain
+     * @param realDomain the realDomain
+     * @return true if successfilly
+     * @throws InvalidMappingException
+     */
+    public boolean removeAliasDomainMapping(String virtualUserTable, String aliasDomain,
String realDomain) throws VirtualUserTableManagementException;
 }

Modified: james/server/trunk/src/java/org/apache/james/util/VirtualUserTableUtil.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/VirtualUserTableUtil.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/VirtualUserTableUtil.java (original)
+++ james/server/trunk/src/java/org/apache/james/util/VirtualUserTableUtil.java Wed Dec 20
04:18:43 2006
@@ -129,7 +129,8 @@
       */
      public static String getSeparator(String targetString) {
         return (targetString.indexOf(',') > -1 ? "," : (targetString
-        .indexOf(';') > -1 ? ";" : ((targetString.indexOf(VirtualUserTable.ERROR_PREFIX)
> -1 || targetString.indexOf(VirtualUserTable.REGEX_PREFIX) > -1)? "" : ":")));
+        .indexOf(';') > -1 ? ";" : ((targetString.indexOf(VirtualUserTable.ERROR_PREFIX)
> -1 
+            || targetString.indexOf(VirtualUserTable.REGEX_PREFIX) > -1 || targetString.indexOf(VirtualUserTable.ALIASDOMAIN_PREFIX)
> -1)? "" : ":")));
      }
      
      /**
@@ -156,16 +157,10 @@
      * Return a Collection which holds the extracted mappings of the given String
      * 
      * @param rawMapping
+     * @deprecated Use mappingToCollection(String rawMapping)
      */
      public static Collection getMappings(String rawMapping) {
-        ArrayList map = new ArrayList();
-        StringTokenizer tokenizer = new StringTokenizer(rawMapping,
-        VirtualUserTableUtil.getSeparator(rawMapping));
-
-        while (tokenizer.hasMoreTokens()) {
-            map.add(tokenizer.nextToken().trim());
-        }
-        return map;
+        return mappingToCollection(rawMapping);
     }
      
      /**

Modified: james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java Wed Dec
20 04:18:43 2006
@@ -85,7 +85,11 @@
         Configuration mappingLimitConf = arg0.getChild("mappingLimit", false);
         
         if (mappingLimitConf != null )  {
-            setMappingLimit(mappingLimitConf.getValueAsInteger(10));
+            try {
+                setMappingLimit(mappingLimitConf.getValueAsInteger(10));
+            } catch (IllegalArgumentException e) {
+                throw new ConfigurationException(e.getMessage());
+            }
         }
     }
     
@@ -93,7 +97,14 @@
         this.recursive = recursive;
     }
     
-    public void setMappingLimit(int mappingLimit) {
+    /**
+     * Set the mappingLimit
+     * 
+     * @param mappingLimit the mappingLimit
+     * @throws IllegalArgumentException get thrown if mappingLimit smaller then 1 is used
+     */
+    public void setMappingLimit(int mappingLimit) throws IllegalArgumentException {
+        if (mappingLimit < 1) throw new IllegalArgumentException("The minimum mappingLimit
is 1");
         this.mappingLimit = mappingLimit;
     }
     
@@ -119,7 +130,7 @@
                 throw new ErrorMappingException(targetString.substring(VirtualUserTable.ERROR_PREFIX.length()));
 
             } else {
-                Iterator map = VirtualUserTableUtil.getMappings(targetString).iterator();
+                Iterator map = VirtualUserTableUtil.mappingToCollection(targetString).iterator();
 
                 while (map.hasNext()) {
                     String target = map.next().toString();
@@ -133,10 +144,12 @@
                             // should never happen
                             getLogger().error("Exception during regexMap processing: ", e);
                         } 
-
-                        if (target == null) continue;
+                    } else if (target.startsWith(VirtualUserTable.ALIASDOMAIN_PREFIX)) {
+                        target = user + "@" + target.substring(VirtualUserTable.ALIASDOMAIN_PREFIX.length());
                     }
 
+                    if (target == null) continue;
+                    
                     StringBuffer buf = new StringBuffer().append("Valid virtual user mapping
")
                                                          .append(user).append("@").append(domain)
                                                          .append(" to ").append(target);
@@ -176,9 +189,7 @@
                     } else {
                         mappings.add(target);
                     }
-               
-                }
-                
+                } 
             }
             return mappings;
         }
@@ -274,6 +285,9 @@
             return addErrorMapping(user,domain,map.substring(VirtualUserTable.ERROR_PREFIX.length()));
         } else if (map.startsWith(VirtualUserTable.REGEX_PREFIX)) {
             return addRegexMapping(user,domain,map.substring(VirtualUserTable.REGEX_PREFIX.length()));
+        } else if (map.startsWith(VirtualUserTable.ALIASDOMAIN_PREFIX)) {
+            if (user != null) throw new InvalidMappingException("User must be null for aliasDomain
mappings");
+            return addAliasDomainMapping(domain,map.substring(VirtualUserTable.ALIASDOMAIN_PREFIX.length()));
         } else {
             return addAddressMapping(user,domain,map);
         }
@@ -289,6 +303,9 @@
             return removeErrorMapping(user,domain,map.substring(VirtualUserTable.ERROR_PREFIX.length()));
         } else if (map.startsWith(VirtualUserTable.REGEX_PREFIX)) {
             return removeRegexMapping(user,domain,map.substring(VirtualUserTable.REGEX_PREFIX.length()));
+        } else if (map.startsWith(VirtualUserTable.ALIASDOMAIN_PREFIX)) {
+            if (user != null) throw new InvalidMappingException("User must be null for aliasDomain
mappings");
+            return removeAliasDomainMapping(domain,map.substring(VirtualUserTable.ALIASDOMAIN_PREFIX.length()));
         } else {
             return removeAddressMapping(user,domain,map);
         }
@@ -340,8 +357,7 @@
             if (autoDetect == true && hostName.equals("localhost") == false &&
domains.contains(hostName) == false) {
                 domains.add(hostName);
             }
-
-            
+           
             if (autoDetectIP == true) {
                 List ipList = DomainListUtil.getDomainsIP(domains,dns,getLogger());
                 for(int i = 0; i < ipList.size(); i++) {
@@ -386,19 +402,56 @@
     }
 
     /**
-     * Override to map virtual recipients to real recipients, both local and non-local.
-     * Each key in the provided map corresponds to a potential virtual recipient, stored
as
-     * a <code>MailAddress</code> object.
-     * 
-     * Translate virtual recipients to real recipients by mapping a string containing the
-     * address of the real recipient as a value to a key. Leave the value <code>null<code>
-     * if no mapping should be performed. Multiple recipients may be specified by delineating
-     * the mapped string with commas, semi-colons or colons.
+     * @see org.apache.james.services.VirtualUserTableManagement#addAliasDomainMapping(java.lang.String,
java.lang.String)
+     */
+    public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException
{
+        getLogger().info("Add domain mapping: " + aliasDomain  + " => " + realDomain);
+        return addMappingInternal(null, aliasDomain, VirtualUserTable.ALIASDOMAIN_PREFIX
+ realDomain);
+    }
+    
+    /**
+     * @see org.apache.james.services.VirtualUserTableManagement#removeAliasDomainMapping(java.lang.String,
java.lang.String)
+     */
+    public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws
InvalidMappingException {
+        getLogger().info("Remove domain mapping: " + aliasDomain  + " => " + realDomain);
+        return removeMappingInternal(null, aliasDomain, VirtualUserTable.ALIASDOMAIN_PREFIX
+ realDomain);
+    }
+    
+    /**
+     * Get all mappings for the given user and domain. If a aliasdomain mapping was found
get sure it is in the map as first mapping. 
      * 
-     * @param user the mapping of virtual to real recipients, as 
-     *    <code>MailAddress</code>es to <code>String</code>s.
+     * @param user the username
+     * @param domain the domain
+     * @return the mappings
      */
-    protected abstract String mapAddress(String user, String 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
+        if (mappings != null && mappings.indexOf(VirtualUserTable.ALIASDOMAIN_PREFIX)
> -1) {
+            Collection mapCol = VirtualUserTableUtil.mappingToCollection(mappings);
+            Iterator mapIt = mapCol.iterator();
+        
+            List col = new ArrayList(mapCol.size());
+        
+            while (mapIt.hasNext()) {
+                int i = 0;
+                String mapping = mapIt.next().toString();
+        
+                if (mapping.startsWith(VirtualUserTable.ALIASDOMAIN_PREFIX)) {
+                    col.add(i,mapping);
+                    i++;
+                } else {
+                    col.add(mapping);
+                }
+            }
+            return VirtualUserTableUtil.CollectionToMapping(col);
+        } else {  
+            return mappings;
+        }
+    }
+      
     
     /**
      * Add new mapping
@@ -444,4 +497,19 @@
      * @return Map
      */
     protected abstract Map getAllMappingsInternal();
+    
+    /**
+     * Override to map virtual recipients to real recipients, both local and non-local.
+     * Each key in the provided map corresponds to a potential virtual recipient, stored
as
+     * a <code>MailAddress</code> object.
+     * 
+     * Translate virtual recipients to real recipients by mapping a string containing the
+     * address of the real recipient as a value to a key. Leave the value <code>null<code>
+     * if no mapping should be performed. Multiple recipients may be specified by delineating
+     * the mapped string with commas, semi-colons or colons.
+     * 
+     * @param user the mapping of virtual to real recipients, as 
+     *    <code>MailAddress</code>es to <code>String</code>s.
+     */
+    protected abstract String mapAddressInternal(String user, String domain);
 }

Modified: james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java Wed Dec 20
04:18:43 2006
@@ -254,9 +254,9 @@
     }
     
     /**
-     * @see org.apache.james.vut.AbstractVirtualUserTable#mapAddress(java.lang.String, java.lang.String)
+     * @see org.apache.james.vut.AbstractVirtualUserTable#mapAddressInternal(java.lang.String,
java.lang.String)
      */
-    public String mapAddress(String user, String domain) {
+    public String mapAddressInternal(String user, String domain) {
         Connection conn = null;
         PreparedStatement mappingStmt = null;
         try {

Modified: james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java Wed Dec 20 04:18:43
2006
@@ -53,7 +53,7 @@
         mappings = new HashMap();
         domains = new ArrayList();
         
-        if (mapConf != null) {
+        if (mapConf != null && mapConf.length > 0) {
             for (int i = 0; i < mapConf.length; i ++) {       
                 mappings.putAll(VirtualUserTableUtil.getXMLMappings(mapConf[i].getValue()));
             }
@@ -96,10 +96,15 @@
     }
 
     /**
-     * @see org.apache.james.vut.AbstractVirtualUserTable#mapAddress(java.lang.String, java.lang.String)
+     * @see org.apache.james.vut.AbstractVirtualUserTable#mapAddressInternal(java.lang.String,
java.lang.String)
      */
-    protected String mapAddress(String user, String domain) {
-        return VirtualUserTableUtil.getTargetString(user, domain, mappings);
+    protected String mapAddressInternal(String user, String domain) {
+        if (mappings == null) {
+            return null;
+        } else {
+            return VirtualUserTableUtil.getTargetString(user, domain, mappings);
+    
+        }
     }
 
     /**
@@ -114,11 +119,15 @@
      * @see org.apache.james.vut.AbstractVirtualUserTable#getUserDomainMappingsInternal(java.lang.String,
java.lang.String)
      */
     public Collection getUserDomainMappingsInternal(String user, String domain) {
-        Object maps = mappings.get(user + "@" + domain);
-        if (maps != null) {
-            return VirtualUserTableUtil.mappingToCollection(maps.toString());
-        } else {
+        if (mappings == null) {
             return null;
+        } else {
+            String maps = (String) mappings.get(user + "@" + domain);
+            if (maps != null) {
+                return VirtualUserTableUtil.mappingToCollection(maps);
+            } else {
+                return null;
+            }
         }
     }
 
@@ -133,14 +142,18 @@
      * @see org.apache.james.services.DomainList#containsDomain(java.lang.String)
      */
     public boolean containsDomain(String domain) {
-        return domains.contains(domain);
+        if (domains == null) {
+            return false;
+        } else {
+            return domains.contains(domain);
+        }
     }
 
     /**
      * @see org.apache.james.vut.AbstractVirtualUserTable#getAllMappingsInternal()
      */
     public Map getAllMappingsInternal() {
-        if (mappings.size() > 0) {
+        if ( mappings != null && mappings.size() > 0) {
             Map mappingsNew = new HashMap();
             Iterator maps = mappings.keySet().iterator();
                 

Modified: james/server/trunk/src/test/org/apache/james/test/mock/james/MockVirtualUserTableManagementImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/test/mock/james/MockVirtualUserTableManagementImpl.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/test/org/apache/james/test/mock/james/MockVirtualUserTableManagementImpl.java
(original)
+++ james/server/trunk/src/test/org/apache/james/test/mock/james/MockVirtualUserTableManagementImpl.java
Wed Dec 20 04:18:43 2006
@@ -134,4 +134,12 @@
         return false;
     }
 
+    public boolean addAliasDomainMapping(String aliasDomain, String realDomain) throws InvalidMappingException
{
+    return addRawMapping(null,aliasDomain,VirtualUserTable.ALIASDOMAIN_PREFIX + realDomain);
+    }
+
+    public boolean removeAliasDomainMapping(String aliasDomain, String realDomain) throws
InvalidMappingException {
+        return removeRawMapping(null,aliasDomain,VirtualUserTable.ALIASDOMAIN_PREFIX + realDomain);
+    }
+
 }

Modified: james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java Wed
Dec 20 04:18:43 2006
@@ -23,12 +23,16 @@
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.james.services.AbstractDNSServer;
 import org.apache.james.services.DNSServer;
+import org.apache.james.services.VirtualUserTable;
 
 import junit.framework.TestCase;
 
@@ -38,16 +42,51 @@
     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();
     }
     
     protected void tearDown() throws Exception {
-        super.tearDown();
+        Map mappings = virtualUserTable.getAllMappings();
+        
+        if (mappings != null) {
+            Iterator mappingsIt = virtualUserTable.getAllMappings().keySet().iterator();
+    
+    
+            while(mappingsIt.hasNext()) {
+                String key = mappingsIt.next().toString();
+                String args[] = key.split("@");
+        
+                Collection map = (Collection) mappings.get(key);
+        
+                Iterator mapIt = map.iterator();
+        
+                while (mapIt.hasNext()) {
+                    try {
+                        removeMapping(args[0], args[1], mapIt.next().toString());
+                    } catch (InvalidMappingException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
         ContainerUtil.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);
+        } else if (rawMapping.startsWith(VirtualUserTable.REGEX_PREFIX)) {
+            removeMapping(user, domain, rawMapping.substring(VirtualUserTable.REGEX_PREFIX.length()),
REGEX_TYPE);
+        } else if (rawMapping.startsWith(VirtualUserTable.ALIASDOMAIN_PREFIX)) {
+            removeMapping(user, domain, rawMapping.substring(VirtualUserTable.ALIASDOMAIN_PREFIX.length()),
ALIASDOMAIN_TYPE);
+        } else {
+            removeMapping(user, domain, rawMapping, ADDRESS_TYPE);
+        }
+    }
+    
     protected abstract AbstractVirtualUserTable getVirtalUserTable() throws ServiceException,
ConfigurationException, Exception;
     
     protected abstract boolean addMapping(String user , String domain, String mapping,int
type)throws InvalidMappingException;
@@ -88,8 +127,6 @@
 
             assertEquals("Two mappings",virtualUserTable.getMappings(user, domain).size(),
2);           
             assertEquals("One mappingline",virtualUserTable.getAllMappings().size(),1);
-            
-            System.err.println("MAPPINGS:" + virtualUserTable.getAllMappings() + " domains:"
+ virtualUserTable.getDomains().size()); 
            
             // Test DomainList implementations!
             assertEquals("Three domains",virtualUserTable.getDomains().size(), 3);
@@ -251,4 +288,29 @@
             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));
+        
+            Iterator 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));
+        
+        } catch (InvalidMappingException e) {
+            fail("Storing failed");
+        }
+    }
+    
 }

Modified: james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java Wed Dec
20 04:18:43 2006
@@ -21,10 +21,6 @@
 
 package org.apache.james.vut;
 
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Map;
-
 import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
 import org.apache.avalon.framework.configuration.ConfigurationException;
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
@@ -42,33 +38,6 @@
 
 public class JDBCVirtualUserTableTest extends AbstractVirtualUserTableTest {
     
-    public void tearDown() throws Exception {
-        Map mappings = virtualUserTable.getAllMappings();
-    
-        if (mappings != null) {
-            Iterator mappingsIt = virtualUserTable.getAllMappings().keySet().iterator();
-    
-    
-            while(mappingsIt.hasNext()) {
-                String key = mappingsIt.next().toString();
-                String args[] = key.split("@");
-        
-                Collection map = (Collection) mappings.get(key);
-        
-                Iterator mapIt = map.iterator();
-        
-                while (mapIt.hasNext()) {
-                    try {
-                        virtualUserTable.removeMapping(args[0], args[1], mapIt.next().toString());
-                    } catch (InvalidMappingException e) {
-                        e.printStackTrace();
-                    }
-                }
-            }
-        }
-        super.tearDown();
-    }
-    
     /**
      * @see org.apache.james.vut.AbstractVirtualUserTableTest#getVirtalUserTable()
      */
@@ -100,6 +69,8 @@
             return virtualUserTable.addRegexMapping(user, domain, mapping);
         } else if (type == ADDRESS_TYPE) {
             return virtualUserTable.addAddressMapping(user, domain, mapping);
+        } else if (type == ALIASDOMAIN_TYPE) {
+            return virtualUserTable.addAliasDomainMapping(domain, mapping);
         } else {
             return false;
         }
@@ -115,6 +86,8 @@
             return virtualUserTable.removeRegexMapping(user, domain, mapping);
         } else if (type == ADDRESS_TYPE) {
             return virtualUserTable.removeAddressMapping(user, domain, mapping);
+        } else if (type == ALIASDOMAIN_TYPE) {
+            return virtualUserTable.removeAliasDomainMapping(domain, mapping);
         } else {
             return false;
         }

Modified: james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java?view=diff&rev=489065&r1=489064&r2=489065
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java Wed Dec
20 04:18:43 2006
@@ -30,7 +30,6 @@
 import org.apache.avalon.framework.configuration.DefaultConfiguration;
 import org.apache.avalon.framework.container.ContainerUtil;
 import org.apache.avalon.framework.service.DefaultServiceManager;
-import org.apache.avalon.framework.service.ServiceException;
 
 import org.apache.james.services.DNSServer;
 import org.apache.james.services.FileSystem;
@@ -47,7 +46,7 @@
 public class XMLVirtualUserTableTest extends AbstractVirtualUserTableTest {
     DefaultConfiguration defaultConfiguration = new DefaultConfiguration("conf");
     
-    protected AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException,
Exception {
+    protected AbstractVirtualUserTable getVirtalUserTable() throws Exception {
         DefaultServiceManager serviceManager = new DefaultServiceManager();
         serviceManager.put(FileSystem.ROLE, new MockFileSystem());
         serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());
@@ -56,7 +55,6 @@
         ContainerUtil.enableLogging(mr, new MockLogger());
 
         ContainerUtil.service(mr, serviceManager);
-        ContainerUtil.configure(mr, defaultConfiguration);
         return mr;
     }
     
@@ -83,7 +81,10 @@
             mappings.add(VirtualUserTable.REGEX_PREFIX + mapping);
         } else if (type == ADDRESS_TYPE) {
             mappings.add(mapping);
+        }  else if (type == ALIASDOMAIN_TYPE) {
+            mappings.add(VirtualUserTable.ALIASDOMAIN_PREFIX + mapping);
         }
+        
         if (mappings.size() > 0) { 
             defaultConfiguration.addChild(new AttrValConfiguration("mapping",user + "@" +
domain +"=" + VirtualUserTableUtil.CollectionToMapping(mappings)));
         }
@@ -91,8 +92,11 @@
         try {
             ContainerUtil.configure(((XMLVirtualUserTable) virtualUserTable),defaultConfiguration);
         } catch (ConfigurationException e) {
-            e.printStackTrace();
-            return false;
+            if (mappings.size() > 0) {
+                return false;
+            } else {
+                return true;
+            }
         }
         return true;
     }
@@ -118,7 +122,9 @@
             mappings.remove(VirtualUserTable.REGEX_PREFIX + mapping);
         } else if (type == ADDRESS_TYPE) {
             mappings.remove(mapping);    
-        } 
+        }  else if (type == ALIASDOMAIN_TYPE) {
+            mappings.remove(VirtualUserTable.ALIASDOMAIN_PREFIX + mapping);
+        }
 
         if (mappings.size() > 0) {
             defaultConfiguration.addChild(new AttrValConfiguration("mapping",user + "@" +
domain +"=" + VirtualUserTableUtil.CollectionToMapping(mappings)));
@@ -127,8 +133,11 @@
         try {
             ContainerUtil.configure(((XMLVirtualUserTable) virtualUserTable),defaultConfiguration);
         } catch (ConfigurationException e) {
-            e.printStackTrace();
-           return false;
+           if (mappings.size() > 0) {
+               return false;
+           } else {
+               return true;
+           }
         }
         return true;
     }



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