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

75520: Merged V4.2-BUG-FIX (4.2.3) to HEAD-BUG-FIX (5.0/Cloud)
      75206: Merged DEV to V4.2-BUG-FIX (4.2.3)
         74383 : MNT-11726 : CMIS change log isn't returning valid cmis:objectId values for deleted objects
            - Use context safe objectId generation in CMISChangeLogDataExtractor. Test for the fix
         74484 : MNT-11726 : CMIS change log isn't returning valid cmis:objectId values for deleted objects
            - Test implemented in CMISTest
            - Changed CMISConnector.isFolder(NodeRef) logic. Can cause NPE if NodeRef is not FOLDER or FILE
         75113 : MNT-11726 : CMIS change log isn't returning valid cmis:objectId values for deleted objects
            - alfresco-audit-cmis.xml moved to Repository project


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@77482 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Mark Rogers
2014-07-22 12:52:57 +00:00
parent 238a2a02c1
commit 27e2d25a8b
5 changed files with 207 additions and 18 deletions

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<Audit xmlns="http://www.alfresco.org/repo/audit/model/3.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.alfresco.org/repo/audit/model/3.2 alfresco-audit-3.2.xsd">
<DataExtractors>
<DataExtractor name="simpleValue" registeredName="auditModel.extractor.simpleValue"/>
<DataExtractor name="nullValue" registeredName="auditModel.extractor.nullValue"/>
<DataExtractor name="changeLog" registeredName="CMISChangeLogDataExtractor"/>
</DataExtractors>
<PathMappings>
<PathMap source="/CMISChangeLog" target="/CMISChangeLog" />
<PathMap source="/alfresco-api/post/FileFolderService/create" target="/CMISChangeLog/CREATED" />
<PathMap source="/alfresco-api/post/NodeService/createNode" target="/CMISChangeLog/CREATED" />
<PathMap source="/alfresco-api/post/NodeService/setProperties" target="/CMISChangeLog/UPDATED" />
<PathMap source="/alfresco-api/post/NodeService/addProperties" target="/CMISChangeLog/UPDATED" />
<PathMap source="/alfresco-api/post/NodeService/setProperty" target="/CMISChangeLog/UPDATED" />
<PathMap source="/alfresco-api/post/NodeService/removeProperty" target="/CMISChangeLog/UPDATED" />
<PathMap source="/alfresco-node/beforeDeleteNode" target="/CMISChangeLog/DELETED" />
<PathMap source="/alfresco-api/post/PermissionService/setPermission" target="/CMISChangeLog/SECURITY" />
<PathMap source="/alfresco-api/post/PermissionService/setInheritParentPermissions" target="/CMISChangeLog/SECURITY" />
<PathMap source="/alfresco-api/post/PermissionService/clearPermission" target="/CMISChangeLog/SECURITY" />
<PathMap source="/alfresco-api/post/PermissionService/deletePermission" target="/CMISChangeLog/SECURITY" />
</PathMappings>
<Application name="CMISChangeLog" key="CMISChangeLog">
<AuditPath key="CREATED">
<AuditPath key="result">
<RecordValue key="value" dataExtractor="changeLog" />
</AuditPath>
<AuditPath key="error">
<RecordValue key="value" dataExtractor="nullValue" />
</AuditPath>
</AuditPath>
<AuditPath key="UPDATED">
<AuditPath key="args">
<AuditPath key="nodeRef">
<RecordValue key="value" dataExtractor="changeLog" />
</AuditPath>
</AuditPath>
<AuditPath key="error">
<RecordValue key="value" dataExtractor="nullValue" />
</AuditPath>
</AuditPath>
<AuditPath key="DELETED">
<AuditPath key="node">
<RecordValue key="value" dataExtractor="changeLog" />
</AuditPath>
</AuditPath>
<AuditPath key="SECURITY">
<AuditPath key="args">
<AuditPath key="nodeRef">
<RecordValue key="value" dataExtractor="changeLog" />
</AuditPath>
</AuditPath>
<AuditPath key="error">
<RecordValue key="value" dataExtractor="nullValue" />
</AuditPath>
</AuditPath>
</Application>
</Audit>

View File

@@ -208,11 +208,13 @@
<property name="nodeService" ref="NodeService" />
<property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService" />
<property name="registry" ref="auditModel.extractorRegistry" />
<property name="cmisConnector" ref="CMISConnector" />
</bean>
<bean id="CMISChangeLogDataExtractor1.1" class="org.alfresco.opencmis.CMISChangeLogDataExtractor">
<property name="nodeService" ref="NodeService" />
<property name="OpenCMISDictionaryService" ref="OpenCMISDictionaryService1.1" />
<property name="registry" ref="auditModel.extractorRegistry" />
<property name="cmisConnector" ref="CMISConnector" />
</bean>
</beans>

View File

@@ -22,7 +22,6 @@ import java.io.Serializable;
import java.util.HashMap;
import org.alfresco.opencmis.dictionary.CMISDictionaryService;
import org.alfresco.opencmis.dictionary.CMISPropertyAccessor;
import org.alfresco.opencmis.dictionary.TypeDefinitionWrapper;
import org.alfresco.repo.audit.extractor.AbstractDataExtractor;
import org.alfresco.service.cmr.model.FileInfo;
@@ -30,7 +29,6 @@ import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.chemistry.opencmis.commons.PropertyIds;
import org.apache.chemistry.opencmis.commons.enums.BaseTypeId;
/**
@@ -46,6 +44,7 @@ public class CMISChangeLogDataExtractor extends AbstractDataExtractor
private NodeService nodeService;
private CMISDictionaryService cmisDictionaryService;
private CMISConnector cmisConnector;
/**
* Extracts relevant node refs and Ids from auditing data
@@ -57,15 +56,10 @@ public class CMISChangeLogDataExtractor extends AbstractDataExtractor
{
NodeRef nodeRef = getNodeRef(value);
QName typeQName = nodeService.getType(nodeRef);
TypeDefinitionWrapper type = cmisDictionaryService.findNodeType(typeQName);
HashMap<String, Serializable> result = new HashMap<String, Serializable>(5);
result.put(KEY_NODE_REF, nodeRef);
// Support version nodes by recording the object ID
CMISPropertyAccessor accessor = type.getPropertyById(PropertyIds.OBJECT_ID).getPropertyAccessor();
result.put(KEY_OBJECT_ID, accessor.getValue(accessor.createNodeInfo(nodeRef)));
result.put(KEY_OBJECT_ID, cmisConnector.createObjectId(nodeRef, true));
return result;
}
@@ -125,4 +119,8 @@ public class CMISChangeLogDataExtractor extends AbstractDataExtractor
{
this.cmisDictionaryService = cmisDictionaryService;
}
public void setCmisConnector(CMISConnector cmisConnector) {
this.cmisConnector = cmisConnector;
}
}

View File

@@ -1170,9 +1170,14 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
* be the assocRef guid.
*/
public String constructObjectId(AssociationRef assocRef, String versionLabel)
{
return constructObjectId(assocRef, versionLabel, isPublicApi());
}
public String constructObjectId(AssociationRef assocRef, String versionLabel, boolean dropStoreRef)
{
StringBuilder sb = new StringBuilder(CMISConnector.ASSOC_ID_PREFIX);
if(isPublicApi())
if(dropStoreRef)
{
// always return the guid
sb.append(assocRef.getId());
@@ -1204,9 +1209,14 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
* be the node guid.
*/
public String constructObjectId(String incomingNodeId, String versionLabel)
{
return constructObjectId(incomingNodeId, versionLabel, isPublicApi());
}
public String constructObjectId(String incomingNodeId, String versionLabel, boolean dropStoreRef)
{
StringBuilder sb = new StringBuilder();
if(isPublicApi())
if(dropStoreRef)
{
// always return the guid
sb.append(getGuid(incomingNodeId));
@@ -1264,9 +1274,14 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
* be the incomingNodeRef guid.
*/
public String constructObjectId(NodeRef incomingNodeRef, String versionLabel)
{
return constructObjectId(incomingNodeRef, versionLabel, isPublicApi());
}
public String constructObjectId(NodeRef incomingNodeRef, String versionLabel, boolean dropStoreRef)
{
StringBuilder sb = new StringBuilder();
sb.append(isPublicApi() ? incomingNodeRef.getId() : incomingNodeRef.toString());
sb.append(dropStoreRef ? incomingNodeRef.getId() : incomingNodeRef.toString());
if(versionLabel != null)
{
sb.append(CMISConnector.ID_SEPERATOR);
@@ -1278,29 +1293,39 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
/**
* Compiles a CMIS object if for a live node.
*/
public String createObjectId(NodeRef currentVersionNodeRef)
public String createObjectId(NodeRef nodeRef)
{
QName typeQName = nodeService.getType(currentVersionNodeRef);
return createObjectId(nodeRef, isPublicApi());
}
public String createObjectId(NodeRef nodeRef, boolean dropStoreRef)
{
QName typeQName = nodeService.getType(nodeRef);
TypeDefinitionWrapper type = getOpenCMISDictionaryService().findNodeType(typeQName);
if(type instanceof ItemTypeDefinitionWrapper)
{
return constructObjectId(currentVersionNodeRef, null);
return constructObjectId(nodeRef, null);
}
if(type instanceof FolderTypeDefintionWrapper)
{
return constructObjectId(currentVersionNodeRef, null);
return constructObjectId(nodeRef, null, dropStoreRef);
}
Serializable versionLabel = getNodeService()
.getProperty(currentVersionNodeRef, ContentModel.PROP_VERSION_LABEL);
.getProperty(nodeRef, ContentModel.PROP_VERSION_LABEL);
if (versionLabel == null)
{
versionLabel = CMISConnector.UNVERSIONED_VERSION_LABEL;
}
return constructObjectId(currentVersionNodeRef, (String)versionLabel);
return constructObjectId(nodeRef, (String)versionLabel, dropStoreRef);
}
private boolean isFolder(NodeRef nodeRef)
{
return getType(nodeRef) instanceof FolderTypeDefintionWrapper;
}
/**

View File

@@ -38,12 +38,19 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.cmis.CMISAccessControlService;
import org.alfresco.cmis.CMISChangeEvent;
import org.alfresco.cmis.CMISChangeLog;
import org.alfresco.cmis.CMISChangeLogService;
import org.alfresco.cmis.CMISDictionaryModel;
import org.alfresco.model.ContentModel;
import org.alfresco.opencmis.search.CMISQueryOptions;
import org.alfresco.opencmis.search.CMISQueryOptions.CMISQueryMode;
import org.alfresco.repo.action.evaluator.ComparePropertyValueEvaluator;
import org.alfresco.repo.action.executer.AddFeaturesActionExecuter;
import org.alfresco.repo.audit.AuditComponent;
import org.alfresco.repo.audit.AuditServiceImpl;
import org.alfresco.repo.audit.UserAuditFilter;
import org.alfresco.repo.audit.model.AuditModelRegistryImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.model.Repository;
@@ -134,6 +141,8 @@ public class CMISTest
private TaggingService taggingService;
private NamespaceService namespaceService;
private AuthorityService authorityService;
private AuditModelRegistryImpl auditSubsystem;
private CMISChangeLogService changeLogService;
private PermissionService permissionService;
private AlfrescoCmisServiceFactory factory;
@@ -302,6 +311,8 @@ public class CMISTest
this.cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
this.nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
this.authorityService = (AuthorityService)ctx.getBean("AuthorityService");
this.changeLogService = (CMISChangeLogService) ctx.getBean("CMISChangeLogService");
this.auditSubsystem = (AuditModelRegistryImpl) ctx.getBean("Audit");
this.permissionService = (PermissionService) ctx.getBean("permissionService");
}
@@ -2149,4 +2160,90 @@ public class CMISTest
AuthenticationUtil.popAuthentication();
}
}
/**
* MNT-11726: Test that {@link CMISChangeEvent} contains objectId of node in short form (without StoreRef).
*/
@Test
public void testCMISChangeLogObjectIds() throws Exception
{
// setUp audit subsystem
setupAudit();
AuthenticationUtil.pushAuthentication();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
try
{
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
{
@Override
public Void execute() throws Throwable
{
NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();
String changeToken = changeLogService.getLastChangeLogToken();
// perform CREATED, UPDATED, SECURITY, DELETED CMIS change type actions
String folder = GUID.generate();
FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folder, ContentModel.TYPE_FOLDER);
nodeService.setProperty(folderInfo.getNodeRef(), ContentModel.PROP_NAME, folder);
assertNotNull(folderInfo);
String content = GUID.generate();
FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), content, ContentModel.TYPE_CONTENT);
assertNotNull(document);
nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, content);
permissionService.setPermission(document.getNodeRef(), "SomeAuthority", PermissionService.EXECUTE_CONTENT, true);
fileFolderService.delete(document.getNodeRef());
fileFolderService.delete(folderInfo.getNodeRef());
CMISChangeLog changeLogEvents = changeLogService.getChangeLogEvents(changeToken, 10);
// get all recent events
for (CMISChangeEvent event : changeLogEvents.getChangeEvents())
{
String objectId = event.getObjectId();
NodeRef nodeRef = event.getChangedNode();
assertFalse("CMISChangeEvent " + event.getChangeType() + " should store short form of objectId " + objectId,
objectId.contains(nodeRef.getStoreRef().toString()));
}
return null;
}
});
}
finally
{
auditSubsystem.destroy();
AuthenticationUtil.popAuthentication();
}
}
private void setupAudit()
{
UserAuditFilter userAuditFilter = new UserAuditFilter();
userAuditFilter.setUserFilterPattern("System;.*");
userAuditFilter.afterPropertiesSet();
AuditComponent auditComponent = (AuditComponent) ctx.getBean("auditComponent");
auditComponent.setUserAuditFilter(userAuditFilter);
AuditServiceImpl auditServiceImpl = (AuditServiceImpl) ctx.getBean("auditService");
auditServiceImpl.setAuditComponent(auditComponent);
RetryingTransactionCallback<Void> initAudit = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Exception
{
auditSubsystem.stop();
auditSubsystem.setProperty("audit.enabled", "true");
auditSubsystem.setProperty("audit.cmischangelog.enabled", "true");
auditSubsystem.start();
return null;
}
};
transactionService.getRetryingTransactionHelper().doInTransaction(initAudit, false, true);
}
}