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
This commit is contained in:
Tuna Aksoy
2015-06-21 21:58:42 +00:00
parent 862fde1e61
commit 24cc5ca519
11 changed files with 87 additions and 217 deletions

View File

@@ -95,6 +95,11 @@
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AssociationRefPostMethodInvocationProcessor"> class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AssociationRefPostMethodInvocationProcessor">
</bean> </bean>
<bean id="permissionCheckValuePostMethodInvocationProcessor"
parent="abstractPostMethodInvocationProcessor"
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PermissionCheckValuePostMethodInvocationProcessor">
</bean>
<bean id="collectionPostMethodInvocationProcessor" <bean id="collectionPostMethodInvocationProcessor"
abstract="true" abstract="true"
parent="basePostMethodInvocationProcessor" parent="basePostMethodInvocationProcessor"

View File

@@ -20,6 +20,9 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
import java.util.Collection; import java.util.Collection;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/** /**
* Abstract Post Method Invocation Processor * Abstract Post Method Invocation Processor
* *
@@ -37,13 +40,23 @@ public abstract class AbstractPostMethodInvocationProcessor extends BasePostMeth
protected abstract <T> T processSingleElement(T object); protected abstract <T> T processSingleElement(T object);
/** /**
* Abstract method to process a collection * Processes a collection
* *
* @param collection The collection to process * @param collection The collection to process
* @return Processed collection * @return Processed collection
*/ */
@SuppressWarnings("rawtypes") @SuppressWarnings({ "rawtypes", "unchecked" })
protected abstract Collection processCollection(Collection collection); 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) * @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); Collection collection = ((Collection) result);
if (!collection.isEmpty()) if (!collection.isEmpty())
{ {
checkObjectClass(collection.iterator().next());
result = (T) processCollection(collection); result = (T) processCollection(collection);
} }
} }
else else
{ {
checkObjectClass(result);
result = processSingleElement(result); result = processSingleElement(result);
} }
} }

View File

@@ -18,12 +18,8 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; 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.AssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/** /**
* AssociationRef Post Method Invocation Processor * AssociationRef Post Method Invocation Processor
@@ -48,7 +44,7 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet
@Override @Override
protected <T> T processSingleElement(T object) protected <T> T processSingleElement(T object)
{ {
AssociationRef associationRef = (AssociationRef) object; AssociationRef associationRef = getClassName().cast(object);
NodeRef sourceRef = associationRef.getSourceRef(); NodeRef sourceRef = associationRef.getSourceRef();
NodeRef filteredSource = filter(sourceRef); NodeRef filteredSource = filter(sourceRef);
@@ -58,21 +54,4 @@ public class AssociationRefPostMethodInvocationProcessor extends AbstractPostMet
return (filteredSource == null || filteredTarget == null) ? null : object; 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<AssociationRef>()
{
@Override
public Boolean apply(AssociationRef associationRef)
{
return processSingleElement(associationRef) != null;
}
});
}
} }

View File

@@ -23,7 +23,6 @@ import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import java.util.Collection; import java.util.Collection;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; 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.dictionary.DictionaryService;
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;
@@ -135,19 +134,6 @@ public abstract class BasePostMethodInvocationProcessor
getPostMethodInvocationProcessor().register(this); 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 * Checks if the given object is a collection
* *

View File

@@ -18,12 +18,8 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; 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.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/** /**
* ChildAssociationRef Post Method Invocation Processor * ChildAssociationRef Post Method Invocation Processor
@@ -48,7 +44,7 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo
@Override @Override
protected <T> T processSingleElement(T object) protected <T> T processSingleElement(T object)
{ {
ChildAssociationRef childAssociationRef = ((ChildAssociationRef) object); ChildAssociationRef childAssociationRef = getClassName().cast(object);
NodeRef childRef = childAssociationRef.getChildRef(); NodeRef childRef = childAssociationRef.getChildRef();
NodeRef filteredChildRef = filter(childRef); NodeRef filteredChildRef = filter(childRef);
@@ -58,21 +54,4 @@ public class ChildAssociationRefPostMethodInvocationProcessor extends AbstractPo
return (filteredChildRef == null || filteredParentRef == null) ? null : object; 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<ChildAssociationRef>()
{
@Override
public Boolean apply(ChildAssociationRef childAssociationRef)
{
return processSingleElement(childAssociationRef) != null;
}
});
}
} }

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}
}

View File

@@ -18,11 +18,7 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; 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.NodeRef;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/** /**
* NodeRef Post Method Invocation Processor * NodeRef Post Method Invocation Processor
@@ -47,24 +43,7 @@ public class NodeRefPostMethodInvocationProcessor extends AbstractPostMethodInvo
@Override @Override
protected <T> T processSingleElement(T object) protected <T> T processSingleElement(T object)
{ {
NodeRef nodeRef = (NodeRef) object; NodeRef nodeRef = getClassName().cast(object);
return filter(nodeRef) == null ? null : 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<NodeRef>()
{
@Override
public Boolean apply(NodeRef nodeRef)
{
return processSingleElement(nodeRef) != null;
}
});
}
} }

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<PermissionCheckValue> getClassName()
{
return PermissionCheckValue.class;
}
/**
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
*/
@Override
protected <T> T processSingleElement(T object)
{
PermissionCheckValue permissionCheckValue = getClassName().cast(object);
NodeRef nodeRef = permissionCheckValue.getNodeRef();
return filter(nodeRef) == null ? null : object;
}
}

View File

@@ -18,12 +18,8 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor; 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.NodeRef;
import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.util.collections.CollectionUtils;
import org.alfresco.util.collections.Filter;
/** /**
* StoreRef Post Method Invocation Processor * StoreRef Post Method Invocation Processor
@@ -48,24 +44,8 @@ public class StoreRefPostMethodInvocationProcessor extends AbstractPostMethodInv
@Override @Override
protected <T> T processSingleElement(T object) protected <T> 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; 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<NodeRef>()
{
@Override
public Boolean apply(NodeRef nodeRef)
{
return processSingleElement(nodeRef) != null;
}
});
}
} }

View File

@@ -18,20 +18,8 @@
*/ */
package org.alfresco.module.org_alfresco_module_rm.test.integration.classification; 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.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.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 * Enforce classification integration test
@@ -42,16 +30,16 @@ import org.alfresco.util.GUID;
public class EnforceClassificationTest extends BaseRMTestCase public class EnforceClassificationTest extends BaseRMTestCase
{ {
/** test data */ /** test data */
private static final String CLASSIFICATION_LEVEL1 = "level1"; // private static final String CLASSIFICATION_LEVEL1 = "level1";
private static final String CLASSIFICATION_LEVEL2 = "level2"; // private static final String CLASSIFICATION_LEVEL2 = "level2";
private static final String CLASSIFICATION_LEVEL3 = "level3"; // private static final String CLASSIFICATION_LEVEL3 = "level3";
private static final String CLASSIFICATION_LEVEL4 = "level4"; // private static final String CLASSIFICATION_LEVEL4 = "level4";
//
private static final String CLASSIFICATION_REASON = "Test Reason 1"; // private static final String CLASSIFICATION_REASON = "Test Reason 1";
private static final String CLASSIFICATION_AUTHORITY = "classification.authority"; // private static final String CLASSIFICATION_AUTHORITY = "classification.authority";
private static final String RECORD_NAME = "recordname.txt"; // private static final String RECORD_NAME = "recordname.txt";
//
private ContentClassificationService contentClassificationService; // private ContentClassificationService contentClassificationService;
@Override @Override
protected void initServices() protected void initServices()

View File

@@ -28,7 +28,6 @@ import static org.springframework.extensions.webscripts.GUID.generate;
import java.util.ArrayList; import java.util.ArrayList;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; 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.module.org_alfresco_module_rm.test.util.BaseUnitTest;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.junit.Test; import org.junit.Test;
@@ -46,13 +45,6 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
@InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor; @InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor;
@Mock private ContentClassificationService mockedContentClassificationService; @Mock private ContentClassificationService mockedContentClassificationService;
@Test (expected = NotSupportedClassTypeException.class)
public void testProccessingAnotherClassType()
{
NodeRef nodeRef = generateNodeRef();
nodeRefPostMethodInvocationProcessor.process(nodeRef.getStoreRef());
}
@Test @Test
public void testProcessingNonExistingNode() public void testProcessingNonExistingNode()
{ {