Revert to original code structure pre-mavenization

* merges from previous branches are now possible without tree conflicts
  * added back missing commits when structure was changed (r59445, r59446) .. see RM-765
  * updated Maven POM's to use existing code structure
  * NOTE: r59454 and r59473 may have been missed in this update .. will go back and re-add



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@59491 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2014-01-08 06:38:59 +00:00
parent 098833f8d5
commit ebe454f13e
885 changed files with 535 additions and 361 deletions

View File

@@ -0,0 +1,132 @@
/*
* Copyright (C) 2005-2013 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.repo.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionDefinition;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.repo.action.evaluator.ActionConditionEvaluator;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
/**
* Extended action service implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public class ExtendedActionServiceImpl extends ActionServiceImpl implements ApplicationContextAware
{
/** File plan service */
private FilePlanService filePlanService;
/** Application context */
private ApplicationContext extendedApplicationContext;
/**
* @see org.alfresco.repo.action.ActionServiceImpl#setApplicationContext(org.springframework.context.ApplicationContext)
*/
public void setApplicationContext(ApplicationContext applicationContext)
{
super.setApplicationContext(applicationContext);
extendedApplicationContext = applicationContext;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionConditionDefinition(java.lang.String)
*/
public ActionConditionDefinition getActionConditionDefinition(String name)
{
// get direct access to action condition definition (i.e. ignoring public flag of executer)
ActionConditionDefinition definition = null;
Object bean = extendedApplicationContext.getBean(name);
if (bean != null && bean instanceof ActionConditionEvaluator)
{
ActionConditionEvaluator evaluator = (ActionConditionEvaluator) bean;
definition = evaluator.getActionConditionDefintion();
}
return definition;
}
/**
* @see org.alfresco.repo.action.ActionServiceImpl#getActionDefinitions(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public List<ActionDefinition> getActionDefinitions(NodeRef nodeRef)
{
List<ActionDefinition> result = null;
// first use the base implementation to get the list of action definitions
List<ActionDefinition> actionDefinitions = super.getActionDefinitions(nodeRef);
if (nodeRef == null)
{
// nothing to filter
result = actionDefinitions;
}
else
{
// get the file component kind of the node reference
FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef);
result = new ArrayList<ActionDefinition>(actionDefinitions.size());
// check each action definition
for (ActionDefinition actionDefinition : actionDefinitions)
{
if (actionDefinition instanceof RecordsManagementActionDefinition)
{
if (kind != null)
{
Set<FilePlanComponentKind> applicableKinds = ((RecordsManagementActionDefinition)actionDefinition).getApplicableKinds();
if (applicableKinds == null || applicableKinds.size() == 0 || applicableKinds.contains(kind))
{
// an RM action can only act on a RM artifact
result.add(actionDefinition);
}
}
}
else
{
if (kind == null)
{
// a non-RM action can only act on a non-RM artifact
result.add(actionDefinition);
}
}
}
}
return result;
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (C) 2005-2013 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.repo.action.parameter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Date parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class DateParameterProcessor extends ParameterProcessor
{
private static final String DAY = "day";
private static final String WEEK = "week";
private static final String MONTH = "month";
private static final String YEAR = "year";
private static final String SHORT = "short";
private static final String LONG = "long";
private static final String NUMBER = "number";
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (value.isEmpty() == false)
{
String[] values = value.split("\\.", 2);
String field = values[0].trim();
if (DAY.equalsIgnoreCase(field))
{
result = handleDay(values);
}
else if (MONTH.equalsIgnoreCase(field))
{
result = handleMonth(values);
}
else if (YEAR.equalsIgnoreCase(field))
{
result = handleYear(values);
}
else
{
throw new AlfrescoRuntimeException("Cannot process the field '" + field + "'.");
}
}
return result;
}
private String handleDay(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "EE";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "EEEE";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "u";
}
else if (YEAR.equalsIgnoreCase(style))
{
pattern = "D";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.day." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleMonth(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "MMM";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "MMMM";
}
else if (NUMBER.equalsIgnoreCase(style))
{
pattern = "MM";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.month." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String handleYear(String[] values)
{
String style = getStyle(values);
String pattern;
if (SHORT.equalsIgnoreCase(style))
{
pattern = "yy";
}
else if (LONG.equalsIgnoreCase(style))
{
pattern = "yyyy";
}
else if (WEEK.equalsIgnoreCase(style))
{
pattern = "w";
}
else
{
throw new AlfrescoRuntimeException("The pattern 'date.year." + style + "' is not supported!");
}
return new SimpleDateFormat(pattern).format(new Date());
}
private String getStyle(String[] values)
{
String style;
if (values.length == 1)
{
style = SHORT;
}
else
{
style = values[1].trim();
}
return style;
}
}

View File

@@ -0,0 +1,55 @@
/*
* Copyright (C) 2005-2013 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.repo.action.parameter;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.surf.util.I18NUtil;
/**
* Message parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class MessageParameterProcessor extends ParameterProcessor
{
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (value.isEmpty() == false)
{
result = I18NUtil.getMessage(value);
if (result == null)
{
throw new AlfrescoRuntimeException("The message parameter processor could not resolve the message for the id " + value);
}
}
return result;
}
}

View File

@@ -0,0 +1,130 @@
/*
* Copyright (C) 2005-2013 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.repo.action.parameter;
import java.io.Serializable;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.lang.ArrayUtils;
/**
* Node parameter processor.
*
* @author Roy Wetherall
* @since 2.1
*/
public class NodeParameterProcessor extends ParameterProcessor
{
/** Supported data types */
private QName[] supportedDataTypes =
{
DataTypeDefinition.TEXT,
DataTypeDefinition.BOOLEAN,
DataTypeDefinition.DATE,
DataTypeDefinition.DATETIME,
DataTypeDefinition.DOUBLE,
DataTypeDefinition.FLOAT,
DataTypeDefinition.INT,
DataTypeDefinition.MLTEXT
};
/** Node service */
private NodeService nodeService;
/** Namespace service */
private NamespaceService namespaceService;
/** Dictionary service */
private DictionaryService dictionaryService;
/**
* @param nodeService node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @param dictionaryService dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.repo.action.parameter.ParameterProcessor#process(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public String process(String value, NodeRef actionedUponNodeRef)
{
// the default position is to return the value un-changed
String result = value;
// strip the processor name from the value
value = stripName(value);
if (value.isEmpty() == false)
{
QName qname = QName.createQName(value, namespaceService);
PropertyDefinition propertyDefinition = dictionaryService.getProperty(qname);
if (propertyDefinition == null)
{
throw new AlfrescoRuntimeException("The property " + value + " does not have a property definition.");
}
QName type = propertyDefinition.getDataType().getName();
if (ArrayUtils.contains(supportedDataTypes, type) == true)
{
Serializable propertyValue = nodeService.getProperty(actionedUponNodeRef, qname);
if (propertyValue != null)
{
result = propertyValue.toString();
}
else
{
// set the result to the empty string
result = "";
}
}
else
{
throw new AlfrescoRuntimeException("The property " + value + " is of type " + type.toString() + " which is not supported by parameter substitution.");
}
}
return result;
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright (C) 2005-2013 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.repo.action.parameter;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Abstract parameter processor implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public abstract class ParameterProcessor
{
/** Processor name */
private String name;
/** Parameter processor component */
private ParameterProcessorComponent parameterProcessorComponent;
/**
* @return parameter processor name
*/
public String getName()
{
return name;
}
/**
* @param name parameter processor name
*/
public void setName(String name)
{
this.name = name;
}
/**
* @param parameterProcessorComponent parameter processor component
*/
public void setParameterProcessorComponent(ParameterProcessorComponent parameterProcessorComponent)
{
this.parameterProcessorComponent = parameterProcessorComponent;
}
/**
* Init method
*/
public void init()
{
parameterProcessorComponent.register(this);
}
/**
* Process the parameter value.
*
* @param value substitution value
* @param actionedUponNodeRef actioned upon node reference
* @return String processed string, original string if subs string invalid
*/
public abstract String process(String value, NodeRef actionedUponNodeRef);
/**
* Strips the name of the processor from the subs value.
*
* @param value subs value
* @return String subs value with the name and '.' delimiter removed
*/
protected String stripName(String value)
{
String result = "";
String[] values = value.split("\\.", 2);
if (values.length == 2)
{
result = values[1];
}
return result;
}
}

View File

@@ -0,0 +1,137 @@
/*
* Copyright (C) 2005-2013 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.repo.action.parameter;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.action.ParameterizedItem;
import org.alfresco.service.cmr.action.ParameterizedItemDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Parameter processor component
*
* @author Roy Wetherall
* @since 2.1
*/
public class ParameterProcessorComponent
{
/** regex used to parse parameters */
private static final String REG_EX = "\\$\\{([^\\$\\{]+)\\}";
/** registry of parameter processors */
private Map<String, ParameterProcessor> processors = new HashMap<String, ParameterProcessor>(5);
/**
* Register parameter processor
*
* @param processor
*/
public void register(ParameterProcessor processor)
{
this.processors.put(processor.getName(), processor);
}
/**
*
* @param ruleItem
* @param ruleItemDefinition
* @param actionedUponNodeRef
*/
public void process(ParameterizedItem ruleItem, ParameterizedItemDefinition ruleItemDefinition, NodeRef actionedUponNodeRef)
{
for (Map.Entry<String, Serializable> entry : ruleItem.getParameterValues().entrySet())
{
String parameterName = entry.getKey();
Object parameterValue = entry.getValue();
// only sub string property values
if (parameterValue != null && parameterValue instanceof String)
{
// set the updated parameter value
ruleItem.setParameterValue(parameterName, process((String)parameterValue, actionedUponNodeRef));
}
}
}
/**
* Process the value for substitution within the context of the provided node.
*
* @param value value
* @param nodeRef node reference
* @return String resulting value
*/
public String process(String value, NodeRef nodeRef)
{
// match the substitution pattern
Pattern patt = Pattern.compile(REG_EX);
Matcher m = patt.matcher(value);
StringBuffer sb = new StringBuffer(value.length());
while (m.find())
{
String text = m.group(1);
// lookup parameter processor to use
ParameterProcessor processor = lookupProcessor(text);
if (processor == null)
{
throw new AlfrescoRuntimeException("A parameter processor has not been found for the substitution string " + text);
}
else
{
// process each substitution value
text = processor.process(text, nodeRef);
}
// append new value
m.appendReplacement(sb, Matcher.quoteReplacement(text));
}
m.appendTail(sb);
return sb.toString();
}
/**
* Look up parameter processor
*
* @param value
* @return
*/
private ParameterProcessor lookupProcessor(String value)
{
ParameterProcessor result = null;
if (value != null && value.isEmpty() == false)
{
String[] values = value.split("\\.", 2);
if (values.length != 0)
{
// get the processor from the registered map
result = processors.get(values[0]);
}
}
return result;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 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.repo.jscript;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.util.ParameterCheck;
/**
* Extended jscript search implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public class ExtendedSearch extends Search
{
/**
* Extended to take into account record read permission check.
*
* @see org.alfresco.repo.jscript.Search#findNode(org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
public ScriptNode findNode(NodeRef ref)
{
ParameterCheck.mandatory("ref", ref);
if (this.services.getNodeService().exists(ref) &&
(this.services.getPermissionService().hasPermission(ref, PermissionService.READ) == AccessStatus.ALLOWED ||
this.services.getPermissionService().hasPermission(ref, RMPermissionModel.READ_RECORDS) == AccessStatus.ALLOWED))
{
return new ScriptNode(ref, this.services, getScope());
}
return null;
}
}

View File

@@ -0,0 +1,258 @@
/*
* Copyright (C) 2005-2013 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.repo.policy.annotation;
import java.lang.reflect.Method;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
/**
* Annotated behaviour bean post processor.
* <p>
* Registers the annotated methods on behaviour beans with the policy component.
*
* @author Roy Wetherall
*/
public class AnnotatedBehaviourPostProcessor implements BeanPostProcessor
{
/** logger */
private static Log logger = LogFactory.getLog(AnnotatedBehaviourPostProcessor.class);
/** policy component */
private PolicyComponent policyComponent;
/** namespace service */
private NamespaceService namespaceService;
/**
* @param policyComponent policy component
*/
public void setPolicyComponent(PolicyComponent policyComponent)
{
this.policyComponent = policyComponent;
}
/**
* @param namespaceService namespace service
*/
public void setNamespaceService(NamespaceService namespaceService)
{
this.namespaceService = namespaceService;
}
/**
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessAfterInitialization(java.lang.Object, java.lang.String)
*/
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
{
// register annotated behavior methods
registerBehaviours(bean, beanName);
// return the bean
return bean;
}
/**
* @see org.springframework.beans.factory.config.BeanPostProcessor#postProcessBeforeInitialization(java.lang.Object, java.lang.String)
*/
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
{
// do nothing
return bean;
}
/**
* Register behaviours.
*
* @param bean bean
* @param beanName bean name
*/
private void registerBehaviours(Object bean, String beanName)
{
if (bean.getClass().isAnnotationPresent(BehaviourBean.class) == true)
{
BehaviourBean behaviourBean = bean.getClass().getAnnotation(BehaviourBean.class);
if (logger.isDebugEnabled() == true)
{
logger.debug("Annotated behaviour post processing for " + beanName);
}
Method[] methods = bean.getClass().getMethods();
for (Method method : methods)
{
if (method.isAnnotationPresent(Behaviour.class) == true)
{
registerBehaviour(behaviourBean, bean, beanName, method);
}
}
}
}
/**
* Register behaviour.
*
* @param behaviourBean behaviour bean annotation
* @param bean bean
* @param beanName bean name
* @param method method
*/
private void registerBehaviour(BehaviourBean behaviourBean, Object bean, String beanName, Method method)
{
Behaviour behaviour = method.getAnnotation(Behaviour.class);
QName policy = resolvePolicy(behaviour.policy(), method);
QName type = resolveType(behaviourBean, behaviour);
// assert that the policy and type have been set!!
ParameterCheck.mandatory("policy", policy);
if (behaviour.isService() == false)
{
ParameterCheck.mandatory("type", type);
}
if (logger.isDebugEnabled() == true)
{
if (behaviour.isService() == false)
{
logger.debug(" ... binding " + behaviour.kind() + " behaviour for " + beanName + "." + method.getName() +
" for policy " + policy.toString() +
" and type " + type.toString());
}
else
{
logger.debug(" ... binding " + behaviour.kind() + " service behaviour for " + beanName + "." + method.getName() +
" for policy " + policy.toString());
}
}
// create java behaviour object
JavaBehaviour javaBehaviour = new JavaBehaviour(bean, method.getName(), behaviour.notificationFrequency());
// determine whether we should register the behaviour
if (bean instanceof BehaviourRegistry && behaviour.name().isEmpty() == false)
{
if (logger.isDebugEnabled() == true)
{
logger.debug(" ... adding behaviour to registry with name " + behaviour.name());
}
((BehaviourRegistry)bean).registerBehaviour(behaviour.name(), javaBehaviour);
}
// deal with class behaviours
if (BehaviourKind.CLASS.equals(behaviour.kind()) == true)
{
if (behaviour.isService() == false)
{
// bind class behaviour for given type
policyComponent.bindClassBehaviour(policy, type, javaBehaviour);
}
else
{
// bind class service behaviour
policyComponent.bindClassBehaviour(policy, bean, javaBehaviour);
}
}
// deal with association behaviours
else if (BehaviourKind.ASSOCIATION.equals(behaviour.kind()) == true)
{
if (behaviour.isService() == false)
{
// bind association behaviour for given type and assoc type
policyComponent.bindAssociationBehaviour(policy,
type,
toQName(behaviour.assocType()),
javaBehaviour);
}
else
{
// bind association service behaviour
policyComponent.bindAssociationBehaviour(policy, bean, javaBehaviour);
}
}
}
/**
* Resolve the policy qname, defaulting to the qualified name of the method if none specified.
*
* @param policyName policy name
* @param method method
* @return {@link QName} qualified name of the policy
*/
private QName resolvePolicy(String policyName, Method method)
{
QName policy = null;
if (policyName.isEmpty() == true)
{
policy = QName.createQName(NamespaceService.ALFRESCO_URI, method.getName());
}
else
{
policy = toQName(policyName);
}
return policy;
}
/**
*
* @param behaviourBean
* @param typeName
* @return
*/
private QName resolveType(BehaviourBean behaviourBean, Behaviour behaviour)
{
QName type = null;
if (behaviour.isService() == false)
{
if (behaviour.type().isEmpty() == true)
{
// get default
type = toQName(behaviourBean.defaultType());
}
else
{
// convert set
type = toQName(behaviour.type());
}
}
return type;
}
/**
*
* @param name
* @return
*/
private QName toQName(String name)
{
return QName.createQName(name, namespaceService);
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2005-2013 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.repo.policy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
/**
* Behaviour method annotation.
*
* @author Roy Wetherall
*/
@Target(value = ElementType.METHOD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Behaviour
{
/** lookup name of the behaviour, if none specified behaviour is not recorded in the registry */
String name() default "";
/** kind of behaviour */
BehaviourKind kind();
/** qualified name of policy */
String policy() default "";
/** indicates whether this is a service behaviour or not */
boolean isService() default false;
/** qualified name of type/aspect */
String type() default "";
/** qualified name of association */
String assocType() default "cm:contains";
/** notification frequency */
NotificationFrequency notificationFrequency() default NotificationFrequency.EVERY_EVENT;
}

View File

@@ -0,0 +1,36 @@
/*
* Copyright (C) 2005-2013 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.repo.policy.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author Roy Wetherall
*/
@Target(value = ElementType.TYPE)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface BehaviourBean
{
/** qualified name of type/aspect */
String defaultType() default "";
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright (C) 2005-2013 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.repo.policy.annotation;
/**
* Enumeration describing the different kinds of behaviour.
*
* @author Roy Wetherall
* @since 2.2
*/
public enum BehaviourKind
{
CLASS,
ASSOCIATION
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (C) 2005-2013 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.repo.policy.annotation;
import org.alfresco.repo.policy.Behaviour;
/**
* Interface for a behaviour registry.
*
* @author Roy Wetherall
* @since 2.2
*/
public interface BehaviourRegistry
{
/**
* Register a behaviour against a given name.
*
* @param behaviour behaviour
*/
void registerBehaviour(String name, org.alfresco.repo.policy.Behaviour behaviour);
/**
* Gets the behaviour for a given name.
*
* @param name behaviour name
* @return {@link Behaviour} behaviour, null otherwise
*/
org.alfresco.repo.policy.Behaviour getBehaviour(String name);
}

View File

@@ -0,0 +1,219 @@
/*
* Copyright (C) 2005-2013 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.repo.rule;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.module.org_alfresco_module_rm.security.FilePlanAuthenticationService;
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.cmr.repository.NodeService;
import org.alfresco.service.cmr.rule.Rule;
import org.alfresco.service.namespace.QName;
/**
* Extended rule service implementation.
*
* @author Roy Wetherall
* @since 2.1
*/
public class ExtendedRuleServiceImpl extends RuleServiceImpl
{
/** indicates whether the rules should be run as rmadmin or not */
private boolean runAsRmAdmin = true;
/** ignore types */
private Set<QName> ignoredTypes = new HashSet<QName>();
/** file plan service */
private FilePlanService filePlanService;
/** file plan authentication service */
private FilePlanAuthenticationService filePlanAuthenticationService;
/** node service */
protected NodeService nodeService;
/**
* @param runAsRmAdmin true if run rules as rmadmin, false otherwise
*/
public void setRunAsRmAdmin(boolean runAsRmAdmin)
{
this.runAsRmAdmin = runAsRmAdmin;
}
/**
* @param filePlanAuthenticationService file plan authentication service
*/
public void setFilePlanAuthenticationService(FilePlanAuthenticationService filePlanAuthenticationService)
{
this.filePlanAuthenticationService = filePlanAuthenticationService;
}
/**
* @param nodeService node service
*/
public void setNodeService2(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @param filePlanService file plan service
*/
public void setFilePlanService(FilePlanService filePlanService)
{
this.filePlanService = filePlanService;
}
/**
* Init method
*/
@Override
public void init()
{
super.init();
// Specify a set of system types to be ignored by rule executions
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_SCHEDULE);
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION);
ignoredTypes.add(RecordsManagementModel.TYPE_DISPOSITION_ACTION_DEFINITION);
ignoredTypes.add(RecordsManagementModel.TYPE_EVENT_EXECUTION);
}
/**
* @see org.alfresco.repo.rule.RuleServiceImpl#saveRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
*/
@Override
public void saveRule(final NodeRef nodeRef, final Rule rule)
{
if (filePlanService.isFilePlanComponent(nodeRef) == true)
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
ExtendedRuleServiceImpl.super.saveRule(nodeRef, rule);
return null;
}
});
}
else
{
super.saveRule(nodeRef, rule);
}
}
/**
* @see org.alfresco.repo.rule.RuleServiceImpl#removeRule(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.rule.Rule)
*/
@Override
public void removeRule(final NodeRef nodeRef, final Rule rule)
{
if (filePlanService.isFilePlanComponent(nodeRef) == true)
{
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
ExtendedRuleServiceImpl.super.removeRule(nodeRef, rule);
return null;
}
});
}
else
{
super.removeRule(nodeRef, rule);
}
}
/**
* @see org.alfresco.repo.rule.RuleServiceImpl#executeRule(org.alfresco.service.cmr.rule.Rule, org.alfresco.service.cmr.repository.NodeRef, java.util.Set)
*/
@Override
public void executeRule(final Rule rule, final NodeRef nodeRef, final Set<ExecutedRuleData> executedRules)
{
if (nodeService.exists(nodeRef) == true)
{
QName typeQName = nodeService.getType(nodeRef);
// check if this is a rm rule on a rm artifact
if (filePlanService.isFilePlanComponent(nodeRef) == true &&
isFilePlanComponentRule(rule) == true)
{
// ignore and
if (isIgnoredType(typeQName) == false)
{
if (runAsRmAdmin == true)
{
// run as rmadmin
filePlanAuthenticationService.runAsRmAdmin(new RunAsWork<Void>()
{
@Override
public Void doWork() throws Exception
{
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
return null;
}
});
}
else
{
// run as current user
ExtendedRuleServiceImpl.super.executeRule(rule, nodeRef, executedRules);
}
}
}
else
{
// just execute the rule as the current user
super.executeRule(rule, nodeRef, executedRules);
}
}
}
/**
* Indicates whether the rule is a file plan component
*
* @param rule rule
* @return boolean true if rule is set on a file plan component, false otherwise
*/
private boolean isFilePlanComponentRule(Rule rule)
{
NodeRef nodeRef = getOwningNodeRef(rule);
return filePlanService.isFilePlanComponent(nodeRef);
}
/**
* @param typeQName type qname
* @return boolean true if ignore type, false otherwise
*/
private boolean isIgnoredType(QName typeQName)
{
return ignoredTypes.contains(typeQName);
}
}

View File

@@ -0,0 +1,103 @@
/*
* Copyright (C) 2005-2013 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.repo.rule.ruletrigger;
import java.util.Set;
import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.transaction.TransactionalResourceHelper;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Prevent multiple triggering of outbound rules when moving records.
*
* @author Roy Wetherall
*/
public class ExtendedBeforeDeleteChildAssociationRuleTrigger
extends RuleTriggerAbstractBase
implements NodeServicePolicies.BeforeDeleteChildAssociationPolicy
{
/**
* The logger
*/
private static Log logger = LogFactory.getLog(BeforeDeleteChildAssociationRuleTrigger.class);
private static final String POLICY = "beforeDeleteChildAssociation";
private boolean isClassBehaviour = false;
public void setIsClassBehaviour(boolean isClassBehaviour)
{
this.isClassBehaviour = isClassBehaviour;
}
/**
* @see org.alfresco.repo.rule.ruletrigger.RuleTrigger#registerRuleTrigger()
*/
public void registerRuleTrigger()
{
if (isClassBehaviour == true)
{
this.policyComponent.bindClassBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
this,
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
}
else
{
this.policyComponent.bindAssociationBehaviour(
QName.createQName(NamespaceService.ALFRESCO_URI, POLICY),
this,
new JavaBehaviour(this, POLICY, NotificationFrequency.FIRST_EVENT));
}
}
public void beforeDeleteChildAssociation(ChildAssociationRef childAssocRef)
{
// Break out early if rules are not enabled
if (!areRulesEnabled())
{
return;
}
NodeRef childNodeRef = childAssocRef.getChildRef();
// Avoid renamed nodes
Set<NodeRef> renamedNodeRefSet = TransactionalResourceHelper.getSet(RULE_TRIGGER_RENAMED_NODES);
if (renamedNodeRefSet.contains(childNodeRef))
{
return;
}
if (logger.isDebugEnabled() == true)
{
logger.debug("Single child assoc trigger (policy = " + POLICY + ") fired for parent node " + childAssocRef.getParentRef() + " and child node " + childAssocRef.getChildRef());
}
triggerRules(childAssocRef.getParentRef(), childNodeRef);
}
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (C) 2005-2013 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.repo.security.authority;
/**
* Interface for defining constants
*
* @author Tuna Aksoy
* @since 2.1
*/
public interface RMAuthority
{
/**
* The default rm zone.
*/
public static String ZONE_APP_RM = "APP.RM";
/**
* The constant for all roles display name
*/
public static String ALL_ROLES_DISPLAY_NAME = "All Roles";
/**
* The constant for all roles prefix
*/
public static String ALL_ROLES_PREFIX = "AllRoles";
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2005-2011 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.repo.security.authority;
import java.util.Set;
import java.util.regex.Pattern;
import org.alfresco.service.cmr.security.AuthorityType;
/**
* This class extends {@link AuthorityDAOImpl}</br>
* and overrides two methods from the original class</br>
* </br>
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)</br>
* </br>
* and</br>
* </br>
* addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)</br>
*/
public class RMAuthorityDAOImpl extends AuthorityDAOImpl
{
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)
{
if (isAuthorityNameMatching(authorities, authorityName, type))
{
authorities.add(authorityName);
}
}
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type, Pattern pattern)
{
if (isAuthorityNameMatching(authorities, authorityName, type))
{
if (pattern == null)
{
authorities.add(authorityName);
}
else
{
if (pattern.matcher(getShortName(authorityName)).matches())
{
authorities.add(authorityName);
}
else
{
String displayName = getAuthorityDisplayName(authorityName);
if (displayName != null && pattern.matcher(displayName).matches())
{
authorities.add(authorityName);
}
}
}
}
}
private boolean isAuthorityNameMatching(Set<String> authorities, String authorityName, AuthorityType type)
{
boolean isMatching = false;
if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type) && !getAuthorityZones(authorityName).contains("APP.RM"))
{
isMatching = true;
}
return isMatching;
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (C) 2005-2012 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.repo.security.permissions.impl;
import java.util.Set;
import org.alfresco.service.cmr.security.PermissionService;
/**
* Extended Permission Service Interface used in RM.
*
* @author Roy Wetherall
* @since 2.1
*/
public interface ExtendedPermissionService extends PermissionService
{
public Set<String> getWriters(Long aclId);
}

View File

@@ -0,0 +1,266 @@
/*
* Copyright (C) 2005-2012 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.repo.security.permissions.impl;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.cache.SimpleCache;
import org.alfresco.repo.security.permissions.AccessControlEntry;
import org.alfresco.repo.security.permissions.AccessControlList;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.util.PropertyCheck;
import org.springframework.context.ApplicationEvent;
/**
* Extends the core permission service implementation allowing the consideration of the read records
* permission.
* <p>
* This is required for SOLR support.
*
* @author Roy Wetherall
*/
public class RMPermissionServiceImpl extends PermissionServiceImpl
implements ExtendedPermissionService
{
/** Writers simple cache */
protected SimpleCache<Serializable, Set<String>> writersCache;
/**
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#setAnyDenyDenies(boolean)
*/
@Override
public void setAnyDenyDenies(boolean anyDenyDenies)
{
super.setAnyDenyDenies(anyDenyDenies);
writersCache.clear();
}
/**
* @param writersCache the writersCache to set
*/
public void setWritersCache(SimpleCache<Serializable, Set<String>> writersCache)
{
this.writersCache = writersCache;
}
/**
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#onBootstrap(org.springframework.context.ApplicationEvent)
*/
@Override
protected void onBootstrap(ApplicationEvent event)
{
super.onBootstrap(event);
PropertyCheck.mandatory(this, "writersCache", writersCache);
}
/**
* Override to deal with the possibility of hard coded permission checks in core code.
*
* Note: Eventually we need to merge the RM permission model into the core to make this more rebust.
*
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#hasPermission(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
*/
@Override
public AccessStatus hasPermission(NodeRef nodeRef, String perm)
{
AccessStatus acs = super.hasPermission(nodeRef, perm);
if (AccessStatus.DENIED.equals(acs) == true &&
PermissionService.READ.equals(perm) == true &&
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
{
return super.hasPermission(nodeRef, RMPermissionModel.READ_RECORDS);
}
else if (AccessStatus.DENIED.equals(acs) == true &&
PermissionService.WRITE.equals(perm) == true &&
nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT) == true)
{
return super.hasPermission(nodeRef, RMPermissionModel.FILE_RECORDS);
}
return acs;
}
/**
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#canRead(java.lang.Long)
*/
@Override
protected AccessStatus canRead(Long aclId)
{
Set<String> authorities = getAuthorisations();
// test denied
if(anyDenyDenies)
{
Set<String> aclReadersDenied = getReadersDenied(aclId);
for(String auth : aclReadersDenied)
{
if(authorities.contains(auth))
{
return AccessStatus.DENIED;
}
}
}
// test acl readers
Set<String> aclReaders = getReaders(aclId);
for(String auth : aclReaders)
{
if(authorities.contains(auth))
{
return AccessStatus.ALLOWED;
}
}
return AccessStatus.DENIED;
}
/**
* @see org.alfresco.repo.security.permissions.impl.PermissionServiceImpl#getReaders(java.lang.Long)
*/
@Override
public Set<String> getReaders(Long aclId)
{
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
if (acl == null)
{
return Collections.emptySet();
}
Set<String> aclReaders = readersCache.get((Serializable)acl.getProperties());
if (aclReaders != null)
{
return aclReaders;
}
HashSet<String> assigned = new HashSet<String>();
HashSet<String> readers = new HashSet<String>();
for (AccessControlEntry ace : acl.getEntries())
{
assigned.add(ace.getAuthority());
}
for (String authority : assigned)
{
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.READ));
UnconditionalAclTest rmTest = new UnconditionalAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
if (test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
{
readers.add(authority);
}
}
aclReaders = Collections.unmodifiableSet(readers);
readersCache.put((Serializable)acl.getProperties(), aclReaders);
return aclReaders;
}
/**
* Override with check for RM read
*
* @param aclId
* @return
*/
private Set<String> getReadersDenied(Long aclId)
{
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
if (acl == null)
{
return Collections.emptySet();
}
Set<String> denied = readersDeniedCache.get(aclId);
if (denied != null)
{
return denied;
}
denied = new HashSet<String>();
Set<String> assigned = new HashSet<String>();
for (AccessControlEntry ace : acl.getEntries())
{
assigned.add(ace.getAuthority());
}
for(String authority : assigned)
{
UnconditionalDeniedAclTest test = new UnconditionalDeniedAclTest(getPermissionReference(PermissionService.READ));
UnconditionalDeniedAclTest rmTest = new UnconditionalDeniedAclTest(getPermissionReference(RMPermissionModel.READ_RECORDS));
if(test.evaluate(authority, aclId) || rmTest.evaluate(authority, aclId))
{
denied.add(authority);
}
}
readersDeniedCache.put((Serializable)acl.getProperties(), denied);
return denied;
}
/**
* @see org.alfresco.repo.security.permissions.impl.ExtendedPermissionService#getWriters(java.lang.Long)
*/
public Set<String> getWriters(Long aclId)
{
AccessControlList acl = aclDaoComponent.getAccessControlList(aclId);
if (acl == null)
{
return Collections.emptySet();
}
Set<String> aclWriters = writersCache.get((Serializable)acl.getProperties());
if (aclWriters != null)
{
return aclWriters;
}
HashSet<String> assigned = new HashSet<String>();
HashSet<String> readers = new HashSet<String>();
for (AccessControlEntry ace : acl.getEntries())
{
assigned.add(ace.getAuthority());
}
for (String authority : assigned)
{
UnconditionalAclTest test = new UnconditionalAclTest(getPermissionReference(PermissionService.WRITE));
if (test.evaluate(authority, aclId))
{
readers.add(authority);
}
}
aclWriters = Collections.unmodifiableSet(readers);
writersCache.put((Serializable)acl.getProperties(), aclWriters);
return aclWriters;
}
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (C) 2005-2012 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.repo.security.permissions.impl.acegi;
import java.lang.reflect.Method;
import org.alfresco.service.cmr.security.OwnableService;
/**
* This is a workaround to make RM 2.1 backwards compatible with the Community version 4.2.d.
* This class will be removed after Community 4.2.e has been released.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RMACLEntryVoter extends ACLEntryVoter
{
public void setOwnableService(OwnableService ownableService)
{
boolean exists = false;
Method[] declaredMethods = ACLEntryVoter.class.getDeclaredMethods();
for (Method method : declaredMethods)
{
if (method.getName().equals("setOwnableService"))
{
exists = true;
break;
}
}
if (exists)
{
super.setOwnableService(ownableService);
}
}
}

View File

@@ -0,0 +1,243 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Classdefinitions using classfilter , namespaceprefix and name
*
* This class makes it possible to get only RM related class definitions
* @see ClassesGet for the original implementation
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmClassesGet extends DictionaryWebServiceBase implements RecordsManagementModel
{
private static final String MODEL_PROP_KEY_CLASS_DEFS = "classdefs";
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String MODEL_PROP_KEY_ASSOCIATION_DETAILS = "assocdefs";
private static final String CLASS_FILTER_OPTION_TYPE1 = "all";
private static final String CLASS_FILTER_OPTION_TYPE2 = "aspect";
private static final String CLASS_FILTER_OPTION_TYPE3 = "type";
private static final String REQ_URL_TEMPL_VAR_CLASS_FILTER = "cf";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
private static final String REQ_URL_TEMPL_VAR_NAME = "n";
/** Site service*/
private SiteService siteService;
/**
* @param siteService the site service to set
*/
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
return executeImpl(req, status, cache, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param status Web Script status
* @param cache Web Script cache
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache, boolean isRM)
{
String classFilter = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_CLASS_FILTER));
String namespacePrefix = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX));
String name = getValidInput(req.getParameter(REQ_URL_TEMPL_VAR_NAME));
String className = null;
Map<QName, ClassDefinition> classdef = new HashMap<QName, ClassDefinition>();
Map<QName, Collection<PropertyDefinition>> propdef = new HashMap<QName, Collection<PropertyDefinition>>();
Map<QName, Collection<AssociationDefinition>> assocdef = new HashMap<QName, Collection<AssociationDefinition>>();
Map<String, Object> model = new HashMap<String, Object>();
List<QName> qnames = new ArrayList<QName>();
QName classQname = null;
QName myModel = null;
//if classfilter is not given, then it defaults to all
if (classFilter == null)
{
classFilter = "all";
}
//validate classfilter
if (isValidClassFilter(classFilter) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the classfilter - " + classFilter + " provided in the URL");
}
//name alone has no meaning without namespaceprefix
if (namespacePrefix == null && name != null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Missing namespaceprefix parameter in the URL - both combination of name and namespaceprefix is needed");
}
//validate the namespaceprefix and name parameters => if namespaceprefix is given, then name has to be validated along with it
if (namespacePrefix != null)
{
//validate name parameter if present along with the namespaceprefix
if (name != null)
{
className = namespacePrefix + "_" + name;
if (isValidClassname(className) == false)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the name - " + name + "parameter in the URL");
}
classQname = QName.createQName(getFullNamespaceURI(className));
classdef.put(classQname, this.dictionaryservice.getClass(classQname));
propdef.put(classQname, this.dictionaryservice.getClass(classQname).getProperties().values());
assocdef.put(classQname, this.dictionaryservice.getClass(classQname).getAssociations().values());
}
else
{
//if name is not given then the model is extracted from the namespaceprefix, there can be more than one model associated with one namespaceprefix
String namespaceUri = namespaceService.getNamespaceURI(namespacePrefix);
for (QName qnameObj : this.dictionaryservice.getAllModels())
{
if (qnameObj.getNamespaceURI().equals(namespaceUri))
{
name = qnameObj.getLocalName();
myModel = QName.createQName(getFullNamespaceURI(namespacePrefix + "_" + name));
// check the classfilter to pull out either all or type or aspects
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(this.dictionaryservice.getTypes(myModel));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(this.dictionaryservice.getAspects(myModel));
}
}
}
}
}
// if namespacePrefix is null, then check the class filter to pull out either all, type or aspects
if (myModel == null)
{
if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE1))
{
qnames.addAll(getAspects(isRM));
qnames.addAll(getTypes(isRM));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE3))
{
qnames.addAll(getTypes(isRM));
}
else if (classFilter.equalsIgnoreCase(CLASS_FILTER_OPTION_TYPE2))
{
qnames.addAll(getAspects(isRM));
}
}
if (classdef.isEmpty() == true)
{
for (QName qnameObj : qnames)
{
classdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj));
propdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getProperties().values());
assocdef.put(qnameObj, this.dictionaryservice.getClass(qnameObj).getAssociations().values());
}
}
List<ClassDefinition> classDefinitions = new ArrayList<ClassDefinition>(classdef.values());
Collections.sort(classDefinitions, new DictionaryComparators.ClassDefinitionComparator(dictionaryservice));
model.put(MODEL_PROP_KEY_CLASS_DEFS, classDefinitions);
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, propdef.values());
model.put(MODEL_PROP_KEY_ASSOCIATION_DETAILS, assocdef.values());
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
return model;
}
/**
* Returns the names of the types depending on {@link isRM} parameter
*
* @param isRM if true only RM related types will be retrieved
* @return The names of the types defined within the specified model or all of them depending on {@link isRM} parameter
*/
private Collection<QName> getTypes(boolean isRM)
{
if (isRM == true)
{
return this.dictionaryservice.getTypes(RM_MODEL);
}
else
{
return this.dictionaryservice.getAllTypes();
}
}
/**
* Returns the names of the aspects depending on {@link isRM} parameter
*
* @param isRM if true only RM related aspects will be retrieved
* @return The names of the aspects defined within the specified model or all of them depending on {@link isRM} parameter
*/
private Collection<QName> getAspects(boolean isRM)
{
if (isRM == true)
{
return this.dictionaryservice.getAspects(RM_MODEL);
}
else
{
return this.dictionaryservice.getAllAspects();
}
}
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.dictionary;
import org.alfresco.service.cmr.site.SiteInfo;
import org.alfresco.service.cmr.site.SiteService;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Util class for dictionary web services
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmDictionaryWebServiceUtils
{
private static final String SITE_ID = "siteId";
private static final String SITE_PRESET = "rm-site-dashboard";
public static boolean isRmSite(WebScriptRequest req, SiteService siteService)
{
boolean isRmSite = false;
String siteId = req.getParameter(SITE_ID);
if (StringUtils.isNotBlank(siteId) == true)
{
SiteInfo site = siteService.getSite(siteId);
if (site != null)
{
if (site.getSitePreset().equals(SITE_PRESET) == true)
{
isRmSite = true;
}
}
}
return isRmSite;
}
}

View File

@@ -0,0 +1,177 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.dictionary;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.namespace.QName;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript to get the Propertydefinitions for a given classname eg. =>cm_person
*
* This class makes it possible to get only RM related property definitions
* @see PropertiesGet for the original implementation
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmPropertiesGet extends DictionaryWebServiceBase implements RecordsManagementModel
{
private static final String MODEL_PROP_KEY_PROPERTY_DETAILS = "propertydefs";
private static final String DICTIONARY_CLASS_NAME = "classname";
private static final String PARAM_NAME = "name";
private static final String REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX = "nsp";
/** Site service*/
private SiteService siteService;
/**
* @param siteService the site service to set
*/
public void setSiteService(SiteService siteService)
{
this.siteService = siteService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
return executeImpl(req, status, cache, RmDictionaryWebServiceUtils.isRmSite(req, siteService));
}
/**
* Execute custom Java logic
*
* @param req Web Script request
* @param status Web Script status
* @param cache Web Script cache
* @param isRM indicates whether the request comes from an RM site or not
* @return custom service model
*/
private Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache, boolean isRM)
{
QName classQName = null;
String className = req.getServiceMatch().getTemplateVars().get(DICTIONARY_CLASS_NAME);
if (className != null && className.length() != 0)
{
classQName = createClassQName(className);
if (classQName == null)
{
// Error
throw new WebScriptException(Status.STATUS_NOT_FOUND, "Check the className - " + className + " - parameter in the URL");
}
}
String[] names = req.getParameterValues(PARAM_NAME);
String namespacePrefix = req.getParameter(REQ_URL_TEMPL_VAR_NAMESPACE_PREFIX);
String namespaceURI = null;
if (namespacePrefix != null)
{
namespaceURI = this.namespaceService.getNamespaceURI(namespacePrefix);
}
Map<QName, PropertyDefinition> propMap = null;
if (classQName == null)
{
if (names != null)
{
propMap = new HashMap<QName, PropertyDefinition>(names.length);
for (String name : names)
{
QName propQName = QName.createQName(name, namespaceService);
PropertyDefinition propDef = dictionaryservice.getProperty(propQName);
if (propDef != null)
{
propMap.put(propQName, propDef);
}
}
}
else
{
Collection<QName> propQNames = getProperties(isRM);
propMap = new HashMap<QName, PropertyDefinition>(propQNames.size());
for (QName propQName : propQNames)
{
propMap.put(propQName, dictionaryservice.getProperty(propQName));
}
}
}
else
{
// Get all the property definitions for the class
propMap = dictionaryservice.getClass(classQName).getProperties();
}
// Filter the properties by URI
List<PropertyDefinition> props = new ArrayList<PropertyDefinition>(propMap.size());
for (Map.Entry<QName, PropertyDefinition> entry : propMap.entrySet())
{
if ((namespaceURI != null &&
namespaceURI.equals(entry.getKey().getNamespaceURI()) == true) ||
namespaceURI == null)
{
props.add(entry.getValue());
}
}
// Order property definitions by title
Collections.sort(props, new DictionaryComparators.PropertyDefinitionComparator(dictionaryservice));
// Pass list of property definitions to template
Map<String, Object> model = new HashMap<String, Object>();
model.put(MODEL_PROP_KEY_PROPERTY_DETAILS, props);
model.put(MODEL_PROP_KEY_MESSAGE_LOOKUP, dictionaryservice);
return model;
}
/**
* Returns the names of the properties depending on {@link isRM} parameter
*
* @param isRM if true only RM related properties will be retrieved
* @return The names of the properties defined within the specified model or all of them depending on {@link isRM} parameter
*/
private Collection<QName> getProperties(boolean isRM)
{
if (isRM == true)
{
return dictionaryservice.getProperties(RM_MODEL);
}
else
{
return dictionaryservice.getAllProperties(null);
}
}
}

View File

@@ -0,0 +1,99 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.roles;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.script.admin.RoleDeclarativeWebScript;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.lang.StringUtils;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptException;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Abstract class for adding/removing a user/group to/from a role
* This class contains the common methods needed in the sub classes.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class AbstractRmAuthorities extends RoleDeclarativeWebScript
{
/** Constants for the url parameters */
private static final String ROLE_ID = "roleId";
private static final String AUTHORITY_NAME = "authorityName";
/**
* Util method for getting the nodeRef from the request
*
* @param req The webscript request
* @return The nodeRef passed in the request
*/
protected NodeRef getFilePlan(WebScriptRequest req)
{
NodeRef filePlan = super.getFilePlan(req);
if (filePlan == null)
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No filePlan was provided on the URL.");
}
return filePlan;
}
/**
* Util method for getting the roleId from the request
*
* @param req The webscript request
* @return The role id passed in the request
*/
protected String getRoleId(WebScriptRequest req)
{
return getParamValue(req, ROLE_ID);
}
/**
* Util method for getting the authorityName from the request
*
* @param req The webscript request
* @return The authorityName passed in the request
*/
protected String getAuthorityName(WebScriptRequest req)
{
return getParamValue(req, AUTHORITY_NAME);
}
/**
* Helper method to get the value of parameter from the request
*
* @param req The webscript request
* @param param The name of the parameter for which the value is requested
* @return The value for the requested parameter
*/
private String getParamValue(WebScriptRequest req, String param)
{
Map<String, String> templateVars = req.getServiceMatch().getTemplateVars();
String authorityName = templateVars.get(param);
if (StringUtils.isBlank(authorityName))
{
throw new WebScriptException(Status.STATUS_NOT_FOUND, "No '" + param + "' was provided on the URL.");
}
return authorityName;
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for removing a user or a group from a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesDelete extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.unassignRoleFromAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}

View File

@@ -0,0 +1,53 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.roles;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.NodeRef;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Webscript for adding a user or a group to a role
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmAuthoritiesPost extends AbstractRmAuthorities
{
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest,
* org.springframework.extensions.webscripts.Status,
* org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
NodeRef filePlan = getFilePlan(req);
String roleId = getRoleId(req);
String authorityName = getAuthorityName(req);
filePlanRoleService.assignRoleToAuthority(filePlan, roleId, authorityName);
return new HashMap<String, Object>();
}
}

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.rule;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionCondition;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionConditionDefinition;
import org.alfresco.service.cmr.action.ActionService;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action condition definition list.
*
* @author Roy Wetherall
* @since 2.1
*/
public class RmActionConditionDefinitionsGet extends DeclarativeWebScript
{
private ActionService actionService;
private RecordsManagementActionService recordsManagementActionService;
public void setActionService(ActionService actionService)
{
this.actionService = actionService;
}
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<ActionConditionDefinition> dmDefs = actionService.getActionConditionDefinitions();
List<RecordsManagementActionCondition> conditions = recordsManagementActionService.getRecordsManagementActionConditions();
List<ActionConditionDefinition> defs = new ArrayList<ActionConditionDefinition>(dmDefs.size()+conditions.size());
defs.addAll(dmDefs);
for (RecordsManagementActionCondition condition: conditions)
{
if (condition.isPublicCondition() == true)
{
defs.add(condition.getRecordsManagementActionConditionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actionconditiondefinitions", defs);
return model;
}
}

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2005-2013 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.repo.web.scripts.rule;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction;
import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.springframework.extensions.webscripts.Cache;
import org.springframework.extensions.webscripts.DeclarativeWebScript;
import org.springframework.extensions.webscripts.Status;
import org.springframework.extensions.webscripts.WebScriptRequest;
/**
* Implementation for Java backed webscript to get the RM related action definition list.
*
* @author Tuna Aksoy
* @since 2.1
*/
public class RmActionDefinitionsGet extends DeclarativeWebScript
{
private RecordsManagementActionService recordsManagementActionService;
public void setRecordsManagementActionService(RecordsManagementActionService recordsManagementActionService)
{
this.recordsManagementActionService = recordsManagementActionService;
}
/**
* @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
*/
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache)
{
List<RecordsManagementAction> actions = recordsManagementActionService.getRecordsManagementActions();
Set<ActionDefinition> defs = new HashSet<ActionDefinition>(actions.size());
for (RecordsManagementAction action : actions)
{
if (action.isPublicAction() == true)
{
defs.add(action.getRecordsManagementActionDefinition());
}
}
Map<String, Object> model = new HashMap<String, Object>();
model.put("actiondefinitions", defs);
return model;
}
}