diff --git a/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java b/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java index afdb4c092f..46ccdee71d 100644 --- a/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java +++ b/source/java/org/alfresco/repo/action/executer/MailActionExecuter.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2013 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * This file is part of Alfresco * @@ -1336,7 +1336,13 @@ public class MailActionExecuter extends ActionExecuterAbstractBase // If the domain is null, then the beahviour here varies depending on whether it's a single tenant or multi-tenant cloud. if (personExists(user)) { - localeString = (String) preferenceService.getPreference(user, "locale"); + localeString = AuthenticationUtil.runAsSystem(new RunAsWork() + { + public String doWork() throws Exception + { + return (String) preferenceService.getPreference(user, "locale"); + }; + }); } // else leave it as null - there's no tenant, no user for that username, so we can't get a preferred locale. } diff --git a/source/test-java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java b/source/test-java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java index e2a4018a8b..230400f712 100644 --- a/source/test-java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java +++ b/source/test-java/org/alfresco/repo/action/executer/AbstractMailActionExecuterTest.java @@ -33,6 +33,7 @@ import javax.mail.internet.MimeMessage; import org.alfresco.model.ContentModel; import org.alfresco.repo.management.subsystems.ApplicationContextFactory; import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.tenant.TenantService; import org.alfresco.repo.tenant.TenantUtil; import org.alfresco.repo.tenant.TenantUtil.TenantRunAsWork; @@ -336,8 +337,8 @@ public abstract class AbstractMailActionExecuterTest { final String USER1 = "test_user1"; final String USER2 = "test_user2"; - createUser(USER1); - NodeRef userNode = createUser(USER2); + createUser(USER1, null); + NodeRef userNode = createUser(USER2, null); groupName = AUTHORITY_SERVICE.createAuthority(AuthorityType.GROUP, "testgroup1"); AUTHORITY_SERVICE.addAuthority(groupName, USER1); AUTHORITY_SERVICE.addAuthority(groupName, USER2); @@ -373,15 +374,59 @@ public abstract class AbstractMailActionExecuterTest } } - private NodeRef createUser(String userName) + /** + * Creates a test user with the specified username and optionally custom email. + * + * @param userName + * @param email Optional, if not specified assigned to userName + "@email.com" + * @return + */ + private NodeRef createUser(String userName, String email) { PropertyMap personProps = new PropertyMap(); personProps.put(ContentModel.PROP_USERNAME, userName); personProps.put(ContentModel.PROP_FIRSTNAME, userName); personProps.put(ContentModel.PROP_LASTNAME, userName); - personProps.put(ContentModel.PROP_EMAIL, userName + "@email.com"); + if (email != null) + { + personProps.put(ContentModel.PROP_EMAIL, email); + } + else + { + personProps.put(ContentModel.PROP_EMAIL, userName + "@email.com"); + } return PERSON_SERVICE.createPerson(personProps); } + /** + * Test for MNT-10874 + * @throws Exception + */ + @Test + public void testUserWithNonExistingTenant() throws Exception + { + final String USER_WITH_NON_EXISTING_TENANT = "test_user_non_tenant@non_existing_tenant.com"; + + createUser(USER_WITH_NON_EXISTING_TENANT, USER_WITH_NON_EXISTING_TENANT); + + final Action mailAction = ACTION_SERVICE.createAction(MailActionExecuter.NAME); + mailAction.setParameterValue(MailActionExecuter.PARAM_TO, USER_WITH_NON_EXISTING_TENANT); + mailAction.setParameterValue(MailActionExecuter.PARAM_SUBJECT, "Testing"); + mailAction.setParameterValue(MailActionExecuter.PARAM_TEXT, "This is a test message."); + + // run as non admin and non system + AuthenticationUtil.setFullyAuthenticatedUser(BRITISH_USER.getUsername()); + TRANSACTION_SERVICE.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback() + { + @Override + public Void execute() throws Throwable + { + ACTION_EXECUTER.executeImpl(mailAction, null); + return null; + } + }); + + AuthenticationUtil.clearCurrentSecurityContext(); + } }