mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-01 14:41:46 +00:00
ACE-5943 / REPO-4132: Rejecting a record in RM doesn't work with 6.1.0-RC4 (#323)
The reject action in RM triggers an email notification from repo. Code in EMailNotificationProvider.buildTemplateModel(...) requests for the person associated with the current authenticated user.
Potentially another bug in Repository.getPerson() (next call in the stack trace), considers the current user to be AuthenticationUtil.getRunAsUser(), instead of the fully authenticated one. This calls, down the line, for the retrieval of the person for the username System, which ends up in trying to actually create the user System (which is not permitted), hence the exception.
The most simple (and safe) fix was to add a check for username System, in the low-level method PersonServiceImpl.getPersonImpl(...), and return null or throw NoSuchPersonException.
2 tests were added, for the Person service and for the email notification generation.
(cherry picked from master commit 3b7849bbdb
)
This commit is contained in:
@@ -493,6 +493,15 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName()))
|
||||||
|
{
|
||||||
|
if (exceptionOrNull)
|
||||||
|
{
|
||||||
|
throw new NoSuchPersonException(userName);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final NodeRef personNode = getPersonOrNullImpl(userName);
|
final NodeRef personNode = getPersonOrNullImpl(userName);
|
||||||
if (personNode == null)
|
if (personNode == null)
|
||||||
{
|
{
|
||||||
|
@@ -33,6 +33,7 @@ import org.alfresco.model.ContentModel;
|
|||||||
import org.alfresco.repo.content.MimetypeMap;
|
import org.alfresco.repo.content.MimetypeMap;
|
||||||
import org.alfresco.repo.model.Repository;
|
import org.alfresco.repo.model.Repository;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||||
import org.alfresco.service.cmr.model.FileFolderService;
|
import org.alfresco.service.cmr.model.FileFolderService;
|
||||||
import org.alfresco.service.cmr.notification.NotificationContext;
|
import org.alfresco.service.cmr.notification.NotificationContext;
|
||||||
@@ -197,19 +198,23 @@ public class NotificationServiceImplSystemTest extends BaseAlfrescoTestCase
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleEmailNotification()
|
public void testSimpleEmailNotificationSystem()
|
||||||
{
|
{
|
||||||
doTestInTransaction(new Test<Void>()
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public Void run()
|
public Void doWork()
|
||||||
{
|
{
|
||||||
NotificationContext context = new NotificationContext();
|
NotificationContext context = new NotificationContext();
|
||||||
|
|
||||||
context.setFrom(FROM_EMAIL);
|
context.setFrom(FROM_EMAIL);
|
||||||
context.addTo(TO_USER1);
|
context.addTo(TO_USER1);
|
||||||
context.setSubject(SUBJECT);
|
context.setSubject(SUBJECT);
|
||||||
context.setBody(BODY);
|
context.setBodyTemplate(template.toString());
|
||||||
|
|
||||||
|
Map<String, Serializable> templateArgs = new HashMap<String, Serializable>(1);
|
||||||
|
templateArgs.put("template", template);
|
||||||
|
context.setTemplateArgs(templateArgs);
|
||||||
|
|
||||||
notificationService.sendNotification(EMailNotificationProvider.NAME, context);
|
notificationService.sendNotification(EMailNotificationProvider.NAME, context);
|
||||||
|
|
||||||
@@ -218,6 +223,8 @@ public class NotificationServiceImplSystemTest extends BaseAlfrescoTestCase
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void testTemplateEmailNotification()
|
public void testTemplateEmailNotification()
|
||||||
{
|
{
|
||||||
doTestInTransaction(new Test<Void>()
|
doTestInTransaction(new Test<Void>()
|
||||||
|
@@ -47,6 +47,7 @@ import org.alfresco.query.PagingRequest;
|
|||||||
import org.alfresco.query.PagingResults;
|
import org.alfresco.query.PagingResults;
|
||||||
import org.alfresco.repo.policy.BehaviourFilter;
|
import org.alfresco.repo.policy.BehaviourFilter;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
|
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||||
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
import org.alfresco.repo.security.authentication.MutableAuthenticationDao;
|
||||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
|
||||||
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState;
|
||||||
@@ -1788,4 +1789,27 @@ public class PersonTest extends TestCase
|
|||||||
// expect to go here
|
// expect to go here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testBuitInSystemUser()
|
||||||
|
{
|
||||||
|
|
||||||
|
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Void doWork()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NodeRef person = personService.getPerson(AuthenticationUtil.SYSTEM_USER_NAME);
|
||||||
|
fail("A NoSuchPersonException should have been thrown for " + AuthenticationUtil.SYSTEM_USER_NAME +
|
||||||
|
" but " + person + " was returned");
|
||||||
|
}
|
||||||
|
catch(NoSuchPersonException ignore)
|
||||||
|
{
|
||||||
|
// This is expected for system.;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user