Author: bago
Date: Sat May 20 04:22:03 2006
New Revision: 407988
URL: http://svn.apache.org/viewvc?rev=407988&view=rev
Log:
Backported fix for ClassCastException and NullPointerException while storing
mail for localusers and file users repository (JAMES-505)
Merged commits: r407935, r407976, r407980, r407986
Modified:
james/server/branches/v2.3/src/java/org/apache/james/core/LocalUsersRepository.java
james/server/branches/v2.3/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
james/server/branches/v2.3/src/java/org/apache/james/services/UsersRepository.java
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersFileRepository.java
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersLDAPRepository.java
james/server/branches/v2.3/src/test/org/apache/james/userrepository/MockUsersRepository.java
Modified:
james/server/branches/v2.3/src/java/org/apache/james/core/LocalUsersRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/core/LocalUsersRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/core/LocalUsersRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/core/LocalUsersRepository.java
Sat May 20 04:22:03 2006
@@ -52,6 +52,10 @@
users.addUser(name,attributes);
}
+ public boolean addUser(String username, String password) {
+ return users.addUser(username, password);
+ }
+
public User getUserByName(String name) {
return users.getUserByName(name);
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/mailrepository/AvalonMailRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/mailrepository/AvalonMailRepository.java
Sat May 20 04:22:03 2006
@@ -286,7 +286,7 @@
.append(destination)
.append("/")
.append(mc.getName());
- if
(wrapper.getSourceId().equals(destinationBuffer.toString()) &&
!wrapper.isModified()) {
+ if
(destinationBuffer.toString().equals(wrapper.getSourceId()) &&
!wrapper.isModified()) {
//We're trying to save to the same place, and it's not
modified... we shouldn't save.
//More importantly, if we try to save, we will create
a 0-byte file since we're
//retrying to retrieve from a file we'll be
overwriting.
@@ -324,7 +324,7 @@
}
} catch (Exception e) {
- getLogger().error("Exception storing mail: " + e);
+ getLogger().error("Exception storing mail: " + e, e);
throw new MessagingException("Exception caught while storing
Message Container: " + e);
}
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
Sat May 20 04:22:03 2006
@@ -25,7 +25,6 @@
import org.apache.james.services.JamesUser;
import org.apache.james.services.User;
import org.apache.james.services.UsersRepository;
-import org.apache.james.userrepository.DefaultUser;
import org.apache.james.util.watchdog.Watchdog;
import org.apache.james.util.watchdog.WatchdogTarget;
import org.apache.mailet.MailAddress;
@@ -459,9 +458,7 @@
String response = responseBuffer.toString();
writeLoggedResponse(response);
} else {
- DefaultUser user = new DefaultUser(username, "SHA");
- user.setPassword(passwd);
- success = users.addUser(user);
+ success = users.addUser(username, passwd);
}
if ( success ) {
StringBuffer responseBuffer =
Modified:
james/server/branches/v2.3/src/java/org/apache/james/services/UsersRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/services/UsersRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/services/UsersRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/services/UsersRepository.java
Sat May 20 04:22:03 2006
@@ -54,6 +54,17 @@
* @param attributes see decription
*/
void addUser(String name, Object attributes);
+
+ /**
+ * Adds a user to the repository with the specified password
+ *
+ * @param username the username of the user to be added
+ * @param password the password of the user to add
+ * @return true if succesful, false otherwise
+ *
+ * @since James 2.3.0
+ */
+ boolean addUser(String username, String password);
/**
* Get the user object with the specified user name. Return null if no
Modified:
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/ToMultiRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/ToMultiRepository.java
Sat May 20 04:22:03 2006
@@ -177,7 +177,7 @@
// the sender. Note that this email doesn't include any details
// regarding the details of the failure(s).
// In the future we may wish to address this.
- getMailetContext().sendMail(mail.getSender(), errors, message,
+ getMailetContext().sendMail(mail.getSender(), errors,
mail.getMessage(),
Mail.ERROR);
}
// We always consume this message
Modified:
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/transport/mailets/UsersRepositoryAliasingForwarding.java
Sat May 20 04:22:03 2006
@@ -21,6 +21,7 @@
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.mailet.RFC2822Headers;
@@ -188,39 +189,41 @@
} else {
username = recipient.getUser();
}
- JamesUser user;
+ User user;
if (enableAliases || enableForwarding) {
- user = (JamesUser) usersRepository.getUserByName(username);
- if (enableAliases && user.getAliasing()) {
- username = user.getAlias();
- }
- // Forwarding takes precedence over local aliases
- if (enableForwarding && user.getForwarding()) {
- MailAddress forwardTo = 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());
+ user = usersRepository.getUserByName(username);
+ if (user instanceof JamesUser) {
+ if (enableAliases && ((JamesUser) user).getAliasing()) {
+ username = ((JamesUser) user).getAlias();
}
- Collection recipients = new HashSet();
- recipients.add(forwardTo);
- try {
- getMailetContext().sendMail(sender, recipients, message);
- StringBuffer logBuffer = new StringBuffer(128).append(
- "Mail for ").append(username).append(
- " forwarded to ").append(forwardTo.toString());
- 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");
- getMailetContext().log(logBuffer.toString());
- throw me;
+ // 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());
+ }
+ Collection recipients = new HashSet();
+ recipients.add(forwardTo);
+ try {
+ getMailetContext().sendMail(sender, recipients,
message);
+ StringBuffer logBuffer = new StringBuffer(128).append(
+ "Mail for ").append(username).append(
+ " forwarded to ").append(forwardTo.toString());
+ 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");
+ getMailetContext().log(logBuffer.toString());
+ throw me;
+ }
}
}
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/AbstractUsersRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/AbstractUsersRepository.java
Sat May 20 04:22:03 2006
@@ -151,6 +151,15 @@
}
/**
+ * @see
org.apache.james.services.UsersRepository#addUser(java.lang.String,
java.lang.String)
+ */
+ public boolean addUser(String username, String password) {
+ User newbie = new DefaultJamesUser(username, "SHA");
+ newbie.setPassword(password);
+ return addUser(newbie);
+ }
+
+ /**
* Update the repository with the specified user object. A user object
* with this username must already exist.
*
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/DefaultUsersJdbcRepository.java
Sat May 20 04:22:03 2006
@@ -94,5 +94,16 @@
userUpdate.setString(1, defUser.getHashAlgorithm());
userUpdate.setString(2, defUser.getHashedPassword());
}
+
+ /**
+ * @see
org.apache.james.services.UsersRepository#addUser(java.lang.String,
java.lang.String)
+ */
+ public boolean addUser(String username, String password) {
+ User newbie = new DefaultUser(username, "SHA");
+ newbie.setPassword(password);
+ return addUser(newbie);
+ }
+
+
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/JamesUsersJdbcRepository.java
Sat May 20 04:22:03 2006
@@ -160,4 +160,16 @@
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) {
+ User newbie = new DefaultJamesUser(username, "SHA");
+ newbie.setPassword(password);
+ return addUser(newbie);
+ }
+
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/ListUsersJdbcRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/ListUsersJdbcRepository.java
Sat May 20 04:22:03 2006
@@ -77,4 +77,15 @@
throw new UnsupportedOperationException("Can't update a List User - " +
"only has a single
attribute.");
}
+
+ /**
+ * @see
org.apache.james.services.UsersRepository#addUser(java.lang.String,
java.lang.String)
+ */
+ public boolean addUser(String username, String password) {
+ User newbie = new DefaultUser(username, "SHA");
+ newbie.setPassword(password);
+ return addUser(newbie);
+ }
+
+
}
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersFileRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersFileRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersFileRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersFileRepository.java
Sat May 20 04:22:03 2006
@@ -167,6 +167,12 @@
}
}
+ public boolean addUser(String username, String password) {
+ User newbie = new DefaultJamesUser(username, "SHA");
+ newbie.setPassword(password);
+ return addUser(newbie);
+ }
+
public synchronized User getUserByName(String name) {
if (contains(name)) {
try {
Modified:
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersLDAPRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersLDAPRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersLDAPRepository.java
(original)
+++
james/server/branches/v2.3/src/java/org/apache/james/userrepository/UsersLDAPRepository.java
Sat May 20 04:22:03 2006
@@ -344,6 +344,18 @@
// String userPassword = (String) attributes; // Not yet implemented
// }
}
+
+ /**
+ * @see
org.apache.james.services.UsersRepository#addUser(java.lang.String,
java.lang.String)
+ */
+ public boolean addUser(String username, String password) {
+ if (!contains(username)) {
+ addUser(username, password);
+ return contains(username);
+ } else {
+ return false;
+ }
+ }
private void addGroupToUser(String userName) {
String[] attrIDs = {membersAttr};
Modified:
james/server/branches/v2.3/src/test/org/apache/james/userrepository/MockUsersRepository.java
URL:
http://svn.apache.org/viewvc/james/server/branches/v2.3/src/test/org/apache/james/userrepository/MockUsersRepository.java?rev=407988&r1=407987&r2=407988&view=diff
==============================================================================
---
james/server/branches/v2.3/src/test/org/apache/james/userrepository/MockUsersRepository.java
(original)
+++
james/server/branches/v2.3/src/test/org/apache/james/userrepository/MockUsersRepository.java
Sat May 20 04:22:03 2006
@@ -74,6 +74,26 @@
}
}
+ public boolean addUser(String username, String password) {
+ if (m_users.containsKey(username)) return false;
+ try {
+ String passwordHash = DigestUtil.digestString((password), "SHA");
+
+ User user;
+
+ if (m_forceUseJamesUser) {
+ user = new DefaultJamesUser(username, passwordHash, "SHA");
+ } else {
+ user = new DefaultUser(username, passwordHash, "SHA");
+ }
+
+ return addUser(user);
+ } catch (Exception e) {
+ e.printStackTrace(); // encoding failed
+ }
+ return false;
+ }
+
public Object getAttributes(String name) {
return null; // trivial implementation
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]