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 type
|
||||||
* @param namePattern
|
* @param namePattern
|
||||||
|
* @param zones - may be null to indicate all zones
|
||||||
* @return
|
* @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
|
* 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)
|
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;
|
Pattern pattern = null;
|
||||||
if (namePattern != null)
|
if (namePattern != null)
|
||||||
@@ -208,6 +208,8 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
|||||||
|
|
||||||
// For other types, we just look directly under the authority container
|
// For other types, we just look directly under the authority container
|
||||||
if (type == null || !type.equals(AuthorityType.USER))
|
if (type == null || !type.equals(AuthorityType.USER))
|
||||||
|
{
|
||||||
|
if (zones == null)
|
||||||
{
|
{
|
||||||
NodeRef container = getAuthorityContainer();
|
NodeRef container = getAuthorityContainer();
|
||||||
if (container != null)
|
if (container != null)
|
||||||
@@ -218,6 +220,24 @@ public class AuthorityDAOImpl implements AuthorityDAO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -244,25 +244,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
|
|
||||||
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
||||||
{
|
{
|
||||||
Set<String> authorities = new HashSet<String>();
|
return findAuthoritiesInZone(type, namePattern, null);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -441,4 +423,38 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
{
|
{
|
||||||
return authorityDAO.getAllRootAuthoritiesInZone(zoneName, type);
|
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;
|
package org.alfresco.repo.security.authority;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -160,7 +161,6 @@ public class AuthorityServiceTest extends TestCase
|
|||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void testZones()
|
public void testZones()
|
||||||
{
|
{
|
||||||
assertNull(pubAuthorityService.getAuthorityZones("GROUP_DEFAULT"));
|
assertNull(pubAuthorityService.getAuthorityZones("GROUP_DEFAULT"));
|
||||||
@@ -251,6 +251,9 @@ public class AuthorityServiceTest extends TestCase
|
|||||||
{
|
{
|
||||||
long before, after;
|
long before, after;
|
||||||
char end = 'd';
|
char end = 'd';
|
||||||
|
String[] zones = new String[] { null, "ONE", "TWO", "THREE" };
|
||||||
|
for (String zone : zones)
|
||||||
|
{
|
||||||
for (char i = 'a'; i <= end; i++)
|
for (char i = 'a'; i <= end; i++)
|
||||||
{
|
{
|
||||||
for (char j = 'a'; j <= end; j++)
|
for (char j = 'a'; j <= end; j++)
|
||||||
@@ -258,35 +261,75 @@ public class AuthorityServiceTest extends TestCase
|
|||||||
for (char k = 'a'; k <= end; k++)
|
for (char k = 'a'; k <= end; k++)
|
||||||
{
|
{
|
||||||
StringBuilder name = new StringBuilder();
|
StringBuilder name = new StringBuilder();
|
||||||
name.append("__").append(i).append(j).append(k);
|
name.append("__").append(zone).append("__").append(i).append(j).append(k);
|
||||||
|
if (zone == null)
|
||||||
|
{
|
||||||
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString());
|
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString());
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pubAuthorityService.createAuthority(AuthorityType.GROUP, name.toString(), name.toString(), Collections.singleton(zone));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int size = end - 'a' + 1;
|
int size = end - 'a' + 1;
|
||||||
before = System.nanoTime();
|
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 * zones.length, matches.size());
|
||||||
|
|
||||||
|
before = System.nanoTime();
|
||||||
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__aa*");
|
||||||
|
after = System.nanoTime();
|
||||||
|
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");
|
||||||
|
after = System.nanoTime();
|
||||||
|
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");
|
||||||
|
after = System.nanoTime();
|
||||||
|
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();
|
after = System.nanoTime();
|
||||||
System.out.println("GROUP___a* in " + ((after - before) / 1000000000.0f));
|
System.out.println("GROUP___a* in " + ((after - before) / 1000000000.0f));
|
||||||
assertEquals(size * size, matches.size());
|
assertEquals(size * size, matches.size());
|
||||||
|
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___aa*");
|
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__aa*", zone);
|
||||||
after = System.nanoTime();
|
after = System.nanoTime();
|
||||||
System.out.println("GROUP___aa* in " + ((after - before) / 1000000000.0f));
|
System.out.println("GROUP___aa* in " + ((after - before) / 1000000000.0f));
|
||||||
assertEquals(size, matches.size());
|
assertEquals(size, matches.size());
|
||||||
|
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*aa");
|
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*aa", zone);
|
||||||
after = System.nanoTime();
|
after = System.nanoTime();
|
||||||
System.out.println("GROUP___*aa in " + ((after - before) / 1000000000.0f));
|
System.out.println("GROUP___*aa in " + ((after - before) / 1000000000.0f));
|
||||||
assertEquals(size, matches.size());
|
assertEquals(size, matches.size());
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
|
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*a");
|
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*a", zone);
|
||||||
after = System.nanoTime();
|
after = System.nanoTime();
|
||||||
System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f));
|
System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f));
|
||||||
assertEquals(size * size, matches.size());
|
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
|
@NotAuditable
|
||||||
public Set<String> getDefaultZones();
|
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