mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Big honkin' merge from head. Sheesh!
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@3617 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -61,7 +61,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
|
||||
private DictionaryService dictionaryService;
|
||||
|
||||
private SimpleCache<String, ArrayList<NodeRef>> userToAuthorityCache;
|
||||
private SimpleCache<String, HashSet<String>> userToAuthorityCache;
|
||||
|
||||
public AuthorityDAOImpl()
|
||||
{
|
||||
@@ -90,7 +90,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
public void setUserToAuthorityCache(SimpleCache<String, ArrayList<NodeRef>> userToAuthorityCache)
|
||||
public void setUserToAuthorityCache(SimpleCache<String, HashSet<String>> userToAuthorityCache)
|
||||
{
|
||||
this.userToAuthorityCache = userToAuthorityCache;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
nodeService.setProperty(parentRef, ContentModel.PROP_MEMBERS, members);
|
||||
userToAuthorityCache.remove(childName);
|
||||
}
|
||||
else
|
||||
else if (AuthorityType.getAuthorityType(childName).equals(AuthorityType.GROUP))
|
||||
{
|
||||
NodeRef childRef = getAuthorityOrNull(childName);
|
||||
if (childRef == null)
|
||||
@@ -127,6 +127,11 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
}
|
||||
nodeService.addChild(parentRef, childRef, ContentModel.ASSOC_MEMBER, QName.createQName("usr", childName,
|
||||
namespacePrefixResolver));
|
||||
userToAuthorityCache.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Authorities of the type "+AuthorityType.getAuthorityType(childName)+" may not be added to other authorities");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -161,7 +166,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
throw new UnknownAuthorityException("An authority was not found for " + name);
|
||||
}
|
||||
nodeService.deleteNode(nodeRef);
|
||||
|
||||
userToAuthorityCache.clear();
|
||||
}
|
||||
|
||||
public Set<String> getAllRootAuthorities(AuthorityType type)
|
||||
@@ -230,15 +235,31 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
throw new UnknownAuthorityException("An authority was not found for " + childName);
|
||||
}
|
||||
nodeService.removeChild(parentRef, childRef);
|
||||
userToAuthorityCache.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Set<String> getContainingAuthorities(AuthorityType type, String name, boolean immediate)
|
||||
{
|
||||
HashSet<String> authorities = new HashSet<String>();
|
||||
findAuthorities(type, name, authorities, true, !immediate);
|
||||
return authorities;
|
||||
if (AuthorityType.getAuthorityType(name).equals(AuthorityType.USER) && ! immediate && (type == null))
|
||||
{
|
||||
// Cache user to authority look ups
|
||||
HashSet<String> authorities = userToAuthorityCache.get(name);
|
||||
if(authorities == null)
|
||||
{
|
||||
authorities = new HashSet<String>();
|
||||
findAuthorities(type, name, authorities, true, !immediate);
|
||||
userToAuthorityCache.put(name, authorities);
|
||||
}
|
||||
return authorities;
|
||||
}
|
||||
else
|
||||
{
|
||||
HashSet<String> authorities = new HashSet<String>();
|
||||
findAuthorities(type, name, authorities, true, !immediate);
|
||||
return authorities;
|
||||
}
|
||||
}
|
||||
|
||||
private void findAuthorities(AuthorityType type, String name, Set<String> authorities, boolean parents,
|
||||
@@ -272,12 +293,7 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
|
||||
private ArrayList<NodeRef> getUserContainers(String name)
|
||||
{
|
||||
ArrayList<NodeRef> containers = userToAuthorityCache.get(name);
|
||||
if (containers == null)
|
||||
{
|
||||
containers = findUserContainers(name);
|
||||
userToAuthorityCache.put(name, containers);
|
||||
}
|
||||
ArrayList<NodeRef> containers = findUserContainers(name);
|
||||
return containers;
|
||||
}
|
||||
|
||||
|
@@ -156,6 +156,13 @@ public class AuthorityServiceImpl implements AuthorityService
|
||||
|
||||
public void addAuthority(String parentName, String childName)
|
||||
{
|
||||
if (AuthorityType.getAuthorityType(childName).equals(AuthorityType.USER))
|
||||
{
|
||||
if(!personService.personExists(childName))
|
||||
{
|
||||
throw new AuthorityException("The person "+childName+" does not exist and can not be added to a group");
|
||||
}
|
||||
}
|
||||
authorityDAO.addAuthority(parentName, childName);
|
||||
}
|
||||
|
||||
|
@@ -310,6 +310,8 @@ public class AuthorityServiceTest extends TestCase
|
||||
|
||||
public void testCreateAuthTree()
|
||||
{
|
||||
personService.getPerson("andy");
|
||||
|
||||
String auth1;
|
||||
String auth2;
|
||||
String auth3;
|
||||
@@ -339,12 +341,12 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
pubAuthorityService.addAuthority(auth5, "andy");
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
|
||||
@@ -362,7 +364,7 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(0, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertEquals(1, pubAuthorityService.getContainingAuthorities(null, auth5, false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, auth5, false).contains(auth2));
|
||||
@@ -375,6 +377,8 @@ public class AuthorityServiceTest extends TestCase
|
||||
|
||||
public void testCreateAuthNet()
|
||||
{
|
||||
personService.getPerson("andy");
|
||||
|
||||
String auth1;
|
||||
String auth2;
|
||||
String auth3;
|
||||
@@ -399,14 +403,14 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
pubAuthorityService.addAuthority(auth5, "andy");
|
||||
pubAuthorityService.addAuthority(auth1, "andy");
|
||||
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
|
||||
@@ -425,7 +429,7 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(2, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
|
||||
@@ -440,6 +444,8 @@ public class AuthorityServiceTest extends TestCase
|
||||
|
||||
public void testCreateAuthNet2()
|
||||
{
|
||||
personService.getPerson("andy");
|
||||
|
||||
String auth1;
|
||||
String auth2;
|
||||
String auth3;
|
||||
@@ -464,14 +470,14 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
pubAuthorityService.addAuthority(auth5, "andy");
|
||||
pubAuthorityService.addAuthority(auth1, "andy");
|
||||
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
|
||||
@@ -491,7 +497,7 @@ public class AuthorityServiceTest extends TestCase
|
||||
assertEquals(5, pubAuthorityService.getAllAuthorities(AuthorityType.GROUP).size());
|
||||
assertEquals(2, pubAuthorityService.getAllRootAuthorities(AuthorityType.GROUP).size());
|
||||
// The next call looks for people not users :-)
|
||||
assertEquals(2, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(3, pubAuthorityService.getAllAuthorities(AuthorityType.USER).size());
|
||||
assertEquals(4, pubAuthorityService.getContainingAuthorities(null, "andy", false).size());
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth5));
|
||||
assertTrue(pubAuthorityService.getContainingAuthorities(null, "andy", false).contains(auth2));
|
||||
|
@@ -26,6 +26,8 @@ public class ExtendedPermissionServiceTest extends AbstractPermissionTest
|
||||
{
|
||||
public void testGroupPermission()
|
||||
{
|
||||
personService.getPerson("andy");
|
||||
|
||||
runAs("andy");
|
||||
assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
|
||||
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ),
|
||||
@@ -41,6 +43,8 @@ public class ExtendedPermissionServiceTest extends AbstractPermissionTest
|
||||
|
||||
public void testDeletePermissionByRecipient()
|
||||
{
|
||||
personService.getPerson("andy");
|
||||
|
||||
runAs("andy");
|
||||
assertFalse(permissionService.hasPermission(rootNodeRef, getPermission(PermissionService.READ)) == AccessStatus.ALLOWED);
|
||||
permissionService.setPermission(new SimplePermissionEntry(rootNodeRef, getPermission(PermissionService.READ),
|
||||
|
Reference in New Issue
Block a user