From a5fcf3ff1e6fb57d42f96d21a56c2c288e20cc6f Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Fri, 6 Dec 2013 00:35:57 +0000 Subject: [PATCH] RM-1098: RM behvaiour refactoring git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@58640 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org_alfresco_module_rm/module-context.xml | 3 - .../rm-model-context.xml | 4 + .../rm-service-context.xml | 10 +- .../event/OnReferenceCreateEventType.java | 40 ++---- .../event/OnReferencedRecordActionedUpon.java | 37 ++--- .../rma/aspect/ExtendedSecurityAspect.java | 92 +++++++++++++ .../security/ModelSecurityServiceImpl.java | 97 +++++--------- .../security/ExtendedSecurityServiceImpl.java | 126 ++++-------------- 8 files changed, 179 insertions(+), 230 deletions(-) create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/ExtendedSecurityAspect.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml index 68db35dc44..ef3ba4d3ca 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -121,14 +121,12 @@ - - @@ -138,7 +136,6 @@ - diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml index fda6e8263b..afc16a7923 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml @@ -133,6 +133,10 @@ + + + + - @@ -673,12 +671,10 @@ + parent = "rm.baseBehaviour"> - - - - + + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferenceCreateEventType.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferenceCreateEventType.java index c46837f325..3e67c5439a 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferenceCreateEventType.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferenceCreateEventType.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; @@ -32,8 +31,9 @@ import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionAction; import org.alfresco.module.org_alfresco_module_rm.disposition.DispositionService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; -import org.alfresco.repo.policy.JavaBehaviour; -import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.namespace.QName; @@ -43,6 +43,7 @@ import org.alfresco.service.namespace.QName; * * @author Roy Wetherall */ +@BehaviourBean public class OnReferenceCreateEventType extends SimpleRecordsManagementEventTypeImpl implements RecordsManagementModel, OnCreateReference @@ -53,9 +54,6 @@ public class OnReferenceCreateEventType extends SimpleRecordsManagementEventType /** Disposition service */ private DispositionService dispositionService; - /** Policy component */ - private PolicyComponent policyComponent; - /** Reference */ private QName reference; @@ -75,16 +73,6 @@ public class OnReferenceCreateEventType extends SimpleRecordsManagementEventType this.recordsManagementActionService = recordsManagementActionService; } - /** - * Set policy components - * - * @param policyComponent policy component - */ - public void setPolicyComponent(PolicyComponent policyComponent) - { - this.policyComponent = policyComponent; - } - /** * Set the reference * @@ -95,19 +83,6 @@ public class OnReferenceCreateEventType extends SimpleRecordsManagementEventType this.reference = QName.createQName(reference); } - /** - * @see org.alfresco.module.org_alfresco_module_rm.event.SimpleRecordsManagementEventTypeImpl#init() - */ - public void init() - { - super.init(); - - // Register interest in the on create reference policy - policyComponent.bindClassBehaviour(RecordsManagementPolicies.ON_CREATE_REFERENCE, - ASPECT_RECORD, - new JavaBehaviour(this, "onCreateReference", NotificationFrequency.TRANSACTION_COMMIT)); - } - /** * @see org.alfresco.module.org_alfresco_module_rm.event.SimpleRecordsManagementEventTypeImpl#isAutomaticEvent() */ @@ -120,6 +95,13 @@ public class OnReferenceCreateEventType extends SimpleRecordsManagementEventType /** * @see org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies.OnCreateReference#onCreateReference(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) */ + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + type = "rma:record", + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + ) public void onCreateReference(final NodeRef fromNodeRef, final NodeRef toNodeRef, final QName reference) { AuthenticationUtil.RunAsWork work = new AuthenticationUtil.RunAsWork() diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferencedRecordActionedUpon.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferencedRecordActionedUpon.java index 24a5298f32..54a8d3204c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferencedRecordActionedUpon.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/event/OnReferencedRecordActionedUpon.java @@ -24,7 +24,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies; import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementActionService; import org.alfresco.module.org_alfresco_module_rm.action.impl.CompleteEventAction; import org.alfresco.module.org_alfresco_module_rm.admin.RecordsManagementAdminService; @@ -34,8 +33,9 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.recordfolder.RecordFolderService; import org.alfresco.repo.policy.Behaviour.NotificationFrequency; -import org.alfresco.repo.policy.JavaBehaviour; -import org.alfresco.repo.policy.PolicyComponent; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.AssociationRef; import org.alfresco.service.cmr.repository.ChildAssociationRef; @@ -49,6 +49,7 @@ import org.alfresco.service.namespace.RegexQNamePattern; * * @author Roy Wetherall */ +@BehaviourBean public class OnReferencedRecordActionedUpon extends SimpleRecordsManagementEventTypeImpl implements RecordsManagementModel @@ -65,9 +66,6 @@ public class OnReferencedRecordActionedUpon extends SimpleRecordsManagementEvent /** Node service */ private NodeService nodeService; - /** Policy component */ - private PolicyComponent policyComponent; - /** Record service */ private RecordService recordService; @@ -128,14 +126,6 @@ public class OnReferencedRecordActionedUpon extends SimpleRecordsManagementEvent this.recordFolderService = recordFolderService; } - /** - * @param policyComponent policy component - */ - public void setPolicyComponent(PolicyComponent policyComponent) - { - this.policyComponent = policyComponent; - } - /** * @param reference reference name */ @@ -152,19 +142,6 @@ public class OnReferencedRecordActionedUpon extends SimpleRecordsManagementEvent this.actionName = actionName; } - /** - * @see org.alfresco.module.org_alfresco_module_rm.event.SimpleRecordsManagementEventTypeImpl#init() - */ - public void init() - { - super.init(); - - // Register interest in the on create reference policy - policyComponent.bindClassBehaviour(RecordsManagementPolicies.BEFORE_RM_ACTION_EXECUTION, - ASPECT_FILE_PLAN_COMPONENT, - new JavaBehaviour(this, "beforeActionExecution", NotificationFrequency.FIRST_EVENT)); - } - /** * @see org.alfresco.module.org_alfresco_module_rm.event.SimpleRecordsManagementEventTypeImpl#isAutomaticEvent() */ @@ -181,6 +158,12 @@ public class OnReferencedRecordActionedUpon extends SimpleRecordsManagementEvent * @param name * @param parameters */ + @Behaviour + ( + kind = BehaviourKind.CLASS, + type = "rma:filePlanComponent", + notificationFrequency = NotificationFrequency.FIRST_EVENT + ) public void beforeActionExecution(final NodeRef nodeRef, final String name, final Map parameters) { AuthenticationUtil.RunAsWork work = new AuthenticationUtil.RunAsWork() diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/ExtendedSecurityAspect.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/ExtendedSecurityAspect.java new file mode 100644 index 0000000000..deb84acf42 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/ExtendedSecurityAspect.java @@ -0,0 +1,92 @@ +/* + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect; + +import java.util.Set; + +import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean; +import org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService; +import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.ChildAssociationRef; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * rma:extendedSecurity behaviour bean + * + * @author Roy Wetherall + * @since 2.2 + */ +@BehaviourBean +( + defaultType = "rma:extendedSecurity" +) +public class ExtendedSecurityAspect extends BaseBehaviourBean + implements NodeServicePolicies.OnMoveNodePolicy +{ + /** extended security service */ + protected ExtendedSecurityService extendedSecurityService; + + /** + * @param extendedSecurityService extended security service + */ + public void setExtendedSecurityService(ExtendedSecurityService extendedSecurityService) + { + this.extendedSecurityService = extendedSecurityService; + } + + /** + * Update extended security when moving a node. + * + * @see org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy#onMoveNode(org.alfresco.service.cmr.repository.ChildAssociationRef, org.alfresco.service.cmr.repository.ChildAssociationRef) + */ + @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + notificationFrequency = NotificationFrequency.TRANSACTION_COMMIT + ) + public void onMoveNode(final ChildAssociationRef origAssoc, final ChildAssociationRef newAssoc) + { + AuthenticationUtil.runAsSystem(new RunAsWork() + { + @Override + public Void doWork() throws Exception + { + NodeRef record = newAssoc.getChildRef(); + NodeRef newParent = newAssoc.getParentRef(); + NodeRef oldParent = origAssoc.getParentRef(); + + Set readers = extendedSecurityService.getExtendedReaders(record); + Set writers = extendedSecurityService.getExtendedWriters(record); + + extendedSecurityService.addExtendedSecurity(newParent, readers, writers); + extendedSecurityService.removeExtendedSecurity(oldParent, readers, writers); + + return null; + } + }); + } + +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/security/ModelSecurityServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/security/ModelSecurityServiceImpl.java index 153552f397..019470ead5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/security/ModelSecurityServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/model/security/ModelSecurityServiceImpl.java @@ -26,14 +26,13 @@ import java.util.Set; import org.alfresco.module.org_alfresco_module_rm.capability.Capability; 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.model.BaseBehaviourBean; import org.alfresco.repo.node.NodeServicePolicies; -import org.alfresco.repo.policy.JavaBehaviour; -import org.alfresco.repo.policy.PolicyComponent; -import org.alfresco.repo.policy.Behaviour.NotificationFrequency; +import org.alfresco.repo.policy.annotation.Behaviour; +import org.alfresco.repo.policy.annotation.BehaviourBean; +import org.alfresco.repo.policy.annotation.BehaviourKind; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.service.cmr.repository.NodeRef; -import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; @@ -48,8 +47,9 @@ import org.alfresco.util.EqualsHelper; * @author Roy Wetherall * @since 2.1 */ -public class ModelSecurityServiceImpl implements ModelSecurityService, - RecordsManagementModel, +@BehaviourBean +public class ModelSecurityServiceImpl extends BaseBehaviourBean + implements ModelSecurityService, NodeServicePolicies.BeforeAddAspectPolicy, NodeServicePolicies.BeforeRemoveAspectPolicy, NodeServicePolicies.OnUpdatePropertiesPolicy @@ -57,12 +57,6 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, /** Indicates whether model security is enabled or not */ private boolean enabled = true; - /** Policy component */ - private PolicyComponent policyComponent; - - /** Node service */ - private NodeService nodeService; - /** Namespace service */ private NamespaceService namespaceService; @@ -75,17 +69,6 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, /** Map of protected aspects keyed by name */ private Map protectedAspects= new HashMap(21); - /** Behaviour instances */ - private JavaBehaviour beforeAddAspectBehaviour = new JavaBehaviour(this, - "beforeAddAspect", - NotificationFrequency.EVERY_EVENT); - private JavaBehaviour beforeRemoveAspectBehaviour = new JavaBehaviour(this, - "beforeRemoveAspect", - NotificationFrequency.EVERY_EVENT); - private JavaBehaviour onUpdatePropertiesBehaviour = new JavaBehaviour(this, - "onUpdateProperties", - NotificationFrequency.EVERY_EVENT); - /** * @see org.alfresco.module.org_alfresco_module_rm.model.security.ModelSecurityService#setEnabled(boolean) */ @@ -102,22 +85,6 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, return enabled; } - /** - * @param policyComponent policy component - */ - public void setPolicyComponent(PolicyComponent policyComponent) - { - this.policyComponent = policyComponent; - } - - /** - * @param nodeService node service - */ - public void setNodeService(NodeService nodeService) - { - this.nodeService = nodeService; - } - /** * @param namespaceService namespace service */ @@ -133,26 +100,6 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, { this.filePlanService = filePlanService; } - - /** - * Init method - */ - public void init() - { - // bind model security behaviours to all records management artifacts components - policyComponent.bindClassBehaviour( - NodeServicePolicies.BeforeAddAspectPolicy.QNAME, - this, - beforeAddAspectBehaviour); - policyComponent.bindClassBehaviour( - NodeServicePolicies.BeforeRemoveAspectPolicy.QNAME, - this, - beforeRemoveAspectBehaviour); - policyComponent.bindClassBehaviour( - NodeServicePolicies.OnUpdatePropertiesPolicy.QNAME, - this, - onUpdatePropertiesBehaviour); - } /** * @see org.alfresco.module.org_alfresco_module_rm.model.security.ModelSecurityService#disable() @@ -160,9 +107,9 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, @Override public void disable() { - beforeAddAspectBehaviour.disable(); - beforeRemoveAspectBehaviour.disable(); - onUpdatePropertiesBehaviour.disable(); + getBehaviour("beforeAddAspect").disable(); + getBehaviour("beforeRemoveAspect").disable(); + getBehaviour("onUpdateProperties").disable(); } /** @@ -171,9 +118,9 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, @Override public void enable() { - beforeAddAspectBehaviour.enable(); - beforeRemoveAspectBehaviour.enable(); - onUpdatePropertiesBehaviour.enable(); + getBehaviour("beforeAddAspect").enable(); + getBehaviour("beforeRemoveAspect").enable(); + getBehaviour("onUpdateProperties").enable(); } /** @@ -322,6 +269,12 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, * @see org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy#beforeAddAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) */ @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + isService = true, + name = "beforeAddAspect" + ) public void beforeAddAspect(NodeRef nodeRef, QName aspect) { if (enabled == true) @@ -345,6 +298,12 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, * @see org.alfresco.repo.node.NodeServicePolicies.BeforeRemoveAspectPolicy#beforeRemoveAspect(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.namespace.QName) */ @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + isService = true, + name = "beforeRemoveAspect" + ) public void beforeRemoveAspect(NodeRef nodeRef, QName aspect) { if (enabled == true) @@ -368,6 +327,12 @@ public class ModelSecurityServiceImpl implements ModelSecurityService, * @see org.alfresco.repo.node.NodeServicePolicies.OnUpdatePropertiesPolicy#onUpdateProperties(org.alfresco.service.cmr.repository.NodeRef, java.util.Map, java.util.Map) */ @Override + @Behaviour + ( + kind = BehaviourKind.CLASS, + isService = true, + name = "onUpdateProperties" + ) public void onUpdateProperties(NodeRef nodeRef, Map before, Map after) { if (enabled == true) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/ExtendedSecurityServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/ExtendedSecurityServiceImpl.java index a4f681db98..77cc58dc5f 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/ExtendedSecurityServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/ExtendedSecurityServiceImpl.java @@ -30,12 +30,6 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.role.FilePlanRoleService; import org.alfresco.module.org_alfresco_module_rm.util.ServiceBaseImpl; -import org.alfresco.repo.node.NodeServicePolicies; -import org.alfresco.repo.policy.JavaBehaviour; -import org.alfresco.repo.policy.PolicyComponent; -import org.alfresco.repo.policy.Behaviour.NotificationFrequency; -import org.alfresco.repo.security.authentication.AuthenticationUtil; -import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.service.cmr.repository.ChildAssociationRef; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.security.PermissionService; @@ -51,16 +45,12 @@ import org.alfresco.util.ParameterCheck; */ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl implements ExtendedSecurityService, - RecordsManagementModel, - NodeServicePolicies.OnMoveNodePolicy + RecordsManagementModel { /** Ad hoc properties used for reference counting */ private final static QName PROP_EXTENDED_READER_ROLE = QName.createQName(RM_URI, "extendedReaderRole"); private final static QName PROP_EXTENDED_WRITER_ROLE = QName.createQName(RM_URI, "extendedWriterRole"); - /** Policy component */ - private PolicyComponent policyComponent; - /** Record service */ private RecordService recordService; @@ -70,14 +60,6 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl /** File plan role service */ private FilePlanRoleService filePlanRoleService; - /** - * @param policyComponent policy component - */ - public void setPolicyComponent(PolicyComponent policyComponent) - { - this.policyComponent = policyComponent; - } - /** * @param recordService record service */ @@ -102,17 +84,6 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl this.filePlanRoleService = filePlanRoleService; } - /** - * Init method - */ - public void init() - { - policyComponent.bindClassBehaviour( - NodeServicePolicies.OnMoveNodePolicy.QNAME, - ASPECT_EXTENDED_SECURITY, - new JavaBehaviour(this, "onMoveNode", NotificationFrequency.TRANSACTION_COMMIT)); - } - /** * @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#hasExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef) */ @@ -181,6 +152,14 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl } } + /** + * Add extended security implementation method + * + * @param nodeRef + * @param readers + * @param writers + * @param applyToParents + */ @SuppressWarnings("unchecked") private void addExtendedSecurityImpl(NodeRef nodeRef, Set readers, Set writers, boolean applyToParents) { @@ -288,47 +267,6 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl } } -// private void removeExtendedSecurityRoles(NodeRef nodeRef, Set readers, Set writers) -// { -// NodeRef filePlan = filePlanService.getFilePlan(nodeRef); -// -// removeExtendedSecurityRolesImpl(filePlan, readers, PROP_EXTENDED_READER_ROLE, FilePlanRoleService.ROLE_EXTENDED_READERS); -// removeExtendedSecurityRolesImpl(filePlan, writers, PROP_EXTENDED_WRITER_ROLE, FilePlanRoleService.ROLE_EXTENDED_WRITERS); -// } -// -// private void removeExtendedSecurityRolesImpl(NodeRef filePlan, Set authorities, QName propertyName, String roleName) -// { -// if (authorities != null) -// { -// // get the reference count -// Map referenceCountMap = (Map)nodeService.getProperty(filePlan, propertyName); -// -// for (String authority : authorities) -// { -// if (authority.equals(PermissionService.ALL_AUTHORITIES) == false) -// { -// if (referenceCountMap == null) -// { -// // remove the authority from the role -// filePlanRoleService.unassignRoleFromAuthority(filePlan, roleName, authority); -// } -// else -// { -// Integer count = referenceCountMap.get(authority); -// if (count == null || count == 1) -// { -// // remove the authority from the role -// filePlanRoleService.unassignRoleFromAuthority(filePlan, roleName, authority); -// } -// } -// } -// } -// -// // update the reference count -// nodeService.setProperty(filePlan, propertyName, (Serializable)removeFromMap(referenceCountMap, authorities)); -// } -// } - /** * * @param map @@ -364,13 +302,18 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl return map; } - + /** + * @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set) + */ @Override public void removeExtendedSecurity(NodeRef nodeRef, Set readers, Set writers) { removeExtendedSecurity(nodeRef, readers, writers, true); } + /** + * @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, java.util.Set, java.util.Set, boolean) + */ @Override public void removeExtendedSecurity(NodeRef nodeRef, Set readers, Setwriters, boolean applyToParents) { @@ -428,6 +371,13 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl } } + /** + * Helper method to remove items from map or reduce reference count + * + * @param map ref count map + * @param keys keys + * @return Map ref count map + */ private Map removeFromMap(Map map, Set keys) { if (map != null && keys != null && keys.size() != 0) @@ -464,12 +414,18 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl return map; } + /** + * @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeAllExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef) + */ @Override public void removeAllExtendedSecurity(NodeRef nodeRef) { removeAllExtendedSecurity(nodeRef, true); } + /** + * @see org.alfresco.module.org_alfresco_module_rm.security.ExtendedSecurityService#removeAllExtendedSecurity(org.alfresco.service.cmr.repository.NodeRef, boolean) + */ @Override public void removeAllExtendedSecurity(NodeRef nodeRef, boolean applyToParents) { @@ -478,30 +434,4 @@ public class ExtendedSecurityServiceImpl extends ServiceBaseImpl removeExtendedSecurity(nodeRef, getExtendedReaders(nodeRef), getExtendedWriters(nodeRef)); } } - - /** - * @see org.alfresco.repo.node.NodeServicePolicies.OnMoveNodePolicy#onMoveNode(org.alfresco.service.cmr.repository.ChildAssociationRef, org.alfresco.service.cmr.repository.ChildAssociationRef) - */ - @Override - public void onMoveNode(final ChildAssociationRef origAssoc, final ChildAssociationRef newAssoc) - { - AuthenticationUtil.runAsSystem(new RunAsWork() - { - @Override - public Void doWork() throws Exception - { - NodeRef record = newAssoc.getChildRef(); - NodeRef newParent = newAssoc.getParentRef(); - NodeRef oldParent = origAssoc.getParentRef(); - - Set readers = getExtendedReaders(record); - Set writers = getExtendedWriters(record); - - addExtendedSecurity(newParent, readers, writers); - removeExtendedSecurity(oldParent, readers, writers); - - return null; - } - }); - } }