REPO-4132: User 'System' cleanup follow-up (Revert changes in REPO-3743) (#330)

* Reverted changes for REPO-3743 #276
* Changes in PersonService to ensure a consistent behaviour for the System case:
- PersonService.createPerson() throws now an AlfrescoRuntimeException when trying to create a person for the username 'System'
- PersonService.getPerson("System") throws NoSuchPersonException
- PersonService.personExists("System") returns false
* Remove StandardRenditionLocationResolverTest tests from the suite - the RenditionService deprecated, so related tests won't be maintained
* Fixes for the System user case in ImapService
* Update alfresco-data-model 8.27
This commit is contained in:
Ancuta Morarasu
2019-01-23 20:45:01 +02:00
committed by GitHub
parent e93effbf13
commit 9f739a53d5
36 changed files with 206 additions and 170 deletions

View File

@@ -38,7 +38,7 @@
<dependency.alfresco-legacy-lucene.version>6.2</dependency.alfresco-legacy-lucene.version> <dependency.alfresco-legacy-lucene.version>6.2</dependency.alfresco-legacy-lucene.version>
<dependency.alfresco-core.version>7.9</dependency.alfresco-core.version> <dependency.alfresco-core.version>7.9</dependency.alfresco-core.version>
<dependency.alfresco-greenmail.version>6.1</dependency.alfresco-greenmail.version> <dependency.alfresco-greenmail.version>6.1</dependency.alfresco-greenmail.version>
<dependency.alfresco-data-model.version>8.26</dependency.alfresco-data-model.version> <dependency.alfresco-data-model.version>8.27</dependency.alfresco-data-model.version>
<dependency.alfresco-jlan.version>7.1</dependency.alfresco-jlan.version> <dependency.alfresco-jlan.version>7.1</dependency.alfresco-jlan.version>
<dependency.alfresco-pdf-renderer.version>1.1</dependency.alfresco-pdf-renderer.version> <dependency.alfresco-pdf-renderer.version>1.1</dependency.alfresco-pdf-renderer.version>
<dependency.alfresco-hb-data-sender.version>1.0.9</dependency.alfresco-hb-data-sender.version> <dependency.alfresco-hb-data-sender.version>1.0.9</dependency.alfresco-hb-data-sender.version>

View File

@@ -667,7 +667,7 @@ public class ContentDiskDriver extends AlfrescoTxDiskDriver implements DiskInter
// Use the system user as the authenticated context for the filesystem initialization // Use the system user as the authenticated context for the filesystem initialization
AuthenticationUtil.pushAuthentication(); AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Start the transaction // Start the transaction

View File

@@ -264,7 +264,7 @@ public class SiteLoadPatch extends AbstractPatch
); );
// At this point we can go back to being the system // At this point we can go back to being the system
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Setup the Importer Bootstrap Beans // Setup the Importer Bootstrap Beans
for(ImporterBootstrap bootstrap : new ImporterBootstrap[] { spacesBootstrap, usersBootstrap }) for(ImporterBootstrap bootstrap : new ImporterBootstrap[] { spacesBootstrap, usersBootstrap })

View File

@@ -98,6 +98,7 @@ import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.SearchService; import org.alfresco.service.cmr.search.SearchService;
import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.NoSuchPersonException;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.security.PersonService; import org.alfresco.service.cmr.security.PersonService;
import org.alfresco.service.cmr.site.SiteInfo; import org.alfresco.service.cmr.site.SiteInfo;
@@ -470,7 +471,7 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
for (String mountPointName : imapConfigMountPoints.keySet()) for (String mountPointName : imapConfigMountPoints.keySet())
{ {
result.addAll(listMailboxes(new AlfrescoImapUser(null, AuthenticationUtil result.addAll(listMailboxes(new AlfrescoImapUser(null, AuthenticationUtil
.getAdminUserName(), null), mountPointName + "*", false)); .getSystemUserName(), null), mountPointName + "*", false));
} }
return result; return result;
@@ -1388,12 +1389,22 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
{ {
Set<NodeRef> result = new HashSet<NodeRef>(); Set<NodeRef> result = new HashSet<NodeRef>();
PersonService personService = serviceRegistry.getPersonService(); PersonService personService = serviceRegistry.getPersonService();
NodeRef userRef = personService.getPerson(userName);
NodeRef userRef = null;
if (personService.personExists(userName))
{
userRef = personService.getPerson(userName);
}
if (userRef != null)
{
List<AssociationRef> unsubscribedFodlers = nodeService.getTargetAssocs(userRef, ImapModel.ASSOC_IMAP_UNSUBSCRIBED); List<AssociationRef> unsubscribedFodlers = nodeService.getTargetAssocs(userRef, ImapModel.ASSOC_IMAP_UNSUBSCRIBED);
for (AssociationRef asocRef : unsubscribedFodlers) for (AssociationRef asocRef : unsubscribedFodlers)
{ {
result.add(asocRef.getTargetRef()); result.add(asocRef.getTargetRef());
} }
}
return result; return result;
} }
@@ -1412,6 +1423,8 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
*/ */
private List<NodeRef> getFavouriteSites(final String userName) private List<NodeRef> getFavouriteSites(final String userName)
{ {
PersonService personService = serviceRegistry.getPersonService();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("[getFavouriteSites] entry for user: " + userName); logger.debug("[getFavouriteSites] entry for user: " + userName);
@@ -1432,10 +1445,10 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
{ {
favSites = new LinkedList<NodeRef>(); favSites = new LinkedList<NodeRef>();
PreferenceService preferenceService = (PreferenceService) serviceRegistry if (personService.personExists(userName))
.getService(ServiceRegistry.PREFERENCE_SERVICE); {
Map<String, Serializable> prefs = preferenceService.getPreferences( PreferenceService preferenceService = (PreferenceService) serviceRegistry.getService(ServiceRegistry.PREFERENCE_SERVICE);
userName, AlfrescoImapConst.PREF_IMAP_FAVOURITE_SITES); Map<String, Serializable> prefs = preferenceService.getPreferences(userName, AlfrescoImapConst.PREF_IMAP_FAVOURITE_SITES);
for (String key : prefs.keySet()) for (String key : prefs.keySet())
{ {
@@ -1474,6 +1487,7 @@ public class ImapServiceImpl implements ImapService, OnRestoreNodePolicy, OnCrea
} }
AlfrescoTransactionSupport.bindResource(FAVORITE_SITES, favSites); AlfrescoTransactionSupport.bindResource(FAVORITE_SITES, favSites);
} }
}
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug("[getFavouriteSites] end for user: " + userName); logger.debug("[getFavouriteSites] end for user: " + userName);

View File

@@ -94,7 +94,7 @@ public class HashPasswordTransactionListener implements TransactionListener
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
AuthenticationUtil.pushAuthentication(); AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
try try
{ {
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())

View File

@@ -493,8 +493,9 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
{ {
return null; return null;
} }
if (EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName())) if (isSystemUserName(userName))
{ {
// The built-in authority SYSTEM is a user, but not a Person (i.e. it does not have a profile).
if (exceptionOrNull) if (exceptionOrNull)
{ {
throw new NoSuchPersonException(userName); throw new NoSuchPersonException(userName);
@@ -532,9 +533,9 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
*/ */
public boolean personExists(String caseSensitiveUserName) public boolean personExists(String caseSensitiveUserName)
{ {
if (isBuiltInAuthorities(caseSensitiveUserName)) if (isSystemUserName(caseSensitiveUserName))
{ {
return true; return false;
} }
NodeRef person = getPersonOrNullImpl(caseSensitiveUserName); NodeRef person = getPersonOrNullImpl(caseSensitiveUserName);
@@ -546,20 +547,6 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
return false; return false;
} }
private boolean isBuiltInAuthorities(String caseSensitiveUserName)
{
if (EqualsHelper.nullSafeEquals(caseSensitiveUserName, AuthenticationUtil.getSystemUserName()))
{
return true;
}
else if (EqualsHelper.nullSafeEquals(caseSensitiveUserName, AuthenticationUtil.getGuestUserName()))
{
return true;
}
return false;
}
private NodeRef getPersonOrNullImpl(String searchUserName) private NodeRef getPersonOrNullImpl(String searchUserName)
{ {
Set<NodeRef> allRefs = getFromCache(searchUserName); Set<NodeRef> allRefs = getFromCache(searchUserName);
@@ -993,6 +980,11 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
throw new IllegalArgumentException("No username specified when creating the person."); throw new IllegalArgumentException("No username specified when creating the person.");
} }
if (EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName()))
{
throw new AlfrescoRuntimeException("The built-in authority '" + AuthenticationUtil.getSystemUserName() + "' is a user, but not a Person (i.e. it does not have a profile).");
}
AuthorityType authorityType = AuthorityType.getAuthorityType(userName); AuthorityType authorityType = AuthorityType.getAuthorityType(userName);
if (authorityType != AuthorityType.USER) if (authorityType != AuthorityType.USER)
{ {
@@ -2195,5 +2187,9 @@ public class PersonServiceImpl extends TransactionListenerAdapter implements Per
this.eventPublisher = eventPublisher; this.eventPublisher = eventPublisher;
} }
private boolean isSystemUserName(String userName)
{
return EqualsHelper.nullSafeEquals(userName, AuthenticationUtil.getSystemUserName(), true);
}
} }

View File

@@ -117,7 +117,7 @@ public class PersonServiceLoader
// check the lazy creation // check the lazy creation
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
final AuthenticationService authenticationService = serviceRegistry.getAuthenticationService(); final AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();

View File

@@ -56,7 +56,6 @@ import org.junit.runners.Suite;
// This test opens, closes and again opens the alfresco application context. // This test opens, closes and again opens the alfresco application context.
org.alfresco.repo.dictionary.CustomModelRepoRestartTest.class, org.alfresco.repo.dictionary.CustomModelRepoRestartTest.class,
org.alfresco.repo.rendition.StandardRenditionLocationResolverTest.class,
org.alfresco.repo.rendition.executer.HTMLRenderingEngineTest.class, org.alfresco.repo.rendition.executer.HTMLRenderingEngineTest.class,
org.alfresco.repo.rendition.executer.XSLTFunctionsTest.class, org.alfresco.repo.rendition.executer.XSLTFunctionsTest.class,
org.alfresco.repo.rendition.executer.XSLTRenderingEngineTest.class, org.alfresco.repo.rendition.executer.XSLTRenderingEngineTest.class,

View File

@@ -811,8 +811,11 @@ public class ActionServiceImplTest extends BaseAlfrescoSpringTest
@Test @Test
public void testActionResult() public void testActionResult()
{ {
// We need to run this test as Administrator. The ScriptAction has to run as a full user (instead of as System)
// so that we can setup the Person object in the ScriptNode
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try
{
// Create the script node reference // Create the script node reference
NodeRef script = this.nodeService.createNode( NodeRef script = this.nodeService.createNode(
this.folder, this.folder,
@@ -837,6 +840,11 @@ public class ActionServiceImplTest extends BaseAlfrescoSpringTest
assertNotNull(result); assertNotNull(result);
assertEquals("VALUE", result); assertEquals("VALUE", result);
} }
finally
{
AuthenticationUtil.clearCurrentSecurityContext();
}
}
/** =================================================================================== /** ===================================================================================
* Test asynchronous actions * Test asynchronous actions

View File

@@ -104,9 +104,9 @@ public class SpecialiseTypeActionExecuterTest extends BaseAlfrescoSpringTest
checkActionAgainAndExpectTypeToChange(action, nodeRef1); checkActionAgainAndExpectTypeToChange(action, nodeRef1);
} }
// check with "Admin user" // check with "System user"
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Check the type of the node // Check the type of the node
ActionImpl action = checkActionToChangeNodeType(nodeRef2); ActionImpl action = checkActionToChangeNodeType(nodeRef2);

View File

@@ -622,7 +622,7 @@ public abstract class AbstractFeedCleanerTest
if (type == 2) if (type == 2)
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
int deleteCount = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Integer>() int deleteCount = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Integer>()
{ {

View File

@@ -99,7 +99,7 @@ public class AuditMethodInterceptorTest extends TestCase
nodeService = serviceRegistry.getNodeService(); nodeService = serviceRegistry.getNodeService();
searchService = serviceRegistry.getSearchService(); searchService = serviceRegistry.getSearchService();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE); nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// Register the models // Register the models

View File

@@ -281,7 +281,7 @@ public class AuditableAspectTest extends TestCase
String modifiedBy = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER); String modifiedBy = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIER);
assertEquals( assertEquals(
"The modifier should have changed to reflect the current user", "The modifier should have changed to reflect the current user",
AuthenticationUtil.getFullyAuthenticatedUser(), modifiedBy); AuthenticationUtil.getRunAsUser(), modifiedBy);
RetryingTransactionCallback<Void> setAuditableCallback1 = new RetryingTransactionCallback<Void>() RetryingTransactionCallback<Void> setAuditableCallback1 = new RetryingTransactionCallback<Void>()
{ {

View File

@@ -77,7 +77,7 @@ public class GuessMimetypeTest extends TestCase
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
// As system user // As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE; storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
@@ -97,7 +97,7 @@ public class GuessMimetypeTest extends TestCase
@Override @Override
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13);
properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt"); properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt");
@@ -121,7 +121,7 @@ public class GuessMimetypeTest extends TestCase
@Override @Override
public Object execute() throws Throwable public Object execute() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13); Map<QName, Serializable> properties = new HashMap<QName, Serializable>(13);
properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt"); properties.put(ContentModel.PROP_NAME, (Serializable) "test.txt");

View File

@@ -219,7 +219,7 @@ public class ArchiveContentTransformerTest extends AbstractContentTransformerTes
return; return;
} }
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
ContentTransformer transformer = serviceRegistry.getContentService().getTransformer(sourceMimetype, targetMimetype); ContentTransformer transformer = serviceRegistry.getContentService().getTransformer(sourceMimetype, targetMimetype);
assertNotNull(transformer); assertNotNull(transformer);

View File

@@ -135,7 +135,7 @@ public class EMLTransformerTest extends AbstractContentTransformerTest
return; return;
} }
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
ContentTransformer transformer = serviceRegistry.getContentService().getTransformer(sourceMimetype, targetMimetype); ContentTransformer transformer = serviceRegistry.getContentService().getTransformer(sourceMimetype, targetMimetype);
assertNotNull(transformer); assertNotNull(transformer);

View File

@@ -457,8 +457,8 @@ public class DictionaryModelTypeTest extends BaseSpringTest
@Test @Test
public void testCreateAndUpdateDictionaryModelNodeContent() throws Exception public void testCreateAndUpdateDictionaryModelNodeContent() throws Exception
{ {
// just to make sure we don't regress ACE-5852, some tests should run as Admin // just to make sure we don't regress ACE-5852, some tests should run as System
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
try try
{ {
// Check that the model has not yet been loaded into the dictionary // Check that the model has not yet been loaded into the dictionary
@@ -609,8 +609,8 @@ public class DictionaryModelTypeTest extends BaseSpringTest
@Test @Test
public void testUpdateDictionaryModelPropertyDelete() throws Exception public void testUpdateDictionaryModelPropertyDelete() throws Exception
{ {
// just to make sure we don't regress ACE-5852, some tests should run as Admin // just to make sure we don't regress ACE-5852, some tests should run as System
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
try try
{ {
// Check that the model has not yet been loaded into the dictionary // Check that the model has not yet been loaded into the dictionary
@@ -1105,7 +1105,7 @@ public class DictionaryModelTypeTest extends BaseSpringTest
public void testImportingSameNamespaceFails() throws Exception public void testImportingSameNamespaceFails() throws Exception
{ {
// just to make sure we don't regress ACE-5852, some tests should run as System // just to make sure we don't regress ACE-5852, some tests should run as System
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Create model // Create model
final NodeRef modelNode = createActiveModel("dictionary/testModel.xml"); final NodeRef modelNode = createActiveModel("dictionary/testModel.xml");

View File

@@ -86,7 +86,7 @@ public class FixedAclUpdaterTest extends TestCase
permissionService = (PermissionService) ctx.getBean("permissionService"); permissionService = (PermissionService) ctx.getBean("permissionService");
nodeDAO = (NodeDAO) ctx.getBean("nodeDAO"); nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
NodeRef home = repository.getCompanyHome(); NodeRef home = repository.getCompanyHome();
// create a folder hierarchy for which will change permission inheritance // create a folder hierarchy for which will change permission inheritance
@@ -319,7 +319,7 @@ public class FixedAclUpdaterTest extends TestCase
final FixedAclUpdater fixedAclUpdater = (FixedAclUpdater) ctx.getBean("fixedAclUpdater"); final FixedAclUpdater fixedAclUpdater = (FixedAclUpdater) ctx.getBean("fixedAclUpdater");
final PermissionsDaoComponent permissionsDaoComponent = (PermissionsDaoComponent) ctx.getBean("admPermissionsDaoComponent"); final PermissionsDaoComponent permissionsDaoComponent = (PermissionsDaoComponent) ctx.getBean("admPermissionsDaoComponent");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
NodeRef home = repository.getCompanyHome(); NodeRef home = repository.getCompanyHome();
final NodeRef root = createFile(fileFolderService, home, "ROOT", ContentModel.TYPE_FOLDER); final NodeRef root = createFile(fileFolderService, home, "ROOT", ContentModel.TYPE_FOLDER);

View File

@@ -154,7 +154,7 @@ public class MessageServiceImplTest extends TestCase implements MessageDeployer
private void setupRepo() throws Exception private void setupRepo() throws Exception
{ {
AuthenticationUtil.clearCurrentSecurityContext(); AuthenticationUtil.clearCurrentSecurityContext();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Create a test workspace // Create a test workspace
this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); this.testStoreRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());

View File

@@ -137,6 +137,7 @@ public class ImapServiceImplTest extends TestCase
private NodeRef testImapFolderNodeRef; private NodeRef testImapFolderNodeRef;
private Flags flags; private Flags flags;
private ImapServiceImpl imapServiceImpl;
String anotherUserName; String anotherUserName;
@@ -192,7 +193,7 @@ public class ImapServiceImplTest extends TestCase
ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap"); ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
ApplicationContext imapCtx = imap.getApplicationContext(); ApplicationContext imapCtx = imap.getApplicationContext();
ImapServiceImpl imapServiceImpl = (ImapServiceImpl)imapCtx.getBean("imapService"); imapServiceImpl = (ImapServiceImpl)imapCtx.getBean("imapService");
// Creating IMAP test folder for IMAP root // Creating IMAP test folder for IMAP root
LinkedList<String> folders = new LinkedList<String>(); LinkedList<String> folders = new LinkedList<String>();
@@ -1006,6 +1007,12 @@ public class ImapServiceImplTest extends TestCase
assertTrue("New node should have original node aspects", nodeService.hasAspect(copiedNode.getNodeRef(), ContentModel.ASPECT_TAGGABLE)); assertTrue("New node should have original node aspects", nodeService.hasAspect(copiedNode.getNodeRef(), ContentModel.ASPECT_TAGGABLE));
} }
public void testListMailboxOnStartup()
{
authenticationService.clearCurrentSecurityContext();
// Starting IMAP
imapServiceImpl.startupInTxn(true);
}
/** /**
* @param mailbox - {@link AlfrescoImapFolder} instance which should be checked * @param mailbox - {@link AlfrescoImapFolder} instance which should be checked

View File

@@ -84,7 +84,7 @@ public class ImporterComponentTest extends BaseSpringTest
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); this.authenticationComponent.setSystemUserAsCurrentUser();
this.versionService = (VersionService)this.applicationContext.getBean("VersionService"); this.versionService = (VersionService)this.applicationContext.getBean("VersionService");
@@ -162,7 +162,7 @@ public class ImporterComponentTest extends BaseSpringTest
// Check that the cm:auditable properties are correct // Check that the cm:auditable properties are correct
assertEquals("cm:created not preserved during import", ISO8601DateFormat.format(ISO8601DateFormat.parse("2009-04-30T23:00:00.000Z")), createdDate); assertEquals("cm:created not preserved during import", ISO8601DateFormat.format(ISO8601DateFormat.parse("2009-04-30T23:00:00.000Z")), createdDate);
assertEquals("cm:creator not preserved during import", "Import Creator", creator); assertEquals("cm:creator not preserved during import", "Import Creator", creator);
assertEquals("cm:modifier not preserved during import", AuthenticationUtil.getFullyAuthenticatedUser(), modifier); assertEquals("cm:modifier not preserved during import", AuthenticationUtil.getSystemUserName(), modifier);
} }
@Test @Test

View File

@@ -200,7 +200,7 @@ public class ScriptNodeTest
@Before public void createTestContent() @Before public void createTestContent()
{ {
excludedOnUpdateProps = VERSIONABLE_ASPECT.getExcludedOnUpdateProps(); excludedOnUpdateProps = VERSIONABLE_ASPECT.getExcludedOnUpdateProps();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Create the store and get the root node // Create the store and get the root node
storeRef = NODE_SERVICE.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); storeRef = NODE_SERVICE.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
rootNodeRef = NODE_SERVICE.getRootNode(storeRef); rootNodeRef = NODE_SERVICE.getRootNode(storeRef);

View File

@@ -624,7 +624,7 @@ public class FileFolderPerformanceTester extends TestCase
NodeRef folderNodeRef = null; NodeRef folderNodeRef = null;
try try
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
if (selectedFolderNodeRef == null) if (selectedFolderNodeRef == null)
{ {
// find the guest folder // find the guest folder

View File

@@ -86,7 +86,7 @@ public class DbNodeServiceImplPropagationTest extends BaseSpringTest
authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent"); authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); authenticationComponent.setSystemUserAsCurrentUser();
DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO"); DictionaryDAO dictionaryDao = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
// load the system model // load the system model

View File

@@ -126,7 +126,7 @@ public class NotificationServiceImplSystemTest extends BaseAlfrescoTestCase
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
// As system user // As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Create people and users // Create people and users
fromPerson = createPerson(FROM_USER, PASSWORD, FROM_FIRST_NAME, FROM_LAST_NAME, FROM_EMAIL); fromPerson = createPerson(FROM_USER, PASSWORD, FROM_FIRST_NAME, FROM_LAST_NAME, FROM_EMAIL);
@@ -157,7 +157,7 @@ public class NotificationServiceImplSystemTest extends BaseAlfrescoTestCase
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
// As system user // As system user
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
// Delete the template // Delete the template
nodeService.deleteNode(template); nodeService.deleteNode(template);

View File

@@ -32,6 +32,7 @@ import java.util.List;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.model.Repository; import org.alfresco.repo.model.Repository;
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl; import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.rendition.RenditionDefinition; import org.alfresco.service.cmr.rendition.RenditionDefinition;
@@ -121,6 +122,10 @@ public class XSLTRenderingEngineTest extends BaseAlfrescoSpringTest
@Test @Test
public void testSimplestTemplateWithTargetPath() throws Exception public void testSimplestTemplateWithTargetPath() throws Exception
{ {
// We need to run this test as Administrator. The ScriptAction has to run as a full user (instead of as System)
// so that we can setup the Person object in the ScriptNode
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try try
{ {
FileInfo file = createXmlFile(companyHome); FileInfo file = createXmlFile(companyHome);
@@ -147,6 +152,11 @@ public class XSLTRenderingEngineTest extends BaseAlfrescoSpringTest
log.error("Error!", ex); log.error("Error!", ex);
fail(); fail();
} }
finally
{
AuthenticationUtil.clearCurrentSecurityContext();
}
} }

View File

@@ -194,7 +194,7 @@ public class AuthenticationTest extends TestCase
@Override @Override
public Void execute() throws Throwable public Void execute() throws Throwable
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
try try
{ {
deleteAndy(); deleteAndy();
@@ -224,7 +224,7 @@ public class AuthenticationTest extends TestCase
personAndyNodeRef = nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef(); personAndyNodeRef = nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();
assertNotNull(personAndyNodeRef); assertNotNull(personAndyNodeRef);
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
authenticationComponent.clearCurrentSecurityContext(); authenticationComponent.clearCurrentSecurityContext();
} }

View File

@@ -78,7 +78,7 @@ public class ResetPasswordServiceImplTest
public static final ApplicationContextInit APP_CONTEXT_INIT = new ApplicationContextInit(); public static final ApplicationContextInit APP_CONTEXT_INIT = new ApplicationContextInit();
@Rule @Rule
public final RunAsFullyAuthenticatedRule runAsRule = new RunAsFullyAuthenticatedRule(AuthenticationUtil.getAdminUserName()); public final RunAsFullyAuthenticatedRule runAsRule = new RunAsFullyAuthenticatedRule(AuthenticationUtil.getSystemUserName());
private static final String DEFAULT_SENDER = "noreply@test-alfresco.test"; private static final String DEFAULT_SENDER = "noreply@test-alfresco.test";
@@ -161,7 +161,7 @@ public class ResetPasswordServiceImplTest
// Make sure to run as system // Make sure to run as system
AuthenticationUtil.clearCurrentSecurityContext(); AuthenticationUtil.clearCurrentSecurityContext();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setRunAsUserSystem();
// Request password reset // Request password reset
resetPasswordService.requestReset(testPerson.userName, "share"); resetPasswordService.requestReset(testPerson.userName, "share");

View File

@@ -107,7 +107,7 @@ public class UpgradePasswordHashTest extends TestCase
upgradePasswordHashWorker = (UpgradePasswordHashWorker)ctx.getBean("upgradePasswordHashWorker"); upgradePasswordHashWorker = (UpgradePasswordHashWorker)ctx.getBean("upgradePasswordHashWorker");
nodeService = serviceRegistry.getNodeService(); nodeService = serviceRegistry.getNodeService();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
} }
protected void createTestUsers(String encoding) throws Exception protected void createTestUsers(String encoding) throws Exception

View File

@@ -91,7 +91,7 @@ public class SubscriptionServiceImplTest extends TestCase
searchService = (SearchService) ctx.getBean("SearchService"); searchService = (SearchService) ctx.getBean("SearchService");
repositoryHelper = (Repository) ctx.getBean("repositoryHelper"); repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
txn = transactionService.getNonPropagatingUserTransaction(false); txn = transactionService.getNonPropagatingUserTransaction(false);
txn.begin(); txn.begin();

View File

@@ -887,7 +887,7 @@ public class MultiTDemoTest extends TestCase
} }
finally finally
{ {
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
deleteTenant(tenantDomain1); deleteTenant(tenantDomain1);
deleteTenant(tenantDomain2); deleteTenant(tenantDomain2);

View File

@@ -41,6 +41,7 @@ import org.apache.commons.lang.mutable.MutableInt;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;

View File

@@ -69,7 +69,7 @@ public class StartWorkflowActionExecuterTest extends BaseSpringTest
this.personService = (PersonService)this.applicationContext.getBean("personService"); this.personService = (PersonService)this.applicationContext.getBean("personService");
AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent"); AuthenticationComponent authenticationComponent = (AuthenticationComponent)applicationContext.getBean("authenticationComponent");
authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
// Create the store and get the root node // Create the store and get the root node
rootNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore")); rootNodeRef = nodeService.getRootNode(new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore"));

View File

@@ -264,6 +264,8 @@ public class ActivitiTimerExecutionTest extends BaseSpringTest
PersonService personService = registry.getPersonService(); PersonService personService = registry.getPersonService();
this.personManager = new TestPersonManager(authenticationService, personService, nodeService); this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
authenticationComponent.setSystemUserAsCurrentUser();
} }
private void waitForTimersToBeExecuted(String workflowInstanceId) throws Exception private void waitForTimersToBeExecuted(String workflowInstanceId) throws Exception

View File

@@ -178,7 +178,7 @@ public class ActivitiWorkflowServiceIntegrationTest extends AbstractWorkflowServ
@Test @Test
public void testReviewAndPooledNotModifiedDate() public void testReviewAndPooledNotModifiedDate()
{ {
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); authenticationComponent.setSystemUserAsCurrentUser();
Map<QName, Serializable> props = new HashMap<QName, Serializable>(); Map<QName, Serializable> props = new HashMap<QName, Serializable>();
props.put(ContentModel.PROP_NAME, "MNT-11522-testfile.txt"); props.put(ContentModel.PROP_NAME, "MNT-11522-testfile.txt");

View File

@@ -31,7 +31,6 @@ import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.cmr.action.ActionService; import org.alfresco.service.cmr.action.ActionService;
import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
@@ -94,7 +93,7 @@ public abstract class BaseAlfrescoSpringTest extends BaseSpringTest
// Authenticate as the system user // Authenticate as the system user
authenticationComponent = (AuthenticationComponent) this.applicationContext authenticationComponent = (AuthenticationComponent) this.applicationContext
.getBean("authenticationComponent"); .getBean("authenticationComponent");
this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName()); authenticationComponent.setSystemUserAsCurrentUser();
// Create the store and get the root node // Create the store and get the root node
this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());