From 66a82b57816e6edbe144d54f94a2180e280254c1 Mon Sep 17 00:00:00 2001 From: Britt Park Date: Sat, 15 Sep 2007 10:09:28 +0000 Subject: [PATCH] Should fix failing tests. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6792 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/simple/permission/ACLImpl.java | 26 +++++-- .../AuthorityCapabilityRegistryImpl.java | 68 +++++++++++++++++-- .../AuthorityCapabilityRegistry.java | 7 ++ 3 files changed, 93 insertions(+), 8 deletions(-) diff --git a/source/java/org/alfresco/repo/simple/permission/ACLImpl.java b/source/java/org/alfresco/repo/simple/permission/ACLImpl.java index ca51b5ba37..6b904fc32f 100644 --- a/source/java/org/alfresco/repo/simple/permission/ACLImpl.java +++ b/source/java/org/alfresco/repo/simple/permission/ACLImpl.java @@ -25,8 +25,10 @@ package org.alfresco.repo.simple.permission; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -102,12 +104,18 @@ public class ACLImpl implements ACL */ public void allow(String capability, String... authorities) { + capability = capability.toLowerCase(); + List auths = new ArrayList(); + for (String auth : authorities) + { + auths.add(fCapabilityRegistry.normalizeAuthority(auth)); + } digest(); // First remove any explicit denies. Set denied = fDenied.get(capability); if (denied != null) { - for (String authority : authorities) + for (String authority : auths) { denied.remove(authority); } @@ -119,7 +127,7 @@ public class ACLImpl implements ACL allowed = new HashSet(); fAllowed.put(capability, allowed); } - for (String authority : authorities) + for (String authority : auths) { allowed.add(authority); } @@ -181,6 +189,8 @@ public class ACLImpl implements ACL */ public boolean can(String authority, boolean isOwner, String capability) { + authority = fCapabilityRegistry.normalizeAuthority(authority); + capability = capability.toLowerCase(); digest(); AuthorityType type = AuthorityType.getAuthorityType(authority); // Admin trumps. @@ -228,12 +238,18 @@ public class ACLImpl implements ACL */ public void deny(String capability, String ... authorities) { + capability = capability.toLowerCase(); + List auths = new ArrayList(); + for (String auth : authorities) + { + auths.add(fCapabilityRegistry.normalizeAuthority(auth)); + } digest(); // Remove corresponding explicit allows. Set allowed = fAllowed.get(capability); if (allowed != null) { - for (String authority : authorities) + for (String authority : auths) { allowed.remove(authority); } @@ -245,7 +261,7 @@ public class ACLImpl implements ACL denied = new HashSet(); fDenied.put(capability, denied); } - for (String authority : authorities) + for (String authority : auths) { if (AuthorityType.getAuthorityType(authority) == AuthorityType.ADMIN) { @@ -260,6 +276,7 @@ public class ACLImpl implements ACL */ public Set getAllowed(String capability) { + capability = capability.toLowerCase(); digest(); Set allowed = new HashSet(); allowed.add(AuthorityType.ADMIN.getFixedString()); @@ -294,6 +311,7 @@ public class ACLImpl implements ACL */ public Set getCapabilities(String authority, boolean isOwner) { + authority = fCapabilityRegistry.normalizeAuthority(authority); digest(); AuthorityType type = AuthorityType.getAuthorityType(authority); if (type == AuthorityType.ADMIN) diff --git a/source/java/org/alfresco/repo/simple/permission/AuthorityCapabilityRegistryImpl.java b/source/java/org/alfresco/repo/simple/permission/AuthorityCapabilityRegistryImpl.java index fd09dac9a3..6b7b1d8ebf 100644 --- a/source/java/org/alfresco/repo/simple/permission/AuthorityCapabilityRegistryImpl.java +++ b/source/java/org/alfresco/repo/simple/permission/AuthorityCapabilityRegistryImpl.java @@ -36,6 +36,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.TransactionListener; import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityType; +import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.simple.permission.AuthorityCapabilityRegistry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -124,11 +125,13 @@ public class AuthorityCapabilityRegistryImpl implements List entries = fCapabilityEntryDAO.getAll(); for (CapabilityEntry entry : entries) { - fCapabilityToID.put(entry.getName(), entry.getId()); - fIDToCapability.put(entry.getId(), entry.getName()); + String capability = entry.getName().toLowerCase(); + fCapabilityToID.put(capability, entry.getId()); + fIDToCapability.put(entry.getId(), capability); } for (String entry : fInitialCapabilities) { + entry = entry.toLowerCase(); if (!fCapabilityToID.containsKey(entry)) { CapabilityEntry newEntry = new CapabilityEntryImpl(entry); @@ -140,13 +143,13 @@ public class AuthorityCapabilityRegistryImpl implements List authorities = fAuthorityEntryDAO.get(); for (AuthorityEntry entry : authorities) { - String name = entry.getName(); + String name = normalizeAuthority(entry.getName()); Integer id = entry.getId(); fAuthorityToID.put(name, id); fIDToAuthority.put(id, name); for (AuthorityEntry child : entry.getChildren()) { - String childName = child.getName(); + String childName = normalizeAuthority(child.getName()); Set children = fAuthorityToChild.get(name); if (children == null) { @@ -170,6 +173,7 @@ public class AuthorityCapabilityRegistryImpl implements Set auths = fAuthorityService.getAllAuthorities(type); for (String auth : auths) { + auth = normalizeAuthority(auth); if (fAuthorityToID.containsKey(auth)) { continue; @@ -191,6 +195,7 @@ public class AuthorityCapabilityRegistryImpl implements { continue; } + auth = normalizeAuthority(auth); Set children = fAuthorityService.getContainedAuthorities(null, auth, true); Set found = fAuthorityToChild.get(auth); if (found == null) @@ -201,6 +206,7 @@ public class AuthorityCapabilityRegistryImpl implements AuthorityEntry entry = fAuthorityEntryDAO.get(fAuthorityToID.get(auth)); for (String child : children) { + child = normalizeAuthority(child); if (found.contains(child)) { continue; @@ -225,6 +231,8 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized void addAuthority(String authority, String parent) { + authority = normalizeAuthority(authority); + parent = normalizeAuthority(parent); AlfrescoTransactionSupport.bindListener(this); AuthorityEntry entry = null; if (!fAuthorityToID.containsKey(authority)) @@ -271,11 +279,56 @@ public class AuthorityCapabilityRegistryImpl implements } } + /** + * Get case normalized authority. + */ + public String normalizeAuthority(String authority) + { + if (authority == null) + { + return null; + } + AuthorityType type = AuthorityType.getAuthorityType(authority); + switch (type) + { + case ADMIN : + { + return authority; + } + case EVERYONE : + { + return PermissionService.ALL_AUTHORITIES; + } + case GROUP : + { + return PermissionService.GROUP_PREFIX + authority.substring(PermissionService.GROUP_PREFIX.length()).toLowerCase(); + } + case USER : + case GUEST : + { + return authority.toLowerCase(); + } + case OWNER : + { + return PermissionService.OWNER_AUTHORITY; + } + case ROLE : + { + return PermissionService.ROLE_PREFIX + authority.substring(PermissionService.ROLE_PREFIX.length()).toLowerCase(); + } + default : + { + return null; + } + } + } + /* (non-Javadoc) * @see org.alfresco.service.simple.permission.AuthorityCapabilityRegistry#removeAuthority(java.lang.String) */ public synchronized void removeAuthority(String authority) { + authority = normalizeAuthority(authority); AlfrescoTransactionSupport.bindListener(this); Integer id = fAuthorityToID.get(authority); if (id == null) @@ -312,6 +365,8 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized void removeAuthorityChild(String parent, String child) { + parent = normalizeAuthority(parent); + child = normalizeAuthority(child); AlfrescoTransactionSupport.bindListener(this); Integer id = fAuthorityToID.get(child); if (id == null) @@ -335,6 +390,7 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized void addCapability(String capability) { + capability = capability.toLowerCase(); AlfrescoTransactionSupport.bindListener(this); CapabilityEntry entry = fCapabilityEntryDAO.get(capability); if (entry != null) @@ -369,6 +425,7 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized int getAuthorityID(String authority) { + authority = normalizeAuthority(authority); Integer id = fAuthorityToID.get(authority); if (id == null) { @@ -390,6 +447,7 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized int getCapabilityID(String capability) { + capability = capability.toLowerCase(); Integer id = fCapabilityToID.get(capability); if (id == null) { @@ -411,6 +469,7 @@ public class AuthorityCapabilityRegistryImpl implements */ public synchronized Set getContainedAuthorities(String authority) { + authority = normalizeAuthority(authority); Set contained = new HashSet(); contained.add(authority); int count = 1; @@ -439,6 +498,7 @@ public class AuthorityCapabilityRegistryImpl implements */ public Set getContainerAuthorities(String authority) { + authority = normalizeAuthority(authority); Set containers = new HashSet(); containers.add(authority); int count = 1; diff --git a/source/java/org/alfresco/service/simple/permission/AuthorityCapabilityRegistry.java b/source/java/org/alfresco/service/simple/permission/AuthorityCapabilityRegistry.java index bcf02612d1..d262011759 100644 --- a/source/java/org/alfresco/service/simple/permission/AuthorityCapabilityRegistry.java +++ b/source/java/org/alfresco/service/simple/permission/AuthorityCapabilityRegistry.java @@ -111,4 +111,11 @@ public interface AuthorityCapabilityRegistry * @return The container authorities. */ public Set getContainerAuthorities(String authority); + + /** + * Get the case normalized version of authority. + * @param authority The authority. + * @return The case normalized version. + */ + public String normalizeAuthority(String authority); }