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
This commit is contained in:
Mark Rogers
2014-04-30 16:02:29 +00:00
parent 8234cb10de
commit 70aeb2fa4a
2 changed files with 57 additions and 6 deletions

View File

@@ -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<String>()
{
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.
}

View File

@@ -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 <code>userName + "@email.com"</code>
* @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<Void>()
{
@Override
public Void execute() throws Throwable
{
ACTION_EXECUTER.executeImpl(mailAction, null);
return null;
}
});
AuthenticationUtil.clearCurrentSecurityContext();
}
}