mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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<QName, QName> mapAlfrescoQNameToCmisQName = new HashMap<QName, QName>();
|
||||
private Map<QName, CMISDataTypeEnum> mapAlfrescoToCmisDataType = new HashMap<QName, CMISDataTypeEnum>();
|
||||
private Map<String, AbstractProperty> propertyAccessors = new HashMap<String, AbstractProperty>();
|
||||
private Map<CMISScope, Map<CMISAllowedActionEnum, CMISActionEvaluator>> actionEvaluators = new HashMap<CMISScope, Map<CMISAllowedActionEnum, CMISActionEvaluator>>();
|
||||
|
||||
|
||||
/*
|
||||
@@ -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<CMISAllowedActionEnum, CMISActionEvaluator> getActionEvaluators(CMISScope scope)
|
||||
{
|
||||
Map<CMISAllowedActionEnum, CMISActionEvaluator> 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<CMISAllowedActionEnum, CMISActionEvaluator> evaluators = actionEvaluators.get(scope);
|
||||
if (evaluators == null)
|
||||
{
|
||||
evaluators = new LinkedHashMap<CMISAllowedActionEnum, CMISActionEvaluator>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user