From 24cc5ca519e4e8df7835317d955d8a4969e99e5a Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Sun, 21 Jun 2015 21:58:42 +0000 Subject: [PATCH] RM-2130 (Check classification after method execution, filtering results where appropriate) +review RM-94 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/ENFORCE@106658 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../classified-content-context.xml | 5 ++ ...AbstractPostMethodInvocationProcessor.java | 21 +++-- ...ationRefPostMethodInvocationProcessor.java | 23 +----- .../BasePostMethodInvocationProcessor.java | 14 ---- ...ationRefPostMethodInvocationProcessor.java | 23 +----- ...ficationPostMethodInvocationException.java | 80 ------------------- .../NodeRefPostMethodInvocationProcessor.java | 23 +----- ...eckValuePostMethodInvocationProcessor.java | 51 ++++++++++++ ...StoreRefPostMethodInvocationProcessor.java | 24 +----- .../EnforceClassificationTest.java | 32 +++----- ...PostMethodInvocationProcessorUnitTest.java | 8 -- 11 files changed, 87 insertions(+), 217 deletions(-) delete mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ClassificationPostMethodInvocationException.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml index cf15c1b485..c3dd709f3b 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/classified-content-context.xml @@ -95,6 +95,11 @@ class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AssociationRefPostMethodInvocationProcessor"> + + + T processSingleElement(T object); /** - * Abstract method to process a collection + * Processes a collection * * @param collection The collection to process * @return Processed collection */ - @SuppressWarnings("rawtypes") - protected abstract Collection processCollection(Collection collection); + @SuppressWarnings({ "rawtypes", "unchecked" }) + protected Collection processCollection(Collection collection) + { + return CollectionUtils.filter(collection, new Filter() + { + @Override + public Boolean apply(Object element) + { + return processSingleElement(element) != null; + } + }); + } /** * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object) @@ -61,13 +74,11 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth Collection collection = ((Collection) result); if (!collection.isEmpty()) { - checkObjectClass(collection.iterator().next()); result = (T) processCollection(collection); } } else { - checkObjectClass(result); result = processSingleElement(result); } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java index e077e6558d..300430cb81 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/AssociationRefPostMethodInvocationProcessor.java @@ -18,12 +18,8 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; -import java.util.Collection; - import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.collections.CollectionUtils; -import org.alfresco.util.collections.Filter; /** * AssociationRef Post Method Invocation Processor @@ -48,7 +44,7 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet @Override protected T processSingleElement(T object) { - AssociationRef associationRef = (AssociationRef) object; + AssociationRef associationRef = getClassName().cast(object); NodeRef sourceRef = associationRef.getSourceRef(); NodeRef filteredSource = filter(sourceRef); @@ -58,21 +54,4 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet return (filteredSource == null || filteredTarget == null) ? null : object; } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - protected Collection processCollection(Collection collection) - { - return CollectionUtils.filter(collection, new Filter() - { - @Override - public Boolean apply(AssociationRef associationRef) - { - return processSingleElement(associationRef) != null; - } - }); - } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java index ba690141f2..9d681bcd02 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/BasePostMethodInvocationProcessor.java @@ -23,7 +23,6 @@ import static org.alfresco.model.ContentModel.TYPE_CONTENT; import java.util.Collection; import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; -import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ClassificationPostMethodInvocationException.NotSupportedClassTypeException; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; @@ -135,19 +134,6 @@ public abstract class BasePostMethodInvocationProcessor getPostMethodInvocationProcessor().register(this); } - /** - * Checks if the given object's class is suitable for the processor - * - * @param object The object to process - */ - protected void checkObjectClass(Object object) - { - if (!(object.getClass().equals(getClassName()))) - { - throw new NotSupportedClassTypeException("The object is not an instance of '" + getClassName() + "' but '" + object.getClass() + "'."); - } - } - /** * Checks if the given object is a collection * diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java index 89a62e0714..5e00f06bda 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ChildAssociationRefPostMethodInvocationProcessor.java @@ -18,12 +18,8 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; -import java.util.Collection; - import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.collections.CollectionUtils; -import org.alfresco.util.collections.Filter; /** * ChildAssociationRef Post Method Invocation Processor @@ -48,7 +44,7 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo @Override protected T processSingleElement(T object) { - ChildAssociationRef childAssociationRef = ((ChildAssociationRef) object); + ChildAssociationRef childAssociationRef = getClassName().cast(object); NodeRef childRef = childAssociationRef.getChildRef(); NodeRef filteredChildRef = filter(childRef); @@ -58,21 +54,4 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo return (filteredChildRef == null || filteredParentRef == null) ? null : object; } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - protected Collection processCollection(Collection collection) - { - return CollectionUtils.filter(collection, new Filter() - { - @Override - public Boolean apply(ChildAssociationRef childAssociationRef) - { - return processSingleElement(childAssociationRef) != null; - } - }); - } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ClassificationPostMethodInvocationException.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ClassificationPostMethodInvocationException.java deleted file mode 100644 index 8bb41253e4..0000000000 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/ClassificationPostMethodInvocationException.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2005-2015 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 . - */ -package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; - -import org.alfresco.error.AlfrescoRuntimeException; - -/** - * Generic class for any runtime exception thrown within the {@link BasePostMethodInvocationProcessor} and subclasses. - * - * @author Tuna Aksoy - * @since 3.0 - */ -public class ClassificationPostMethodInvocationException extends AlfrescoRuntimeException -{ - /** Serial version UID */ - private static final long serialVersionUID = 2614182915625548638L; - - /** - * Base classification post method invocation exception - * - * @param msgId The text which will be shown in the exception - */ - public ClassificationPostMethodInvocationException(String msgId) - { - super(msgId); - } - - /** - * Base classification post method invocation exception - * - * @param msgId The text which will be shown in the exception - * @param cause The cause of the exception - */ - public ClassificationPostMethodInvocationException(String msgId, Throwable cause) - { - super(msgId, cause); - } - - /** - * Represents a fatal error due to a wrong class type - */ - public static class NotSupportedClassTypeException extends ClassificationPostMethodInvocationException - { - /** Serial version UID */ - private static final long serialVersionUID = 7614080640030648878L; - - /** - * @param msgId The text which will be shown in the exception - */ - public NotSupportedClassTypeException(String msgId) - { - super(msgId); - } - - /** - * @param msgId The text which will be shown in the exception - * @param cause The cause of the exception - */ - public NotSupportedClassTypeException(String msgId, Throwable cause) - { - super(msgId, cause); - } - } -} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java index 4abde0e223..193fd47d0a 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessor.java @@ -18,11 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; -import java.util.Collection; - import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.util.collections.CollectionUtils; -import org.alfresco.util.collections.Filter; /** * NodeRef Post Method Invocation Processor @@ -47,24 +43,7 @@ public class NodeRefPostMethodInvocationProcessor extends AbstractPostMethodInvo @Override protected T processSingleElement(T object) { - NodeRef nodeRef = (NodeRef) object; + NodeRef nodeRef = getClassName().cast(object); return filter(nodeRef) == null ? null : object; } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - protected Collection processCollection(Collection collection) - { - return CollectionUtils.filter(collection, new Filter() - { - @Override - public Boolean apply(NodeRef nodeRef) - { - return processSingleElement(nodeRef) != null; - } - }); - } } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java new file mode 100644 index 0000000000..0bb13ad1f1 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/PermissionCheckValuePostMethodInvocationProcessor.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2005-2015 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; + +import org.alfresco.repo.security.permissions.PermissionCheckValue; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Permission Check Value Post Method Invocation Processor + * + * @author Tuna Aksoy + * @since 3.0 + */ +public class PermissionCheckValuePostMethodInvocationProcessor extends AbstractPostMethodInvocationProcessor +{ + /** + * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName() + */ + @Override + protected Class getClassName() + { + return PermissionCheckValue.class; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object) + */ + @Override + protected T processSingleElement(T object) + { + PermissionCheckValue permissionCheckValue = getClassName().cast(object); + NodeRef nodeRef = permissionCheckValue.getNodeRef(); + return filter(nodeRef) == null ? null : object; + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java index 5f9e39251b..6f3f773374 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/StoreRefPostMethodInvocationProcessor.java @@ -18,12 +18,8 @@ */ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; -import java.util.Collection; - import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; -import org.alfresco.util.collections.CollectionUtils; -import org.alfresco.util.collections.Filter; /** * StoreRef Post Method Invocation Processor @@ -48,24 +44,8 @@ public class StoreRefPostMethodInvocationProcessor extends AbstractPostMethodInv @Override protected T processSingleElement(T object) { - NodeRef nodeRef = getNodeService().getRootNode((StoreRef) object); + StoreRef storeRef = getClassName().cast(object); + NodeRef nodeRef = getNodeService().getRootNode(storeRef); return filter(nodeRef) == null ? null : object; } - - /** - * @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processCollection(java.util.Collection) - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - protected Collection processCollection(Collection collection) - { - return CollectionUtils.filter(collection, new Filter() - { - @Override - public Boolean apply(NodeRef nodeRef) - { - return processSingleElement(nodeRef) != null; - } - }); - } } diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/EnforceClassificationTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/EnforceClassificationTest.java index 6ed0072c4c..ed4ced735c 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/EnforceClassificationTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/classification/EnforceClassificationTest.java @@ -18,20 +18,8 @@ */ package org.alfresco.module.org_alfresco_module_rm.test.integration.classification; -import java.util.Collections; -import java.util.List; - import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; -import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearanceService; -import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; -import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.repo.security.permissions.impl.model.PermissionModel; -import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.security.PermissionService; -import org.alfresco.util.GUID; /** * Enforce classification integration test @@ -42,16 +30,16 @@ import org.alfresco.util.GUID; public class EnforceClassificationTest extends BaseRMTestCase { /** test data */ - private static final String CLASSIFICATION_LEVEL1 = "level1"; - private static final String CLASSIFICATION_LEVEL2 = "level2"; - private static final String CLASSIFICATION_LEVEL3 = "level3"; - private static final String CLASSIFICATION_LEVEL4 = "level4"; - - private static final String CLASSIFICATION_REASON = "Test Reason 1"; - private static final String CLASSIFICATION_AUTHORITY = "classification.authority"; - private static final String RECORD_NAME = "recordname.txt"; - - private ContentClassificationService contentClassificationService; +// private static final String CLASSIFICATION_LEVEL1 = "level1"; +// private static final String CLASSIFICATION_LEVEL2 = "level2"; +// private static final String CLASSIFICATION_LEVEL3 = "level3"; +// private static final String CLASSIFICATION_LEVEL4 = "level4"; +// +// private static final String CLASSIFICATION_REASON = "Test Reason 1"; +// private static final String CLASSIFICATION_AUTHORITY = "classification.authority"; +// private static final String RECORD_NAME = "recordname.txt"; +// +// private ContentClassificationService contentClassificationService; @Override protected void initServices() diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessorUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessorUnitTest.java index 89735d7472..1d4ae13864 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessorUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/interceptor/processor/NodeRefPostMethodInvocationProcessorUnitTest.java @@ -28,7 +28,6 @@ import static org.springframework.extensions.webscripts.GUID.generate; import java.util.ArrayList; import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; -import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.ClassificationPostMethodInvocationException.NotSupportedClassTypeException; import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; import org.alfresco.service.cmr.repository.NodeRef; import org.junit.Test; @@ -46,13 +45,6 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest @InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor; @Mock private ContentClassificationService mockedContentClassificationService; - @Test (expected = NotSupportedClassTypeException.class) - public void testProccessingAnotherClassType() - { - NodeRef nodeRef = generateNodeRef(); - nodeRefPostMethodInvocationProcessor.process(nodeRef.getStoreRef()); - } - @Test public void testProcessingNonExistingNode() {