From 7038f07076840844c9ecf68c5b0053db79b1effc Mon Sep 17 00:00:00 2001 From: Andrew Hind Date: Tue, 23 Jun 2009 13:39:55 +0000 Subject: [PATCH] Fix for MOB-1029: Read operations for zones should not create zones git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14859 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../public-services-security-context.xml | 1 + .../repo/security/authority/AuthorityDAO.java | 9 +++++ .../security/authority/AuthorityDAOImpl.java | 34 +++++++++++++++---- .../authority/AuthorityServiceImpl.java | 5 +++ .../authority/SimpleAuthorityServiceImpl.java | 5 +++ .../cmr/security/AuthorityService.java | 10 ++++++ 6 files changed, 57 insertions(+), 7 deletions(-) diff --git a/config/alfresco/public-services-security-context.xml b/config/alfresco/public-services-security-context.xml index 77a7115472..b2e684b0da 100644 --- a/config/alfresco/public-services-security-context.xml +++ b/config/alfresco/public-services-security-context.xml @@ -710,6 +710,7 @@ org.alfresco.service.cmr.security.AuthorityService.setAuthorityDisplayName=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getAuthorityDisplayName=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getOrCreateZone=ACL_METHOD.ROLE_ADMINISTRATOR + org.alfresco.service.cmr.security.AuthorityService.getZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthorityZones=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllAuthoritiesInZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthoritiesInZone=ACL_ALLOW diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java index 8102782664..37ea38488c 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java @@ -159,6 +159,15 @@ public interface AuthorityDAO */ public NodeRef getOrCreateZone(String zoneName); + /** + * Gets an authority zone node with the specified name + * + * @param zoneName + * the zone name + * @return reference to the zone node ot null if the zone does not exists + */ + public NodeRef getZone(String zoneName); + /** * Gets the name of the zone containing the specified authority. * diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index a818e2b8fa..644c027415 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -224,7 +224,7 @@ public class AuthorityDAOImpl implements AuthorityDAO { for (String zone : zones) { - NodeRef container = getOrCreateZone(zone); + NodeRef container = getZone(zone); if (container != null) { if (container != null) @@ -500,15 +500,27 @@ public class AuthorityDAOImpl implements AuthorityDAO } public NodeRef getOrCreateZone(String zoneName) + { + return getOrCreateZone(zoneName, true); + } + + private NodeRef getOrCreateZone(String zoneName, boolean create) { NodeRef zoneContainerRef = getZoneContainer(); QName zoneQName = QName.createQName("cm", zoneName, namespacePrefixResolver); List results = nodeService.getChildAssocs(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName); if (results.isEmpty()) { - HashMap props = new HashMap(); - props.put(ContentModel.PROP_NAME, zoneName); - return nodeService.createNode(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName, ContentModel.TYPE_ZONE, props).getChildRef(); + if (create) + { + HashMap props = new HashMap(); + props.put(ContentModel.PROP_NAME, zoneName); + return nodeService.createNode(zoneContainerRef, ContentModel.ASSOC_CHILDREN, zoneQName, ContentModel.TYPE_ZONE, props).getChildRef(); + } + else + { + return null; + } } else { @@ -516,6 +528,11 @@ public class AuthorityDAOImpl implements AuthorityDAO } } + public NodeRef getZone(String zoneName) + { + return getOrCreateZone(zoneName, false); + } + public Set getAuthorityZones(String name) { HashSet zones = new HashSet(); @@ -550,10 +567,13 @@ public class AuthorityDAOImpl implements AuthorityDAO public Set getAllAuthoritiesInZone(String zoneName, AuthorityType type) { HashSet authorities = new HashSet(); - NodeRef zoneRef = getOrCreateZone(zoneName); - for (ChildAssociationRef childRef : nodeService.getChildAssocs(zoneRef)) + NodeRef zoneRef = getZone(zoneName); + if (zoneRef != null) { - addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null); + for (ChildAssociationRef childRef : nodeService.getChildAssocs(zoneRef)) + { + addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null); + } } return authorities; } diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java index a85c3d850b..dd8dc9c8f1 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -397,6 +397,11 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean { return authorityDAO.getOrCreateZone(zoneName); } + + public NodeRef getZone(String zoneName) + { + return authorityDAO.getZone(zoneName); + } public Set getAllAuthoritiesInZone(String zoneName, AuthorityType type) { diff --git a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java index 6359065836..d1573bb42d 100644 --- a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java +++ b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java @@ -340,4 +340,9 @@ public class SimpleAuthorityServiceImpl implements AuthorityService { return Collections.emptySet(); } + + public NodeRef getZone(String zoneName) + { + return null; + } } diff --git a/source/java/org/alfresco/service/cmr/security/AuthorityService.java b/source/java/org/alfresco/service/cmr/security/AuthorityService.java index 9e9d058948..2653739924 100644 --- a/source/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/source/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -322,6 +322,16 @@ public interface AuthorityService @Auditable(parameters = {"zoneName"}) public NodeRef getOrCreateZone(String zoneName); + /** + * Gets an authority zone node with the specified name + * + * @param zoneName + * the zone name + * @return reference to the zone node or null + */ + @Auditable(parameters = {"zoneName"}) + public NodeRef getZone(String zoneName); + /** * Gets the name of the zone containing the specified authority. *