RM-2129 (Check classification before method execution)

* Code tidy up

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108640 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2015-07-21 10:55:57 +00:00
parent 353afe04a8
commit 3ea9843ac3

View File

@@ -20,12 +20,11 @@ package org.alfresco.module.org_alfresco_module_rm.classification.interceptor.pr
import static java.lang.Boolean.TRUE; import static java.lang.Boolean.TRUE;
import static org.alfresco.model.ContentModel.TYPE_CONTENT; import static org.alfresco.model.ContentModel.TYPE_CONTENT;
import static org.alfresco.repo.security.authentication.AuthenticationUtil.getFullyAuthenticatedUser;
import static org.alfresco.util.GUID.generate; import static org.alfresco.util.GUID.generate;
import static org.alfresco.util.ParameterCheck.mandatory; import static org.alfresco.util.ParameterCheck.mandatory;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceBootstrap; import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationServiceBootstrap;
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService; import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
@@ -53,9 +52,6 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
/** Key to mark the transaction as processing */ /** Key to mark the transaction as processing */
private static final String KEY_PROCESSING = generate(); private static final String KEY_PROCESSING = generate();
/** List of method names to check before invocation */
private List<String> methodNames = new ArrayList<>();
/** Application context */ /** Application context */
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@@ -128,20 +124,10 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
return (ClassificationServiceBootstrap) applicationContext.getBean("classificationServiceBootstrap"); return (ClassificationServiceBootstrap) applicationContext.getBean("classificationServiceBootstrap");
} }
/**
* Returns a list of method names to check before invocation
*
* @return List of method names to check before invocation
*/
protected List<String> getMethodNames()
{
return this.methodNames;
}
/** /**
* is pre-processing enabled? * is pre-processing enabled?
* *
* @return boolean true if enabled, false otherwise * @return boolean <code>true</code> if enabled, <code>false</code> otherwise
*/ */
public boolean isEnabled() public boolean isEnabled()
{ {
@@ -196,12 +182,6 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
{ {
// if the param is a node reference // if the param is a node reference
if (NodeRef.class.isAssignableFrom(param)) if (NodeRef.class.isAssignableFrom(param))
{
String className = method.getDeclaringClass().getSimpleName();
String methodName = method.getName();
String name = className + "." + methodName;
if (!getMethodNames().contains(name))
{ {
// disable pre-processing // disable pre-processing
disable(); disable();
@@ -211,7 +191,7 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
NodeRef testNodeRef = (NodeRef) invocation.getArguments()[position]; NodeRef testNodeRef = (NodeRef) invocation.getArguments()[position];
// if node exists then see if the current user has clearance // if node exists then see if the current user has clearance
isNodeCleared(testNodeRef, name); isNodeCleared(testNodeRef, method);
} }
finally finally
{ {
@@ -219,7 +199,6 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
enable(); enable();
} }
} }
}
position++; position++;
} }
@@ -236,16 +215,21 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
* the currently logged in user is cleared to see it. * the currently logged in user is cleared to see it.
* *
* @param nodeRef Node reference to check * @param nodeRef Node reference to check
* @param name The name of the invoked method * @param method The invoked method
*/ */
private void isNodeCleared(NodeRef nodeRef, String name) private void isNodeCleared(NodeRef nodeRef, Method method)
{ {
if (nodeRef != null && if (nodeRef != null &&
getNodeService().exists(nodeRef) && getNodeService().exists(nodeRef) &&
getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) && getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) &&
!getContentClassificationService().hasClearance(nodeRef)) !getContentClassificationService().hasClearance(nodeRef))
{ {
throw new ClassificationEnforcementException("The method '" + name + "' was called, but you are not cleared for the node."); String className = method.getDeclaringClass().getSimpleName();
String methodName = method.getName();
String name = className + "." + methodName;
throw new ClassificationEnforcementException("The user '" + getFullyAuthenticatedUser() + "' called the method '"
+ name + "' for the node '" + nodeRef + "' but is not cleared to see it.");
} }
} }
} }