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 rd...@apache.org on 2009/09/06 11:30:28 UTC
svn commit: r811784 - in /james/server/trunk:
phoenix-deployment/src/test/org/apache/james/smtpserver/
smtpserver-function/src/main/java/org/apache/james/smtpserver/
smtpserver-function/src/main/java/org/apache/james/smtpserver/core/
smtpserver-functio...
Author: rdonkin
Date: Sun Sep 6 09:30:26 2009
New Revision: 811784
URL: http://svn.apache.org/viewvc?rev=811784&view=rev
Log:
Inject UserRepository to those handlers that require it. Remove getter from session.
Modified:
james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/UsersRepositoryAuthHook.java
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/AbstractSMTPSession.java
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/smtpserver/SMTPServerRemoteDeliveryIntegrationTest.java Sun Sep 6 09:30:26 2009
@@ -204,6 +204,7 @@
m_serviceManager.put(MailServer.ROLE, m_mailServer);
// Phoenix loader does not understand aliases
m_serviceManager.put("James", m_mailServer);
+ m_serviceManager.put("localusersrepository", m_usersRepository);
m_serviceManager.put(UsersRepository.ROLE, m_usersRepository);
m_serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_smtpListenerPort));
m_serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPSession.java Sun Sep 6 09:30:26 2009
@@ -21,8 +21,6 @@
import java.util.Map;
-import org.apache.james.api.user.UsersRepository;
-
/**
* All the handlers access this interface to communicate with
* SMTPHandler object
@@ -63,14 +61,6 @@
*
*/
void resetState();
-
- /**
- * Returns the UsersRepository for this service.
- *
- * @return the local users repository
- * @deprecated this service should be injection
- */
- UsersRepository getUsersRepository();
/**
* Returns the service wide hello name
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/UsersRepositoryAuthHook.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/UsersRepositoryAuthHook.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/UsersRepositoryAuthHook.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/UsersRepositoryAuthHook.java Sun Sep 6 09:30:26 2009
@@ -18,6 +18,9 @@
****************************************************************/
package org.apache.james.smtpserver.core;
+import javax.annotation.Resource;
+
+import org.apache.james.api.user.UsersRepository;
import org.apache.james.smtpserver.SMTPSession;
import org.apache.james.smtpserver.hook.AuthHook;
import org.apache.james.smtpserver.hook.HookResult;
@@ -27,11 +30,32 @@
* This Auth hook can be used to authenticate against the james user repository
*/
public class UsersRepositoryAuthHook implements AuthHook {
+
+ private UsersRepository users;
+
+ /**
+ * Gets the users repository.
+ * @return the users
+ */
+ public final UsersRepository getUsers() {
+ return users;
+ }
+
+ /**
+ * Sets the users repository.
+ * @param users the users to set
+ */
+ @Resource(name="localusersrepository")
+ public final void setUsers(UsersRepository users) {
+ this.users = users;
+ }
+
+
/**
* @see org.apache.james.smtpserver.hook.AuthHook#doAuth(org.apache.james.smtpserver.SMTPSession, java.lang.String, java.lang.String)
*/
public HookResult doAuth(SMTPSession session, String username, String password) {
- if (session.getUsersRepository().test(username, password)) {
+ if (users.test(username, password)) {
session.setUser(username);
session.setRelayingAllowed(true);
return new HookResult(HookReturnCode.OK, "Authentication Successful");
Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/core/filter/fastfail/ValidRcptHandler.java Sun Sep 6 09:30:26 2009
@@ -27,6 +27,8 @@
import java.util.Iterator;
import java.util.StringTokenizer;
+import javax.annotation.Resource;
+
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
@@ -34,6 +36,7 @@
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.api.user.UsersRepository;
import org.apache.james.api.vut.ErrorMappingException;
import org.apache.james.api.vut.VirtualUserTable;
import org.apache.james.api.vut.VirtualUserTableStore;
@@ -55,6 +58,25 @@
*/
public class ValidRcptHandler extends AbstractLogEnabled implements RcptHook, Configurable, Serviceable {
+ private UsersRepository users;
+
+ /**
+ * Gets the users repository.
+ * @return the users
+ */
+ public final UsersRepository getUsers() {
+ return users;
+ }
+
+ /**
+ * Sets the users repository.
+ * @param users the users to set
+ */
+ @Resource(name="localusersrepository")
+ public final void setUsers(UsersRepository users) {
+ this.users = users;
+ }
+
private Collection recipients = new ArrayList();
private Collection domains = new ArrayList();
private Collection regex = new ArrayList();
@@ -171,7 +193,7 @@
if (!session.isRelayingAllowed()) {
boolean invalidUser = true;
- if (session.getUsersRepository().contains(rcpt.getLocalPart()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getDomain().toLowerCase())) {
+ if (users.contains(rcpt.getLocalPart()) == true || recipients.contains(rcpt.toString().toLowerCase()) || domains.contains(rcpt.getDomain().toLowerCase())) {
invalidUser = false;
}
Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/AbstractSMTPSession.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/AbstractSMTPSession.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/AbstractSMTPSession.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/AbstractSMTPSession.java Sun Sep 6 09:30:26 2009
@@ -22,7 +22,6 @@
import java.util.Map;
-import org.apache.james.api.user.UsersRepository;
import org.apache.james.services.MailServer;
/**
@@ -167,10 +166,6 @@
return getConfigurationData().getSMTPGreeting();
}
- public UsersRepository getUsersRepository() {
- return getConfigurationData().getUsersRepository();
- }
-
public boolean useAddressBracketsEnforcement() {
return getConfigurationData().useAddressBracketsEnforcement();
}
Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java Sun Sep 6 09:30:26 2009
@@ -206,6 +206,7 @@
m_serviceManager.put(MailServer.ROLE, m_mailServer);
// Phoenix loader does not understand aliases
m_serviceManager.put("James", m_mailServer);
+ m_serviceManager.put("localusersrepository", m_usersRepository);
m_serviceManager.put(UsersRepository.ROLE, m_usersRepository);
m_serviceManager.put(SocketManager.ROLE, new MockSocketManager(m_smtpListenerPort));
m_serviceManager.put(ThreadManager.ROLE, new MockThreadManager());
Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java?rev=811784&r1=811783&r2=811784&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/ValidRcptHandlerTest.java Sun Sep 6 09:30:26 2009
@@ -50,6 +50,17 @@
private final static String USER2 = "user2";
private MockServiceManager serviceMan;
+ UsersRepository users;
+ ValidRcptHandler handler;
+
+ @Override
+ protected void setUp() throws Exception {
+ users = new MockUsersRepository();
+ users.addUser(VALID_USER,"xxx");
+ handler = new ValidRcptHandler();
+ handler.setUsers(users);
+ }
+
private SMTPSession setupMockedSMTPSession(final SMTPHandlerConfigurationData conf, final MailAddress rcpt, final boolean relayingAllowed) {
SMTPSession session = new AbstractSMTPSession() {
HashMap state = new HashMap();
@@ -58,10 +69,6 @@
return relayingAllowed;
}
- public SMTPHandlerConfigurationData getConfigurationData() {
- return conf;
- }
-
public Map getState() {
return state;
}
@@ -94,7 +101,7 @@
private SMTPHandlerConfigurationData setupMockedSMTPConfiguration() {
SMTPHandlerConfigurationData conf = new SMTPHandlerConfigurationData() {
- UsersRepository user = new MockUsersRepository();
+
public String getHelloName() {
throw new UnsupportedOperationException("Unimplemented Stub Method");
@@ -117,8 +124,8 @@
}
public UsersRepository getUsersRepository() {
- user.addUser(VALID_USER,"xxx");
- return user;
+
+ return users;
}
public boolean isRelayingAllowed(String remoteIP) {
@@ -136,22 +143,12 @@
public boolean isAuthRequired(String remoteIP) {
throw new UnsupportedOperationException("Unimplemented Stub Method");
}
-
- public boolean isAuthRequired() {
- return false;
- }
-
- public boolean isVerifyIdentity() {
- return false;
- }
-
};
return conf;
}
public void testRejectInvalidUser() throws Exception {
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
@@ -163,7 +160,6 @@
}
public void testNotRejectInvalidUserRelay() throws Exception {
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(INVALID_USER + "@localhost");
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,true);
@@ -175,7 +171,6 @@
}
public void testNotRejectValidUser() throws Exception {
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(VALID_USER + "@localhost");
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
@@ -188,7 +183,6 @@
public void testNotRejectValidUserRecipient() throws Exception {
String recipient = "recip@domain";
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(recipient);
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
@@ -205,7 +199,6 @@
String domain = "domain";
String recipient = "recip@" + domain;
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(recipient);
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
@@ -222,7 +215,6 @@
String domain = "domain";
String recipient = "recip@" + domain;
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
MailAddress mailAddress = new MailAddress(recipient);
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
@@ -237,7 +229,6 @@
public void testInvalidRegex() throws Exception{
boolean exception = false;
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
ContainerUtil.enableLogging(handler,new MockLogger());
@@ -254,7 +245,6 @@
MailAddress mailAddress = new MailAddress(USER1 + "@localhost");
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
ContainerUtil.enableLogging(handler,new MockLogger());
@@ -267,7 +257,6 @@
MailAddress mailAddress = new MailAddress(USER2 + "@localhost");
SMTPSession session = setupMockedSMTPSession(setupMockedSMTPConfiguration(),mailAddress,false);
- ValidRcptHandler handler = new ValidRcptHandler();
ContainerUtil.service(handler, setUpServiceManager());
ContainerUtil.enableLogging(handler,new MockLogger());
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org