From 79c938f0b49499b4aba2a9eaa31b85b88a7f0b30 Mon Sep 17 00:00:00 2001 From: David Caruana Date: Thu, 2 Apr 2009 17:20:26 +0000 Subject: [PATCH] Plumbing for CMIS Allowable Actions - add CMIS enum for Allowable Actions - introduce Action Evaluator, with Permission based and fixed boolean implementations - registry of available action evaluators based on CMIS type - CMIS Type Definition has getter for applicable action evaluators - couple of CMIS actions registered TODO: - register all actions as defined in spec - serialize in AtomPub binding git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13816 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco/cmis/CMISActionEvaluator.java | 45 ++++++++++ .../alfresco/cmis/CMISAllowedActionEnum.java | 84 +++++++++++++++++++ .../org/alfresco/cmis/CMISTypeDefinition.java | 8 +- .../CMISAbstractDictionaryService.java | 1 + .../CMISAbstractTypeDefinition.java | 13 ++- .../CMISDocumentTypeDefinition.java | 2 + .../dictionary/CMISFolderTypeDefinition.java | 2 + .../dictionary/CMISObjectTypeDefinition.java | 2 + .../dictionary/CMISPolicyTypeDefinition.java | 3 + .../CMISRelationshipTypeDefinition.java | 3 + .../cmis/mapping/AbstractActionEvaluator.java | 70 ++++++++++++++++ .../alfresco/cmis/mapping/CMISMapping.java | 80 +++++++++++++++++- .../mapping/FixedValueActionEvaluator.java | 61 ++++++++++++++ .../mapping/PermissionActionEvaluator.java | 72 ++++++++++++++++ .../cmr/security/PermissionService.java | 2 - 15 files changed, 443 insertions(+), 5 deletions(-) create mode 100644 source/java/org/alfresco/cmis/CMISActionEvaluator.java create mode 100644 source/java/org/alfresco/cmis/CMISAllowedActionEnum.java create mode 100644 source/java/org/alfresco/cmis/mapping/AbstractActionEvaluator.java create mode 100644 source/java/org/alfresco/cmis/mapping/FixedValueActionEvaluator.java create mode 100644 source/java/org/alfresco/cmis/mapping/PermissionActionEvaluator.java diff --git a/source/java/org/alfresco/cmis/CMISActionEvaluator.java b/source/java/org/alfresco/cmis/CMISActionEvaluator.java new file mode 100644 index 0000000000..c692aa0a1b --- /dev/null +++ b/source/java/org/alfresco/cmis/CMISActionEvaluator.java @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.cmis; + +import org.alfresco.service.cmr.repository.NodeRef; + +public interface CMISActionEvaluator +{ + /** + * Gets the CMIS Allowed Action + * + * @return + */ + public CMISAllowedActionEnum getAction(); + + /** + * Determines if Action is allowed + * + * @param nodeRef + * @return + */ + public boolean isAllowed(NodeRef nodeRef); +} diff --git a/source/java/org/alfresco/cmis/CMISAllowedActionEnum.java b/source/java/org/alfresco/cmis/CMISAllowedActionEnum.java new file mode 100644 index 0000000000..c710a90374 --- /dev/null +++ b/source/java/org/alfresco/cmis/CMISAllowedActionEnum.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.cmis; + +/** + * CMIS Allowed Action Enum + * + * @author davidc + */ +public enum CMISAllowedActionEnum implements EnumLabel +{ + CAN_DELETE("canDelete"), + CAN_UPDATE_PROPERTIES("canUpdateProperties"), + CAN_GET_PROPERTIES("canGetProperties"), + CAN_GET_RELATIONSHIPS("canGetRelationships"), + CAN_GET_PARENTS("canGetParents"), + CAN_GET_FOLDER_PARENT("canGetFolderParents"), + CAN_GET_DESCENDANTS("canGetDescendants"), + CAN_MOVE("canMove"), + CAN_DELETE_VERSION("canDeleteVersion"), + CAN_DELETE_CONTENT("canDeleteContent"), + CAN_CHECKOUT("canCheckout"), + CAN_CANCEL_CHECKOUT("canCancelCheckout"), + CAN_CHECKIN("canCheckin"), + CAN_SET_CONTENT("canSetContent"), + CAN_GET_ALL_VERSIONS("canGetAllVersions"), + CAN_ADD_TO_FOLDER("canAddToFolder"), + CAN_REMOVE_FROM_FOLDER("canRemoveFromFolder"), + CAN_VIEW_CONTENT("canViewContent"), + CAN_ADD_POLICY("canAddPolicy"), + CAN_GET_APPLIED_POLICIES("canGetAppliedPolicies"), + CAN_REMOVE_POLICY("canRemovePolicy"), + CAN_GET_CHILDREN("canGetChildren"), + CAN_CREATE_DOCUMENT("canCreateDocument"), + CAN_CREATE_FOLDER("canCreateFolder"), + CAN_CREATE_RELATIONSHIP("canCreateRelationship"), + CAN_CREATE_POLICY("canCreatePolicy"), + CAN_DELETE_TREE("canDeleteTree"); + + + private String label; + + /** + * Construct + * + * @param label + */ + CMISAllowedActionEnum(String label) + { + this.label = label; + } + + /* (non-Javadoc) + * @see org.alfresco.cmis.EnumLabel#label() + */ + public String getLabel() + { + return label; + } + + public static EnumFactory FACTORY = new EnumFactory(CMISAllowedActionEnum.class); +} diff --git a/source/java/org/alfresco/cmis/CMISTypeDefinition.java b/source/java/org/alfresco/cmis/CMISTypeDefinition.java index b7022b8156..8d39cf771a 100644 --- a/source/java/org/alfresco/cmis/CMISTypeDefinition.java +++ b/source/java/org/alfresco/cmis/CMISTypeDefinition.java @@ -168,6 +168,12 @@ public interface CMISTypeDefinition * * @return */ - public Map getOwnedPropertyDefinitions(); + public Map getOwnedPropertyDefinitions(); + /** + * Gets the Action evaluators for this type + * + * @return + */ + public Map getActionEvaluators(); } diff --git a/source/java/org/alfresco/cmis/dictionary/CMISAbstractDictionaryService.java b/source/java/org/alfresco/cmis/dictionary/CMISAbstractDictionaryService.java index 7aaef9ae27..e04521d7ea 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISAbstractDictionaryService.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISAbstractDictionaryService.java @@ -158,6 +158,7 @@ public abstract class CMISAbstractDictionaryService extends AbstractLifecycleBea logger.debug("Registered type " + typeDef.getTypeId() + " (scope=" + typeDef.getTypeId().getScope() + ", public=" + typeDef.isPublic() + ")"); logger.debug(" QName: " + typeDef.getTypeId().getQName()); logger.debug(" Table: " + typeDef.getQueryName()); + logger.debug(" Action Evaluators: " + typeDef.getActionEvaluators().size()); } } diff --git a/source/java/org/alfresco/cmis/dictionary/CMISAbstractTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISAbstractTypeDefinition.java index 2bfed79ce2..09b222fcf6 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISAbstractTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISAbstractTypeDefinition.java @@ -32,6 +32,8 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; +import org.alfresco.cmis.CMISActionEvaluator; +import org.alfresco.cmis.CMISAllowedActionEnum; import org.alfresco.cmis.CMISContentStreamAllowedEnum; import org.alfresco.cmis.CMISPropertyDefinition; import org.alfresco.cmis.CMISPropertyId; @@ -80,7 +82,7 @@ public class CMISAbstractTypeDefinition implements CMISTypeDefinition, Serializa protected Map properties = new HashMap(); protected Map inheritedProperties = new HashMap(); protected Map ownedProperties = new HashMap(); - + protected Map actionEvaluators; /** @@ -386,6 +388,15 @@ public class CMISAbstractTypeDefinition implements CMISTypeDefinition, Serializa return ownedProperties; } + /* + * (non-Javadoc) + * @see org.alfresco.cmis.CMISTypeDefinition#getActionEvaluators() + */ + public Map getActionEvaluators() + { + return actionEvaluators; + } + // // Document Type specific // diff --git a/source/java/org/alfresco/cmis/dictionary/CMISDocumentTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISDocumentTypeDefinition.java index 767d14936a..acf8e7a1bd 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISDocumentTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISDocumentTypeDefinition.java @@ -92,6 +92,8 @@ public class CMISDocumentTypeDefinition extends CMISAbstractTypeDefinition controllable = false; includeInSuperTypeQuery = true; + actionEvaluators = cmisMapping.getActionEvaluators(objectTypeId.getScope()); + // Document type properties versionable = false; List defaultAspects = cmisClassDef.getDefaultAspects(); diff --git a/source/java/org/alfresco/cmis/dictionary/CMISFolderTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISFolderTypeDefinition.java index 8811732106..b7c1d12dd4 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISFolderTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISFolderTypeDefinition.java @@ -75,6 +75,8 @@ public class CMISFolderTypeDefinition extends CMISAbstractTypeDefinition } } + actionEvaluators = cmisMapping.getActionEvaluators(objectTypeId.getScope()); + creatable = true; queryable = true; controllable = false; diff --git a/source/java/org/alfresco/cmis/dictionary/CMISObjectTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISObjectTypeDefinition.java index 64f838fcdf..551c8c6049 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISObjectTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISObjectTypeDefinition.java @@ -71,6 +71,8 @@ public class CMISObjectTypeDefinition extends CMISAbstractTypeDefinition } } + actionEvaluators = cmisMapping.getActionEvaluators(objectTypeId.getScope()); + creatable = false; queryable = false; controllable = false; diff --git a/source/java/org/alfresco/cmis/dictionary/CMISPolicyTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISPolicyTypeDefinition.java index d4f6f89b3f..0ea6022647 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISPolicyTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISPolicyTypeDefinition.java @@ -75,6 +75,9 @@ public class CMISPolicyTypeDefinition extends CMISAbstractTypeDefinition parentTypeId = CMISDictionaryModel.POLICY_TYPE_ID; } description = cmisClassDef.getDescription(); + + actionEvaluators = cmisMapping.getActionEvaluators(objectTypeId.getScope()); + creatable = false; queryable = false; controllable = false; diff --git a/source/java/org/alfresco/cmis/dictionary/CMISRelationshipTypeDefinition.java b/source/java/org/alfresco/cmis/dictionary/CMISRelationshipTypeDefinition.java index 2b5c432c0b..1706ba72ec 100644 --- a/source/java/org/alfresco/cmis/dictionary/CMISRelationshipTypeDefinition.java +++ b/source/java/org/alfresco/cmis/dictionary/CMISRelationshipTypeDefinition.java @@ -75,6 +75,9 @@ public class CMISRelationshipTypeDefinition extends CMISAbstractTypeDefinition isPublic = true; this.cmisClassDef = cmisClassDef; objectTypeId = typeId; + + actionEvaluators = cmisMapping.getActionEvaluators(objectTypeId.getScope()); + creatable = false; queryable = false; controllable = false; diff --git a/source/java/org/alfresco/cmis/mapping/AbstractActionEvaluator.java b/source/java/org/alfresco/cmis/mapping/AbstractActionEvaluator.java new file mode 100644 index 0000000000..20256abb7b --- /dev/null +++ b/source/java/org/alfresco/cmis/mapping/AbstractActionEvaluator.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.cmis.mapping; + +import org.alfresco.cmis.CMISActionEvaluator; +import org.alfresco.cmis.CMISAllowedActionEnum; +import org.alfresco.service.ServiceRegistry; + +/** + * Base class for all action evaluators + * + * @author davidc + * + */ +public abstract class AbstractActionEvaluator implements CMISActionEvaluator +{ + private ServiceRegistry serviceRegistry; + private CMISAllowedActionEnum action; + + /** + * Construct + * + * @param serviceRegistry + * @param action + */ + protected AbstractActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action) + { + this.serviceRegistry = serviceRegistry; + this.action = action; + } + + /** + * @return service registry + */ + protected ServiceRegistry getServiceRegistry() + { + return serviceRegistry; + } + + /* + * (non-Javadoc) + * @see org.alfresco.cmis.CMISActionEvaluator#getAction() + */ + public CMISAllowedActionEnum getAction() + { + return action; + } +} diff --git a/source/java/org/alfresco/cmis/mapping/CMISMapping.java b/source/java/org/alfresco/cmis/mapping/CMISMapping.java index 2040b7704f..3b0b87520a 100644 --- a/source/java/org/alfresco/cmis/mapping/CMISMapping.java +++ b/source/java/org/alfresco/cmis/mapping/CMISMapping.java @@ -25,9 +25,13 @@ package org.alfresco.cmis.mapping; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; +import org.alfresco.cmis.CMISActionEvaluator; +import org.alfresco.cmis.CMISAllowedActionEnum; import org.alfresco.cmis.CMISContentStreamAllowedEnum; import org.alfresco.cmis.CMISDataTypeEnum; import org.alfresco.cmis.CMISDictionaryModel; @@ -40,6 +44,7 @@ import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.AspectDefinition; import org.alfresco.service.cmr.dictionary.AssociationDefinition; import org.alfresco.service.cmr.dictionary.DataTypeDefinition; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.namespace.NamespaceException; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; @@ -102,6 +107,7 @@ public class CMISMapping implements InitializingBean private Map mapAlfrescoQNameToCmisQName = new HashMap(); private Map mapAlfrescoToCmisDataType = new HashMap(); private Map propertyAccessors = new HashMap(); + private Map> actionEvaluators = new HashMap>(); /* @@ -110,6 +116,10 @@ public class CMISMapping implements InitializingBean */ public void afterPropertiesSet() throws Exception { + // + // Type Mappings + // + mapAlfrescoQNameToTypeId.put(OBJECT_QNAME, OBJECT_TYPE_ID); mapAlfrescoQNameToTypeId.put(FILESYSTEM_OBJECT_QNAME, FILESYSTEM_OBJECT_TYPE_ID); mapAlfrescoQNameToTypeId.put(DOCUMENT_QNAME, CMISDictionaryModel.DOCUMENT_TYPE_ID); @@ -125,6 +135,10 @@ public class CMISMapping implements InitializingBean mapCmisQNameToAlfrescoQName.put(RELATIONSHIP_QNAME, null); mapCmisQNameToAlfrescoQName.put(POLICY_QNAME, null); + // + // Data Type Mappings + // + mapAlfrescoToCmisDataType.put(DataTypeDefinition.ANY, null); mapAlfrescoToCmisDataType.put(DataTypeDefinition.ASSOC_REF, null); mapAlfrescoToCmisDataType.put(DataTypeDefinition.BOOLEAN, CMISDataTypeEnum.BOOLEAN); @@ -148,6 +162,10 @@ public class CMISMapping implements InitializingBean mapAlfrescoToCmisDataType.put(CMIS_DATATYPE_XML, CMISDataTypeEnum.XML); mapAlfrescoToCmisDataType.put(CMIS_DATATYPE_HTML, CMISDataTypeEnum.HTML); + // + // Property Mappings + // + registerPropertyAccessor(new ObjectIdProperty(serviceRegistry)); registerPropertyAccessor(new FixedValueProperty(serviceRegistry, CMISDictionaryModel.PROP_URI, null)); registerPropertyAccessor(new ObjectTypeIdProperty(serviceRegistry)); @@ -174,9 +192,32 @@ public class CMISMapping implements InitializingBean registerPropertyAccessor(new ContentStreamUriProperty(serviceRegistry)); registerPropertyAccessor(new ParentProperty(serviceRegistry)); registerPropertyAccessor(new FixedValueProperty(serviceRegistry, CMISDictionaryModel.PROP_ALLOWED_CHILD_OBJECT_TYPE_IDS, null)); + + // + // Action Evaluator Mappings + // + + registerActionEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE, PermissionService.DELETE_NODE)); + registerActionEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES)); + registerActionEvaluator(CMISScope.DOCUMENT, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES)); + registerActionEvaluator(CMISScope.DOCUMENT, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_RELATIONSHIPS, true)); + + registerActionEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE, PermissionService.DELETE_NODE)); + registerActionEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, PermissionService.WRITE_PROPERTIES)); + registerActionEvaluator(CMISScope.FOLDER, new PermissionActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, PermissionService.READ_PROPERTIES)); + registerActionEvaluator(CMISScope.FOLDER, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_RELATIONSHIPS, true)); + + registerActionEvaluator(CMISScope.RELATIONSHIP, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE, true)); + registerActionEvaluator(CMISScope.RELATIONSHIP, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, false)); + registerActionEvaluator(CMISScope.RELATIONSHIP, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, false)); + + registerActionEvaluator(CMISScope.POLICY, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_DELETE, false)); + registerActionEvaluator(CMISScope.POLICY, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_UPDATE_PROPERTIES, false)); + registerActionEvaluator(CMISScope.POLICY, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_PROPERTIES, false)); + registerActionEvaluator(CMISScope.POLICY, new FixedValueActionEvaluator(serviceRegistry, CMISAllowedActionEnum.CAN_GET_RELATIONSHIPS, false)); } - + /** * @param serviceRegistry */ @@ -678,4 +719,41 @@ public class CMISMapping implements InitializingBean propertyAccessors.put(propertyAccessor.getName(), propertyAccessor); } + /** + * Gets the Action Evaluators applicable for the given CMIS Scope + * + * @param cmisScope + * @return + */ + public Map getActionEvaluators(CMISScope scope) + { + Map evaluators = actionEvaluators.get(scope); + if (evaluators == null) + { + evaluators = Collections.emptyMap(); + } + return evaluators; + } + + /** + * Register an Action Evaluator + * + * @param scope + * @param evaluator + */ + private void registerActionEvaluator(CMISScope scope, CMISActionEvaluator evaluator) + { + Map evaluators = actionEvaluators.get(scope); + if (evaluators == null) + { + evaluators = new LinkedHashMap(); + actionEvaluators.put(scope, evaluators); + } + if (evaluators.get(evaluator.getAction()) != null) + { + throw new AlfrescoRuntimeException("Already registered Action Evaluator " + evaluator.getAction() + " for scope " + scope); + } + evaluators.put(evaluator.getAction(), evaluator); + } + } diff --git a/source/java/org/alfresco/cmis/mapping/FixedValueActionEvaluator.java b/source/java/org/alfresco/cmis/mapping/FixedValueActionEvaluator.java new file mode 100644 index 0000000000..dcc976bb99 --- /dev/null +++ b/source/java/org/alfresco/cmis/mapping/FixedValueActionEvaluator.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.cmis.mapping; + +import org.alfresco.cmis.CMISAllowedActionEnum; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Alfresco Permission based Action Evaluator + * + * @author davidc + * + */ +public class FixedValueActionEvaluator extends AbstractActionEvaluator +{ + private boolean allowed; + + /** + * Construct + * + * @param serviceRegistry + * @param action + */ + protected FixedValueActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, boolean allowed) + { + super(serviceRegistry, action); + this.allowed = allowed; + } + + /* + * (non-Javadoc) + * @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef) + */ + public boolean isAllowed(NodeRef nodeRef) + { + return allowed; + } +} diff --git a/source/java/org/alfresco/cmis/mapping/PermissionActionEvaluator.java b/source/java/org/alfresco/cmis/mapping/PermissionActionEvaluator.java new file mode 100644 index 0000000000..aaf885e1ad --- /dev/null +++ b/source/java/org/alfresco/cmis/mapping/PermissionActionEvaluator.java @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program 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 General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.cmis.mapping; + +import org.alfresco.cmis.CMISAllowedActionEnum; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; + +/** + * Alfresco Permission based Action Evaluator + * + * @author davidc + * + */ +public class PermissionActionEvaluator extends AbstractActionEvaluator +{ + private String[] permissions; + private PermissionService permissionService; + + /** + * Construct + * + * @param serviceRegistry + * @param permission + */ + protected PermissionActionEvaluator(ServiceRegistry serviceRegistry, CMISAllowedActionEnum action, String... permission) + { + super(serviceRegistry, action); + this.permissions = permission; + this.permissionService = serviceRegistry.getPermissionService(); + } + + /* + * (non-Javadoc) + * @see org.alfresco.cmis.CMISActionEvaluator#isAllowed(org.alfresco.service.cmr.repository.NodeRef) + */ + public boolean isAllowed(NodeRef nodeRef) + { + for (String permission : permissions) + { + if (permissionService.hasPermission(nodeRef, permission) == AccessStatus.DENIED) + { + return false; + } + } + return true; + } +} diff --git a/source/java/org/alfresco/service/cmr/security/PermissionService.java b/source/java/org/alfresco/service/cmr/security/PermissionService.java index 5ac05b33a3..184bbd1550 100644 --- a/source/java/org/alfresco/service/cmr/security/PermissionService.java +++ b/source/java/org/alfresco/service/cmr/security/PermissionService.java @@ -27,13 +27,11 @@ package org.alfresco.service.cmr.security; import java.util.Map; import java.util.Set; -import org.alfresco.repo.security.permissions.PermissionReference; import org.alfresco.service.Auditable; import org.alfresco.service.PublicService; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.StoreRef; import org.alfresco.service.namespace.QName; -import org.apache.axis.wsdl.symbolTable.Parameters; /** * The public API for a permission service The implementation may be changed in the application configuration