You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/10/19 15:34:17 UTC

svn commit: r465621 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/domain/ java/org/apache/james/services/ java/org/apache/james/vut/ test/org/apache/james/ test/org/apache/james/domain/ test/org/apache/james/vut/

Author: norman
Date: Thu Oct 19 06:34:16 2006
New Revision: 465621

URL: http://svn.apache.org/viewvc?view=rev&rev=465621
Log:
Implement VirtualUserTable in UserRepositories.
Add tests

Added:
    james/server/trunk/src/java/org/apache/james/domain/
    james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java   (with props)
    james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java   (with props)
    james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.xinfo
    james/server/trunk/src/java/org/apache/james/services/DomainList.java   (with props)
    james/server/trunk/src/test/org/apache/james/domain/
    james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java   (with props)
Modified:
    james/server/trunk/src/conf/james-assembly.xml
    james/server/trunk/src/conf/james-config.xml
    james/server/trunk/src/conf/sqlResources.xml
    james/server/trunk/src/java/org/apache/james/James.java
    james/server/trunk/src/java/org/apache/james/James.xinfo
    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/JDBCVirtualUserTable.xinfo
    james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java
    james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo
    james/server/trunk/src/test/org/apache/james/JamesTest.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-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-assembly.xml?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/conf/james-assembly.xml (original)
+++ james/server/trunk/src/conf/james-assembly.xml Thu Oct 19 06:34:16 2006
@@ -30,6 +30,7 @@
     <provide name="localusersrepository" role="org.apache.james.services.UsersRepository"/>
     <provide name="spoolrepository" role="org.apache.james.services.SpoolRepository"/>
     <provide name="filesystem" role="org.apache.james.services.FileSystem" />
+    <provide name="domainlist" role="org.apache.james.services.DomainList" />
     <provide name="sockets"
              role="org.apache.avalon.cornerstone.services.sockets.SocketManager"/>
     <provide name="scheduler"
@@ -224,6 +225,10 @@
   <!-- 
   <block name="virtualusertable" class="org.apache.james.vut.JDBCVirtualUserTable" />
   -->
+  <!-- The context DomainList implementation -->
+  <block name="domainlist" class="org.apache.james.domain.HardCodedDomainList">
+      <provide name="dnsserver" role="org.apache.james.services.DNSServer"/>
+  </block>
   
   
   <!-- Configuration for Cornerstone Blocks only after here

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Thu Oct 19 06:34:16 2006
@@ -51,11 +51,14 @@
       <!-- -->
       <!-- Warning: If you are using fetchmail it is important to include the -->
       <!-- fetched domains in the server name list to prevent looping.       -->
+      
+      <!-- TEMPORARY DISABLED -->
+      <!--
       <servernames autodetect="true" autodetectIP="true">
-<!-- CONFIRM? -->
          <servername>localhost</servername>
       </servernames>
-
+      -->
+      
       <!-- Set whether user names are case sensitive or case insensitive -->
       <!-- Set whether to enable local aliases -->
       <!-- Set whether to enable forwarding -->
@@ -796,6 +799,29 @@
       <singleIPperMX> true </singleIPperMX>
       -->
    </dnsserver>
+   
+   <domainlist>
+      <!-- servernames identifies the DNS namespace served by this instance of James. -->
+      <!-- These servernames are used for both matcher/mailet processing and SMTP auth -->
+      <!-- to determine when a mail is intended for local delivery. -->
+      <!-- -->
+      <!-- If autodetect is TRUE, James wil attempt to discover its own host name AND -->
+      <!-- use any explicitly specified servernames. -->
+      <!-- If autodetect is FALSE, James will use only the specified servernames. -->
+      <!-- -->
+      <!-- If autodetectIP is not FALSE, James will also allow add the IP address for each servername. -->
+      <!-- The automatic IP detection is to support RFC 2821, Sec 4.1.3, address literals. -->
+      <!-- -->
+      <!-- To override autodetected server names simply add explicit servername elements. -->
+      <!-- In most cases this will be necessary. -->
+      <!-- By default, the servername 'localhost' is specified. This can be removed, if required. -->
+      <!-- -->
+      <!-- Warning: If you are using fetchmail it is important to include the -->
+      <!-- fetched domains in the server name list to prevent looping.       -->
+      <servernames autodetect="true" autodetectIP="true">
+         <servername>localhost</servername>
+      </servernames>
+   </domainlist>
    
       
    <!-- Uncommment this block to enable the BayesianAnalyserManagement. -->

Modified: james/server/trunk/src/conf/sqlResources.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/sqlResources.xml?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/conf/sqlResources.xml (original)
+++ james/server/trunk/src/conf/sqlResources.xml Thu Oct 19 06:34:16 2006
@@ -1001,6 +1001,9 @@
     <sql name="updateMapping">update VirtualUserTable set VirtualUserTable.target_address = ? where VirtualUserTable."user" = ? and VirtualUserTable.domain = ? </sql>
    
     <sql name="addMapping">insert into VirtualUserTable values(?,?,?) </sql>
+    
+    <sql name="selectDomains">select domain from VirtualUserTable</sql>
+    
     <!-- Statements used to create the table associated with this class. -->
     <sql name="createTable" db="mysql">
         CREATE TABLE VirtualUserTable (

Modified: james/server/trunk/src/java/org/apache/james/James.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/James.java?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/James.java (original)
+++ james/server/trunk/src/java/org/apache/james/James.java Thu Oct 19 06:34:16 2006
@@ -40,6 +40,7 @@
 import org.apache.james.core.MailImpl;
 import org.apache.james.core.MailetConfigImpl;
 import org.apache.james.services.DNSServer;
+import org.apache.james.services.DomainList;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailRepository;
 import org.apache.james.services.MailServer;
@@ -63,8 +64,6 @@
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
 import java.io.SequenceInputStream;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Enumeration;
@@ -172,6 +171,8 @@
     protected Mailet localDeliveryMailet;
 
     private FileSystem fileSystem;
+    
+    private DomainList domains;
 
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(ServiceManager)
@@ -180,6 +181,7 @@
         compMgr = new DefaultServiceManager(comp);
         mailboxes = new ReferenceMap();
         setFileSystem((FileSystem) comp.lookup(FileSystem.ROLE));
+        domains = (DomainList) comp.lookup(DomainList.ROLE);
     }
 
     /**
@@ -299,58 +301,9 @@
     }
 
     private void initializeServernamesAndPostmaster() throws ConfigurationException, ParseException {
-        String hostName = null;
-        try {
-            hostName = lookupDNSServer().getHostName(InetAddress.getLocalHost());
-        } catch  (UnknownHostException ue) {
-            hostName = "localhost";
-        }
-
-        getLogger().info("Local host is: " + hostName);
-
-        // Get the domains and hosts served by this instance
-        serverNames = new HashSet();
-        Configuration serverConf = conf.getChild("servernames");
-        if (serverConf.getAttributeAsBoolean("autodetect") && (!hostName.equals("localhost"))) {
-            serverNames.add(hostName.toLowerCase(Locale.US));
-        }
-
-        final Configuration[] serverNameConfs =
-                conf.getChild( "servernames" ).getChildren( "servername" );
-        for ( int i = 0; i < serverNameConfs.length; i++ ) {
-            serverNames.add( serverNameConfs[i].getValue().toLowerCase(Locale.US));
-
-            if (serverConf.getAttributeAsBoolean("autodetectIP", true)) {
-                try {
-                    /* This adds the IP address(es) for each host to support
-                    * support <us...@address-literal> - RFC 2821, sec 4.1.3.
-                    * It might be proper to use the actual IP addresses
-                    * available on this server, but we can't do that
-                    * without NetworkInterface from JDK 1.4.  Because of
-                    * Virtual Hosting considerations, we may need to modify
-                    * this to keep hostname and IP associated, rather than
-                    * just both in the set.
-                    */
-                    InetAddress[] addrs = InetAddress.getAllByName(serverNameConfs[i].getValue());
-                    for (int j = 0; j < addrs.length ; j++) {
-                        serverNames.add(addrs[j].getHostAddress());
-                    }
-                }
-                catch(Exception genericException) {
-                    getLogger().error("Cannot get IP address(es) for " + serverNameConfs[i].getValue());
-                }
-            }
-        }
-        if (serverNames.isEmpty()) {
-            throw new ConfigurationException( "Fatal configuration error: no servernames specified!");
-        }
-
-        if (getLogger().isInfoEnabled()) {
-            for (Iterator i = serverNames.iterator(); i.hasNext(); ) {
-                getLogger().info("Handling mail for: " + i.next());
-            }
-        }
-
+        //TODO: Make backward compatible
+        serverNames = domains.getDomains();
+    
         String defaultDomain = (String) serverNames.iterator().next();
         // used by RemoteDelivery for HELO
         attributes.put(Constants.DEFAULT_DOMAIN, defaultDomain);
@@ -363,14 +316,14 @@
         if (postMasterAddress.indexOf('@') < 0) {
             String domainName = null;    // the domain to use
             // loop through candidate domains until we find one or exhaust the list
-            for ( int i = 0; domainName == null && i < serverNameConfs.length ; i++ ) {
-                String serverName = serverNameConfs[i].getValue().toLowerCase(Locale.US);
+            for ( Iterator i = serverNames.iterator(); i.hasNext()&& domainName == null;) {
+                String serverName = i.next().toString().toLowerCase(Locale.US);
                 if (!("localhost".equals(serverName))) {
                     domainName = serverName;    // ok, not localhost, so use it
                 }
             }
             // if we found a suitable domain, use it.  Otherwise fallback to the host name.
-            postMasterAddress = postMasterAddress + "@" + (domainName != null ? domainName : hostName);
+            postMasterAddress = postMasterAddress + "@" + (domainName != null ? domainName : defaultDomain);
         }
         this.postmaster = new MailAddress( postMasterAddress );
 

Modified: james/server/trunk/src/java/org/apache/james/James.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/James.xinfo?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/James.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/James.xinfo Thu Oct 19 06:34:16 2006
@@ -42,6 +42,9 @@
     <dependency>
       <service name="org.apache.james.services.FileSystem" version="1.0"/>
     </dependency>
+    <dependency>
+      <service name="org.apache.james.services.DomainList" version="1.0"/>
+    </dependency>
   </dependencies>
 
 

Added: james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java?view=auto&rev=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java (added)
+++ james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java Thu Oct 19 06:34:16 2006
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.domain;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.services.DNSServer;
+import org.apache.james.services.DomainList;
+
+public abstract class AbstractDomainList extends AbstractLogEnabled implements Serviceable, DomainList {
+    DNSServer dns;
+
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager arg0) throws ServiceException {
+        dns = (DNSServer) arg0.lookup(DNSServer.ROLE);
+    }
+    
+
+    /**
+     * @see org.apache.james.services.DomainList#getDomains()
+     */
+    public List getDomains() {  
+        List domains = getInternalDomainList();
+        if (getLogger().isInfoEnabled()) {
+            for (Iterator i = domains.iterator(); i.hasNext(); ) {
+                getLogger().info("Handling mail for: " + i.next());
+            }
+        }  
+        return domains;
+    }
+    
+    /**
+     * 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
+     */
+    protected List getDomainsIP(List domains) {
+        List domainIP = new ArrayList();
+        if (domains.size() > 0 ) {
+            for (int i = 0; i < domains.size(); i++) {
+                try {
+                    InetAddress[]  addrs = InetAddress.getAllByName(domains.get(i).toString());
+                    for (int j = 0; j < addrs.length ; j++) {
+                        domainIP.add(addrs[j].getHostAddress());
+                    }
+                } catch (UnknownHostException e) {
+                    getLogger().error("Cannot get IP address(es) for " + domains.get(i));
+                }
+            }
+        }
+        return domainIP;    
+    }
+    
+    /**
+     * Return dnsServer
+     * 
+     * @return dns
+     */
+    protected DNSServer getDNSServer() {
+        return dns;
+    }
+    
+    /**
+     * Return domainList
+     * 
+     * @return List
+     */
+    protected abstract List getInternalDomainList();
+}

Propchange: james/server/trunk/src/java/org/apache/james/domain/AbstractDomainList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java?view=auto&rev=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java (added)
+++ james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java Thu Oct 19 06:34:16 2006
@@ -0,0 +1,82 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.domain;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+
+/**
+ * Mimic the old behavoir of JAMES
+ */
+public class HardCodedDomainList extends AbstractDomainList implements Configurable {
+    private List serverNames;
+
+    /**
+     * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
+     */
+    public void configure(Configuration arg0) throws ConfigurationException {
+        Configuration conf = arg0.getChild("servernames");
+        
+        if (conf != null) {
+            serverNames = new ArrayList();
+        
+            String hostName = null;
+            try {
+                hostName = getDNSServer().getHostName(InetAddress.getLocalHost());
+            } catch  (UnknownHostException ue) {
+                hostName = "localhost";
+            }
+
+            getLogger().info("Local host is: " + hostName);
+    
+            if (conf.getAttributeAsBoolean("autodetect") && (!hostName.equals("localhost"))) {
+                serverNames.add(hostName.toLowerCase(Locale.US));
+            }
+
+            Configuration[] serverNameConfs = conf.getChildren( "servername" );
+            for ( int i = 0; i < serverNameConfs.length; i++ ) {
+                serverNames.add( serverNameConfs[i].getValue().toLowerCase(Locale.US));
+
+                if (conf.getAttributeAsBoolean("autodetectIP", true)) {
+                    serverNames.addAll(getDomainsIP(serverNames));
+                }
+            }
+            if (serverNames.isEmpty()) {
+                throw new ConfigurationException( "Fatal configuration error: no servernames specified!");
+            }
+        } 
+    }
+    
+    /**
+     * @see org.apache.james.domain.AbstractDomainList#getInternalDomainList()
+     */
+    protected List getInternalDomainList() {
+        return serverNames;
+    }
+}

Propchange: james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.xinfo?view=auto&rev=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.xinfo (added)
+++ james/server/trunk/src/java/org/apache/james/domain/HardCodedDomainList.xinfo Thu Oct 19 06:34:16 2006
@@ -0,0 +1,19 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+  <!-- section to describe block -->
+  <block>
+    <version>1.0</version>
+  </block>
+
+  <services>
+    <service name="org.apache.james.services.DomainList" version="1.0" />
+  </services>
+  
+  <dependencies>
+    <dependency>
+      <service name="org.apache.james.services.DNSServer" version="1.0"/>
+    </dependency>
+  </dependencies>
+</blockinfo>

Added: james/server/trunk/src/java/org/apache/james/services/DomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/DomainList.java?view=auto&rev=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/DomainList.java (added)
+++ james/server/trunk/src/java/org/apache/james/services/DomainList.java Thu Oct 19 06:34:16 2006
@@ -0,0 +1,35 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+package org.apache.james.services;
+
+import java.util.List;
+
+public interface DomainList {
+
+    public final static String ROLE ="org.apache.james.services.DomainList";
+    
+    /**
+     * Return List of domains which should be used as localdomains
+     * 
+     * @return domains
+     */
+    public List getDomains();
+}

Propchange: james/server/trunk/src/java/org/apache/james/services/DomainList.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/AbstractVirtualUserTable.java Thu Oct 19 06:34:16 2006
@@ -24,11 +24,13 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.List;
 import java.util.StringTokenizer;
 
 import javax.mail.internet.ParseException;
 
 import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.services.DomainList;
 import org.apache.james.services.VirtualUserTable;
 import org.apache.james.services.VirtualUserTableManagement;
 import org.apache.james.util.VirtualUserTableUtil;
@@ -40,14 +42,13 @@
  * 
  */
 public abstract class AbstractVirtualUserTable extends AbstractLogEnabled
-    implements VirtualUserTable, VirtualUserTableManagement {
+    implements VirtualUserTable, VirtualUserTableManagement, DomainList {
 
     /**
      * @see org.apache.james.services.VirtualUserTable#getMapping(org.apache.mailet.MailAddress)
      */
     public Collection getMappings(String user,String domain) throws ErrorMappingException {
 
-
         String targetString = mapAddress(user, domain);
 
         // Only non-null mappings are translated
@@ -212,6 +213,14 @@
    }
 
  
+    /**
+     * @see org.apache.james.services.DomainList#getDomains()
+     */
+    public List getDomains() {
+        List domains = getDomainsInternal();
+        getLogger().debug("Add ServerNames: " + domains);
+        return domains;
+    }
 
     /**
      * Override to map virtual recipients to real recipients, both local and non-local.
@@ -237,7 +246,7 @@
      * @return true if successfully
      * @throws InvalidMappingException 
      */
-    public abstract boolean  addMappingInternal(String user, String domain, String mapping) throws InvalidMappingException;
+    protected abstract boolean  addMappingInternal(String user, String domain, String mapping) throws InvalidMappingException;
     
     /**
      * Remove mapping 
@@ -248,6 +257,12 @@
      * @return true if successfully
      * @throws InvalidMappingException 
      */
-    public abstract boolean  removeMappingInternal(String user, String domain, String mapping) throws InvalidMappingException;
+    protected abstract boolean  removeMappingInternal(String user, String domain, String mapping) throws InvalidMappingException;
 
+    /**
+     * Return List of all domains for which email should accepted
+     * 
+     * @return domains 
+     */
+    protected abstract List getDomainsInternal();
 }

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.java Thu Oct 19 06:34:16 2006
@@ -282,8 +282,8 @@
         Collection map = getUserDomainMappings(newUser,newDomain);
 
         if (map != null && map.size() > 1) {
-                map.remove(mapping);
-                return updateMapping(newUser,newDomain,CollectionToMapping(map));
+            map.remove(mapping);
+            return updateMapping(newUser,newDomain,CollectionToMapping(map));
         } else {
             return removeMapping(newUser,newDomain,mapping);
         }
@@ -493,7 +493,43 @@
         }
         return null;
     }
-    
-    
+
+    /**
+     * @see org.apache.james.vut.AbstractVirtualUserTable#getDomainsInternal()
+     */
+    protected List getDomainsInternal() {
+        List domains = new ArrayList();
+        Connection conn = null;
+        PreparedStatement mappingStmt = null;
+        
+        try {
+            conn = dataSourceComponent.getConnection();
+            mappingStmt = conn.prepareStatement(sqlQueries.getSqlString("selectDomains", true));
+
+            ResultSet mappingRS = null;
+            try {
+                mappingRS = mappingStmt.executeQuery();
+                while (mappingRS.next()) {
+                    String domain = mappingRS.getString(1).toLowerCase();
+                    if(domains.equals(WILDCARD) == false && domains.contains(domains) == false) {
+                        domains.add(domain);
+                    }
+                }
+            } finally {
+                theJDBCUtil.closeJDBCResultSet(mappingRS);
+            }
+            
+        } catch (SQLException sqle) {
+            getLogger().error("Error accessing database", sqle);
+        } finally {
+            theJDBCUtil.closeJDBCStatement(mappingStmt);
+            theJDBCUtil.closeJDBCConnection(conn);
+        }
+        if (domains.size() == 0) {
+            return null;
+        } else {
+            return domains;
+        }
+    } 
 }
 

Modified: james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo Thu Oct 19 06:34:16 2006
@@ -10,6 +10,7 @@
   <services>
     <service name="org.apache.james.services.VirtualUserTableManagement" version="1.0" />
     <service name="org.apache.james.services.VirtualUserTable" version="1.0" />
+    <service name="org.apache.james.services.DomainList" version="1.0"/>
   </services>
   
   <dependencies>

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java (original)
+++ james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.java Thu Oct 19 06:34:16 2006
@@ -21,8 +21,11 @@
 
 package org.apache.james.vut;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.avalon.framework.configuration.Configurable;
@@ -36,17 +39,36 @@
      */
     private Map mappings = new HashMap();
     
+    private List domains = new ArrayList(); 
     
     /**
      * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
      */
     public void configure(Configuration arg0) throws ConfigurationException {
-        Configuration mapConf = arg0.getChild("mapping");
+        Configuration[] mapConf = arg0.getChildren("mapping");
         if (mapConf != null) {
-            mappings = VirtualUserTableUtil.getXMLMappings(mapConf.getValue());
+            for (int i = 0; i < mapConf.length; i ++) {       
+                mappings.putAll(VirtualUserTableUtil.getXMLMappings(mapConf[i].getValue()));
+            }
         } else {
             throw new ConfigurationException("No mapping configured");
         }
+        
+        // Add domains of the mappings map to the domains List
+        Iterator keys = mappings.keySet().iterator();
+        
+        while (keys.hasNext()) {
+            String key = keys.next().toString();
+            Collection values = mappingToCollection(mappings.get(key).toString());
+            
+            String[] args1 = key.split("@");
+            if (args1 != null && args1.length == 2) {
+                String domain = args1[1].toLowerCase();
+                if (domains.contains(domain) == false) {
+                    domains.add(domain);
+                }
+            }
+        }
     
     }
     
@@ -74,11 +96,22 @@
     }
 
     /**
-     * Not implemented
+     * @see org.apache.james.services.VirtualUserTableManagement#getUserDomainMappings(java.lang.String, java.lang.String)
      */
     public Collection getUserDomainMappings(String user, String domain) {
-    // Not supported
-    return null;
+        Object maps = mappings.get(user + "@" + domain);
+        if (maps != null) {
+            return mappingToCollection(maps.toString());
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * @see org.apache.james.vut.AbstractVirtualUserTable#getDomainsInternal()
+     */
+    protected List getDomainsInternal() {
+        return domains;
     }
 
 }

Modified: james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo Thu Oct 19 06:34:16 2006
@@ -10,12 +10,15 @@
   <services>
     <service name="org.apache.james.services.VirtualUserTableManagment" version="1.0" />
     <service name="org.apache.james.services.VirtualUserTable" version="1.0" />
+    <service name="org.apache.james.services.DomainList" version="1.0"/>
   </services>
   
-  <!-- interfaces that may be exported to manange this block -->
-  <!--
-  <management-access-points>
-    <service name="org.apache.james.management.BayesianAnalyzerManagementMBean"/>
-  </management-access-points>
--->
+  <dependencies>
+    <dependency>
+      <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector" version="1.0"/>
+    </dependency>
+    <dependency>
+      <service name="org.apache.james.services.FileSystem" version="1.0"/>
+    </dependency>
+  </dependencies>
 </blockinfo>

Modified: james/server/trunk/src/test/org/apache/james/JamesTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/JamesTest.java?view=diff&rev=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/test/org/apache/james/JamesTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/JamesTest.java Thu Oct 19 06:34:16 2006
@@ -26,6 +26,7 @@
 import org.apache.avalon.framework.service.ServiceException;
 import org.apache.james.services.AbstractDNSServer;
 import org.apache.james.services.DNSServer;
+import org.apache.james.services.DomainList;
 import org.apache.james.services.FileSystem;
 import org.apache.james.services.MailServer;
 import org.apache.james.services.MailServerTestAllImplementations;
@@ -41,6 +42,8 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.InetAddress;
+import java.util.ArrayList;
+import java.util.List;
 
 public class JamesTest extends MailServerTestAllImplementations {
     
@@ -94,6 +97,14 @@
                 return new File("./conf/");
             }
             
+        });
+        serviceManager.put(DomainList.ROLE, new DomainList() {
+
+            public List getDomains() {
+                ArrayList d = new ArrayList();
+                d.add("localhost");
+                return d;
+            }            
         });
         MockStore mockStore = new MockStore();
         mockMailRepository = new InMemorySpoolRepository();

Added: james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java?view=auto&rev=465621
==============================================================================
--- james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java Thu Oct 19 06:34:16 2006
@@ -0,0 +1,131 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+
+package org.apache.james.domain;
+
+import java.net.InetAddress;
+import java.util.ArrayList;
+
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+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.test.mock.avalon.MockLogger;
+import org.apache.james.test.mock.avalon.MockServiceManager;
+
+import junit.framework.TestCase;
+
+public class HardCodedDomainListTest extends TestCase {
+    
+    private Configuration setUpConfiguration(boolean auto,boolean autoIP,ArrayList names) {
+        DefaultConfiguration configuration = new DefaultConfiguration("test");
+        DefaultConfiguration sNamesConf = new DefaultConfiguration("servernames");
+        sNamesConf.setAttribute("autodetect", auto);
+        
+        for (int i= 0; i< names.size(); i++) {
+            DefaultConfiguration nameConf = new DefaultConfiguration("servername");
+            nameConf.setAttribute("autodetectIP", autoIP);
+            nameConf.setValue(names.get(i).toString());
+            sNamesConf.addChild(nameConf);
+        }
+
+        configuration.addChild(sNamesConf);
+        return configuration;
+    }
+    
+    private DNSServer setUpDNSServer(final String hostName) {
+        DNSServer dns = new AbstractDNSServer() {
+            public String getHostName(InetAddress inet) {
+                return hostName;
+            }
+        };
+        return dns;
+    }
+    
+    private MockServiceManager setUpServiceManager(DNSServer dns) {
+        MockServiceManager service = new MockServiceManager();
+        service.put(DNSServer.ROLE, dns);
+        return service;
+    }
+    
+    public void testGetDomains() throws ConfigurationException, ServiceException {
+        ArrayList domains = new ArrayList();
+        domains.add("domain1");
+    
+        HardCodedDomainList dom = new HardCodedDomainList();
+        ContainerUtil.enableLogging(dom,new MockLogger());
+        dom.service(setUpServiceManager(setUpDNSServer("localhost")));
+        dom.configure(setUpConfiguration(false,false,domains));
+
+        assertTrue("One domain found",dom.getDomains().size() ==1);
+    }
+    
+    public void testGetDomainsAutoDetectNotLocalHost() throws ConfigurationException, ServiceException {
+        ArrayList domains = new ArrayList();
+        domains.add("domain1");
+    
+        HardCodedDomainList dom = new HardCodedDomainList();
+        ContainerUtil.enableLogging(dom,new MockLogger());
+        dom.service(setUpServiceManager(setUpDNSServer("hostname")));
+        dom.configure(setUpConfiguration(true,false,domains));
+
+        assertTrue("One domain found",dom.getDomains().size() == 2);
+    }
+    
+    public void testGetDomainsAutoDetectLocalHost() throws ConfigurationException, ServiceException {
+        ArrayList domains = new ArrayList();
+        domains.add("domain1");
+    
+        HardCodedDomainList dom = new HardCodedDomainList();
+        ContainerUtil.enableLogging(dom,new MockLogger());
+        dom.service(setUpServiceManager(setUpDNSServer("localhost")));
+        dom.configure(setUpConfiguration(true,false,domains));
+
+        assertTrue("One domain found",dom.getDomains().size() == 1);
+    }
+
+    public void testThrowConfigurationException() throws ConfigurationException, ServiceException {
+        boolean exception = false;
+        boolean exception2 = false;
+        HardCodedDomainList dom = new HardCodedDomainList();
+        ContainerUtil.enableLogging(dom,new MockLogger());
+        dom.service(setUpServiceManager(setUpDNSServer("localhost")));
+        try {
+            dom.configure(new DefaultConfiguration("invalid"));
+        } catch (ConfigurationException e) {
+            exception = true;
+        }
+    
+        assertTrue("Exception thrown",exception);
+    
+        try {
+            dom.configure(setUpConfiguration(true,false,new ArrayList()));
+        } catch (ConfigurationException e) {
+            exception2 = true;
+        }
+    
+        assertTrue("Exception thrown",exception2);
+    }
+}

Propchange: james/server/trunk/src/test/org/apache/james/domain/HardCodedDomainListTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/AbstractVirtualUserTableTest.java Thu Oct 19 06:34:16 2006
@@ -24,13 +24,12 @@
 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.VirtualUserTableManagement;
 
 import junit.framework.TestCase;
 
 public abstract class AbstractVirtualUserTableTest extends TestCase {
 
-    protected VirtualUserTableManagement virtualUserTable;
+    protected AbstractVirtualUserTable virtualUserTable;
     protected void setUp() throws Exception {
         virtualUserTable = getVirtalUserTable();
     }
@@ -40,7 +39,7 @@
         ContainerUtil.dispose(virtualUserTable);
     }
     
-    protected abstract VirtualUserTableManagement getVirtalUserTable() throws ServiceException, ConfigurationException, Exception;
+    protected abstract AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception;
     
 
     public void testStoreAndRetrieveRegexMapping() throws ErrorMappingException {
@@ -59,6 +58,8 @@
             assertTrue("Added virtual mapping", virtualUserTable.addRegexMapping(user, domain, regex2));
 
             assertTrue("Two mappings",virtualUserTable.getMappings(user, domain).size() == 2);
+            
+            assertEquals("One domain",virtualUserTable.getDomains().size(), 1);
         
             assertTrue("remove virtual mapping", virtualUserTable.removeRegexMapping(user, domain, regex));
         

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/JDBCVirtualUserTableTest.java Thu Oct 19 06:34:16 2006
@@ -1,3 +1,24 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
 package org.apache.james.vut;
 
 import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
@@ -8,7 +29,6 @@
 
 import org.apache.james.services.FileSystem;
 
-import org.apache.james.services.VirtualUserTableManagement;
 import org.apache.james.test.mock.avalon.MockLogger;
 
 import org.apache.james.test.mock.james.MockFileSystem;
@@ -17,7 +37,7 @@
 
 public class JDBCVirtualUserTableTest extends AbstractVirtualUserTableTest {
     
-    protected VirtualUserTableManagement getVirtalUserTable() throws ServiceException, ConfigurationException, Exception {
+    protected AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception {
         DefaultServiceManager serviceManager = new DefaultServiceManager();
         serviceManager.put(FileSystem.ROLE, new MockFileSystem());
         serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());

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=465621&r1=465620&r2=465621
==============================================================================
--- james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/vut/XMLVirtualUserTableTest.java Thu Oct 19 06:34:16 2006
@@ -29,8 +29,9 @@
 import org.apache.avalon.framework.service.DefaultServiceManager;
 import org.apache.avalon.framework.service.ServiceException;
 
+import org.apache.james.services.AbstractDNSServer;
+import org.apache.james.services.DNSServer;
 import org.apache.james.services.FileSystem;
-import org.apache.james.services.VirtualUserTable;
 
 import org.apache.james.test.mock.avalon.MockLogger;
 
@@ -41,20 +42,22 @@
 
 public class XMLVirtualUserTableTest extends TestCase {
     private String user = "user1";
-    private String domain = "localhost";
+    private String domain = "anydomain";
     
-    VirtualUserTable table;
+    AbstractVirtualUserTable table;
     
-    protected VirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception {
+    protected AbstractVirtualUserTable getVirtalUserTable() throws ServiceException, ConfigurationException, Exception {
         DefaultServiceManager serviceManager = new DefaultServiceManager();
         serviceManager.put(FileSystem.ROLE, new MockFileSystem());
         serviceManager.put(DataSourceSelector.ROLE, Util.getDataSourceSelector());
+        serviceManager.put(DNSServer.ROLE, new AbstractDNSServer());
         XMLVirtualUserTable mr = new XMLVirtualUserTable();
         
 
         mr.enableLogging(new MockLogger());
         DefaultConfiguration defaultConfiguration = new DefaultConfiguration("conf");
         defaultConfiguration.addChild(new AttrValConfiguration("mapping",user + "@" + domain +"=user2@localhost;user3@localhost"));
+        defaultConfiguration.addChild(new AttrValConfiguration("mapping","*" + "@" + domain +"=user4@localhost;user5@localhost"));
         mr.configure(defaultConfiguration);
         return mr;
     }
@@ -68,6 +71,12 @@
     }
     
     public void testGetMappings() throws ErrorMappingException {
-        assertTrue("Found 2 mappings", table.getMappings(user, domain).size() == 2);
+        assertEquals("Found 2 mappings", table.getMappings(user, domain).size(), 2);
+        assertEquals("Found 2 domains", table.getDomains().size(),1);
+    }
+    
+    public void testGetUserMappings() throws ErrorMappingException, InvalidMappingException {
+        assertTrue("Found 1 mappings", table.getMappings("any", domain).size() == 2);
+        assertNull("Found 0 mappings", table.getUserDomainMappings("any", domain));
     }
 }



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


Re: svn commit: r465621 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/domain/ java/org/apache/james/services/ java/org/apache/james/vut/ test/org/apache/james/ test/org/apache/james/domain/ test/org/apache/james/vut/

Posted by Stefano Bagnara <ap...@bago.org>.
norman@apache.org wrote:
> +    <sql name="selectDomains">select domain from VirtualUserTable</sql>

Shouldn't this use "distinct" or something similar?

> Modified: james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo
> URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo?view=diff&rev=465621&r1=465620&r2=465621
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo (original)
> +++ james/server/trunk/src/java/org/apache/james/vut/JDBCVirtualUserTable.xinfo Thu Oct 19 06:34:16 2006
> @@ -10,6 +10,7 @@
>    <services>
>      <service name="org.apache.james.services.VirtualUserTableManagement" version="1.0" />
>      <service name="org.apache.james.services.VirtualUserTable" version="1.0" />
> +    <service name="org.apache.james.services.DomainList" version="1.0"/>
>    </services>
>    
>    <dependencies>

Cool! So now we can use the virtusertable as the source for the domain 
list, also, like JAMES-426 requested, but with a better architecture!

> Modified: james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo
> URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo?view=diff&rev=465621&r1=465620&r2=465621
> ==============================================================================
> --- james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo (original)
> +++ james/server/trunk/src/java/org/apache/james/vut/XMLVirtualUserTable.xinfo Thu Oct 19 06:34:16 2006
> @@ -10,12 +10,15 @@
>    <services>
>      <service name="org.apache.james.services.VirtualUserTableManagment" version="1.0" />
>      <service name="org.apache.james.services.VirtualUserTable" version="1.0" />
> +    <service name="org.apache.james.services.DomainList" version="1.0"/>
>    </services>
>    
> -  <!-- interfaces that may be exported to manange this block -->
> -  <!--
> -  <management-access-points>
> -    <service name="org.apache.james.management.BayesianAnalyzerManagementMBean"/>
> -  </management-access-points>
> --->
> +  <dependencies>
> +    <dependency>
> +      <service name="org.apache.avalon.cornerstone.services.datasources.DataSourceSelector" version="1.0"/>
> +    </dependency>
> +    <dependency>
> +      <service name="org.apache.james.services.FileSystem" version="1.0"/>
> +    </dependency>
> +  </dependencies>
>  </blockinfo>

Why does XMLVirtualUserTable depend on DataSourceSelector?

Stefano


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


Re: svn commit: r465621 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/domain/ java/org/apache/james/services/ java/org/apache/james/vut/ test/org/apache/james/ test/org/apache/james/domain/ test/org/apache/james/vut/

Posted by Stefano Bagnara <ap...@bago.org>.
I this this configuration should be:

<domainlist autodetect="true" autodetectIP="true">
   <domain>localhost</domain>
</domainlist>

In fact there is a level we don't need anymore and we shouldn't use 
"servername" for a generic domain listing service.

norman@apache.org wrote:
> +   <domainlist>
> +      <!-- servernames identifies the DNS namespace served by this instance of James. -->
> +      <!-- These servernames are used for both matcher/mailet processing and SMTP auth -->
> +      <!-- to determine when a mail is intended for local delivery. -->
> +      <!-- -->
> +      <!-- If autodetect is TRUE, James wil attempt to discover its own host name AND -->
> +      <!-- use any explicitly specified servernames. -->
> +      <!-- If autodetect is FALSE, James will use only the specified servernames. -->
> +      <!-- -->
> +      <!-- If autodetectIP is not FALSE, James will also allow add the IP address for each servername. -->
> +      <!-- The automatic IP detection is to support RFC 2821, Sec 4.1.3, address literals. -->
> +      <!-- -->
> +      <!-- To override autodetected server names simply add explicit servername elements. -->
> +      <!-- In most cases this will be necessary. -->
> +      <!-- By default, the servername 'localhost' is specified. This can be removed, if required. -->
> +      <!-- -->
> +      <!-- Warning: If you are using fetchmail it is important to include the -->
> +      <!-- fetched domains in the server name list to prevent looping.       -->
> +      <servernames autodetect="true" autodetectIP="true">
> +         <servername>localhost</servername>
> +      </servernames>
> +   </domainlist>


Furthermore the current solution read the domainList only the first time.
We should probably add a "contains(String domain)" to the DomainList 
service so that we can make "James.isLocalServer" to delegate to 
DomainList and this way calls to isLocalServer will become dynamic and 
automatically refreshed (implementation specific).

     /**
      * @see 
org.apache.james.services.MailServer#isLocalServer(java.lang.String)
      */
     public boolean isLocalServer( final String serverName ) {
         String lowercase = serverName.toLowerCase(Locale.US);
         return "localhost".equals(serverName) || 
serverNames.contains(lowercase);
     }

Stefano


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


Re: svn commit: r465621 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/domain/ java/org/apache/james/services/ java/org/apache/james/vut/ test/org/apache/james/ test/org/apache/james/domain/ test/org/apache/james/vut/

Posted by Stefano Bagnara <ap...@bago.org>.
Norman Maurer wrote:
> Stefano Bagnara schrieb:
>> I this this configuration should be:
>>
>> <domainlist autodetect="true" autodetectIP="true">
>>   <domain>localhost</domain>
>> </domainlist>
>>
>> In fact there is a level we don't need anymore and we shouldn't use
>> "servername" for a generic domain listing service.
> I just keep it to make it easier to migrate .. Anyway i have no problems
> to change it.. IMHO thats not so importent for now

Not now, but I don't want to make a relase with "servername" for a 
generic domainlist support ;-)
About the "migrate" we should simply support the servernames/servername 
config in James and domainlist/domain in the domainlist configuration.

I saw you already added a TODO for this.
We should simply check the received domainList implementation and if it 
is an hardcoded domainlist and there is still a servernames/servername 
configuration it adds the domains one by one to the live service. This 
is an Hack, but the best hack we can do to keep backward compatibility 
in the config.xml: we will remove this as soon as we don't need the bc.

Stefano



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


Re: svn commit: r465621 - in /james/server/trunk/src: conf/ java/org/apache/james/ java/org/apache/james/domain/ java/org/apache/james/services/ java/org/apache/james/vut/ test/org/apache/james/ test/org/apache/james/domain/ test/org/apache/james/vut/

Posted by Norman Maurer <nm...@byteaction.de>.
Stefano Bagnara schrieb:
> I this this configuration should be:
>
> <domainlist autodetect="true" autodetectIP="true">
>   <domain>localhost</domain>
> </domainlist>
>
> In fact there is a level we don't need anymore and we shouldn't use
> "servername" for a generic domain listing service.
I just keep it to make it easier to migrate .. Anyway i have no problems
to change it.. IMHO thats not so importent for now

>
> norman@apache.org wrote:
>> +   <domainlist>
>> +      <!-- servernames identifies the DNS namespace served by this
>> instance of James. -->
>> +      <!-- These servernames are used for both matcher/mailet
>> processing and SMTP auth -->
>> +      <!-- to determine when a mail is intended for local delivery. -->
>> +      <!-- -->
>> +      <!-- If autodetect is TRUE, James wil attempt to discover its
>> own host name AND -->
>> +      <!-- use any explicitly specified servernames. -->
>> +      <!-- If autodetect is FALSE, James will use only the specified
>> servernames. -->
>> +      <!-- -->
>> +      <!-- If autodetectIP is not FALSE, James will also allow add
>> the IP address for each servername. -->
>> +      <!-- The automatic IP detection is to support RFC 2821, Sec
>> 4.1.3, address literals. -->
>> +      <!-- -->
>> +      <!-- To override autodetected server names simply add explicit
>> servername elements. -->
>> +      <!-- In most cases this will be necessary. -->
>> +      <!-- By default, the servername 'localhost' is specified. This
>> can be removed, if required. -->
>> +      <!-- -->
>> +      <!-- Warning: If you are using fetchmail it is important to
>> include the -->
>> +      <!-- fetched domains in the server name list to prevent
>> looping.       -->
>> +      <servernames autodetect="true" autodetectIP="true">
>> +         <servername>localhost</servername>
>> +      </servernames>
>> +   </domainlist>
>
>
> Furthermore the current solution read the domainList only the first time.
> We should probably add a "contains(String domain)" to the DomainList
> service so that we can make "James.isLocalServer" to delegate to
> DomainList and this way calls to isLocalServer will become dynamic and
> automatically refreshed (implementation specific).
>
>     /**
>      * @see
> org.apache.james.services.MailServer#isLocalServer(java.lang.String)
>      */
>     public boolean isLocalServer( final String serverName ) {
>         String lowercase = serverName.toLowerCase(Locale.US);
>         return "localhost".equals(serverName) ||
> serverNames.contains(lowercase);
>     }
>
> Stefano
>
This make sense. I will add a contains method to the DomainList service ;-)

Thx for the input .

bye
Norman

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>
> !EXCUBATOR:1,453786be53072080913696!



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