mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Fixes to classification enforcement:
* only process services that start with an upper case character. We were being over zealous in our checking which was causing problems, we only care about public services. * add enable/disable/isenabled methods to pre-processor * switch off pre-processing when post-processing * remove method black list * unit tests, integration tests and UI tests run locally +review RM @taksoy git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@108613 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -43,8 +43,7 @@
|
|||||||
<!-- Classification Method Interceptor -->
|
<!-- Classification Method Interceptor -->
|
||||||
|
|
||||||
<bean id="preMethodInvocationProcessor"
|
<bean id="preMethodInvocationProcessor"
|
||||||
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PreMethodInvocationProcessor"
|
class="org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PreMethodInvocationProcessor">
|
||||||
init-method="init">
|
|
||||||
</bean>
|
</bean>
|
||||||
|
|
||||||
<bean id="postMethodInvocationProcessor"
|
<bean id="postMethodInvocationProcessor"
|
||||||
|
@@ -60,7 +60,8 @@ public class ClassificationMethodInterceptorPostProcessor implements BeanFactory
|
|||||||
// only modify proxy factory beans that follow the public service naming postfix convention
|
// only modify proxy factory beans that follow the public service naming postfix convention
|
||||||
if (beanDefinition.getBeanClassName() != null &&
|
if (beanDefinition.getBeanClassName() != null &&
|
||||||
beanDefinition.getBeanClassName().endsWith(TYPE_PROXY_FACTORY_BEAN) &&
|
beanDefinition.getBeanClassName().endsWith(TYPE_PROXY_FACTORY_BEAN) &&
|
||||||
bean.endsWith(POSTFIX_SERVICE))
|
bean.endsWith(POSTFIX_SERVICE) &&
|
||||||
|
Character.isUpperCase(bean.charAt(0)))
|
||||||
{
|
{
|
||||||
// get the property values for the bean definition
|
// get the property values for the bean definition
|
||||||
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
|
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
|
||||||
|
@@ -57,6 +57,10 @@ public abstract class BasePostMethodInvocationProcessor
|
|||||||
@Autowired
|
@Autowired
|
||||||
private PostMethodInvocationProcessor postMethodInvocationProcessor;
|
private PostMethodInvocationProcessor postMethodInvocationProcessor;
|
||||||
|
|
||||||
|
/** Pre method invocation processor */
|
||||||
|
@Autowired
|
||||||
|
private PreMethodInvocationProcessor preMethodInvocationProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the nodeService
|
* @return the nodeService
|
||||||
*/
|
*/
|
||||||
@@ -133,12 +137,22 @@ public abstract class BasePostMethodInvocationProcessor
|
|||||||
{
|
{
|
||||||
NodeRef filter = nodeRef;
|
NodeRef filter = nodeRef;
|
||||||
|
|
||||||
|
// disable pre-method invocation processor
|
||||||
|
preMethodInvocationProcessor.disable();
|
||||||
|
try
|
||||||
|
{
|
||||||
if (getNodeService().exists(nodeRef) &&
|
if (getNodeService().exists(nodeRef) &&
|
||||||
getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) &&
|
getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) &&
|
||||||
!getContentClassificationService().hasClearance(nodeRef))
|
!getContentClassificationService().hasClearance(nodeRef))
|
||||||
{
|
{
|
||||||
filter = null;
|
filter = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// re-enable pre-method invocation processor
|
||||||
|
preMethodInvocationProcessor.enable();
|
||||||
|
}
|
||||||
|
|
||||||
return filter;
|
return filter;
|
||||||
}
|
}
|
||||||
|
@@ -139,15 +139,31 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init method to populate the list of method names which will be checked before invocation
|
* is pre-processing enabled?
|
||||||
|
*
|
||||||
|
* @return boolean true if enabled, false otherwise
|
||||||
*/
|
*/
|
||||||
public void init()
|
public boolean isEnabled()
|
||||||
{
|
{
|
||||||
getMethodNames().add("NodeService.exists");
|
return (getAlfrescoTransactionSupport().getResource(KEY_PROCESSING) == null);
|
||||||
getMethodNames().add("NodeService.getType");
|
}
|
||||||
getMethodNames().add("NodeService.hasAspect");
|
|
||||||
getMethodNames().add("NodeService.getAspects");
|
/**
|
||||||
getMethodNames().add("NodeService.getProperties");
|
* disable pre-processing for this transaction
|
||||||
|
*/
|
||||||
|
public void disable()
|
||||||
|
{
|
||||||
|
// mark the transaction as processing a classification check
|
||||||
|
getAlfrescoTransactionSupport().bindResource(KEY_PROCESSING, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enable pre-processing for this transaction
|
||||||
|
*/
|
||||||
|
public void enable()
|
||||||
|
{
|
||||||
|
// clear the transaction as processed a classification check
|
||||||
|
getAlfrescoTransactionSupport().unbindResource(KEY_PROCESSING);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -169,9 +185,8 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
|
|||||||
// ensure classification service has been bootstrapped
|
// ensure classification service has been bootstrapped
|
||||||
if (getClassificationServiceBootstrap().isInitialised())
|
if (getClassificationServiceBootstrap().isInitialised())
|
||||||
{
|
{
|
||||||
// check that we are not already processing a classification check
|
// if pre-processing is enabled
|
||||||
Object value = getAlfrescoTransactionSupport().getResource(KEY_PROCESSING);
|
if (isEnabled())
|
||||||
if (value == null)
|
|
||||||
{
|
{
|
||||||
Method method = invocation.getMethod();
|
Method method = invocation.getMethod();
|
||||||
Class[] params = method.getParameterTypes();
|
Class[] params = method.getParameterTypes();
|
||||||
@@ -188,8 +203,8 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
|
|||||||
|
|
||||||
if (!getMethodNames().contains(name))
|
if (!getMethodNames().contains(name))
|
||||||
{
|
{
|
||||||
// mark the transaction as processing a classification check
|
// disable pre-processing
|
||||||
getAlfrescoTransactionSupport().bindResource(KEY_PROCESSING, TRUE);
|
disable();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// get the value of the parameter
|
// get the value of the parameter
|
||||||
@@ -200,8 +215,8 @@ public class PreMethodInvocationProcessor implements ApplicationContextAware
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
// clear the transaction as processed a classification check
|
// re-enable pre-processing
|
||||||
getAlfrescoTransactionSupport().unbindResource(KEY_PROCESSING);
|
enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,7 +32,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
|||||||
* @author Tuna Aksoy
|
* @author Tuna Aksoy
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class BrowseClassificationEnforcementTestBase extends BaseRMTestCase
|
public abstract class BrowseClassificationEnforcementTestBase extends BaseRMTestCase
|
||||||
{
|
{
|
||||||
protected String testUser;
|
protected String testUser;
|
||||||
protected static final String LEVEL1 = "level1";
|
protected static final String LEVEL1 = "level1";
|
||||||
|
@@ -1,99 +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.test.integration.classification.interceptor;
|
|
||||||
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
|
|
||||||
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enforce classification integration test
|
|
||||||
*
|
|
||||||
* @author Roy Wetherall
|
|
||||||
* @since 3.0
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void initServices()
|
|
||||||
{
|
|
||||||
super.initServices();
|
|
||||||
contentClassificationService = (ContentClassificationService)applicationContext.getBean("contentClassificationService");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean isCollaborationSiteTest()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public void testUserNotClearedDocument() throws Exception
|
|
||||||
{
|
|
||||||
// doBehaviourDrivenTest(new BehaviourDrivenTest(AccessDeniedException.class)
|
|
||||||
// {
|
|
||||||
// private String userName;
|
|
||||||
//
|
|
||||||
// public void given() throws Exception
|
|
||||||
// {
|
|
||||||
// // create test person and assign read permission to document
|
|
||||||
// userName = GUID.generate();
|
|
||||||
// createPerson(userName, true);
|
|
||||||
// permissionService.setPermission(dmDocument, userName , PermissionService.READ, true);
|
|
||||||
//
|
|
||||||
// // assign security clearance
|
|
||||||
// securityClearanceService.setUserSecurityClearance(userName, CLASSIFICATION_LEVEL3);
|
|
||||||
//
|
|
||||||
// // classify document
|
|
||||||
// contentClassificationService.classifyContent(
|
|
||||||
// CLASSIFICATION_LEVEL1,
|
|
||||||
// CLASSIFICATION_AUTHORITY,
|
|
||||||
// Collections.singleton(CLASSIFICATION_REASON),
|
|
||||||
// dmDocument);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void when() throws Exception
|
|
||||||
// {
|
|
||||||
// AuthenticationUtil.runAs(new RunAsWork<Void>()
|
|
||||||
// {
|
|
||||||
// public Void doWork() throws Exception
|
|
||||||
// {
|
|
||||||
// nodeService.getAspects(dmDocument);
|
|
||||||
//
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }, userName);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
}
|
|
@@ -39,6 +39,7 @@ public class NodeRefPostMethodInvocationProcessorUnitTest extends BaseUnitTest
|
|||||||
{
|
{
|
||||||
@InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor;
|
@InjectMocks private NodeRefPostMethodInvocationProcessor nodeRefPostMethodInvocationProcessor;
|
||||||
@Mock private ContentClassificationService mockedContentClassificationService;
|
@Mock private ContentClassificationService mockedContentClassificationService;
|
||||||
|
@Mock private PreMethodInvocationProcessor mockedPreMethodInvocationProcessor;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProcessingNonExistingNode()
|
public void testProcessingNonExistingNode()
|
||||||
|
Reference in New Issue
Block a user