mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Add pattern based search for authorities constrained to zones
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@14829 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -145,9 +145,10 @@ public interface AuthorityDAO
|
||||
*
|
||||
* @param type
|
||||
* @param namePattern
|
||||
* @param zones - may be null to indicate all zones
|
||||
* @return
|
||||
*/
|
||||
public Set<String> findAuthorities(AuthorityType type, String namePattern);
|
||||
public Set<String> findAuthorities(AuthorityType type, String namePattern, Set<String> zones);
|
||||
|
||||
/**
|
||||
* Gets or creates an authority zone node with the specified name
|
||||
|
@@ -183,10 +183,10 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
|
||||
public Set<String> getAllAuthorities(AuthorityType type)
|
||||
{
|
||||
return findAuthorities(type, null);
|
||||
return findAuthorities(type, null, null);
|
||||
}
|
||||
|
||||
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
||||
public Set<String> findAuthorities(AuthorityType type, String namePattern, Set<String> zones)
|
||||
{
|
||||
Pattern pattern = null;
|
||||
if (namePattern != null)
|
||||
@@ -209,12 +209,32 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
||||
// For other types, we just look directly under the authority container
|
||||
if (type == null || !type.equals(AuthorityType.USER))
|
||||
{
|
||||
NodeRef container = getAuthorityContainer();
|
||||
if (container != null)
|
||||
if (zones == null)
|
||||
{
|
||||
for (ChildAssociationRef childRef : nodeService.getChildAssocs(container))
|
||||
NodeRef container = getAuthorityContainer();
|
||||
if (container != null)
|
||||
{
|
||||
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, pattern);
|
||||
for (ChildAssociationRef childRef : nodeService.getChildAssocs(container))
|
||||
{
|
||||
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (String zone : zones)
|
||||
{
|
||||
NodeRef container = getOrCreateZone(zone);
|
||||
if (container != null)
|
||||
{
|
||||
if (container != null)
|
||||
{
|
||||
for (ChildAssociationRef childRef : nodeService.getChildAssocs(container))
|
||||
{
|
||||
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, pattern);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -244,25 +244,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
||||
|
||||
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
||||
{
|
||||
Set<String> authorities = new HashSet<String>();
|
||||
switch (type)
|
||||
{
|
||||
case ADMIN:
|
||||
case EVERYONE:
|
||||
case GUEST:
|
||||
throw new UnsupportedOperationException();
|
||||
case GROUP:
|
||||
authorities.addAll(authorityDAO.findAuthorities(type, namePattern));
|
||||
break;
|
||||
case OWNER:
|
||||
case ROLE:
|
||||
throw new UnsupportedOperationException();
|
||||
case USER:
|
||||
throw new UnsupportedOperationException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return authorities;
|
||||
return findAuthoritiesInZone(type, namePattern, null);
|
||||
}
|
||||
|
||||
|
||||
@@ -441,4 +423,38 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
||||
{
|
||||
return authorityDAO.getAllRootAuthoritiesInZone(zoneName, type);
|
||||
}
|
||||
|
||||
public Set<String> findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone)
|
||||
{
|
||||
String fullNamePattern = getName(type, shortNamePattern);
|
||||
return findAuthoritiesInZone(type, fullNamePattern, zone);
|
||||
}
|
||||
|
||||
public Set<String> findAuthoritiesInZone(AuthorityType type, String namePattern, String zone)
|
||||
{
|
||||
Set<String> authorities = new HashSet<String>();
|
||||
switch (type)
|
||||
{
|
||||
case ADMIN:
|
||||
case EVERYONE:
|
||||
case GUEST:
|
||||
throw new UnsupportedOperationException();
|
||||
case GROUP:
|
||||
Set<String> zones = null;
|
||||
if(zone != null)
|
||||
{
|
||||
zones = Collections.singleton(zone);
|
||||
}
|
||||
authorities.addAll(authorityDAO.findAuthorities(type, namePattern, zones));
|
||||
break;
|
||||
case OWNER:
|
||||
case ROLE:
|
||||
throw new UnsupportedOperationException();
|
||||
case USER:
|
||||
throw new UnsupportedOperationException();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return authorities;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
package org.alfresco.repo.security.authority;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
@@ -160,7 +161,6 @@ public class AuthorityServiceTest extends TestCase
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
|
||||
public void testZones()
|
||||
{
|
||||
assertNull(pubAuthorityService.getAuthorityZones("GROUP_DEFAULT"));
|
||||
@@ -251,42 +251,85 @@ public class AuthorityServiceTest extends TestCase
|
||||
{
|
||||
long before, after;
|
||||
char end = 'd';
|
||||
for (char i = 'a'; i <= end; i++)
|
||||
String[] zones = new String[] { null, "ONE", "TWO", "THREE" };
|
||||
for (String zone : zones)
|
||||
{
|
||||
for (char j = 'a'; j <= end; j++)
|
||||
for (char i = 'a'; i <= end; i++)
|
||||
{
|
||||
for (char k = 'a'; k <= end; k++)
|
||||
for (char j = 'a'; j <= end; j++)
|
||||
{
|
||||
StringBuilder name = new StringBuilder();
|
||||
name.append("__").append(i).append(j).append(k);
|
||||
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString());
|
||||
for (char k = 'a'; k <= end; k++)
|
||||
{
|
||||
StringBuilder name = new StringBuilder();
|
||||
name.append("__").append(zone).append("__").append(i).append(j).append(k);
|
||||
if (zone == null)
|
||||
{
|
||||
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString(), name.toString(), Collections.singleton(zone));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int size = end - 'a' + 1;
|
||||
before = System.nanoTime();
|
||||
Set<String> matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___a*");
|
||||
Set<String> matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__a*");
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___a* in "+((after-before)/1000000000.0f));
|
||||
assertEquals(size*size, matches.size());
|
||||
System.out.println("GROUP___a* in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * size * zones.length, matches.size());
|
||||
|
||||
before = System.nanoTime();
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___aa*");
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__aa*");
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___aa* in "+((after-before)/1000000000.0f));
|
||||
assertEquals(size, matches.size());
|
||||
System.out.println("GROUP___aa* in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * zones.length, matches.size());
|
||||
|
||||
before = System.nanoTime();
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*aa");
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__*aa");
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___*aa in "+((after-before)/1000000000.0f));
|
||||
assertEquals(size, matches.size());
|
||||
System.out.println("GROUP___*aa in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * zones.length, matches.size());
|
||||
before = System.nanoTime();
|
||||
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*a");
|
||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__*a");
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___*a in "+((after-before)/1000000000.0f));
|
||||
assertEquals(size*size, matches.size());
|
||||
System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * size * zones.length, matches.size());
|
||||
|
||||
// Zone specific
|
||||
|
||||
for (String zone : zones)
|
||||
{
|
||||
if (zone != null)
|
||||
{
|
||||
before = System.nanoTime();
|
||||
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__a*", zone);
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___a* in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * size, matches.size());
|
||||
|
||||
before = System.nanoTime();
|
||||
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__aa*", zone);
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___aa* in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size, matches.size());
|
||||
|
||||
before = System.nanoTime();
|
||||
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*aa", zone);
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___*aa in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size, matches.size());
|
||||
before = System.nanoTime();
|
||||
|
||||
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*a", zone);
|
||||
after = System.nanoTime();
|
||||
System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f));
|
||||
assertEquals(size * size, matches.size());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@@ -330,4 +330,14 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Set<String> findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone)
|
||||
{
|
||||
return Collections.<String>emptySet();
|
||||
}
|
||||
|
||||
public Set<String> findAuthoritiesInZone(AuthorityType type, String namePattern, String zone)
|
||||
{
|
||||
return Collections.<String>emptySet();
|
||||
}
|
||||
}
|
||||
|
@@ -379,4 +379,25 @@ public interface AuthorityService
|
||||
*/
|
||||
@NotAuditable
|
||||
public Set<String> getDefaultZones();
|
||||
|
||||
|
||||
/**
|
||||
* Find authorities by pattern matching (* and ?) against the full authority name in a particular zone
|
||||
* @param type - the authority type
|
||||
* @param namePattern - the pattern which will be matched against the full authority name.
|
||||
* @param zone - the zone
|
||||
* @return the names of the authorities matching the pattern and type.
|
||||
*/
|
||||
@Auditable(parameters = {"type"})
|
||||
public Set<String> findAuthoritiesInZone(AuthorityType type, String namePattern, String zone);
|
||||
|
||||
/**
|
||||
* Find authorities by pattern matching (* and ?) against the authority name.
|
||||
* @param type - the authority type
|
||||
* @param shortNamePattern - the pattern which will be matched against the shortName.
|
||||
* @param zone
|
||||
* @return the names of the authorities matching the pattern and type.
|
||||
*/
|
||||
@Auditable(parameters = {"type"})
|
||||
public Set<String> findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone);
|
||||
}
|
||||
|
Reference in New Issue
Block a user