diff --git a/src/main/java/org/alfresco/repo/security/person/PersonServiceImpl.java b/src/main/java/org/alfresco/repo/security/person/PersonServiceImpl.java index d3ed61652c..0c4a21bdc4 100644 --- a/src/main/java/org/alfresco/repo/security/person/PersonServiceImpl.java +++ b/src/main/java/org/alfresco/repo/security/person/PersonServiceImpl.java @@ -493,6 +493,15 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per { return null; } + if (EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName())) + { + if (exceptionOrNull) + { + throw new NoSuchPersonException(userName); + } + return null; + } + final NodeRef personNode = getPersonOrNullImpl(userName); if (personNode == null) { diff --git a/src/test/java/org/alfresco/repo/notification/NotificationServiceImplSystemTest.java b/src/test/java/org/alfresco/repo/notification/NotificationServiceImplSystemTest.java index a9be112392..446486ccb5 100644 --- a/src/test/java/org/alfresco/repo/notification/NotificationServiceImplSystemTest.java +++ b/src/test/java/org/alfresco/repo/notification/NotificationServiceImplSystemTest.java @@ -32,7 +32,8 @@ import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.repo.content.MimetypeMap; 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.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.notification.NotificationContext; @@ -195,28 +196,34 @@ public class NotificationServiceImplSystemTest extends BaseAlfrescoTestCase protected boolean useSpacesStore() { return true; - } + } + + public void testSimpleEmailNotificationSystem() + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() + { + NotificationContext context = new NotificationContext(); + + context.setFrom(FROM_EMAIL); + context.addTo(TO_USER1); + context.setSubject(SUBJECT); + context.setBodyTemplate(template.toString()); + + Map templateArgs = new HashMap(1); + templateArgs.put("template", template); + context.setTemplateArgs(templateArgs); + + notificationService.sendNotification(EMailNotificationProvider.NAME, context); + + return null; + } + }); + } + - public void testSimpleEmailNotification() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - NotificationContext context = new NotificationContext(); - - context.setFrom(FROM_EMAIL); - context.addTo(TO_USER1); - context.setSubject(SUBJECT); - context.setBody(BODY); - - notificationService.sendNotification(EMailNotificationProvider.NAME, context); - - return null; - } - }); - } public void testTemplateEmailNotification() { diff --git a/src/test/java/org/alfresco/repo/security/person/PersonTest.java b/src/test/java/org/alfresco/repo/security/person/PersonTest.java index 5f04b9d9a0..e4b5d056f1 100644 --- a/src/test/java/org/alfresco/repo/security/person/PersonTest.java +++ b/src/test/java/org/alfresco/repo/security/person/PersonTest.java @@ -47,6 +47,7 @@ import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; import org.alfresco.repo.policy.BehaviourFilter; 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.transaction.AlfrescoTransactionSupport; import org.alfresco.repo.transaction.AlfrescoTransactionSupport.TxnReadState; @@ -1788,4 +1789,27 @@ public class PersonTest extends TestCase // expect to go here } } + + public void testBuitInSystemUser() + { + + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @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; + } + }); + } }