Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)

87733: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud)
      87683: Merged V4.1-BUG-FIX (4.1.10) to V4.2-BUG-FIX (4.2.4)
         87387: MNT-12504: Unable to Download as Zip if there is an association between nodes
            - try\catch block was added in ExporterComponent.isWithinExport() method. Appropriate unit test was added.
         87633: MNT-12504: Unable to Download as Zip if there is an association between nodes
            - Corrections for unit test that creates test user if one does not exist.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94550 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2015-01-31 09:49:03 +00:00
parent 2222eee2e9
commit 285eaa0399
2 changed files with 106 additions and 17 deletions

View File

@@ -35,6 +35,7 @@ import java.util.Set;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.MLPropertyInterceptor; import org.alfresco.repo.node.MLPropertyInterceptor;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition; import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
@@ -45,6 +46,7 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader; import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService; import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.MLText; import org.alfresco.service.cmr.repository.MLText;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
@@ -921,30 +923,42 @@ public class ExporterComponent
private boolean isWithinExport(NodeRef nodeRef, ExporterCrawlerParameters parameters) private boolean isWithinExport(NodeRef nodeRef, ExporterCrawlerParameters parameters)
{ {
boolean isWithin = false; boolean isWithin = false;
// Current strategy is to determine if node is a child of the root exported node try
for (NodeRef exportRoot : context.getExportList())
{ {
if (nodeRef.equals(exportRoot) && parameters.isCrawlSelf() == true) // Current strategy is to determine if node is a child of the root exported node
for (NodeRef exportRoot : context.getExportList())
{ {
// node to export is the root export node (and root is to be exported) if (nodeRef.equals(exportRoot) && parameters.isCrawlSelf() == true)
isWithin = true;
}
else
{
// locate export root in primary parent path of node
Path nodePath = nodeService.getPath(nodeRef);
for (int i = nodePath.size() -1; i >= 0; i--)
{ {
Path.ChildAssocElement pathElement = (Path.ChildAssocElement)nodePath.get(i); // node to export is the root export node (and root is to be exported)
if (pathElement.getRef().getChildRef().equals(exportRoot)) isWithin = true;
}
else
{
// locate export root in primary parent path of node
Path nodePath = nodeService.getPath(nodeRef);
for (int i = nodePath.size() - 1; i >= 0; i--)
{ {
isWithin = true; Path.ChildAssocElement pathElement = (Path.ChildAssocElement) nodePath.get(i);
break; if (pathElement.getRef().getChildRef().equals(exportRoot))
{
isWithin = true;
break;
}
} }
} }
} }
} }
catch (AccessDeniedException accessErr)
{
// use default if this occurs
}
catch (InvalidNodeRefException nodeErr)
{
// use default if this occurs
}
return isWithin; return isWithin;
} }
} }

View File

@@ -37,6 +37,8 @@ import java.util.Map;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
import org.alfresco.repo.importer.ACPImportPackageHandler; import org.alfresco.repo.importer.ACPImportPackageHandler;
import org.alfresco.repo.security.authentication.AuthenticationComponent; import org.alfresco.repo.security.authentication.AuthenticationComponent;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.security.permissions.PermissionServiceSPI;
import org.alfresco.service.ServiceRegistry; import org.alfresco.service.ServiceRegistry;
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;
@@ -48,6 +50,9 @@ 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.CategoryService; import org.alfresco.service.cmr.search.CategoryService;
import org.alfresco.service.cmr.security.AccessPermission; import org.alfresco.service.cmr.security.AccessPermission;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.MutableAuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.view.Exporter; import org.alfresco.service.cmr.view.Exporter;
import org.alfresco.service.cmr.view.ExporterContext; import org.alfresco.service.cmr.view.ExporterContext;
import org.alfresco.service.cmr.view.ExporterCrawlerParameters; import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
@@ -60,6 +65,7 @@ import org.alfresco.service.transaction.TransactionService;
import org.alfresco.test_category.BaseSpringTestsCategory; import org.alfresco.test_category.BaseSpringTestsCategory;
import org.alfresco.test_category.OwnJVMTestsCategory; import org.alfresco.test_category.OwnJVMTestsCategory;
import org.alfresco.util.BaseSpringTest; import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.alfresco.util.TempFileProvider; import org.alfresco.util.TempFileProvider;
import org.alfresco.util.debug.NodeStoreInspector; import org.alfresco.util.debug.NodeStoreInspector;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
@@ -77,6 +83,8 @@ public class ExporterComponentTest extends BaseSpringTest
private TransactionService transactionService; private TransactionService transactionService;
private StoreRef storeRef; private StoreRef storeRef;
private AuthenticationComponent authenticationComponent; private AuthenticationComponent authenticationComponent;
private PermissionServiceSPI permissionService;
private MutableAuthenticationService authenticationService;
@Override @Override
@@ -88,8 +96,10 @@ public class ExporterComponentTest extends BaseSpringTest
fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService"); fileFolderService = (FileFolderService) applicationContext.getBean("fileFolderService");
categoryService = (CategoryService) applicationContext.getBean("categoryService"); categoryService = (CategoryService) applicationContext.getBean("categoryService");
transactionService = (TransactionService) applicationContext.getBean("transactionService"); transactionService = (TransactionService) applicationContext.getBean("transactionService");
permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent"); this.authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
this.authenticationComponent.setSystemUserAsCurrentUser(); this.authenticationComponent.setSystemUserAsCurrentUser();
this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis()); this.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
} }
@@ -239,6 +249,71 @@ public class ExporterComponentTest extends BaseSpringTest
I18NUtil.setContentLocale(currentLocale); I18NUtil.setContentLocale(currentLocale);
} }
} }
public void testMNT12504() throws Exception
{
String testUser = "testUserMnt12504";
StoreRef storeRef = StoreRef.STORE_REF_WORKSPACE_SPACESSTORE;
NodeRef rootNode = nodeService.getRootNode(storeRef);
// Create folder and two documents
NodeRef folder = fileFolderService.create(rootNode, getClass().getName() + "testMNT12504" + GUID.generate(), ContentModel.TYPE_FOLDER).getNodeRef();
NodeRef docA = nodeService.createNode(folder, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT,
Collections.singletonMap(ContentModel.PROP_NAME, (Serializable) "docA.txt")).getChildRef();
NodeRef docB = nodeService.createNode(folder, ContentModel.ASSOC_CHILDREN, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT,
Collections.singletonMap(ContentModel.PROP_NAME, (Serializable) "docB.txt")).getChildRef();
// Add association between docA and docB
nodeService.createAssociation(docA, docB, ContentModel.ASSOC_REFERENCES);
// Set read permissions for user1 on folder and docA. docB should be set to false
permissionService.setPermission(folder, testUser, PermissionService.READ, true);
permissionService.setInheritParentPermissions(folder, false);
permissionService.setPermission(docA, testUser, PermissionService.READ, true);
permissionService.setPermission(docB, testUser, PermissionService.READ, false);
if (!authenticationService.authenticationExists(testUser))
{
this.authenticationService.createAuthentication(testUser, testUser.toCharArray());
}
this.authenticationComponent.authenticate(testUser, testUser.toCharArray());
// Check that test goes as expect
assertTrue(this.authenticationComponent.getCurrentUserName().equals(testUser));
assertTrue(permissionService.hasPermission(folder, PermissionService.READ).equals(AccessStatus.ALLOWED));
assertTrue(permissionService.hasPermission(docA, PermissionService.READ).equals(AccessStatus.ALLOWED));
assertTrue(permissionService.hasPermission(docB, PermissionService.READ).equals(AccessStatus.DENIED));
ExporterCrawlerParameters crawlerParameters = new ExporterCrawlerParameters();
crawlerParameters.setExportFrom(new Location(folder));
crawlerParameters.setCrawlSelf(true);
crawlerParameters.setExcludeAspects(new QName[] { ContentModel.ASPECT_WORKING_COPY });
File acpFile = TempFileProvider.createTempFile("alf", ACPExportPackageHandler.ACP_EXTENSION);
ACPExportPackageHandler acpHandler = new ACPExportPackageHandler(new FileOutputStream(acpFile), new File("test"), new File("test"), null);
acpHandler.setNodeService(nodeService);
acpHandler.setExportAsFolders(true);
// Check that fix works as expect
boolean isFixed = true;
try
{
exporterService.exportView(acpHandler, crawlerParameters, null);
}
catch (AccessDeniedException e)
{
isFixed = false;
}
finally
{
this.authenticationComponent.setSystemUserAsCurrentUser();
nodeService.deleteNode(folder);
}
assertTrue("The MNT12504 is reproduced.", isFixed);
}
/** /**
* @param contentChildAssocRef * @param contentChildAssocRef