From 70aeb2fa4a507ae5218ac132c0d6ccb1192e59b7 Mon Sep 17 00:00:00 2001 From: Mark Rogers Date: Wed, 30 Apr 2014 16:02:29 +0000 Subject: [PATCH] Merged HEAD-BUG-FIX (4.3/Cloud) to HEAD (4.3/Cloud) 67750: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (4.3/Cloud) 66138: Merged DEV to V4.2-BUG-FIX (4.2.2) 66134: MNT-10874 : If userA's email address is used as userB's username then the userA cannot be invited to a Share site by a non-admin user Added a JUnit test to simulate the issue. 64109: MNT-10874 : If userA's email address is used as userB's username then the userA cannot be invited to a Share site by a non-admin user Fixed MailActionExecuter to use system user to retrieve user's locale. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@68385 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../action/executer/MailActionExecuter.java | 10 +++- .../AbstractMailActionExecuterTest.java | 53 +++++++++++++++++-- 2 files changed, 57 insertions(+), 6 deletions(-) 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(); + } }