diff --git a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP-context.xml b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP-context.xml
index ae8d6ee2c0..fff5561f95 100755
--- a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP-context.xml
+++ b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP-context.xml
@@ -42,9 +42,15 @@
${email.server.requireTLS}
+
+ ${email.server.auth.enabled}
+
+
+
+
diff --git a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties
index 4e89ec540f..6ef05e33d3 100755
--- a/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties
+++ b/config/alfresco/subsystems/email/InboundSMTP/inboundSMTP.properties
@@ -24,5 +24,8 @@ email.server.enableTLS=true
# Set this to true to require TLS
email.server.requireTLS=false
+# Is the user required to authenticate to use the smtp server?
+email.server.auth.enabled=false
+
# Should duplicate messages to a folder overwrite each other or be named with a (number)
email.handler.folder.overwriteDuplicates=true
\ No newline at end of file
diff --git a/source/java/org/alfresco/email/server/EmailServer.java b/source/java/org/alfresco/email/server/EmailServer.java
index 3839199c43..de8abcc95c 100644
--- a/source/java/org/alfresco/email/server/EmailServer.java
+++ b/source/java/org/alfresco/email/server/EmailServer.java
@@ -24,6 +24,8 @@ import java.util.Set;
import java.util.StringTokenizer;
import org.alfresco.error.AlfrescoRuntimeException;
+import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.security.authentication.AuthenticationException;
import org.alfresco.service.cmr.email.EmailMessageException;
import org.alfresco.service.cmr.email.EmailService;
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
@@ -50,9 +52,10 @@ public abstract class EmailServer extends AbstractLifecycleBean
private boolean hideTLS = false;
private boolean enableTLS = true;
private boolean requireTLS = false;
+ private boolean authenticate = false;
private EmailService emailService;
-
+ private AuthenticationComponent authenticationComponent;
/**
* @param serverConfiguration Server configuration
@@ -328,6 +331,19 @@ public abstract class EmailServer extends AbstractLifecycleBean
System.err.println("Use: EmailServer configLocation1, configLocation2, ...");
System.err.println("\t configLocation - spring xml configs with EmailServer related beans (emailServer, emailServerConfiguration, emailService)");
}
+
+ protected boolean authenticateUserNamePassword(String userName, char[] password)
+ {
+ try
+ {
+ getAuthenticationComponent().authenticate(userName, password);
+ return true;
+ }
+ catch (AuthenticationException e)
+ {
+ return false;
+ }
+ }
/** Hide the TLS (Trusted Login Session) option
*
@@ -363,4 +379,24 @@ public abstract class EmailServer extends AbstractLifecycleBean
return requireTLS;
}
+ public void setAuthenticate(boolean enableAuthentication)
+ {
+ this.authenticate = enableAuthentication;
+ }
+
+ public boolean isAuthenticate()
+ {
+ return authenticate;
+ }
+
+ public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
+ {
+ this.authenticationComponent = authenticationComponent;
+ }
+
+ public AuthenticationComponent getAuthenticationComponent()
+ {
+ return authenticationComponent;
+ }
+
}
diff --git a/source/java/org/alfresco/email/server/EmailServiceImpl.java b/source/java/org/alfresco/email/server/EmailServiceImpl.java
index 6da5917147..f7059b2ce8 100644
--- a/source/java/org/alfresco/email/server/EmailServiceImpl.java
+++ b/source/java/org/alfresco/email/server/EmailServiceImpl.java
@@ -187,7 +187,7 @@ public class EmailServiceImpl implements EmailService
// Get the username for the process using the system account
final RetryingTransactionCallback getUsernameCallback = new RetryingTransactionCallback()
{
-
+
public String execute() throws Throwable
{
String userName = null;
@@ -229,8 +229,6 @@ public class EmailServiceImpl implements EmailService
}
return userName;
-
-
}
};
RunAsWork getUsernameRunAsWork = new RunAsWork()
@@ -240,7 +238,20 @@ public class EmailServiceImpl implements EmailService
return retryingTransactionHelper.doInTransaction(getUsernameCallback, false);
}
};
- String username = AuthenticationUtil.runAs(getUsernameRunAsWork, AuthenticationUtil.SYSTEM_USER_NAME);
+
+
+ String username;
+ if(delivery.getAuth() != null)
+ {
+ // The user has authenticated.
+ username = delivery.getAuth();
+ logger.debug("user has already authenticated as:" + username);
+ }
+ else
+ {
+ // Need to faff with old message stuff.
+ username = AuthenticationUtil.runAs(getUsernameRunAsWork, AuthenticationUtil.SYSTEM_USER_NAME);
+ }
// Process the message using the username's account
final RetryingTransactionCallback