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 ba...@apache.org on 2006/10/20 15:03:52 UTC
svn commit: r466101 [1/2] - in /james/server/trunk/src: conf/
java/org/apache/james/ java/org/apache/james/core/
java/org/apache/james/fetchmail/ java/org/apache/james/services/
java/org/apache/james/transport/mailets/ java/org/apache/james/userreposit...
Author: bago
Date: Fri Oct 20 06:03:50 2006
New Revision: 466101
URL: http://svn.apache.org/viewvc?view=rev&rev=466101
Log:
Moved ignoreCase, enableAliases and enableForwarding to UsersRepository specific options.
Deprecated the use of case insensitive methods.
Kept backward compatibility for config.xml (2.3.0 config still works) (#1,2,3,6 of JAMES-622)
Added:
james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java (with props)
james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.xinfo
james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java (with props)
Modified:
james/server/trunk/src/conf/james-assembly.xml
james/server/trunk/src/conf/james-config.xml
james/server/trunk/src/java/org/apache/james/Constants.java
james/server/trunk/src/java/org/apache/james/James.java
james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java
james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java
james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
james/server/trunk/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
james/server/trunk/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
james/server/trunk/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
james/server/trunk/src/java/org/apache/james/userrepository/UsersFileRepository.java
james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/DefaultUsersJdbcRepositoryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/JamesUsersJdbcRepositoryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/ListUsersJdbcRepositoryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepositoryTest.java
james/server/trunk/src/test/org/apache/james/userrepository/UsersFileRepositoryTest.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=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/conf/james-assembly.xml (original)
+++ james/server/trunk/src/conf/james-assembly.xml Fri Oct 20 06:03:50 2006
@@ -207,7 +207,11 @@
</block>
<!-- This is needed to link the smtpserver to the local user repository -->
- <block name="localusersrepository" class="org.apache.james.core.LocalUsersRepository">
+ <!-- LocalJamesUsersRepository is used for backward compatibility with James 2.3.0 -->
+ <!-- This is needed to support <usernames> configuraion inside James -->
+ <!-- If backward compatibility is not need the LocalUsersRepository implementaion -->
+ <!-- could be safely used -->
+ <block name="localusersrepository" class="org.apache.james.core.LocalJamesUsersRepository">
<provide name="users-store"
role="org.apache.james.services.UsersStore"/>
</block>
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=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/conf/james-config.xml (original)
+++ james/server/trunk/src/conf/james-config.xml Fri Oct 20 06:03:50 2006
@@ -59,10 +59,12 @@
</servernames>
-->
- <!-- Set whether user names are case sensitive or case insensitive -->
- <!-- Set whether to enable local aliases -->
- <!-- Set whether to enable forwarding -->
+ <!-- DEPRECATED: ignoreCase, enableAliases and enableForwarding should -->
+ <!-- be configured in the UsersRepository instance: see the users-store -->
+ <!-- block configuration -->
+ <!--
<usernames ignoreCase="true" enableAliases="true" enableForwarding="true"/>
+ -->
<!-- The inbox repository is the location for users inboxes -->
<!-- Default setting: file based repository - enter path ( use "file:///" for absolute) -->
@@ -1241,6 +1243,9 @@
<!--
<repository name="LocalUsers" class="org.apache.james.userrepository.UsersFileRepository">
<destination URL="file://var/users/"/>
+ <ignoreCase>true</ignoreCase>
+ <enableAliases>true</enableAliases>
+ <enableForwarding>true</enableForwarding>
</repository>
-->
@@ -1254,6 +1259,12 @@
<!-- TEMPORARY DEFAULT: db using Derby -->
<repository name="LocalUsers" class="org.apache.james.userrepository.JamesUsersJdbcRepository" destinationURL="db://maildb/users">
<sqlFile>file://conf/sqlResources.xml</sqlFile>
+ <!-- Set whether user names are case sensitive or case insensitive -->
+ <ignoreCase>true</ignoreCase>
+ <!-- Set whether to enable local aliases -->
+ <enableAliases>true</enableAliases>
+ <!-- Set whether to enable forwarding -->
+ <enableForwarding>true</enableForwarding>
</repository>
<!-- TEMPORARY DEFAULT: db using Derby -->
Modified: james/server/trunk/src/java/org/apache/james/Constants.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/Constants.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/Constants.java (original)
+++ james/server/trunk/src/java/org/apache/james/Constants.java Fri Oct 20 06:03:50 2006
@@ -59,22 +59,4 @@
*/
public static final String AVALON_COMPONENT_MANAGER = "AVALON_COMP_MGR";
- /**
- * Context key used to store the enableAliases configuration for the default
- * LocalUsers Repository.
- */
- public static final String DEFAULT_ENABLE_ALIASES = "JAMES_DEFAULT_ENABLE_ALIASES";
-
- /**
- * Context key used to store the enableForwarding configuration for the default
- * LocalUsers Repository.
- */
- public static final String DEFAULT_ENABLE_FORWARDING = "JAMES_DEFAULT_ENABLE_FORWARDING";
-
- /**
- * Context key used to store the ignoreCase configuration for the
- * UserRepository
- */
- public static final String DEFAULT_IGNORE_USERNAME_CASE = "JAMES_DEFAULT_IGNORE_USERNAME_CASE";
-
}
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=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/James.java (original)
+++ james/server/trunk/src/java/org/apache/james/James.java Fri Oct 20 06:03:50 2006
@@ -42,6 +42,7 @@
import org.apache.james.services.DNSServer;
import org.apache.james.services.DomainList;
import org.apache.james.services.FileSystem;
+import org.apache.james.services.JamesUsersRepository;
import org.apache.james.services.MailRepository;
import org.apache.james.services.MailServer;
import org.apache.james.services.SpoolRepository;
@@ -137,11 +138,6 @@
private Collection serverNames;
/**
- * Whether to ignore case when looking up user names on this server
- */
- private boolean ignoreCase;
-
- /**
* The number of mails generated. Access needs to be synchronized for
* thread safety and to ensure that all threads see the latest value.
*/
@@ -171,7 +167,7 @@
protected Mailet localDeliveryMailet;
private FileSystem fileSystem;
-
+
private DomainList domains;
/**
@@ -211,13 +207,19 @@
initializeServernamesAndPostmaster();
+
Configuration userNamesConf = conf.getChild("usernames");
- ignoreCase = userNamesConf.getAttributeAsBoolean("ignoreCase", false);
- boolean enableAliases = userNamesConf.getAttributeAsBoolean("enableAliases", false);
- boolean enableForwarding = userNamesConf.getAttributeAsBoolean("enableForwarding", false);
- attributes.put(Constants.DEFAULT_ENABLE_ALIASES,new Boolean(enableAliases));
- attributes.put(Constants.DEFAULT_ENABLE_FORWARDING,new Boolean(enableForwarding));
- attributes.put(Constants.DEFAULT_IGNORE_USERNAME_CASE,new Boolean(ignoreCase));
+ if (userNamesConf != null) {
+ if (localusers instanceof JamesUsersRepository) {
+ getLogger().warn("<usernames> parameter in James block is deprecated. Please configure this data in UsersRepository block: configuration injected for backward compatibility");
+ ((JamesUsersRepository) localusers).setIgnoreCase(userNamesConf.getAttributeAsBoolean("ignoreCase", false));
+ ((JamesUsersRepository) localusers).setEnableAliases(userNamesConf.getAttributeAsBoolean("enableAliases", false));
+ ((JamesUsersRepository) localusers).setEnableForwarding(userNamesConf.getAttributeAsBoolean("enableForwarding", false));
+ } else {
+ getLogger().error("<usernames> parameter is no more supported. Backward compatibility is provided when using an AbstractUsersRepository but this repository is a "+localusers.getClass().toString());
+ }
+ }
+
// We don't need this. UsersRepository.ROLE is already in the compMgr we received
// We've just looked up it from the cmpManager
@@ -303,7 +305,7 @@
private void initializeServernamesAndPostmaster() throws ConfigurationException, ParseException {
//TODO: Make backward compatible
serverNames = domains.getDomains();
-
+
String defaultDomain = (String) serverNames.iterator().next();
// used by RemoteDelivery for HELO
attributes.put(Constants.DEFAULT_DOMAIN, defaultDomain);
@@ -693,11 +695,7 @@
if (!isLocalServer(mailAddress.getHost())) {
return false;
}
- if (ignoreCase) {
- return localusers.containsCaseInsensitive(mailAddress.getUser());
- } else {
- return localusers.contains(mailAddress.getUser());
- }
+ return localusers.contains(mailAddress.getUser());
}
/**
Added: james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java?view=auto&rev=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java (added)
+++ james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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.core;
+
+import org.apache.james.services.JamesUsersRepository;
+import org.apache.james.vut.ErrorMappingException;
+
+import java.util.Collection;
+
+/**
+ * This is a wrapper that provide access to the "LocalUsers" repository
+ * but expect to find a JamesUsersRepository and return an object implementing
+ * this extended interface
+ */
+public class LocalJamesUsersRepository extends LocalUsersRepository implements JamesUsersRepository{
+
+ /**
+ * @see org.apache.james.services.JamesUsersRepository#setEnableAliases(boolean)
+ */
+ public void setEnableAliases(boolean enableAliases) {
+ ((JamesUsersRepository) users).setEnableAliases(enableAliases);
+ }
+
+ /**
+ * @see org.apache.james.services.JamesUsersRepository#setEnableForwarding(boolean)
+ */
+ public void setEnableForwarding(boolean enableForwarding) {
+ ((JamesUsersRepository) users).setEnableForwarding(enableForwarding);
+ }
+
+ /**
+ * @see org.apache.james.services.JamesUsersRepository#setIgnoreCase(boolean)
+ */
+ public void setIgnoreCase(boolean ignoreCase) {
+ ((JamesUsersRepository) users).setIgnoreCase(ignoreCase);
+ }
+
+ /**
+ * @see org.apache.james.services.VirtualUserTable#getMappings(java.lang.String, java.lang.String)
+ */
+ public Collection getMappings(String user, String domain) throws ErrorMappingException {
+ return ((JamesUsersRepository) users).getMappings(user, domain);
+ }
+
+}
Propchange: james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.xinfo?view=auto&rev=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.xinfo (added)
+++ james/server/trunk/src/java/org/apache/james/core/LocalJamesUsersRepository.xinfo Fri Oct 20 06:03:50 2006
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+ <!-- section to describe block -->
+ <block>
+ <version>1.0</version>
+ </block>
+
+ <!-- services that are offered by this block -->
+ <services>
+ <service name="org.apache.james.services.UsersRepository" version="1.0" />
+ <service name="org.apache.james.services.JamesUsersRepository" version="1.0" />
+ <service name="org.apache.james.services.VirtualUserTable" version="1.0" />
+ </services>
+
+ <!-- interfaces that may be exported to manange this block -->
+ <management-access-points>
+ <service name="org.apache.james.JamesMBean"/>
+ </management-access-points>
+
+ <dependencies>
+ <dependency>
+ <service name="org.apache.james.services.UsersStore" version="1.0"/>
+ </dependency>
+ </dependencies>
+</blockinfo>
Modified: james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/core/LocalUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -37,7 +37,7 @@
public class LocalUsersRepository implements UsersRepository, Serviceable, Initializable, JamesMBean {
private UsersStore usersStore;
- private UsersRepository users;
+ protected UsersRepository users;
public void setUsersStore(UsersStore usersStore) {
this.usersStore = usersStore;
Modified: james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java (original)
+++ james/server/trunk/src/java/org/apache/james/fetchmail/MessageProcessor.java Fri Oct 20 06:03:50 2006
@@ -882,7 +882,7 @@
*/
protected boolean isLocalRecipient(MailAddress recipient)
{
- return isLocalServer(recipient) && getLocalUsers().containsCaseInsensitive(recipient.getUser());
+ return isLocalServer(recipient) && getLocalUsers().contains(recipient.getUser());
}
/**
Added: james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java?view=auto&rev=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java (added)
+++ james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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;
+
+
+public interface JamesUsersRepository extends UsersRepository, VirtualUserTable {
+
+ /**
+ * enable/disable aliases in case of JamesUsers
+ * @param enableAliases enable
+ */
+ public void setEnableAliases(boolean enableAliases);
+
+ /**
+ * enable/disable aliases in case of JamesUsers
+ * @param enableForwarding enable
+ */
+ public void setEnableForwarding(boolean enableForwarding);
+
+ /**
+ * set case sensitive/insensitive operations
+ * @param ignoreCase ignore
+ */
+ public void setIgnoreCase(boolean ignoreCase);
+
+}
Propchange: james/server/trunk/src/java/org/apache/james/services/JamesUsersRepository.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/LocalDelivery.java Fri Oct 20 06:03:50 2006
@@ -22,7 +22,6 @@
package org.apache.james.transport.mailets;
import org.apache.commons.collections.iterators.IteratorChain;
-import org.apache.james.Constants;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailetConfig;
@@ -86,39 +85,7 @@
super.init();
aliasingMailet = new UsersRepositoryAliasingForwarding();
- MailetConfig mua = new MailetConfig() {
-
- public String getInitParameter(String name) {
- if ("enableAliases".equals(name)) {
- String res = getMailetConfig().getInitParameter("enableAliases");
- return res != null ? res : getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_ALIASES).toString();
- } else if ("enableForwarding".equals(name)) {
- String res = getMailetConfig().getInitParameter("enableForwarding");
- return res != null ? res : getMailetContext().getAttribute(Constants.DEFAULT_ENABLE_FORWARDING).toString();
- } else if ("ignoreCase".equals(name)) {
- String res = getMailetConfig().getInitParameter("ignoreCase");
- return res != null ? res : getMailetContext().getAttribute(Constants.DEFAULT_IGNORE_USERNAME_CASE).toString();
- } else return null;
- }
-
- public Iterator getInitParameterNames() {
- Collection h = new ArrayList();
- h.add("enableAliases");
- h.add("enableForwarding");
- h.add("ignoreCase");
- return h.iterator();
- }
-
- public MailetContext getMailetContext() {
- return getMailetConfig().getMailetContext();
- }
-
- public String getMailetName() {
- return getMailetConfig().getMailetName();
- }
-
- };
- aliasingMailet.init(mua);
+ aliasingMailet.init(getMailetConfig());
deliveryMailet = new ToMultiRepository();
MailetConfig m = new MailetConfig() {
Modified: james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java (original)
+++ james/server/trunk/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java Fri Oct 20 06:03:50 2006
@@ -24,10 +24,10 @@
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.james.Constants;
-import org.apache.james.services.JamesUser;
-import org.apache.james.services.User;
import org.apache.james.services.UsersRepository;
import org.apache.james.services.UsersStore;
+import org.apache.james.services.VirtualUserTable;
+import org.apache.james.vut.ErrorMappingException;
import org.apache.mailet.GenericMailet;
import org.apache.mailet.Mail;
import org.apache.mailet.MailAddress;
@@ -36,8 +36,8 @@
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Vector;
@@ -66,21 +66,6 @@
private UsersRepository usersRepository;
/**
- * Whether to enable aliasing for users on this server
- */
- private boolean enableAliases;
-
- /**
- * Whether to enable forwarding for users on this server
- */
- private boolean enableForwarding;
-
- /**
- * Whether to ignore case when looking up user names on this server
- */
- private boolean ignoreCase;
-
- /**
* Delivers a mail to a local mailbox.
*
* @param mail
@@ -108,19 +93,18 @@
for (Iterator i = recipients.iterator(); i.hasNext();) {
MailAddress recipient = (MailAddress) i.next();
try {
- String username = processMail(mail.getSender(), recipient,
+ Collection usernames = processMail(mail.getSender(), recipient,
message);
// if the username is null or changed we remove it from the
// remaining recipients
- if (username == null) {
+ if (usernames == null) {
i.remove();
- } else if (!username.equals(recipient.getUser())) {
+ } else {
i.remove();
// if the username has been changed we add a new recipient
// with the new name.
- newRecipients.add(new MailAddress(username, recipient
- .getHost()));
+ newRecipients.addAll(usernames);
}
} catch (Exception ex) {
@@ -169,9 +153,8 @@
* @param message
* @throws MessagingException
*/
- public String processMail(MailAddress sender, MailAddress recipient,
+ public Collection processMail(MailAddress sender, MailAddress recipient,
MimeMessage message) throws MessagingException {
- String username;
if (recipient == null) {
throw new IllegalArgumentException(
"Recipient for mail to be spooled cannot be null.");
@@ -180,62 +163,85 @@
throw new IllegalArgumentException(
"Mail message to be spooled cannot be null.");
}
- if (ignoreCase) {
- String originalUsername = recipient.getUser();
- username = usersRepository.getRealName(originalUsername);
- if (username == null) {
- StringBuffer errorBuffer = new StringBuffer(128).append(
- "The inbox for user ").append(originalUsername).append(
- " was not found on this server.");
- throw new MessagingException(errorBuffer.toString());
+
+ if (usersRepository instanceof VirtualUserTable) {
+ Collection mappings;
+ try {
+ mappings = ((VirtualUserTable) usersRepository).getMappings(recipient.getUser(), recipient.getHost());
+ } catch (ErrorMappingException e) {
+ StringBuffer errorBuffer = new StringBuffer(128)
+ .append("A problem as occoured trying to alias and forward user ")
+ .append(recipient)
+ .append(": ")
+ .append(e.getMessage());
+ throw new MessagingException(errorBuffer.toString());
}
- } else {
- username = recipient.getUser();
- }
- User user;
- if (enableAliases || enableForwarding) {
- user = usersRepository.getUserByName(username);
- if (user instanceof JamesUser) {
- if (enableAliases && ((JamesUser) user).getAliasing()) {
- username = ((JamesUser) user).getAlias();
- }
- // Forwarding takes precedence over local aliases
- if (enableForwarding && ((JamesUser) user).getForwarding()) {
- MailAddress forwardTo = ((JamesUser) user).getForwardingDestination();
- if (forwardTo == null) {
- StringBuffer errorBuffer = new StringBuffer(128)
- .append("Forwarding was enabled for ")
- .append(username)
- .append(" but no forwarding address was set for this account.");
- throw new MessagingException(errorBuffer.toString());
+
+ // TODO: what to do when mappings return null?
+ if (mappings != null) {
+ Iterator i = mappings.iterator();
+ Collection remoteRecipients = new ArrayList();
+ Collection localRecipients = new ArrayList();
+ while (i.hasNext()) {
+ MailAddress nextMap = new MailAddress((String) i.next());
+ if (getMailetContext().isLocalServer(nextMap.getHost())) {
+ System.err.println("L: "+nextMap);
+ localRecipients.add(nextMap);
+ } else {
+ System.err.println("R: "+nextMap);
+ remoteRecipients.add(nextMap);
}
- Collection recipients = new HashSet();
- recipients.add(forwardTo);
+ }
+
+ if (remoteRecipients.size() > 0) {
try {
- getMailetContext().sendMail(sender, recipients, message);
+ getMailetContext().sendMail(sender, remoteRecipients, message);
StringBuffer logBuffer = new StringBuffer(128).append(
- "Mail for ").append(username).append(
- " forwarded to ").append(forwardTo.toString());
+ "Mail for ").append(recipient).append(
+ " forwarded to ");
+ for (Iterator j = remoteRecipients.iterator(); j.hasNext(); ) {
+ logBuffer.append(j.next());
+ if (j.hasNext()) logBuffer.append(", ");
+ }
getMailetContext().log(logBuffer.toString());
return null;
} catch (MessagingException me) {
StringBuffer logBuffer = new StringBuffer(128).append(
- "Error forwarding mail to ").append(
- forwardTo.toString()).append(
- "attempting local delivery");
+ "Error forwarding mail to ");
+ for (Iterator j = remoteRecipients.iterator(); j.hasNext(); ) {
+ logBuffer.append(j.next());
+ if (j.hasNext()) logBuffer.append(", ");
+ }
+ logBuffer.append("attempting local delivery");
+
getMailetContext().log(logBuffer.toString());
throw me;
}
}
- } else {
- StringBuffer errorBuffer = new StringBuffer(128)
- .append("Warning: the repository returned an User of the wrong class (")
- .append(user.getClass().getName())
- .append(" does not implement JamesUser).");
- getMailetContext().log(errorBuffer.toString());
+
+ if (localRecipients.size() > 0) {
+ return localRecipients;
+ } else {
+ return null;
+ }
}
+ } else {
+ StringBuffer errorBuffer = new StringBuffer(128)
+ .append("Warning: the repository ")
+ .append(usersRepository.getClass().getName())
+ .append(" does not implement VirtualUserTable interface).");
+ getMailetContext().log(errorBuffer.toString());
+ }
+ String realName = usersRepository.getRealName(recipient.getUser());
+ if (realName != null) {
+ ArrayList ret = new ArrayList();
+ ret.add(new MailAddress(realName, recipient.getHost()));
+ return ret;
+ } else {
+ ArrayList ret = new ArrayList();
+ ret.add(recipient);
+ return ret;
}
- return username;
}
/**
@@ -247,10 +253,6 @@
.getAttribute(Constants.AVALON_COMPONENT_MANAGER);
try {
- enableAliases = new Boolean(getInitParameter("enableAliases","false")).booleanValue();
- enableForwarding = new Boolean(getInitParameter("enableForwarding","false")).booleanValue();
- ignoreCase = new Boolean(getInitParameter("ignoreCase","false")).booleanValue();
-
String userRep = getInitParameter("usersRepository");
if (userRep == null || userRep.length() == 0) {
try {
Modified: james/server/trunk/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/userrepository/AbstractJdbcUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -19,35 +19,34 @@
package org.apache.james.userrepository;
+import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
+import org.apache.avalon.excalibur.datasource.DataSourceComponent;
+import org.apache.avalon.framework.CascadingRuntimeException;
+import org.apache.avalon.framework.activity.Initializable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
+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.FileSystem;
+import org.apache.james.services.User;
+import org.apache.james.util.JDBCUtil;
+import org.apache.james.util.SqlResources;
+
import java.io.File;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import org.apache.avalon.cornerstone.services.datasources.DataSourceSelector;
-import org.apache.avalon.excalibur.datasource.DataSourceComponent;
-import org.apache.avalon.framework.CascadingRuntimeException;
-import org.apache.avalon.framework.activity.Initializable;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
-import org.apache.avalon.framework.configuration.ConfigurationException;
-import org.apache.avalon.framework.service.Serviceable;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.james.util.JDBCUtil;
-import org.apache.james.util.SqlResources;
-import org.apache.james.services.FileSystem;
-import org.apache.james.services.User;
-
/**
* An abstract base class for creating UserRepository implementations
* which use a database for persistence.
@@ -71,8 +70,8 @@
*
*/
public abstract class AbstractJdbcUsersRepository extends
- AbstractUsersRepository implements Serviceable, Configurable,
- Initializable {
+ AbstractUsersRepository implements Serviceable, Initializable {
+
protected Map m_sqlParameters;
@@ -104,6 +103,130 @@
private FileSystem fileSystem;
/**
+ * Removes a user from the repository
+ *
+ * @param userName
+ * the user to be removed
+ */
+ public void removeUser(String userName) {
+ User user = getUserByName(userName);
+ if (user != null) {
+ doRemoveUser(user);
+ }
+ }
+
+ /**
+ * Get the user object with the specified user name. Return null if no such
+ * user.
+ *
+ * @param name
+ * the name of the user to retrieve
+ *
+ * @return the user if found, null otherwise
+ *
+ * @since James 1.2.2
+ */
+ public User getUserByName(String name) {
+ return getUserByName(name, ignoreCase);
+ }
+
+ /**
+ * Get the user object with the specified user name. Match user naems on a
+ * case insensitive basis. Return null if no such user.
+ *
+ * @param name
+ * the name of the user to retrieve
+ *
+ * @return the user if found, null otherwise
+ *
+ * @since James 1.2.2
+ */
+ public User getUserByNameCaseInsensitive(String name) {
+ return getUserByName(name, true);
+ }
+
+ /**
+ * Returns the user name of the user matching name on an equalsIgnoreCase
+ * basis. Returns null if no match.
+ *
+ * @param name
+ * the name of the user to retrieve
+ *
+ * @return the correct case sensitive name of the user
+ */
+ public String getRealName(String name) {
+ // Get the user by name, ignoring case, and return the correct name.
+ User user = getUserByName(name, ignoreCase);
+ if (user == null) {
+ return null;
+ } else {
+ return user.getUserName();
+ }
+ }
+
+ /**
+ * Returns whether or not this user is in the repository
+ *
+ * @return true or false
+ */
+ public boolean contains(String name) {
+ User user = getUserByName(name, ignoreCase);
+ return (user != null);
+ }
+
+ /**
+ * Returns whether or not this user is in the repository. Names are matched
+ * on a case insensitive basis.
+ *
+ * @return true or false
+ */
+ public boolean containsCaseInsensitive(String name) {
+ User user = getUserByName(name, true);
+ return (user != null);
+ }
+
+ /**
+ * Test if user with name 'name' has password 'password'.
+ *
+ * @param name
+ * the name of the user to be tested
+ * @param password
+ * the password to be tested
+ *
+ * @return true if the test is successful, false if the password is
+ * incorrect or the user doesn't exist
+ * @since James 1.2.2
+ */
+ public boolean test(String name, String password) {
+ User user = getUserByName(name, ignoreCase);
+ if (user == null) {
+ return false;
+ } else {
+ return user.verifyPassword(password);
+ }
+ }
+
+ /**
+ * Returns a count of the users in the repository.
+ *
+ * @return the number of users in the repository
+ */
+ public int countUsers() {
+ List usernames = listUserNames();
+ return usernames.size();
+ }
+
+ /**
+ * List users in repository.
+ *
+ * @return Iterator over a collection of Strings, each being one user in the
+ * repository.
+ */
+ public Iterator list() {
+ return listUserNames().iterator();
+ }
+
+ /**
* Set the DataSourceSelector
*
* @param datasources
@@ -162,6 +285,7 @@
*/
public void configure(Configuration configuration)
throws ConfigurationException {
+ super.configure(configuration);
StringBuffer logBuffer = null;
if (getLogger().isDebugEnabled()) {
logBuffer = new StringBuffer(64).append(this.getClass().getName())
@@ -362,12 +486,10 @@
return userNames;
}
- //
- // Superclass methods - overridden from AbstractUsersRepository
- //
-
/**
- * @see org.apache.james.userrepository.AbstractUsersRepository#listAllUsers()
+ * Returns a list populated with all of the Users in the repository.
+ *
+ * @return an <code>Iterator</code> of <code>User</code>s.
*/
protected Iterator listAllUsers() {
return getAllUsers().iterator();
@@ -408,7 +530,11 @@
}
/**
- * @see org.apache.james.userrepository.AbstractUsersRepository#doAddUser(org.apache.james.services.User)
+ * Adds a user to the underlying Repository. The user name must not clash
+ * with an existing user.
+ *
+ * @param user
+ * the user to add
*/
protected void doAddUser(User user) {
Connection conn = openConnection();
@@ -433,7 +559,11 @@
}
/**
- * @see org.apache.james.userrepository.AbstractUsersRepository#doRemoveUser(org.apache.james.services.User)
+ * Removes a user from the underlying repository. If the user doesn't exist,
+ * returns ok.
+ *
+ * @param user
+ * the user to remove
*/
protected void doRemoveUser(User user) {
String username = user.getUserName();
@@ -457,7 +587,10 @@
}
/**
- * @see org.apache.james.userrepository.AbstractUsersRepository#doUpdateUser(org.apache.james.services.User)
+ * Updates a user record to match the supplied User.
+ *
+ * @param user
+ * the user to update
*/
protected void doUpdateUser(User user) {
Connection conn = openConnection();
@@ -479,6 +612,33 @@
}
/**
+ * Gets a user by name, ignoring case if specified. This implementation gets
+ * the entire set of users, and scrolls through searching for one matching
+ * <code>name</code>.
+ *
+ * @param name
+ * the name of the user being retrieved
+ * @param ignoreCase
+ * whether the name is regarded as case-insensitive
+ *
+ * @return the user being retrieved, null if the user doesn't exist
+ */
+ protected User getUserByNameIterating(String name, boolean ignoreCase) {
+ // Just iterate through all of the users until we find one matching.
+ Iterator users = listAllUsers();
+ while (users.hasNext()) {
+ User user = (User) users.next();
+ String username = user.getUserName();
+ if ((!ignoreCase && username.equals(name))
+ || (ignoreCase && username.equalsIgnoreCase(name))) {
+ return user;
+ }
+ }
+ // Not found - return null
+ return null;
+ }
+
+ /**
* Gets a user by name, ignoring case if specified. If the specified SQL
* statement has been defined, this method overrides the basic
* implementation in AbstractUsersRepository to increase performance.
@@ -494,7 +654,7 @@
// See if this statement has been set, if not, use
// simple superclass method.
if (m_userByNameCaseInsensitiveSql == null) {
- return super.getUserByName(name, ignoreCase);
+ return getUserByNameIterating(name, ignoreCase);
}
// Always get the user via case-insensitive SQL,
Modified: james/server/trunk/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/userrepository/AbstractUsersRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/userrepository/AbstractUsersRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/userrepository/AbstractUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -21,12 +21,17 @@
package org.apache.james.userrepository;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.services.JamesUser;
+import org.apache.james.services.JamesUsersRepository;
import org.apache.james.services.User;
-import org.apache.james.services.UsersRepository;
+import org.apache.james.vut.ErrorMappingException;
-import java.util.Iterator;
-import java.util.List;
+import java.util.ArrayList;
+import java.util.Collection;
/**
* A partial implementation of a Repository to store users.
@@ -36,248 +41,175 @@
*/
public abstract class AbstractUsersRepository
extends AbstractLogEnabled
- implements UsersRepository {
-
- //
- // Core Abstract methods - override these for a functional UserRepository.
- //
+ implements Configurable, JamesUsersRepository {
/**
- * Returns a list populated with all of the Users in the repository.
- * @return an <code>Iterator</code> of <code>User</code>s.
+ * Ignore case in usernames
+ */
+ protected boolean ignoreCase;
+
+ /**
+ * Enable Aliases frmo JamesUser
+ */
+ protected boolean enableAliases;
+
+ /**
+ * Wether to enable forwarding for JamesUser or not
*/
- protected abstract Iterator listAllUsers();
+ protected boolean enableForwarding;
/**
- * Adds a user to the underlying Repository.
- * The user name must not clash with an existing user.
- *
- * @param user the user to add
+ * @see org.apache.avalon.framework.configuration.Configurable#configure(org.apache.avalon.framework.configuration.Configuration)
*/
- protected abstract void doAddUser(User user);
+ public void configure(Configuration configuration)
+ throws ConfigurationException {
+ setIgnoreCase(configuration.getChild("usernames").getValueAsBoolean(false));
+ setEnableAliases(configuration.getChild("enableAliases").getValueAsBoolean(false));
+ setEnableForwarding(configuration.getChild("enableForwarding").getValueAsBoolean(false));
+ }
/**
- * Removes a user from the underlying repository.
- * If the user doesn't exist, returns ok.
+ * Adds a user to the underlying Repository. The user name must not clash
+ * with an existing user.
*
- * @param user the user to remove
+ * @param user
+ * the user to add
*/
- protected abstract void doRemoveUser(User user);
+ protected abstract void doAddUser(User user);
/**
* Updates a user record to match the supplied User.
*
- * @param user the user to update
+ * @param user
+ * the user to update
*/
protected abstract void doUpdateUser(User user);
+
/**
- * Produces the complete list of User names, with correct case.
- * @return a <code>List</code> of <code>String</code>s representing
- * user names.
- */
- protected abstract List listUserNames();
-
- /**
- * Gets a user by name, ignoring case if specified.
- * This implementation gets the entire set of users,
- * and scrolls through searching for one matching <code>name</code>.
- *
- * @param name the name of the user being retrieved
- * @param ignoreCase whether the name is regarded as case-insensitive
- *
- * @return the user being retrieved, null if the user doesn't exist
- */
- protected User getUserByName(String name, boolean ignoreCase) {
- // Just iterate through all of the users until we find one matching.
- Iterator users = listAllUsers();
- while ( users.hasNext() ) {
- User user = (User)users.next();
- String username = user.getUserName();
- if (( !ignoreCase && username.equals(name) ) ||
- ( ignoreCase && username.equalsIgnoreCase(name) )) {
- return user;
- }
+ * Adds a user to the repository with the specified attributes. In current
+ * implementations, the Object attributes is generally a String password.
+ *
+ * @param name
+ * the name of the user to be added
+ * @param attributes
+ * the password value as a String
+ */
+ public void addUser(String name, Object attributes) {
+ if (attributes instanceof String) {
+ User newbie = new DefaultUser(name, "SHA");
+ newbie.setPassword((String) attributes);
+ addUser(newbie);
+ } else {
+ throw new RuntimeException("Improper use of deprecated method"
+ + " - use addUser(User user)");
}
- // Not found - return null
- return null;
}
//
// UsersRepository interface implementation.
//
/**
- * Adds a user to the repository with the specified User object.
- * Users names must be unique-case-insensitive in the repository.
- *
- * @param user the user to be added
- *
+ * Adds a user to the repository with the specified User object. Users names
+ * must be unique-case-insensitive in the repository.
+ *
+ * @param user
+ * the user to be added
+ *
* @return true if succesful, false otherwise
* @since James 1.2.2
*/
public boolean addUser(User user) {
String username = user.getUserName();
- if ( containsCaseInsensitive(username) ) {
+ if (contains(username)) {
return false;
}
-
+
doAddUser(user);
return true;
}
/**
- * Adds a user to the repository with the specified attributes. In current
- * implementations, the Object attributes is generally a String password.
- *
- * @param name the name of the user to be added
- * @param attributes the password value as a String
- */
- public void addUser(String name, Object attributes) {
- if (attributes instanceof String) {
- User newbie = new DefaultUser(name, "SHA");
- newbie.setPassword( (String) attributes );
- addUser(newbie);
- } else {
- throw new RuntimeException("Improper use of deprecated method"
- + " - use addUser(User user)");
- }
- }
-
- /**
- * Update the repository with the specified user object. A user object
- * with this username must already exist.
- *
- * @param user the user to be updated
- *
+ * Update the repository with the specified user object. A user object with
+ * this username must already exist.
+ *
+ * @param user
+ * the user to be updated
+ *
* @return true if successful.
*/
public boolean updateUser(User user) {
// Return false if it's not found.
- if ( ! contains(user.getUserName()) ) {
+ if (!contains(user.getUserName())) {
return false;
- }
- else {
+ } else {
doUpdateUser(user);
return true;
}
}
/**
- * Removes a user from the repository
- *
- * @param userName the user to be removed
- */
- public void removeUser(String userName) {
- User user = getUserByName(userName);
- if ( user != null ) {
- doRemoveUser(user);
- }
- }
-
- /**
- * Get the user object with the specified user name. Return null if no
- * such user.
- *
- * @param name the name of the user to retrieve
- *
- * @return the user if found, null otherwise
- *
- * @since James 1.2.2
- */
- public User getUserByName(String name) {
- return getUserByName(name, false);
- }
-
- /**
- * Get the user object with the specified user name. Match user naems on
- * a case insensitive basis. Return null if no such user.
- *
- * @param name the name of the user to retrieve
- *
- * @return the user if found, null otherwise
- *
- * @since James 1.2.2
+ * @see org.apache.james.services.VirtualUserTable#getMappings(java.lang.String,
+ * java.lang.String)
*/
- public User getUserByNameCaseInsensitive(String name) {
- return getUserByName(name, true);
- }
+ public Collection getMappings(String username, String domain)
+ throws ErrorMappingException {
+ Collection mappings = new ArrayList();
+ User user = getUserByName(username);
+
+ if (user instanceof JamesUser) {
+ JamesUser jUser = (JamesUser) user;
+
+ if (enableAliases && jUser.getAliasing()) {
+ String alias = jUser.getAlias();
+ if (alias != null) {
+ mappings.add(alias + "@" + domain);
+ }
+ }
- /**
- * Returns the user name of the user matching name on an equalsIgnoreCase
- * basis. Returns null if no match.
- *
- * @param name the name of the user to retrieve
- *
- * @return the correct case sensitive name of the user
- */
- public String getRealName(String name) {
- // Get the user by name, ignoring case, and return the correct name.
- User user = getUserByName(name, true);
- if ( user == null ) {
+ if (enableForwarding && jUser.getForwarding()) {
+ String forward = null;
+ if (jUser.getForwardingDestination() != null
+ && ((forward = jUser.getForwardingDestination()
+ .toString()) != null)) {
+ mappings.add(forward);
+ } else {
+ StringBuffer errorBuffer = new StringBuffer(128)
+ .append("Forwarding was enabled for ")
+ .append(username)
+ .append(
+ " but no forwarding address was set for this account.");
+ getLogger().error(errorBuffer.toString());
+ }
+ }
+ }
+ if (mappings.size() == 0) {
return null;
} else {
- return user.getUserName();
+ return mappings;
}
}
/**
- * Returns whether or not this user is in the repository
- *
- * @return true or false
+ * @see org.apache.james.services.JamesUsersRepository#setEnableAliases(boolean)
*/
- public boolean contains(String name) {
- User user = getUserByName(name, false);
- return ( user != null );
+ public void setEnableAliases(boolean enableAliases) {
+ this.enableAliases = enableAliases;
}
/**
- * Returns whether or not this user is in the repository. Names are
- * matched on a case insensitive basis.
- *
- * @return true or false
+ * @see org.apache.james.services.JamesUsersRepository#setEnableForwarding(boolean)
*/
- public boolean containsCaseInsensitive(String name) {
- User user = getUserByName( name, true );
- return ( user != null );
+ public void setEnableForwarding(boolean enableForwarding) {
+ this.enableForwarding = enableForwarding;
}
/**
- * Test if user with name 'name' has password 'password'.
- *
- * @param name the name of the user to be tested
- * @param password the password to be tested
- *
- * @return true if the test is successful, false if the
- * password is incorrect or the user doesn't
- * exist
- * @since James 1.2.2
+ * @see org.apache.james.services.JamesUsersRepository#setIgnoreCase(boolean)
*/
- public boolean test(String name, String password) {
- User user = getUserByName(name, false);
- if ( user == null ) {
- return false;
- } else {
- return user.verifyPassword(password);
- }
- }
-
- /**
- * Returns a count of the users in the repository.
- *
- * @return the number of users in the repository
- */
- public int countUsers() {
- List usernames = listUserNames();
- return usernames.size();
+ public void setIgnoreCase(boolean ignoreCase) {
+ this.ignoreCase = ignoreCase;
}
- /**
- * List users in repository.
- *
- * @return Iterator over a collection of Strings, each being one user in the repository.
- */
- public Iterator list() {
- return listUserNames().iterator();
- }
}
Modified: james/server/trunk/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java Fri Oct 20 06:03:50 2006
@@ -17,26 +17,22 @@
* under the License. *
****************************************************************/
+
+
package org.apache.james.userrepository;
-import org.apache.james.services.JamesUser;
import org.apache.james.services.User;
-import org.apache.james.services.VirtualUserTable;
-import org.apache.james.vut.ErrorMappingException;
import org.apache.mailet.MailAddress;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collection;
/**
* A Jdbc-backed UserRepository which handles User instances of the <CODE>DefaultJamesUser</CODE>
* class, or any superclass.
*/
-public class JamesUsersJdbcRepository extends AbstractJdbcUsersRepository
- implements VirtualUserTable {
+public class JamesUsersJdbcRepository extends AbstractJdbcUsersRepository {
/**
* @see org.apache.james.userrepository.AbstractJdbcUsersRepository#readUserFromResultSet(java.sql.ResultSet)
*/
@@ -51,7 +47,7 @@
String alias = rsUsers.getString(7);
MailAddress forwardAddress = null;
- if (forwardingDestination != null) {
+ if ( forwardingDestination != null ) {
try {
forwardAddress = new MailAddress(forwardingDestination);
} catch (javax.mail.internet.ParseException pe) {
@@ -74,11 +70,12 @@
return user;
}
+
/**
* @see org.apache.james.userrepository.AbstractJdbcUsersRepository#setUserForInsertStatement(org.apache.james.services.User,
* java.sql.PreparedStatement)
*/
- protected void setUserForInsertStatement(User user,
+ protected void setUserForInsertStatement(User user,
PreparedStatement userInsert) throws SQLException {
setUserForStatement(user, userInsert, false);
}
@@ -87,7 +84,7 @@
* @see org.apache.james.userrepository.AbstractJdbcUsersRepository#setUserForUpdateStatement(org.apache.james.services.User,
* java.sql.PreparedStatement)
*/
- protected void setUserForUpdateStatement(User user,
+ protected void setUserForUpdateStatement(User user,
PreparedStatement userUpdate) throws SQLException {
setUserForStatement(user, userUpdate, true);
}
@@ -95,7 +92,7 @@
/**
* Sets the data for the prepared statement to match the information in the
* user object.
- *
+ *
* @param user
* the user whose data is to be stored in the PreparedStatement.
* @param stmt
@@ -104,11 +101,11 @@
* whether the user id is the last or the first column
*/
private void setUserForStatement(User user, PreparedStatement stmt,
- boolean userNameLast) throws SQLException {
+ boolean userNameLast) throws SQLException {
// Determine column offsets to use, based on username column pos.
int nameIndex = 1;
int colOffset = 1;
- if (userNameLast) {
+ if ( userNameLast ) {
nameIndex = 7;
colOffset = 0;
}
@@ -116,12 +113,12 @@
// Can handle instances of DefaultJamesUser and DefaultUser.
DefaultJamesUser jamesUser;
if (user instanceof DefaultJamesUser) {
- jamesUser = (DefaultJamesUser) user;
+ jamesUser = (DefaultJamesUser)user;
} else if (user instanceof DefaultUser) {
- DefaultUser aUser = (DefaultUser) user;
+ DefaultUser aUser = (DefaultUser)user;
jamesUser = new DefaultJamesUser(aUser.getUserName(), aUser
.getHashedPassword(), aUser.getHashAlgorithm());
- }
+ }
// Can't handle any other implementations.
else {
throw new RuntimeException("An unknown implementation of User was "
@@ -137,62 +134,24 @@
MailAddress forwardAddress = jamesUser.getForwardingDestination();
String forwardDestination = null;
- if (forwardAddress != null) {
+ if ( forwardAddress != null ) {
forwardDestination = forwardAddress.toString();
}
stmt.setString(4 + colOffset, forwardDestination);
stmt.setInt(5 + colOffset, (jamesUser.getAliasing() ? 1 : 0));
stmt.setString(6 + colOffset, jamesUser.getAlias());
}
-
+
+
+
/**
* @see org.apache.james.services.UsersRepository#addUser(java.lang.String,
* java.lang.String)
*/
- public boolean addUser(String username, String password) {
+ public boolean addUser(String username, String password) {
User newbie = new DefaultJamesUser(username, "SHA");
newbie.setPassword(password);
return addUser(newbie);
}
-
- /**
- * @see org.apache.james.services.VirtualUserTable#getMappings(java.lang.String,
- * java.lang.String)
- */
- public Collection getMappings(String username, String domain)
- throws ErrorMappingException {
- Collection mappings = new ArrayList();
- User user = getUserByName(username);
-
- if (user instanceof JamesUser) {
- JamesUser jUser = (JamesUser) user;
-
- if (jUser.getAliasing()) {
- String alias = jUser.getAlias();
- if (alias != null) {
- mappings.add(alias + "@" + domain);
- }
- }
-
- if (jUser.getForwarding()) {
- String forward = null;
- if (jUser.getForwardingDestination() != null
- && ((forward = jUser.getForwardingDestination()
- .toString()) != null)) {
- mappings.add(forward);
- } else {
- StringBuffer errorBuffer = new StringBuffer(128)
- .append("Forwarding was enabled for ")
- .append(username)
- .append(" but no forwarding address was set for this account.");
- getLogger().error(errorBuffer.toString());
- }
- }
- }
- if (mappings.size() == 0) {
- return null;
- } else {
- return mappings;
- }
- }
+
}
Modified: james/server/trunk/src/java/org/apache/james/userrepository/UsersFileRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/userrepository/UsersFileRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/java/org/apache/james/userrepository/UsersFileRepository.java (original)
+++ james/server/trunk/src/java/org/apache/james/userrepository/UsersFileRepository.java Fri Oct 20 06:03:50 2006
@@ -28,18 +28,11 @@
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.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.JamesUser;
import org.apache.james.services.User;
-import org.apache.james.services.UsersRepository;
-import org.apache.james.services.VirtualUserTable;
-import org.apache.james.vut.ErrorMappingException;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
/**
@@ -56,8 +49,8 @@
*
*/
public class UsersFileRepository
- extends AbstractLogEnabled
- implements UsersRepository, Configurable, Serviceable, Initializable, VirtualUserTable {
+ extends AbstractUsersRepository
+ implements Configurable, Serviceable, Initializable {
/**
* Whether 'deep debugging' is turned on.
@@ -102,7 +95,7 @@
*/
public void configure( final Configuration configuration )
throws ConfigurationException {
-
+ super.configure(configuration);
destination = configuration.getChild( "destination" ).getAttribute( "URL" );
if (!destination.endsWith(urlSeparator)) {
@@ -151,34 +144,14 @@
}
/**
- * @see org.apache.james.services.UsersRepository#addUser(org.apache.james.services.User)
+ * @see org.apache.james.userrepository.AbstractUsersRepository#doAddUser(org.apache.james.services.User)
*/
- public synchronized boolean addUser(User user) {
- String username = user.getUserName();
- if (contains(username)) {
- return false;
- }
+ protected void doAddUser(User user) {
try {
- objectRepository.put(username, user);
+ objectRepository.put(user.getUserName(), user);
} catch (Exception e) {
throw new RuntimeException("Exception caught while storing user: " + e );
}
- return true;
- }
-
- /**
- * @see org.apache.james.services.UsersRepository#addUser(java.lang.String, java.lang.Object)
- */
- public void addUser(String name, Object attributes) {
- if (attributes instanceof String) {
- User newbie = new DefaultUser(name, "SHA");
- newbie.setPassword( (String) attributes);
- addUser(newbie);
- }
- else {
- throw new RuntimeException("Improper use of deprecated method"
- + " - use addUser(User user)");
- }
}
/**
@@ -194,6 +167,12 @@
* @see org.apache.james.services.UsersRepository#getUserByName(java.lang.String)
*/
public synchronized User getUserByName(String name) {
+ if (ignoreCase) {
+ name = getRealName(name);
+ if (name == null ) {
+ return null;
+ }
+ }
if (contains(name)) {
try {
return (User)objectRepository.get(name);
@@ -210,7 +189,7 @@
* @see org.apache.james.services.UsersRepository#getUserByNameCaseInsensitive(java.lang.String)
*/
public User getUserByNameCaseInsensitive(String name) {
- String realName = getRealName(name);
+ String realName = getRealName(name, true);
if (realName == null ) {
return null;
}
@@ -218,33 +197,40 @@
}
/**
- * @see org.apache.james.services.UsersRepository#getRealName(java.lang.String)
+ * Return the real name, given the ignoreCase boolean parameter
*/
- public String getRealName(String name) {
- Iterator it = list();
- while (it.hasNext()) {
- String temp = (String) it.next();
- if (name.equalsIgnoreCase(temp)) {
- return temp;
+ public String getRealName(String name, boolean ignoreCase) {
+ if (ignoreCase) {
+ Iterator it = list();
+ while (it.hasNext()) {
+ String temp = (String) it.next();
+ if (name.equalsIgnoreCase(temp)) {
+ return temp;
+ }
}
+ return null;
+ } else {
+ return objectRepository.containsKey(name) ? name : null;
}
- return null;
}
/**
- * @see org.apache.james.services.UsersRepository#updateUser(org.apache.james.services.User)
+ * @see org.apache.james.services.UsersRepository#getRealName(java.lang.String)
*/
- public boolean updateUser(User user) {
- String username = user.getUserName();
- if (!contains(username)) {
- return false;
- }
+ public String getRealName(String name) {
+ return getRealName(name, ignoreCase);
+ }
+
+ /**
+ * @see org.apache.james.userrepository.AbstractUsersRepository#doUpdateUser(org.apache.james.services.User)
+ */
+ public void doUpdateUser(User user) {
try {
- objectRepository.put(username, user);
+ objectRepository.put(user.getUserName(), user);
} catch (Exception e) {
- throw new RuntimeException("Exception caught while storing user: " + e );
+ throw new RuntimeException("Exception caught while storing user: "
+ + e);
}
- return true;
}
/**
@@ -258,7 +244,11 @@
* @see org.apache.james.services.UsersRepository#contains(java.lang.String)
*/
public boolean contains(String name) {
- return objectRepository.containsKey(name);
+ if (ignoreCase) {
+ return containsCaseInsensitive(name);
+ } else {
+ return objectRepository.containsKey(name);
+ }
}
/**
@@ -280,11 +270,8 @@
public boolean test(String name, String password) {
User user;
try {
- if (contains(name)) {
- user = (User) objectRepository.get(name);
- } else {
- return false;
- }
+ user = getUserByName(name);
+ if (user == null) return false;
} catch (Exception e) {
throw new RuntimeException("Exception retrieving User" + e);
}
@@ -300,43 +287,6 @@
count++;
}
return count;
- }
-
- /**
- * @see org.apache.james.services.VirtualUserTable#getMappings(java.lang.String, java.lang.String)
- */
- public Collection getMappings(String username, String domain) throws ErrorMappingException {
- Collection mappings = new ArrayList();
- User user = getUserByName(username);
-
- if (user instanceof JamesUser) {
- JamesUser jUser = (JamesUser) user;
-
- if (jUser.getAliasing()) {
- String alias = jUser.getAlias();
- if (alias != null) {
- mappings.add(alias+ "@" + domain);
- }
- }
-
- if (jUser.getForwarding()) {
- String forward = null;
- if (jUser.getForwardingDestination() != null && ((forward = jUser.getForwardingDestination().toString()) != null)) {
- mappings.add(forward);
- } else {
- StringBuffer errorBuffer = new StringBuffer(128)
- .append("Forwarding was enabled for ")
- .append(username)
- .append(" but no forwarding address was set for this account.");
- getLogger().error(errorBuffer.toString());
- }
- }
- }
- if (mappings.size() == 0) {
- return null;
- } else {
- return mappings;
- }
}
}
Modified: james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/transport/mailets/LocalDeliveryTest.java Fri Oct 20 06:03:50 2006
@@ -61,6 +61,7 @@
private MockMailContext mockMailetContext;
private MockServiceManager mockServiceManager;
private MockMailServer mockMailServer;
+ private MockUsersRepository mockUsersRepository;
public void testUnknownUser() throws MessagingException {
//mockMailetConfig.setProperty(key, value)
@@ -104,9 +105,8 @@
public void testSimpleDeliveryCaseSensitiveMatch() throws MessagingException {
//mockMailetConfig.setProperty(key, value)
- Properties properties = new Properties();
- properties.setProperty("ignoreCase", "true");
- Mailet m = getMailet(properties);
+ mockUsersRepository.setIgnoreCase(true);
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"localUser@ignoreddomain"});
m.service(mail);
@@ -118,7 +118,7 @@
}
public void testSimpleAliasDelivery() throws MessagingException {
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES, Boolean.TRUE);
+ mockUsersRepository.setEnableAliases(true);
//mockMailetConfig.setProperty(key, value)
Mailet m = getMailet(null);
@@ -160,7 +160,7 @@
public void testForwarding() throws MessagingException {
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING, Boolean.TRUE);
+ mockUsersRepository.setEnableForwarding(true);
//mockMailetConfig.setProperty(key, value)
Mailet m = getMailet(null);
@@ -174,8 +174,8 @@
}
public void testAliasingForwarding() throws MessagingException {
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING, Boolean.TRUE);
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES, Boolean.TRUE);
+ mockUsersRepository.setEnableAliases(true);
+ mockUsersRepository.setEnableForwarding(true);
//mockMailetConfig.setProperty(key, value)
Mailet m = getMailet(null);
@@ -189,11 +189,9 @@
}
public void testAliasingForwardingWithLocallyOverriddenForwarding() throws MessagingException {
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING, Boolean.TRUE);
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES, Boolean.TRUE);
- Properties properties = new Properties();
- properties.setProperty("enableForwarding", "false");
- Mailet m = getMailet(properties);
+ mockUsersRepository.setEnableAliases(true);
+ mockUsersRepository.setEnableForwarding(false);
+ Mailet m = getMailet(null);
Mail mail = createMail(new String[] {"aliasForwardUser@ignoreddomain"});
m.service(mail);
@@ -204,9 +202,13 @@
assertDeliveryWorked(mail, expectedMails);
}
+ /* Commented out because "forwarding" to local is no more available
+ * under the new structure.
+ * If we'll ever change VirtualUserTable to return different collections
+ * for local and remote addresses this will be enabled again.
public void testForwardingToLocal() throws MessagingException {
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING, Boolean.TRUE);
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES, Boolean.TRUE);
+ mockUsersRepository.setEnableAliases(true);
+ mockUsersRepository.setEnableForwarding(true);
//mockMailetConfig.setProperty(key, value)
Mailet m = getMailet(null);
@@ -218,6 +220,7 @@
assertDeliveryWorked(mail, expectedMails);
}
+ */
/**
* @throws ParseException
@@ -225,7 +228,7 @@
*/
public void setUp() throws ParseException {
mockServiceManager = new MockServiceManager();
- MockUsersRepository mockUsersRepository = new MockUsersRepository();
+ mockUsersRepository = new MockUsersRepository();
mockUsersRepository.setForceUseJamesUser();
mockUsersRepository.addUser("localuser", "password");
mockUsersRepository.addUser("aliasedUser", "pass2");
@@ -270,11 +273,19 @@
mockMailServer.sendMail(m);
m.dispose();
}
+
+ public boolean isLocalServer(String serverName) {
+ if ("ignoreddomain".equals(serverName)) {
+ return true;
+ }
+ return super.isLocalServer(serverName);
+ }
+
};
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_ALIASES, Boolean.FALSE);
- mockMailetContext.setAttribute(Constants.DEFAULT_ENABLE_FORWARDING, Boolean.FALSE);
- mockMailetContext.setAttribute(Constants.DEFAULT_IGNORE_USERNAME_CASE, Boolean.FALSE);
+ mockUsersRepository.setEnableAliases(false);
+ mockUsersRepository.setEnableForwarding(false);
+ mockUsersRepository.setIgnoreCase(false);
mockMailetContext.setAttribute(Constants.AVALON_COMPONENT_MANAGER, mockServiceManager);
}
Modified: james/server/trunk/src/test/org/apache/james/userrepository/DefaultUsersJdbcRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/DefaultUsersJdbcRepositoryTest.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/userrepository/DefaultUsersJdbcRepositoryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/userrepository/DefaultUsersJdbcRepositoryTest.java Fri Oct 20 06:03:50 2006
@@ -73,7 +73,7 @@
* @return
*/
protected boolean getCheckCase() {
- return false;
+ return true;
}
protected void disposeUsersRepository() {
Modified: james/server/trunk/src/test/org/apache/james/userrepository/JamesUsersJdbcRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/JamesUsersJdbcRepositoryTest.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/userrepository/JamesUsersJdbcRepositoryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/userrepository/JamesUsersJdbcRepositoryTest.java Fri Oct 20 06:03:50 2006
@@ -52,11 +52,6 @@
return res;
}
-
- protected boolean getAllowMultipleUsersWithDifferentCases() {
- return false;
- }
-
/**
* @param res
* @param tableString
@@ -92,43 +87,45 @@
public void testVirtualUserTableImpl() throws Exception {
- String username = "test";
- String password = "pass";
- String alias = "alias";
- String domain = "localhost";
- String forward = "forward@somewhere";
-
- JamesUsersJdbcRepository repos = (JamesUsersJdbcRepository) getUsersRepository();
- repos.addUser(username,password);
-
- JamesUser user = (JamesUser)repos.getUserByName(username);
- user.setAlias(alias);
- repos.updateUser(user);
-
- Collection map = ((VirtualUserTable) repos).getMappings(username, domain);
- assertNull("No mapping", map);
-
- user.setAliasing(true);
- repos.updateUser(user);
- map = ((VirtualUserTable) repos).getMappings(username, domain);
- assertEquals("One mapping", 1, map.size());
- assertEquals("Alias found", map.iterator().next().toString(), alias + "@" + domain);
-
-
- user.setForwardingDestination(new MailAddress(forward));
- repos.updateUser(user);
- map = ((VirtualUserTable) repos).getMappings(username, domain);
- assertTrue("One mapping", map.size() == 1);
- assertEquals("Alias found", map.iterator().next().toString(), alias + "@" + domain);
-
-
- user.setForwarding(true);
- repos.updateUser(user);
- map = ((VirtualUserTable) repos).getMappings(username, domain);
- Iterator mappings = map.iterator();
- assertTrue("Two mapping",map.size() == 2);
- assertEquals("Alias found", mappings.next().toString(), alias + "@" + domain);
- assertEquals("Forward found", mappings.next().toString(), forward);
+ String username = "test";
+ String password = "pass";
+ String alias = "alias";
+ String domain = "localhost";
+ String forward = "forward@somewhere";
+
+ JamesUsersJdbcRepository repos = (JamesUsersJdbcRepository) getUsersRepository();
+ repos.setEnableAliases(true);
+ repos.setEnableForwarding(true);
+ repos.addUser(username,password);
+
+ JamesUser user = (JamesUser)repos.getUserByName(username);
+ user.setAlias(alias);
+ repos.updateUser(user);
+
+ Collection map = ((VirtualUserTable) repos).getMappings(username, domain);
+ assertNull("No mapping", map);
+
+ user.setAliasing(true);
+ repos.updateUser(user);
+ map = ((VirtualUserTable) repos).getMappings(username, domain);
+ assertEquals("One mapping", 1, map.size());
+ assertEquals("Alias found", map.iterator().next().toString(), alias + "@" + domain);
+
+
+ user.setForwardingDestination(new MailAddress(forward));
+ repos.updateUser(user);
+ map = ((VirtualUserTable) repos).getMappings(username, domain);
+ assertTrue("One mapping", map.size() == 1);
+ assertEquals("Alias found", map.iterator().next().toString(), alias + "@" + domain);
+
+
+ user.setForwarding(true);
+ repos.updateUser(user);
+ map = ((VirtualUserTable) repos).getMappings(username, domain);
+ Iterator mappings = map.iterator();
+ assertTrue("Two mapping",map.size() == 2);
+ assertEquals("Alias found", mappings.next().toString(), alias + "@" + domain);
+ assertEquals("Forward found", mappings.next().toString(), forward);
}
Modified: james/server/trunk/src/test/org/apache/james/userrepository/ListUsersJdbcRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/ListUsersJdbcRepositoryTest.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/userrepository/ListUsersJdbcRepositoryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/userrepository/ListUsersJdbcRepositoryTest.java Fri Oct 20 06:03:50 2006
@@ -54,7 +54,7 @@
protected boolean getCheckCase() {
- return false;
+ return true;
}
/**
Modified: james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java (original)
+++ james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepository.java Fri Oct 20 06:03:50 2006
@@ -21,7 +21,6 @@
import org.apache.james.security.DigestUtil;
import org.apache.james.services.User;
-import org.apache.james.services.UsersRepository;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
@@ -30,7 +29,7 @@
import java.util.List;
import java.util.Locale;
-public class MockUsersRepository implements UsersRepository {
+public class MockUsersRepository extends AbstractUsersRepository {
private final HashMap m_users = new HashMap();
@@ -107,7 +106,11 @@
}
public User getUserByName(String name) {
- return (User) m_users.get(name);
+ if (ignoreCase) {
+ return getUserByNameCaseInsensitive(name);
+ } else {
+ return (User) m_users.get(name);
+ }
}
public User getUserByNameCaseInsensitive(String name) {
@@ -115,7 +118,11 @@
}
public String getRealName(String name) {
- return m_users.get(name.toLowerCase(Locale.US)) != null ? ((User) m_users.get(name.toLowerCase(Locale.US))).getUserName() : null;
+ if (ignoreCase) {
+ return m_users.get(name.toLowerCase(Locale.US)) != null ? ((User) m_users.get(name.toLowerCase(Locale.US))).getUserName() : null;
+ } else {
+ return m_users.get(name) != null ? name : null;
+ }
}
public boolean updateUser(User user) {
@@ -130,7 +137,11 @@
}
public boolean contains(String name) {
- return m_users.containsKey(name);
+ if (ignoreCase) {
+ return containsCaseInsensitive(name);
+ } else {
+ return m_users.containsKey(name);
+ }
}
public boolean containsCaseInsensitive(String name) {
@@ -163,5 +174,13 @@
}
public Iterator list() {
return listUserNames().iterator();
+ }
+
+ protected void doAddUser(User user) {
+ // unused
+ }
+
+ protected void doUpdateUser(User user) {
+ // unused
}
}
Modified: james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepositoryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepositoryTest.java?view=diff&rev=466101&r1=466100&r2=466101
==============================================================================
--- james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepositoryTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/userrepository/MockUsersRepositoryTest.java Fri Oct 20 06:03:50 2006
@@ -94,7 +94,8 @@
assertNull("found the user searching for a different case!", u);
String realname = usersRepository.getRealName("uSERNAMe");
- assertEquals("name is different", "username", realname);
+ assertNull("name is not null", realname);
+ // assertEquals("name is different", "username", realname);
}
public void testUserListing() {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org