mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Merged DEV/ENFORCE to HEAD:
105194: First pass at classification interceptor 105294: Fixed compilation issue 105323: Updated Aikau version to 1.0.20 105565: RM-2129 (Check classification before method execution) 105923: RM-2130 (Check classification after method execution, filtering results where appropriate) 106103: RM-2130 (Check classification after method execution, filtering results where appropriate) 106104: RM-2130 (Check classification after method execution, filtering results where appropriate) 106169: RM-2130 (Check classification after method execution, filtering results where appropriate) 106187: RM-2130 (Check classification after method execution, filtering results where appropriate) 106283: RM-2130 (Check classification after method execution, filtering results where appropriate) 106356: RM-2130 (Check classification after method execution, filtering results where appropriate) 106552: RM-2130 (Check classification after method execution, filtering results where appropriate) 106639: RM-2130 (Check classification after method execution, filtering results where appropriate) 106657: RM-2130 (Check classification after method execution, filtering results where appropriate) 106658: RM-2130 (Check classification after method execution, filtering results where appropriate) 106772: RM-2130 (Check classification after method execution, filtering results where appropriate) 106774: RM-2130 (Check classification after method execution, filtering results where appropriate) 107009: RM-2130 (Check classification after method execution, filtering results where appropriate) 107163: RM-2130 (Check classification after method execution, filtering results where appropriate) 107164: RM-2130 (Check classification after method execution, filtering results where appropriate) 107246: RM-2130 Post method invocation processor for QueryEngineResults. 107252: RM-2130 (Post method invocation processor for QueryEngineResults) 107253: RM-2130 Make CollectionPostMethodInvocationProcessor concrete. 107257: RM-2130 (Check classification after method execution, filtering results where appropriate) 107270: RM-2130 (Check classification after method execution, filtering results where appropriate) 107272: RM-2130 (Check classification after method execution, filtering results where appropriate) 107273: RM-2130 (Check classification after method execution, filtering results where appropriate) 107274: RM-2130 (Check classification after method execution, filtering results where appropriate) 107275: RM-2130 (Check classification after method execution, filtering results where appropriate) 107282: RM-2130 Add support for other collections than Lists. 107344: RM-2367 (Automate AC: Access to saved search) 107355: RM-2130 Support for specific instantiable collections. 107363: RM-2130 (Check classification after method execution, filtering results where appropriate) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@107367 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -23,6 +23,8 @@ import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditService;
|
||||
import org.alfresco.repo.action.RuntimeActionService;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.springframework.aop.framework.ProxyFactoryBean;
|
||||
|
||||
/**
|
||||
@@ -43,6 +45,9 @@ public class RMActionProxyFactoryBean extends ProxyFactoryBean
|
||||
/** Records management audit service */
|
||||
protected RecordsManagementAuditService recordsManagementAuditService;
|
||||
|
||||
/** transaction service */
|
||||
private TransactionService transactionService;
|
||||
|
||||
/**
|
||||
* Set action service
|
||||
*
|
||||
@@ -73,6 +78,15 @@ public class RMActionProxyFactoryBean extends ProxyFactoryBean
|
||||
this.recordsManagementAuditService = recordsManagementAuditService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param transactionService transaction service
|
||||
* @since 3.0.a
|
||||
*/
|
||||
public void setTransactionService(TransactionService transactionService)
|
||||
{
|
||||
this.transactionService = transactionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the action
|
||||
*/
|
||||
@@ -82,8 +96,16 @@ public class RMActionProxyFactoryBean extends ProxyFactoryBean
|
||||
{
|
||||
public Void doWork()
|
||||
{
|
||||
RecordsManagementAction action = (RecordsManagementAction)getObject();
|
||||
recordsManagementActionService.register(action);
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
|
||||
{
|
||||
public Void execute() throws Throwable
|
||||
{
|
||||
RecordsManagementAction action = (RecordsManagementAction)getObject();
|
||||
recordsManagementActionService.register(action);
|
||||
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -69,6 +69,8 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
||||
private ExemptionCategoryFieldsValidator exemptionCategoryFieldsValidator = new ExemptionCategoryFieldsValidator();
|
||||
private ClassificationSchemeEntityValidator<ExemptionCategory> exemptionCategoryValidator = new ClassificationSchemeEntityValidator<>(exemptionCategoryFieldsValidator);
|
||||
|
||||
private boolean isInitialised = false;
|
||||
|
||||
public ClassificationServiceBootstrap(AuthenticationUtil authUtil,
|
||||
TransactionService txService,
|
||||
AttributeService attributeService,
|
||||
@@ -93,6 +95,11 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
||||
public ExemptionCategoryManager getExemptionCategoryManager() { return exemptionCategoryManager; }
|
||||
public ClearanceLevelManager getClearanceLevelManager() { return clearanceLevelManager; }
|
||||
|
||||
public boolean isInitialised()
|
||||
{
|
||||
return isInitialised;
|
||||
}
|
||||
|
||||
@Override public void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
authenticationUtil.runAsSystem(new org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork<Void>()
|
||||
@@ -116,6 +123,7 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
||||
exemptionCategoryManager.setExemptionCategories(exemptionCategories);
|
||||
|
||||
initConfiguredClearanceLevels(classificationLevelManager.getClassificationLevels());
|
||||
isInitialised = true;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
@@ -34,6 +34,7 @@ import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationE
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ClassificationException.LevelIdNotFound;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.model.ClassifiedContentModel;
|
||||
import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
@@ -63,18 +64,24 @@ public class ContentClassificationServiceImpl extends ServiceBaseImpl implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassificationLevel getCurrentClassification(NodeRef nodeRef)
|
||||
public ClassificationLevel getCurrentClassification(final NodeRef nodeRef)
|
||||
{
|
||||
// by default everything is unclassified
|
||||
ClassificationLevel result = ClassificationLevelManager.UNCLASSIFIED;
|
||||
|
||||
if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
|
||||
return AuthenticationUtil.runAsSystem(new RunAsWork<ClassificationLevel>()
|
||||
{
|
||||
String classificationId = (String)nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
|
||||
result = levelManager.findLevelById(classificationId);
|
||||
}
|
||||
public ClassificationLevel doWork() throws Exception
|
||||
{
|
||||
// by default everything is unclassified
|
||||
ClassificationLevel result = ClassificationLevelManager.UNCLASSIFIED;
|
||||
|
||||
return result;
|
||||
if (nodeService.hasAspect(nodeRef, ASPECT_CLASSIFIED))
|
||||
{
|
||||
String classificationId = (String)nodeService.getProperty(nodeRef, PROP_CURRENT_CLASSIFICATION);
|
||||
result = levelManager.findLevelById(classificationId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@Override
|
||||
|
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static org.alfresco.repo.security.authentication.AuthenticationUtil.getFullyAuthenticatedUser;
|
||||
import static org.alfresco.repo.security.authentication.AuthenticationUtil.isRunAsUserTheSystemUser;
|
||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||
import static org.apache.commons.lang3.StringUtils.isNotBlank;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PostMethodInvocationProcessor;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.PreMethodInvocationProcessor;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
|
||||
/**
|
||||
* Classification method interceptor
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ClassificationMethodInterceptor implements MethodInterceptor
|
||||
{
|
||||
/** Pre method invocation processor */
|
||||
private PreMethodInvocationProcessor preMethodInvocationProcessor;
|
||||
|
||||
/** Post method invocation processor */
|
||||
private PostMethodInvocationProcessor postMethodInvocationProcessor;
|
||||
|
||||
/**
|
||||
* @return the preMethodInvocationProcessor
|
||||
*/
|
||||
protected PreMethodInvocationProcessor getPreMethodInvocationProcessor()
|
||||
{
|
||||
return this.preMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the postMethodInvocationProcessor
|
||||
*/
|
||||
protected PostMethodInvocationProcessor getPostMethodInvocationProcessor()
|
||||
{
|
||||
return this.postMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param postMethodInvocationProcessor the postMethodInvocationProcessor to set
|
||||
*/
|
||||
public void setPostMethodInvocationProcessor(PostMethodInvocationProcessor postMethodInvocationProcessor)
|
||||
{
|
||||
this.postMethodInvocationProcessor = postMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param preMethodInvocationProcessor the preMethodInvocationProcessor to set
|
||||
*/
|
||||
public void setPreMethodInvocationProcessor(PreMethodInvocationProcessor preMethodInvocationProcessor)
|
||||
{
|
||||
this.preMethodInvocationProcessor = preMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.aopalliance.intercept.MethodInterceptor#invoke(org.aopalliance.intercept.MethodInvocation)
|
||||
*/
|
||||
@Override
|
||||
public Object invoke(MethodInvocation invocation) throws Throwable
|
||||
{
|
||||
mandatory("invocation", invocation);
|
||||
|
||||
Object result = null;
|
||||
|
||||
boolean canProceed = true;
|
||||
boolean isUserValid = isUserValid();
|
||||
|
||||
if (isUserValid)
|
||||
{
|
||||
//FIXME!!!
|
||||
// Pre method invocation processing
|
||||
//canProceed = getPreMethodInvocationProcessor().process(invocation);
|
||||
}
|
||||
|
||||
if (canProceed)
|
||||
{
|
||||
// Method invocation
|
||||
result = invocation.proceed();
|
||||
|
||||
// Post method invocation processing
|
||||
if (isUserValid && result != null)
|
||||
{
|
||||
result = getPostMethodInvocationProcessor().process(result);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if we have an authenticated user and that they aren't "System"
|
||||
*
|
||||
* @return <code>true</code> if we have an authenticated user and that they aren't "System", <code>false</code> otherwise.
|
||||
*/
|
||||
private boolean isUserValid()
|
||||
{
|
||||
boolean result = false;
|
||||
|
||||
if (isNotBlank(getFullyAuthenticatedUser()) && !isRunAsUserTheSystemUser())
|
||||
{
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanNameReference;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
|
||||
/**
|
||||
* Classification method interceptor bean factory post processor.
|
||||
* <p>
|
||||
* Bean factory post processor that inspects available beans and adds the classification method interceptor
|
||||
* to all public services.
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @since 3.0.a
|
||||
*/
|
||||
public class ClassificationMethodInterceptorPostProcessor implements BeanFactoryPostProcessor
|
||||
{
|
||||
private static final String PROP_INTERCEPTOR_NAMES = "interceptorNames";
|
||||
private static final String TYPE_PROXY_FACTORY_BEAN = "ProxyFactoryBean";
|
||||
private static final String POSTFIX_SERVICE = "Service";
|
||||
private static final String BEAN_NAME_CLASSIFICATION_METHOD_INTERCEPTOR = "classificationMethodInterceptor";
|
||||
|
||||
/**
|
||||
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException
|
||||
{
|
||||
// get all bean definition names
|
||||
String beans[] = beanFactory.getBeanDefinitionNames();
|
||||
for (String bean : beans)
|
||||
{
|
||||
// get bean definition
|
||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(bean);
|
||||
|
||||
// only modify proxy factory beans that follow the public service naming postfix convention
|
||||
if (beanDefinition.getBeanClassName() != null &&
|
||||
beanDefinition.getBeanClassName().endsWith(TYPE_PROXY_FACTORY_BEAN) &&
|
||||
bean.endsWith(POSTFIX_SERVICE))
|
||||
{
|
||||
// get the property values for the bean definition
|
||||
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
|
||||
if (propertyValues.contains(PROP_INTERCEPTOR_NAMES))
|
||||
{
|
||||
// get the current list of interceptor names
|
||||
PropertyValue value = propertyValues.getPropertyValue(PROP_INTERCEPTOR_NAMES);
|
||||
ManagedList<RuntimeBeanNameReference> list = (ManagedList<RuntimeBeanNameReference>)value.getValue();
|
||||
if (!list.isEmpty())
|
||||
{
|
||||
// add reference to classification method interceptor
|
||||
RuntimeBeanNameReference beanReference = new RuntimeBeanNameReference(BEAN_NAME_CLASSIFICATION_METHOD_INTERCEPTOR);
|
||||
list.add(beanReference);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 static java.lang.reflect.Array.newInstance;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Array Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class ArrayPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<Array> getClassName()
|
||||
{
|
||||
return Array.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
T[] objects = (T[]) result;
|
||||
T obj = objects[0];
|
||||
|
||||
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(obj);
|
||||
if (processor != null)
|
||||
{
|
||||
int length = objects.length;
|
||||
List processedObjects = new ArrayList();
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
Object processedObject = processor.process(objects[i]);
|
||||
if (processedObject != null)
|
||||
{
|
||||
processedObjects.add(processedObject);
|
||||
}
|
||||
}
|
||||
|
||||
int size = processedObjects.size();
|
||||
T[] objs = (T[]) newInstance(obj.getClass(), size);
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
objs[i] = (T) processedObjects.get(i);
|
||||
}
|
||||
|
||||
result = (T) objs;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* 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.service.cmr.repository.AssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* AssociationRef Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class AssociationRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<AssociationRef> getClassName()
|
||||
{
|
||||
return AssociationRef.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
AssociationRef associationRef = getClassName().cast(result);
|
||||
|
||||
NodeRef sourceRef = associationRef.getSourceRef();
|
||||
NodeRef filteredSource = filter(sourceRef);
|
||||
|
||||
NodeRef targetRef = associationRef.getTargetRef();
|
||||
NodeRef filteredTarget = filter(targetRef);
|
||||
|
||||
if (filteredSource == null || filteredTarget == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,185 @@
|
||||
/*
|
||||
* 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 static org.alfresco.model.ContentModel.TYPE_CONTENT;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.ContentClassificationService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.classification.SecurityClearanceService;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
/**
|
||||
* Base class for post method invocation processors
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class BasePostMethodInvocationProcessor
|
||||
{
|
||||
/** Node service */
|
||||
@Autowired
|
||||
private NodeService nodeService;
|
||||
|
||||
/** Dictionary service */
|
||||
@Autowired
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
/** Content classification service */
|
||||
@Autowired
|
||||
private ContentClassificationService contentClassificationService;
|
||||
|
||||
/** Security Clearance Service */
|
||||
@Autowired
|
||||
private SecurityClearanceService securityClearanceService;
|
||||
|
||||
/** Post method invocation processor */
|
||||
@Autowired
|
||||
private PostMethodInvocationProcessor postMethodInvocationProcessor;
|
||||
|
||||
/**
|
||||
* @return the nodeService
|
||||
*/
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return this.nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dictionaryService
|
||||
*/
|
||||
protected DictionaryService getDictionaryService()
|
||||
{
|
||||
return this.dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the contentClassificationService
|
||||
*/
|
||||
protected ContentClassificationService getContentClassificationService()
|
||||
{
|
||||
return this.contentClassificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the securityClearanceService
|
||||
*/
|
||||
protected SecurityClearanceService getSecurityClearanceService()
|
||||
{
|
||||
return this.securityClearanceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the postMethodInvocationProcessor
|
||||
*/
|
||||
protected PostMethodInvocationProcessor getPostMethodInvocationProcessor()
|
||||
{
|
||||
return this.postMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nodeService the nodeService to set
|
||||
*/
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dictionaryService the dictionaryService to set
|
||||
*/
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param contentClassificationService the contentClassificationService to set
|
||||
*/
|
||||
public void setContentClassificationService(ContentClassificationService contentClassificationService)
|
||||
{
|
||||
this.contentClassificationService = contentClassificationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param securityClearanceService the securityClearanceService to set
|
||||
*/
|
||||
public void setSecurityClearanceService(SecurityClearanceService securityClearanceService)
|
||||
{
|
||||
this.securityClearanceService = securityClearanceService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param postMethodInvocationProcessor the postMethodInvocationProcessor to set
|
||||
*/
|
||||
public void setPostMethodInvocationProcessor(PostMethodInvocationProcessor postMethodInvocationProcessor)
|
||||
{
|
||||
this.postMethodInvocationProcessor = postMethodInvocationProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the post method invocation processors
|
||||
*/
|
||||
@PostConstruct
|
||||
public void register()
|
||||
{
|
||||
getPostMethodInvocationProcessor().register(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the class name
|
||||
*
|
||||
* @return The class name
|
||||
*/
|
||||
protected abstract Class<?> getClassName();
|
||||
|
||||
/**
|
||||
* Performs checks on the given object and throws exception if not all checks pass
|
||||
*
|
||||
* @param object The object to check
|
||||
* @return The given object
|
||||
*/
|
||||
protected abstract <T extends Object> T process(T object);
|
||||
|
||||
/**
|
||||
* Filters the node if the give node reference exist and it is a
|
||||
* content but the logged in user is not cleared to see the it.
|
||||
*
|
||||
* @param nodeRef Node reference
|
||||
* @return <code>null</code> if the give node reference has been
|
||||
* filtered, the node reference itself otherwise
|
||||
*/
|
||||
protected NodeRef filter(NodeRef nodeRef)
|
||||
{
|
||||
NodeRef filter = nodeRef;
|
||||
|
||||
if (getNodeService().exists(nodeRef) &&
|
||||
getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) &&
|
||||
!getContentClassificationService().hasClearance(nodeRef))
|
||||
{
|
||||
filter = null;
|
||||
}
|
||||
|
||||
return filter;
|
||||
}
|
||||
}
|
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* ChildAssociationRef Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class ChildAssociationRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<ChildAssociationRef> getClassName()
|
||||
{
|
||||
return ChildAssociationRef.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
ChildAssociationRef childAssociationRef = getClassName().cast(result);
|
||||
|
||||
NodeRef childRef = childAssociationRef.getChildRef();
|
||||
NodeRef filteredChildRef = filter(childRef);
|
||||
|
||||
NodeRef parentRef = childAssociationRef.getParentRef();
|
||||
NodeRef filteredParentRef;
|
||||
if (parentRef == null && filteredChildRef == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
filteredParentRef = filter(parentRef);
|
||||
if (filteredChildRef == null || filteredParentRef == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,124 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Collection Post Method Invocation Processor.
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class CollectionPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<?> getClassName()
|
||||
{
|
||||
return Collection.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
Collection collection = ((Collection) object);
|
||||
|
||||
if (collection != null)
|
||||
{
|
||||
BasePostMethodInvocationProcessor processor = pickProcessor(collection);
|
||||
if (processor != null)
|
||||
{
|
||||
object = (T) processCollection(collection, processor);
|
||||
}
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a collection using the supplied processor.
|
||||
*
|
||||
* @param collection The collection to be processed.
|
||||
* @param processor A collection suitable for access by someone with the current security clearance.
|
||||
*/
|
||||
protected <T> Collection<T> processCollection(Collection<T> collection, BasePostMethodInvocationProcessor processor)
|
||||
{
|
||||
Iterator<T> iterator = collection.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Object next = iterator.next();
|
||||
Object processed = processor.process(next);
|
||||
try
|
||||
{
|
||||
if (processed == null)
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
else if (!processed.equals(next))
|
||||
{
|
||||
// Modifying members of this type of collection is not supported, so filter the whole collection.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (UnsupportedOperationException e)
|
||||
{
|
||||
// If the collection cannot be modified and it contains classified data then the whole thing must be filtered.
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pick a suitable processor for the members of the collection. We assume that all the elements of a collection can
|
||||
* be processed by the same processor.
|
||||
*
|
||||
* @param collection The collection to be processed.
|
||||
* @return The chosen processor, or {@code null} if no suitable processor could be found.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
private BasePostMethodInvocationProcessor pickProcessor(Collection collection)
|
||||
{
|
||||
Iterator iterator = collection.iterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Object next = iterator.next();
|
||||
if (next != null)
|
||||
{
|
||||
BasePostMethodInvocationProcessor processor = getPostMethodInvocationProcessor().getProcessor(next);
|
||||
if (processor != null)
|
||||
{
|
||||
return processor;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing
|
||||
* this we gain the ability to replace members of a list, which is not possible using the
|
||||
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets
|
||||
* replaced with an {@code ArrayList}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
public class ListPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
|
||||
{
|
||||
@Override
|
||||
protected Class<?> getClassName()
|
||||
{
|
||||
return List.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
|
||||
{
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* List Post Method Invocation Processor. This replaces the existing list with a filtered {@link ArrayList}. By doing
|
||||
* this we gain the ability to replace members of a list, which is not possible using the
|
||||
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of list was provided gets
|
||||
* replaced with an {@code ArrayList}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
public abstract class ModifiableCollectionPostMethodInvocationProcessor extends CollectionPostMethodInvocationProcessor
|
||||
{
|
||||
@Override
|
||||
abstract protected Class<?> getClassName();
|
||||
|
||||
/**
|
||||
* Create an empty modifiable collection.
|
||||
*
|
||||
* @param collection The source collection to try to mimic.
|
||||
* @return The new empty collection.
|
||||
*/
|
||||
abstract protected <T> Collection<T> createEmptyCollection(Collection<T> collection);
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected <T> Collection<T> processCollection(Collection<T> collection, BasePostMethodInvocationProcessor processor)
|
||||
{
|
||||
Collection<T> returnList = createEmptyCollection(collection);
|
||||
for (T member : collection)
|
||||
{
|
||||
T processed = processor.process(member);
|
||||
if (processed != null)
|
||||
{
|
||||
returnList.add(processed);
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* 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.service.cmr.repository.NodeRef;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* NodeRef Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class NodeRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<NodeRef> getClassName()
|
||||
{
|
||||
return NodeRef.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
NodeRef nodeRef = getClassName().cast(result);
|
||||
if (filter(nodeRef) == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 java.util.List;
|
||||
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* PagingResults Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class PagingResultsPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
protected Class<PagingResults> getClassName()
|
||||
{
|
||||
return PagingResults.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
final PagingResults pagingResults = getClassName().cast(result);
|
||||
List page = pagingResults.getPage();
|
||||
final List processedPage = getPostMethodInvocationProcessor().process(page);
|
||||
|
||||
result = (T) new PagingResults<T>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return pagingResults.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<T> getPage()
|
||||
{
|
||||
return processedPage;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
// hasMoreItems might not be correct. Cannot determine the correct value as request details are needed.
|
||||
return pagingResults.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
int size = processedPage.size();
|
||||
return new Pair<Integer, Integer>(size, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Permission Check Value Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class PermissionCheckValuePostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @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.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
PermissionCheckValue permissionCheckValue = getClassName().cast(result);
|
||||
NodeRef nodeRef = permissionCheckValue.getNodeRef();
|
||||
if (filter(nodeRef) == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* 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 static org.alfresco.util.ParameterCheck.mandatory;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Registry for post method invocation processors
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PostMethodInvocationProcessor
|
||||
{
|
||||
/** Logger */
|
||||
private static Logger LOG = Logger.getLogger(PostMethodInvocationProcessor.class);
|
||||
|
||||
/** Post method invocation processors */
|
||||
private Map<Class<?>, BasePostMethodInvocationProcessor> processors = new HashMap<Class<?>, BasePostMethodInvocationProcessor>();
|
||||
|
||||
/**
|
||||
* Registers a post method invocation processor
|
||||
*
|
||||
* @param Post method invocation processor object
|
||||
*/
|
||||
public void register(BasePostMethodInvocationProcessor object)
|
||||
{
|
||||
mandatory("object", object);
|
||||
|
||||
processors.put(object.getClassName(), object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets all the available processors
|
||||
*
|
||||
* @return the processors Available processors
|
||||
*/
|
||||
private Map<Class<?>, BasePostMethodInvocationProcessor> getProcessors()
|
||||
{
|
||||
return this.processors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the processor from the available processors
|
||||
*
|
||||
* @param object The post invocation object
|
||||
* @return The suitable processor for the given class
|
||||
*/
|
||||
protected BasePostMethodInvocationProcessor getProcessor(Object object)
|
||||
{
|
||||
mandatory("object", object);
|
||||
|
||||
BasePostMethodInvocationProcessor result = null;
|
||||
Class<? extends Object> clazz = object.getClass();
|
||||
|
||||
if (clazz.isArray())
|
||||
{
|
||||
result = getProcessors().get(Array.class);
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
{
|
||||
Set<Entry<Class<?>, BasePostMethodInvocationProcessor>> processorsEntrySet = getProcessors().entrySet();
|
||||
for (Map.Entry<Class<?>, BasePostMethodInvocationProcessor> processorEntry : processorsEntrySet)
|
||||
{
|
||||
if (processorEntry.getKey().isAssignableFrom(clazz))
|
||||
{
|
||||
result = processorEntry.getValue();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the given object
|
||||
*
|
||||
* @param object The object to process
|
||||
* @return The processed object
|
||||
*/
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
BasePostMethodInvocationProcessor processor = getProcessor(result);
|
||||
if (processor != null)
|
||||
{
|
||||
result = processor.process(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG.debug("No processor found for '" + result + "'.");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,288 @@
|
||||
/*
|
||||
* 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 static java.lang.Boolean.TRUE;
|
||||
import static org.alfresco.model.ContentModel.TYPE_CONTENT;
|
||||
import static org.alfresco.util.GUID.generate;
|
||||
import static org.alfresco.util.ParameterCheck.mandatory;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
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.util.AlfrescoTransactionSupport;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* Pre method invocation processor
|
||||
*
|
||||
* @author Roy Wetherall
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
public class PreMethodInvocationProcessor implements ApplicationContextAware
|
||||
{
|
||||
/** Key to mark the transaction as processing */
|
||||
private static final String KEY_PROCESSING = generate();
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
|
||||
{
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
protected ContentClassificationService getContentClassificationService()
|
||||
{
|
||||
return (ContentClassificationService)applicationContext.getBean("contentClassificationService");
|
||||
}
|
||||
|
||||
protected AlfrescoTransactionSupport getAlfrescoTransactionSupport()
|
||||
{
|
||||
return (AlfrescoTransactionSupport)applicationContext.getBean("rm.alfrescoTransactionSupport");
|
||||
}
|
||||
|
||||
protected RetryingTransactionHelper getRetryingTransactionHelper()
|
||||
{
|
||||
return ((TransactionService)applicationContext.getBean("transactionService")).getRetryingTransactionHelper();
|
||||
}
|
||||
|
||||
protected ClassificationServiceBootstrap getClassificationServiceBootstrap()
|
||||
{
|
||||
return (ClassificationServiceBootstrap)applicationContext.getBean("classificationServiceBootstrap");
|
||||
}
|
||||
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return (NodeService)applicationContext.getBean("dbNodeService");
|
||||
}
|
||||
|
||||
protected DictionaryService getDictionaryService()
|
||||
{
|
||||
return (DictionaryService)applicationContext.getBean("dictionaryService");
|
||||
}
|
||||
|
||||
// /** Transaction service */
|
||||
// private TransactionService transactionService;
|
||||
//
|
||||
// /** Classification service bootstrap */
|
||||
// private ClassificationServiceBootstrap classificationServiceBootstrap;
|
||||
//
|
||||
// /** Alfresco transaction support */
|
||||
// private AlfrescoTransactionSupport alfrescoTransactionSupport;
|
||||
//
|
||||
// /** Node service */
|
||||
// private NodeService nodeService;
|
||||
//
|
||||
// /** Dictionary service */
|
||||
// private DictionaryService dictionaryService;
|
||||
//
|
||||
// /** Content classification service */
|
||||
// private ContentClassificationService contentClassificationService;
|
||||
//
|
||||
// /**
|
||||
// * @return the transactionService
|
||||
// */
|
||||
// protected TransactionService getTransactionService()
|
||||
// {
|
||||
// return this.transactionService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the classificationServiceBootstrap
|
||||
// */
|
||||
// protected ClassificationServiceBootstrap getClassificationServiceBootstrap()
|
||||
// {
|
||||
// return this.classificationServiceBootstrap;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the alfrescoTransactionSupport
|
||||
// */
|
||||
// protected AlfrescoTransactionSupport getAlfrescoTransactionSupport()
|
||||
// {
|
||||
// return this.alfrescoTransactionSupport;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the nodeService
|
||||
// */
|
||||
// protected NodeService getNodeService()
|
||||
// {
|
||||
// return this.nodeService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the dictionaryService
|
||||
// */
|
||||
// protected DictionaryService getDictionaryService()
|
||||
// {
|
||||
// return this.dictionaryService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @return the contentClassificationService
|
||||
// */
|
||||
// protected ContentClassificationService getContentClassificationService()
|
||||
// {
|
||||
// return this.contentClassificationService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param transactionService the transactionService to set
|
||||
// */
|
||||
// public void setTransactionService(TransactionService transactionService)
|
||||
// {
|
||||
// this.transactionService = transactionService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param classificationServiceBootstrap the classificationServiceBootstrap to set
|
||||
// */
|
||||
// public void setClassificationServiceBootstrap(ClassificationServiceBootstrap classificationServiceBootstrap)
|
||||
// {
|
||||
// this.classificationServiceBootstrap = classificationServiceBootstrap;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param alfrescoTransactionSupport the alfrescoTransactionSupport to set
|
||||
// */
|
||||
// public void setAlfrescoTransactionSupport(AlfrescoTransactionSupport alfrescoTransactionSupport)
|
||||
// {
|
||||
// this.alfrescoTransactionSupport = alfrescoTransactionSupport;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param nodeService the nodeService to set
|
||||
// */
|
||||
// public void setNodeService(NodeService nodeService)
|
||||
// {
|
||||
// this.nodeService = nodeService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param dictionaryService the dictionaryService to set
|
||||
// */
|
||||
// public void setDictionaryService(DictionaryService dictionaryService)
|
||||
// {
|
||||
// this.dictionaryService = dictionaryService;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @param contentClassificationService the contentClassificationService to set
|
||||
// */
|
||||
// public void setContentClassificationService(ContentClassificationService contentClassificationService)
|
||||
// {
|
||||
// this.contentClassificationService = contentClassificationService;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Checks if the current user is cleared to see the items
|
||||
* passed as parameters to the current method invocation.
|
||||
*
|
||||
* @param invocation The current method invocation
|
||||
* @return <code>true</code> if the user is cleared to see the items, <code>false</code> otherwise
|
||||
*/
|
||||
public boolean process(final MethodInvocation invocation)
|
||||
{
|
||||
mandatory("invocation", invocation);
|
||||
|
||||
// do in transaction
|
||||
return /*getTransactionService().*/getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Boolean>()
|
||||
{
|
||||
@SuppressWarnings("rawtypes")
|
||||
public Boolean execute() throws Throwable
|
||||
{
|
||||
Boolean result = true;
|
||||
|
||||
// ensure classification service has been bootstrapped
|
||||
if (getClassificationServiceBootstrap().isInitialised())
|
||||
{
|
||||
// check that we are not already processing a classification check
|
||||
Object value = getAlfrescoTransactionSupport().getResource(KEY_PROCESSING);
|
||||
if (value == null)
|
||||
{
|
||||
Method method = invocation.getMethod();
|
||||
Class[] params = method.getParameterTypes();
|
||||
|
||||
int position = 0;
|
||||
for (Class param : params)
|
||||
{
|
||||
// if the param is a node reference
|
||||
if (NodeRef.class.isAssignableFrom(param))
|
||||
{
|
||||
// mark the transaction as processing a classification check
|
||||
getAlfrescoTransactionSupport().bindResource(KEY_PROCESSING, TRUE);
|
||||
try
|
||||
{
|
||||
// get the value of the parameter
|
||||
NodeRef testNodeRef = (NodeRef) invocation.getArguments()[position];
|
||||
|
||||
// if node exists then see if the current user has clearance
|
||||
result = isNodeCleared(testNodeRef);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// clear the transaction as processed a classification check
|
||||
getAlfrescoTransactionSupport().unbindResource(KEY_PROCESSING);
|
||||
}
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given node exists, if it is a content and if
|
||||
* the currently logged in user is cleared to see it.
|
||||
*
|
||||
* @param nodeRef Node reference to check
|
||||
* @return <code>true</code> if the node passes the checks, <code>false</code> otherwise
|
||||
*/
|
||||
private boolean isNodeCleared(NodeRef nodeRef)
|
||||
{
|
||||
boolean result = true;
|
||||
|
||||
if (getNodeService().exists(nodeRef) &&
|
||||
getDictionaryService().isSubClass(getNodeService().getType(nodeRef), TYPE_CONTENT) &&
|
||||
!getContentClassificationService().hasClearance(nodeRef))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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 java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.repo.search.impl.querymodel.QueryEngineResults;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* A post method invocation processor for {@link QueryEngineResults}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class QueryEngineResultsPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<QueryEngineResults> getClassName()
|
||||
{
|
||||
return QueryEngineResults.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
QueryEngineResults queryEngineResults = getClassName().cast(result);
|
||||
Map<Set<String>, ResultSet> resultsMap = queryEngineResults.getResults();
|
||||
Map<Set<String>, ResultSet> returnMap = new HashMap<>();
|
||||
BasePostMethodInvocationProcessor processor = null;
|
||||
|
||||
for (Entry<Set<String>, ResultSet> entry : resultsMap.entrySet())
|
||||
{
|
||||
ResultSet value = entry.getValue();
|
||||
if (processor == null)
|
||||
{
|
||||
processor = getPostMethodInvocationProcessor().getProcessor(value);
|
||||
}
|
||||
|
||||
ResultSet newResultSet = processor.process(value);
|
||||
if (newResultSet != null)
|
||||
{
|
||||
returnMap.put(entry.getKey(), newResultSet);
|
||||
}
|
||||
}
|
||||
|
||||
result = (T) new QueryEngineResults(returnMap);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* 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 static org.alfresco.service.cmr.search.PermissionEvaluationMode.EAGER;
|
||||
|
||||
import java.util.BitSet;
|
||||
|
||||
import org.alfresco.repo.search.SimpleResultSetMetaData;
|
||||
import org.alfresco.repo.security.permissions.impl.acegi.FilteringResultSet;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.ResultSetMetaData;
|
||||
import org.alfresco.service.cmr.search.ResultSetRow;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* ResultSet Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class ResultSetPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<ResultSet> getClassName()
|
||||
{
|
||||
return ResultSet.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.CollectionPostMethodInvocationProcessor#process(java.lang.Object)
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
ResultSet returnedObject = getClassName().cast(result);
|
||||
|
||||
BitSet inclusionMask = new BitSet(returnedObject.length());
|
||||
FilteringResultSet filteringResultSet = new FilteringResultSet(returnedObject, inclusionMask);
|
||||
|
||||
ResultSetMetaData resultSetMetaData = returnedObject.getResultSetMetaData();
|
||||
SearchParameters searchParameters = resultSetMetaData.getSearchParameters();
|
||||
|
||||
BasePostMethodInvocationProcessor nodeRefProcessor = null;
|
||||
BasePostMethodInvocationProcessor childAssociationRefProcessor = null;
|
||||
|
||||
for (int i = 0; i < returnedObject.length(); i++)
|
||||
{
|
||||
ResultSetRow row = returnedObject.getRow(i);
|
||||
NodeRef nodeRef = row.getNodeRef();
|
||||
|
||||
if (nodeRefProcessor == null)
|
||||
{
|
||||
nodeRefProcessor = getPostMethodInvocationProcessor().getProcessor(nodeRef);
|
||||
}
|
||||
|
||||
NodeRef processedNodeRef = nodeRefProcessor.process(nodeRef);
|
||||
if (processedNodeRef == null)
|
||||
{
|
||||
inclusionMask.set(i, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChildAssociationRef childAssocRef = row.getChildAssocRef();
|
||||
|
||||
if (childAssociationRefProcessor == null)
|
||||
{
|
||||
childAssociationRefProcessor = getPostMethodInvocationProcessor().getProcessor(childAssocRef);
|
||||
}
|
||||
|
||||
ChildAssociationRef childAssociationRef = childAssociationRefProcessor.process(childAssocRef);
|
||||
if (childAssociationRef == null)
|
||||
{
|
||||
inclusionMask.set(i, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
inclusionMask.set(i, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SimpleResultSetMetaData simpleResultSetMetaData = new SimpleResultSetMetaData(resultSetMetaData.getLimitedBy(), EAGER, searchParameters);
|
||||
filteringResultSet.setResultSetMetaData(simpleResultSetMetaData);
|
||||
result = (T) filteringResultSet;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link HashSet}. By doing
|
||||
* this we gain the ability to replace members of a set, which is not possible using the
|
||||
* {@link CollectionPostMethodInvocationProcessor}. The downside is that whatever type of set was provided gets
|
||||
* replaced with an {@code HashSet}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
|
||||
{
|
||||
@Override
|
||||
protected Class<?> getClassName()
|
||||
{
|
||||
return Set.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
|
||||
{
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* 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 java.util.Collection;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Sorted Set Post Method Invocation Processor. This replaces the existing set with a filtered {@link TreeSet}.
|
||||
*
|
||||
* @author Tom Page
|
||||
* @since 3.0
|
||||
*/
|
||||
public class SortedSetPostMethodInvocationProcessor extends ModifiableCollectionPostMethodInvocationProcessor
|
||||
{
|
||||
@Override
|
||||
protected Class<?> getClassName()
|
||||
{
|
||||
return SortedSet.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected <T> Collection<T> createEmptyCollection(Collection<T> collection)
|
||||
{
|
||||
SortedSet<T> sortedSet = (SortedSet<T>) collection;
|
||||
return new TreeSet<>(sortedSet.comparator());
|
||||
}
|
||||
}
|
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* 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.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* StoreRef Post Method Invocation Processor
|
||||
*
|
||||
* @author Tuna Aksoy
|
||||
* @since 3.0
|
||||
*/
|
||||
@Component
|
||||
public class StoreRefPostMethodInvocationProcessor extends BasePostMethodInvocationProcessor
|
||||
{
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.BasePostMethodInvocationProcessor#getClassName()
|
||||
*/
|
||||
@Override
|
||||
protected Class<StoreRef> getClassName()
|
||||
{
|
||||
return StoreRef.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.module.org_alfresco_module_rm.classification.interceptor.processor.AbstractPostMethodInvocationProcessor#processSingleElement(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public <T> T process(T object)
|
||||
{
|
||||
T result = object;
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
StoreRef storeRef = getClassName().cast(result);
|
||||
NodeRef nodeRef = getNodeService().getRootNode(storeRef);
|
||||
if (filter(nodeRef) == null)
|
||||
{
|
||||
result = null;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -42,4 +42,13 @@ public class AlfrescoTransactionSupport
|
||||
{
|
||||
org.alfresco.repo.transaction.AlfrescoTransactionSupport.unbindResource(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.alfresco.repo.transaction.AlfrescoTransactionSupport#getResource(Object)
|
||||
* @since 3.0.a
|
||||
*/
|
||||
public Object getResource(Object key)
|
||||
{
|
||||
return org.alfresco.repo.transaction.AlfrescoTransactionSupport.getResource(key);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user