mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-30 18:15:39 +00:00
19546: (RECORD ONLY) Merged V3.2 to PATCHES/V3.2.r 19432: Merged V3.1 to V3.2 19427: Merged V3.0 to V3.1 19423: Merged V2.2 to V3.0 19391: Fix for ALF-2076: AUTO does not work if a document has been added and deleted since the index backup 19419: V2.2 Build Fix 19421: Fix for ALF-2076: AUTO does not work if a document has been added and deleted since the index backup 19463: Merged V3.1 to V3.2 19459: Merged V3.0 to V3.1 19457: Merged V2.2 to V3.0 19449: Addition Fix for ALF-2076: AUTO does not work if a document has been added and deleted since the index backup 19493 Merged V3.1 to V3.2 19471: Build fix after changes for ALF-2076 were merged forward. Index checker correctly understands INDETERMINATE state of indexed transactions 19547: (RECORD ONLY) Incremented version label 19555: (RECORD ONLY) Merged V3.2 to PATCHES/V3.2.r 19552: Merged V3.1 to V3.2 19551: Further fix after changes for ALF-2076 were merged forward. Final fix to check for InIndex.No 19566: (RECORD ONLY) Merged V3.2 to PATCHES/V3.2.r 19539: Merged HEAD to V3.2 19538: ALF-2076: Build fix - fix build speed 19802: (RECORD ONLY) ALF-2382, ALF-2383: Merged V3.2 to PATCHES/V3.2.r 19647: ALF-2231: Merged DEV/BELARUS/V2.2-2009_12_01 to V3.2 17704: ENH-681: alfresco webdav does not respect webdav locks 19624: ALF-2231: Merged DEV/BELARUS/V2.2-2009_12_01 to V3.2 17704: ENH-681: alfresco webdav does not respect webdav locks 19623: ALF-1890: Correction to previous checkin to allow defaulting of request body charset 19617: ALF-1890: Improvements to make ALL WebDAV methods retryable - Solution from PutMethod promoted to request wrapper that will handle ALL calls to getInputStream and getReader 19614: ALF-1890: Merged V2.2 to V3.2 17709: Merged DEV_TEMPORARY to V2.2 17700: ETWOTWO-1393: concurrent writes to webdav lead to data loss (0kb resulting file) 19613: Merged DEV/BELARUS/V2.2-2010_02_03 to V2.2 19157: ALF-1890: concurrent writes to webdav lead to data loss (0kb resulting file) 19803: ALF-558: File servers (CIFS / FTP / NFS) can now handle concurrent write operations on Alfresco repository - ContentDiskDriver / AVMDiskDriver now use retrying transactions for write operations - Disable EagerContentStoreCleaner on ContentDiskDriver / AVMDiskDriver closeFile() operations so that they may be retried after rollback (Sony zero byte problem) - Allow manual association of AVM ContentData with nodes so that closeFile() may be retried - Propagation of new argument through AVM interfaces 19804: (RECORD ONLY) Merged PATCHES/V3.2.0 to PATCHES/V3.2.r Merged HEAD to V3.2.0 19786: Refactor of previous test fix. I have pushed down the OOo-specific parts of the change from AbstractContentTransformerTest to OpenOfficeContentTransformerTest leaving an extension point in the base class should other transformations need to be excluded in the future. 19785: Fix for failing test OpenOfficeContentTransformerTest.testAllConversions. Various OOo-related transformations are returned as available but fail on our test server with OOo on it. Pending further work on these failings, I am disabling those transformations in test code whilst leaving them available in the product code. This is because in the wild a different OOo version may succeed with these transformations. I had previously explicitly disabled 3 transformations in the product and I am moving that restriction from product to test code for the same reason. 19707: Return value from isTransformationBlocked was inverted. Fixed now. 19705: Refinement of previous check-in re OOo transformations. I have pulled up the code that handles blocked transformations into a superclass so that the JodConverter-based transformer worker can inherit the same list of blocked transformations. To reiterate, blocked transformations are those that the OOo integration code believes should work but which are broken in practice. These are blocked by the transformers and will always be unavailable regardless of the OOo connection state. 19702: Fix for HEAD builds running on panda build server. OOo was recently installed on panda which has activated various OOo-related transformations/extractions in the test code. It appears that OOo does not support some transformations from Office 97 to Office 2007. Specifically doc to docx and xls to xlsx. These transformations have now been marked as unavailable. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@20004 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
528 lines
26 KiB
Java
528 lines
26 KiB
Java
/*
|
|
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
|
*
|
|
* This file is part of Alfresco
|
|
*
|
|
* Alfresco is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Alfresco is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.alfresco.repo.avm.locking;
|
|
|
|
import java.io.IOException;
|
|
import java.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
import junit.framework.TestCase;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.model.WCMAppModel;
|
|
import org.alfresco.repo.avm.util.BulkLoader;
|
|
import org.alfresco.repo.content.MimetypeMap;
|
|
import org.alfresco.repo.domain.PropertyValue;
|
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
|
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
|
import org.alfresco.service.cmr.attributes.AttributeService;
|
|
import org.alfresco.service.cmr.avm.AVMService;
|
|
import org.alfresco.service.cmr.avm.locking.AVMLock;
|
|
import org.alfresco.service.cmr.avm.locking.AVMLockingService;
|
|
import org.alfresco.service.cmr.avmsync.AVMDifference;
|
|
import org.alfresco.service.cmr.avmsync.AVMSyncService;
|
|
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
|
|
import org.alfresco.service.cmr.remote.RepoRemote;
|
|
import org.alfresco.service.cmr.repository.ContentWriter;
|
|
import org.alfresco.service.cmr.repository.NodeRef;
|
|
import org.alfresco.service.cmr.repository.NodeService;
|
|
import org.alfresco.service.cmr.security.AuthorityService;
|
|
import org.alfresco.service.cmr.security.AuthorityType;
|
|
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
|
import org.alfresco.service.cmr.security.PersonService;
|
|
import org.alfresco.service.namespace.NamespaceService;
|
|
import org.alfresco.service.namespace.QName;
|
|
import org.alfresco.util.ApplicationContextHelper;
|
|
import org.alfresco.wcm.sandbox.SandboxConstants;
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
/**
|
|
* Tests for WCM (web project) locking - AVMLockingService & AVMLockingAwareService
|
|
*
|
|
* @author britt
|
|
*/
|
|
public class AVMLockingServiceTest extends TestCase
|
|
{
|
|
private static ApplicationContext fContext = null;
|
|
|
|
private static AVMLockingService fLockingService;
|
|
|
|
private static AVMService fService;
|
|
|
|
private static AVMSyncService fSyncService;
|
|
|
|
private static AttributeService fAttributeService;
|
|
|
|
private static PersonService fPersonService;
|
|
|
|
private static AuthorityService fAuthorityService;
|
|
|
|
private static MutableAuthenticationService fAuthenticationService;
|
|
|
|
private static NodeService fNodeService;
|
|
|
|
private static RepoRemote fRepoRemote;
|
|
|
|
private static NodeRef fWebProject;
|
|
|
|
private static String[] testUsers = {"Buffy", "Willow", "Xander", "Tara", "Spike"};
|
|
|
|
private static String[] testAuthorities = {"GROUP_Scoobies", "ROLE_SUPER_POWERED", "GROUP_vampires"};
|
|
|
|
private static final String testWP1 = "alfresco-"+System.currentTimeMillis();
|
|
|
|
/* (non-Javadoc)
|
|
* @see junit.framework.TestCase#setUp()
|
|
*/
|
|
@Override
|
|
protected void setUp() throws Exception
|
|
{
|
|
if (fContext == null)
|
|
{
|
|
fContext = ApplicationContextHelper.getApplicationContext();
|
|
fLockingService = (AVMLockingService)fContext.getBean("AVMLockingService");
|
|
fService = (AVMService) fContext.getBean("AVMLockingAwareService");
|
|
fSyncService = (AVMSyncService)fContext.getBean("AVMSyncService");
|
|
fAttributeService = (AttributeService)fContext.getBean("AttributeService");
|
|
fPersonService = (PersonService)fContext.getBean("PersonService");
|
|
fAuthorityService = (AuthorityService)fContext.getBean("AuthorityService");
|
|
fAuthenticationService = (MutableAuthenticationService)fContext.getBean("AuthenticationService");
|
|
fNodeService = (NodeService)fContext.getBean("NodeService");
|
|
fRepoRemote = (RepoRemote)fContext.getBean("RepoRemoteService");
|
|
}
|
|
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
|
|
|
// Set up a fake web project.
|
|
NodeRef root = fRepoRemote.getRoot();
|
|
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
|
properties.put(WCMAppModel.PROP_AVMSTORE, testWP1);
|
|
fWebProject = fNodeService.createNode(root, ContentModel.ASSOC_CONTAINS,
|
|
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, testWP1),
|
|
WCMAppModel.TYPE_AVMWEBFOLDER, properties).getChildRef();
|
|
|
|
// Set up sample users groups and roles.
|
|
|
|
cleanUsersAndGroups();
|
|
|
|
fAuthenticationService.createAuthentication("Buffy", "Buffy".toCharArray());
|
|
fPersonService.getPerson("Buffy");
|
|
fAuthorityService.createAuthority(AuthorityType.GROUP, "Scoobies");
|
|
fAuthorityService.addAuthority("GROUP_Scoobies", "Buffy");
|
|
fAuthorityService.createAuthority(AuthorityType.ROLE, "SUPER_POWERED");
|
|
fAuthorityService.addAuthority("ROLE_SUPER_POWERED", "Buffy");
|
|
|
|
fAuthenticationService.createAuthentication("Willow", "Willow".toCharArray());
|
|
fPersonService.getPerson("Willow");
|
|
fAuthorityService.addAuthority("GROUP_Scoobies", "Willow");
|
|
|
|
fAuthenticationService.createAuthentication("Xander", "Xander".toCharArray());
|
|
fPersonService.getPerson("Xander");
|
|
fAuthorityService.addAuthority("GROUP_Scoobies", "Xander");
|
|
|
|
fAuthenticationService.createAuthentication("Tara", "Tara".toCharArray());
|
|
fPersonService.getPerson("Tara");
|
|
|
|
fAuthenticationService.createAuthentication("Spike", "Spike".toCharArray());
|
|
fPersonService.getPerson("Spike");
|
|
fAuthorityService.addAuthority("ROLE_SUPER_POWERED", "Spike");
|
|
fAuthorityService.createAuthority(AuthorityType.GROUP, "vampires");
|
|
fAuthorityService.addAuthority("GROUP_vampires", "Spike");
|
|
}
|
|
|
|
/* (non-Javadoc)
|
|
* @see junit.framework.TestCase#tearDown()
|
|
*/
|
|
@Override
|
|
protected void tearDown() throws Exception
|
|
{
|
|
List<String> webProjects = fLockingService.getWebProjects();
|
|
for (String webProject : webProjects)
|
|
{
|
|
if (webProject.equals(testWP1))
|
|
{
|
|
fLockingService.removeStoreLocks(webProject);
|
|
fLockingService.removeWebProject(webProject);
|
|
}
|
|
}
|
|
cleanUsersAndGroups();
|
|
fNodeService.deleteNode(fWebProject);
|
|
}
|
|
|
|
private void cleanUsersAndGroups()
|
|
{
|
|
for (String testUser : testUsers)
|
|
{
|
|
if (fAuthenticationService.authenticationExists(testUser))
|
|
{
|
|
fAuthenticationService.deleteAuthentication(testUser);
|
|
}
|
|
|
|
if (fPersonService.personExists(testUser))
|
|
{
|
|
fPersonService.deletePerson(testUser);
|
|
}
|
|
}
|
|
|
|
for (String testAuthority : testAuthorities)
|
|
{
|
|
if (fAuthorityService.authorityExists(testAuthority))
|
|
{
|
|
fAuthorityService.deleteAuthority(testAuthority);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void testAll()
|
|
{
|
|
try
|
|
{
|
|
fLockingService.addWebProject(testWP1);
|
|
System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
|
|
List<String> owners = new ArrayList<String>();
|
|
owners.add("Buffy");
|
|
owners.add("Spike");
|
|
AVMLock lock = new AVMLock(testWP1,
|
|
"Sunnydale",
|
|
"Revello Drive/1630",
|
|
AVMLockingService.Type.DISCRETIONARY,
|
|
owners);
|
|
fLockingService.lockPath(lock);
|
|
System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
|
|
assertNotNull(fLockingService.getLock(testWP1, "Revello Drive/1630"));
|
|
// assertEquals(1, fLockingService.getUsersLocks("Buffy").size());
|
|
assertEquals(1, fLockingService.getWebProjectLocks(testWP1).size());
|
|
List<String> owners2 = new ArrayList<String>();
|
|
owners2.add("Buffy");
|
|
owners2.add("Willow");
|
|
AVMLock lock2 = new AVMLock(testWP1,
|
|
"Sunnydale",
|
|
"UC Sunnydale/Stevenson Hall",
|
|
AVMLockingService.Type.DISCRETIONARY,
|
|
owners2);
|
|
fLockingService.lockPath(lock2);
|
|
System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
|
|
// assertEquals(2, fLockingService.getUsersLocks("Buffy").size());
|
|
assertEquals(2, fLockingService.getWebProjectLocks(testWP1).size());
|
|
System.out.println("Before----------------------------");
|
|
fLockingService.removeLock(testWP1, "Revello Drive/1630");
|
|
System.out.println("After----------------------------");
|
|
System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
|
|
// assertEquals(1, fLockingService.getUsersLocks("Buffy").size());
|
|
assertEquals(1, fLockingService.getWebProjectLocks(testWP1).size());
|
|
fLockingService.removeWebProject(testWP1);
|
|
System.out.println(fAttributeService.getAttribute(".avm_lock_table"));
|
|
// assertEquals(0, fLockingService.getUsersLocks("Spike").size());
|
|
// assertEquals(0, fLockingService.getUsersLocks("Buffy").size());
|
|
// assertEquals(0, fLockingService.getUsersLocks("Willow").size());
|
|
// assertEquals(0, fLockingService.getUsersLocks("Tara").size());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
public void testRoleBasedLocking()
|
|
{
|
|
try
|
|
{
|
|
fLockingService.addWebProject(testWP1);
|
|
List<String> owners = new ArrayList<String>();
|
|
owners.add("ROLE_SUPER_POWERED");
|
|
owners.add("Tara");
|
|
AVMLock lock = new AVMLock(testWP1,
|
|
"Sunnydale",
|
|
"TheInitiative/Adam/plans.txt",
|
|
AVMLockingService.Type.DISCRETIONARY,
|
|
owners);
|
|
fLockingService.lockPath(lock);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
public void testGroupBasedLocking()
|
|
{
|
|
try
|
|
{
|
|
fLockingService.addWebProject(testWP1);
|
|
List<String> owners = new ArrayList<String>();
|
|
owners.add("GROUP_Scoobies");
|
|
owners.add("Tara");
|
|
AVMLock lock = new AVMLock(testWP1,
|
|
"Sunnydale",
|
|
"TheInitiative/Adam/plans.txt",
|
|
AVMLockingService.Type.DISCRETIONARY,
|
|
owners);
|
|
fLockingService.lockPath(lock);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
public void testLockModification()
|
|
{
|
|
try
|
|
{
|
|
fLockingService.addWebProject(testWP1);
|
|
List<String> owners = new ArrayList<String>();
|
|
owners.add("GROUP_Scoobies");
|
|
owners.add("Tara");
|
|
AVMLock lock = new AVMLock(testWP1,
|
|
"Sunnydale",
|
|
"TheInitiative/Adam/plans.txt",
|
|
AVMLockingService.Type.DISCRETIONARY,
|
|
owners);
|
|
fLockingService.lockPath(lock);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Willow"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/TheInitiative/Adam/plans.txt", "Xander"));
|
|
fLockingService.modifyLock(testWP1, "TheInitiative/Adam/plans.txt", "ScrapHeap/Adam/plans.txt", null, null, null);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander"));
|
|
fLockingService.modifyLock(testWP1, "ScrapHeap/Adam/plans.txt", null, "LA", null, null);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Buffy"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Willow"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "Sunnydale:/ScrapHeap/Adam/plans.txt", "Xander"));
|
|
List<String> usersToAdd = new ArrayList<String>();
|
|
usersToAdd.add("Spike");
|
|
fLockingService.modifyLock(testWP1, "ScrapHeap/Adam/plans.txt", null, null, null, usersToAdd);
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
|
|
List<String> usersToRemove = new ArrayList<String>();
|
|
usersToRemove.add("GROUP_Scoobies");
|
|
fLockingService.modifyLock(testWP1, "ScrapHeap/Adam/plans.txt", null, null, usersToRemove, null);
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Buffy"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Spike"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Willow"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Tara"));
|
|
assertFalse(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", "Xander"));
|
|
assertTrue(fLockingService.hasAccess(testWP1, "LA:/ScrapHeap/Adam/plans.txt", AuthenticationUtil.getAdminUserName()));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
fail();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Minimal testing of Locking Aware service.
|
|
*/
|
|
public void testLockingAwareService() throws Exception
|
|
{
|
|
try
|
|
{
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
|
|
|
fService.createStore("main");
|
|
|
|
fLockingService.addWebProject("main");
|
|
|
|
// note: locking applies to WCM web projects, hence relies on WCM sandbox conventions (naming and properties)
|
|
fService.setStoreProperty("main", SandboxConstants.PROP_WEB_PROJECT_NODE_REF, new PropertyValue(DataTypeDefinition.NODE_REF, new NodeRef("workspace://SpacesStore/dummy")));
|
|
|
|
fService.createStore("main--admin");
|
|
|
|
setupBasicTree0();
|
|
|
|
List<AVMDifference> diffs = fSyncService.compare(-1, "main:/", -1, "main--admin:/", null);
|
|
assertEquals(2, diffs.size());
|
|
assertEquals("[main:/a[-1] > main--admin:/a[-1], main:/d[-1] > main--admin:/d[-1]]", diffs.toString());
|
|
|
|
fSyncService.update(diffs, null, false, false, false, false, null, null);
|
|
|
|
RetryingTransactionHelper.RetryingTransactionCallback<Object> cb = new RetryingTransactionHelper.RetryingTransactionCallback<Object>()
|
|
{
|
|
public Object execute() throws Exception
|
|
{
|
|
BulkLoader loader = new BulkLoader();
|
|
loader.setAvmService(fService);
|
|
loader.recursiveLoad("source/java/org/alfresco/repo/avm", "main--admin:/");
|
|
return null;
|
|
}
|
|
};
|
|
RetryingTransactionHelper helper = (RetryingTransactionHelper) fContext.getBean("retryingTransactionHelper");
|
|
helper.doInTransaction(cb);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
throw e;
|
|
}
|
|
finally
|
|
{
|
|
fLockingService.removeStoreLocks("main");
|
|
fLockingService.removeWebProject("main");
|
|
|
|
fService.purgeStore("main--admin");
|
|
fService.purgeStore("main");
|
|
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
|
}
|
|
}
|
|
|
|
// Minimal test of locking with file 'rename' across web projects
|
|
public void testLockingAwareServiceFileRename() throws Exception
|
|
{
|
|
try
|
|
{
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
|
|
|
|
fService.createStore("wpA");
|
|
fLockingService.addWebProject("wpA");
|
|
|
|
fService.createStore("wpA--admin");
|
|
|
|
fService.createStore("wpB");
|
|
fLockingService.addWebProject("wpB");
|
|
|
|
fService.createStore("wpB--admin");
|
|
|
|
// note: locking applies to WCM web projects, hence relies on WCM sandbox conventions (naming and properties)
|
|
fService.setStoreProperty("wpA", SandboxConstants.PROP_WEB_PROJECT_NODE_REF, new PropertyValue(DataTypeDefinition.NODE_REF, new NodeRef("workspace://SpacesStore/dummyA")));
|
|
fService.setStoreProperty("wpB", SandboxConstants.PROP_WEB_PROJECT_NODE_REF, new PropertyValue(DataTypeDefinition.NODE_REF, new NodeRef("workspace://SpacesStore/dummyB")));
|
|
|
|
assertNull(fLockingService.getLock("wpA", "/file1.txt"));
|
|
assertTrue(fLockingService.hasAccess("wpA", "wpA--admin:/file1.txt", "admin"));
|
|
|
|
fService.createFile("wpA--admin:/", "file1.txt").close();
|
|
|
|
assertNotNull(fLockingService.getLock("wpA", "/file1.txt"));
|
|
assertEquals("admin", fLockingService.getLock("wpA", "/file1.txt").getOwners().get(0));
|
|
assertTrue(fLockingService.hasAccess("wpA", "wpA--admin:/file1.txt", "admin"));
|
|
|
|
assertNull(fLockingService.getLock("wpB", "/file1.txt"));
|
|
assertTrue(fLockingService.hasAccess("wpB", "wpB--admin:/file1.txt", "admin"));
|
|
|
|
// ETHREEOH-1544
|
|
fService.rename("wpA--admin:/", "file1.txt", "wpB--admin:/", "file1.txt");
|
|
|
|
assertNull(fLockingService.getLock("wpA", "/file1.txt"));
|
|
assertTrue(fLockingService.hasAccess("wpA", "wpA--admin:/file1.txt", "admin"));
|
|
|
|
assertNotNull(fLockingService.getLock("wpB", "/file1.txt"));
|
|
assertEquals("admin", fLockingService.getLock("wpB", "/file1.txt").getOwners().get(0));
|
|
assertTrue(fLockingService.hasAccess("wpB", "wpB--admin:/file1.txt", "admin"));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
e.printStackTrace();
|
|
throw e;
|
|
}
|
|
finally
|
|
{
|
|
try { fLockingService.removeStoreLocks("wpA"); } catch (Exception e) {}
|
|
try { fLockingService.removeWebProject("wpA"); } catch (Exception e) {}
|
|
|
|
if (fService.getStore("wpA--admin") != null) { fService.purgeStore("wpA--admin"); }
|
|
if (fService.getStore("wpA") != null) { fService.purgeStore("wpA"); }
|
|
|
|
try { fLockingService.removeStoreLocks("wpB"); } catch (Exception e) {}
|
|
try { fLockingService.removeWebProject("wpB"); } catch (Exception e) {}
|
|
|
|
if (fService.getStore("wpB--admin") != null) { fService.purgeStore("wpB--admin"); }
|
|
if (fService.getStore("wpB") != null) { fService.purgeStore("wpB"); }
|
|
|
|
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Setup a basic tree.
|
|
*/
|
|
protected void setupBasicTree0()
|
|
throws IOException
|
|
{
|
|
fService.createDirectory("main:/", "a");
|
|
fService.createDirectory("main:/a", "b");
|
|
fService.createDirectory("main:/a/b", "c");
|
|
fService.createDirectory("main:/", "d");
|
|
fService.createDirectory("main:/d", "e");
|
|
fService.createDirectory("main:/d/e", "f");
|
|
|
|
fService.createFile("main:/a/b/c", "foo").close();
|
|
ContentWriter writer = fService.getContentWriter("main:/a/b/c/foo", true);
|
|
writer.setEncoding("UTF-8");
|
|
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
|
writer.putContent("I am main:/a/b/c/foo");
|
|
|
|
fService.createFile("main:/a/b/c", "bar").close();
|
|
writer = fService.getContentWriter("main:/a/b/c/bar", true);
|
|
// Force a conversion
|
|
writer.setEncoding("UTF-16");
|
|
writer.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
|
|
writer.putContent("I am main:/a/b/c/bar");
|
|
|
|
fService.createSnapshot("main", null, null);
|
|
}
|
|
}
|