diff --git a/config/alfresco/public-services-security-context.xml b/config/alfresco/public-services-security-context.xml index 5144698060..15c74fc114 100644 --- a/config/alfresco/public-services-security-context.xml +++ b/config/alfresco/public-services-security-context.xml @@ -707,10 +707,7 @@ org.alfresco.service.cmr.security.AuthorityService.getAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAuthoritiesForUser=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.getAllAuthorities=ACL_ALLOW - org.alfresco.service.cmr.security.AuthorityService.findAuthoritiesByShortName=ACL_ALLOW - org.alfresco.service.cmr.security.AuthorityService.findAuthoritiesByShortNameInZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.findAuthorities=ACL_ALLOW - org.alfresco.service.cmr.security.AuthorityService.findAuthoritiesInZone=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.getAllRootAuthorities=ACL_ALLOW org.alfresco.service.cmr.security.AuthorityService.createAuthority=ACL_METHOD.ROLE_ADMINISTRATOR org.alfresco.service.cmr.security.AuthorityService.addAuthority=ACL_METHOD.ROLE_ADMINISTRATOR diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java index e241ce8991..b4eb378d1c 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAO.java @@ -50,14 +50,6 @@ public interface AuthorityDAO */ void deleteAuthority(String name); - /** - * Get all root authorities. - * - * @param type - * @return - */ - Set getAllRootAuthorities(AuthorityType type); - /** * Get contained authorities. * @@ -135,14 +127,35 @@ public interface AuthorityDAO void setAuthorityDisplayName(String authorityName, String authorityDisplayName); /** - * Find authorities by pattern. + * Find authorities by display name pattern. * * @param type - * @param namePattern - * @param zones - may be null to indicate all zones + * @param parentAuthority if non-null, will look only for authorities who are a child of the named parent + * @param immediate if true then only search root groups if parentAuthority is null, or immediate children of parentAuthority if it is non-null. + * @param displayNamePattern + * @param zoneName - may be null to indicate all zones * @return */ - public Set findAuthorities(AuthorityType type, String namePattern, Set zones); + public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, + String displayNamePattern, String zoneName); + + /** + * Extract the short name of an authority from its full identifier. + * + * @param name + * @return + */ + public String getShortName(String name); + + /** + * Create the full identifier for an authority given its short name and + * type. + * + * @param type + * @param shortName + * @return + */ + public String getName(AuthorityType type, String shortName); /** * Gets or creates an authority zone node with the specified name @@ -195,13 +208,5 @@ public interface AuthorityDAO * @param authorityName * @param zones */ - public void removeAuthorityFromZones(String authorityName, Set zones); - - /** - * Get all root authorities in a zone - * @param zoneName - * @param type (optional) - * @return the set of authority names - */ - public Set getAllRootAuthoritiesInZone(String zoneName, AuthorityType type); + public void removeAuthorityFromZones(String authorityName, Set zones); } diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java index 56c29fa9de..d709d91807 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityDAOImpl.java @@ -23,13 +23,11 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; -import java.util.regex.Matcher; import java.util.regex.Pattern; import org.alfresco.error.AlfrescoRuntimeException; @@ -244,11 +242,6 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor userAuthorityCache.clear(); } - public Set getAllRootAuthorities(AuthorityType type) - { - return getAllRootAuthoritiesUnderContainer(getAuthorityContainer(), type); - } - public Set getAllAuthorities(AuthorityType type) { Set authorities = new TreeSet(); @@ -279,10 +272,19 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor return authorities; } - public Set findAuthorities(AuthorityType type, String namePattern, Set zones) + + public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, + String displayNamePattern, String zoneName) { - String regExpString = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, namePattern); - Pattern pattern = Pattern.compile(regExpString, Pattern.CASE_INSENSITIVE); + Pattern pattern = displayNamePattern == null ? null : Pattern.compile(SearchLanguageConversion.convert( + SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, displayNamePattern), + Pattern.CASE_INSENSITIVE); + // Use SQL to determine root authorities + if (parentAuthority == null && immediate) + { + return getRootAuthoritiesUnderContainer(zoneName == null ? getAuthorityContainer() : getZone(zoneName), + type, pattern); + } Set authorities = new TreeSet(); SearchParameters sp = new SearchParameters(); sp.addStore(this.storeRef); @@ -297,7 +299,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND @").append( LuceneQueryParser.escape("{" + ContentModel.PROP_USERNAME.getNamespaceURI() + "}" + ISO9075.encode(ContentModel.PROP_USERNAME.getLocalName()))).append(":\"").append( - namePattern).append("\""); + displayNamePattern).append("\""); if (type == null) { query.append(") OR ("); @@ -305,28 +307,39 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } if (type != AuthorityType.USER) { - query.append("TYPE:\"").append(ContentModel.TYPE_AUTHORITY_CONTAINER).append("\" AND @").append( + query.append("TYPE:\"").append(ContentModel.TYPE_AUTHORITY_CONTAINER).append("\" AND (@").append( LuceneQueryParser.escape("{" + ContentModel.PROP_AUTHORITY_NAME.getNamespaceURI() + "}" - + ISO9075.encode(ContentModel.PROP_AUTHORITY_NAME.getLocalName()))).append(":\"").append( - namePattern).append("\""); + + ISO9075.encode(ContentModel.PROP_AUTHORITY_NAME.getLocalName()))).append(":\""); + // Allow for the appropriate type prefix in the authority name + if (type == null && !displayNamePattern.startsWith("*")) + { + query.append("*").append(displayNamePattern); + } + else + { + query.append(getName(type, displayNamePattern)); + } + query.append("\" OR @").append( + LuceneQueryParser.escape("{" + ContentModel.PROP_AUTHORITY_DISPLAY_NAME.getNamespaceURI() + "}" + + ISO9075.encode(ContentModel.PROP_AUTHORITY_DISPLAY_NAME.getLocalName()))).append(":\"").append( + displayNamePattern).append("\")"); if (type == null) { query.append("))"); } } - if (zones != null) + if (parentAuthority != null) { - query.append(" AND PATH:("); - Iterator i = zones.iterator(); - while (i.hasNext()) - { - query.append("\"/sys:system/sys:zones/cm:").append(ISO9075.encode(i.next())).append("/*\""); - if (i.hasNext()) - { - query.append(" "); - } - } - query.append(")"); + query.append(" AND PATH:\"/sys:system/sys:authorities/cm:").append(ISO9075.encode(parentAuthority)); + if (!immediate) + { + query.append('/'); + } + query.append("/*\""); + } + if (zoneName != null) + { + query.append(" AND PATH:\"/sys:system/sys:zones/cm:").append(ISO9075.encode(zoneName)).append("/*\""); } sp.setQuery(query.toString()); sp.setMaxItems(100); @@ -372,7 +385,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } Set authorities = new TreeSet(); - findAuthorities(type, null, nodeRef, authorities, false, !immediate, false); + findAuthorities(type, nodeRef, authorities, false, !immediate, false); return authorities; } } @@ -435,7 +448,41 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } } - private void addAuthorityNameIfMatches(Set authorities, String authorityName, AuthorityType type, Pattern pattern) + public String getShortName(String name) + { + AuthorityType type = AuthorityType.getAuthorityType(name); + if (type.isFixedString()) + { + return ""; + } + else if (type.isPrefixed()) + { + return name.substring(type.getPrefixString().length()); + } + else + { + return name; + } + } + + public String getName(AuthorityType type, String shortName) + { + if (type.isFixedString()) + { + return type.getFixedString(); + } + else if (type.isPrefixed()) + { + return type.getPrefixString() + shortName; + } + else + { + return shortName; + } + } + + private void addAuthorityNameIfMatches(Set authorities, String authorityName, AuthorityType type, + Pattern pattern) { if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type)) { @@ -445,11 +492,18 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } else { - Matcher m = pattern.matcher(authorityName); - if (m.matches()) + if (pattern.matcher(getShortName(authorityName)).matches()) { authorities.add(authorityName); } + else + { + String displayName = getAuthorityDisplayName(authorityName); + if (displayName != null && pattern.matcher(displayName).matches()) + { + authorities.add(authorityName); + } + } } } } @@ -467,7 +521,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor if (ref != null) { - findAuthorities(type, null, ref, authorities, parents, recursive, false); + findAuthorities(type, ref, authorities, parents, recursive, false); } else if (!localType.equals(AuthorityType.USER)) { @@ -478,7 +532,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } } - private void findAuthorities(AuthorityType type, Pattern pattern, NodeRef nodeRef, Set authorities, boolean parents, boolean recursive, boolean includeNode) + private void findAuthorities(AuthorityType type, NodeRef nodeRef, Set authorities, boolean parents, boolean recursive, boolean includeNode) { if (includeNode) { @@ -486,7 +540,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor .getProperty(nodeRef, dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_AUTHORITY_CONTAINER) ? ContentModel.PROP_AUTHORITY_NAME : ContentModel.PROP_USERNAME)); - addAuthorityNameIfMatches(authorities, authorityName, type, pattern); + addAuthorityNameIfMatches(authorities, authorityName, type, null); } // Loop over children if we want immediate children or are in recursive mode @@ -498,7 +552,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor for (ChildAssociationRef car : cars) { - findAuthorities(type, pattern, car.getParentRef(), authorities, true, recursive, true); + findAuthorities(type, car.getParentRef(), authorities, true, recursive, true); } } else @@ -511,10 +565,10 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor { String childName = car.getQName().getLocalName(); AuthorityType childType = AuthorityType.getAuthorityType(childName); - addAuthorityNameIfMatches(authorities, childName, type, pattern); + addAuthorityNameIfMatches(authorities, childName, type, null); if (recursive && childType != AuthorityType.USER) { - findAuthorities(type, pattern, car.getChildRef(), authorities, false, true, false); + findAuthorities(type, car.getChildRef(), authorities, false, true, false); } } } @@ -778,14 +832,8 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor } } } - - public Set getAllRootAuthoritiesInZone(String zoneName, AuthorityType type) - { - NodeRef zone = getZone(zoneName); - return zone == null ? Collections. emptySet() : getAllRootAuthoritiesUnderContainer(zone, type); - } - - private Set getAllRootAuthoritiesUnderContainer(NodeRef container, AuthorityType type) + + private Set getRootAuthoritiesUnderContainer(NodeRef container, AuthorityType type, Pattern pattern) { if (type != null && type.equals(AuthorityType.USER)) { @@ -795,7 +843,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor Set authorities = new TreeSet(); for (ChildAssociationRef childRef : childRefs) { - addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null); + addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, pattern); } 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 706fa13dd0..edadac369d 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityServiceImpl.java @@ -296,21 +296,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean } return authorities; } - - - - public Set findAuthorities(AuthorityType type, String namePattern) - { - return findAuthoritiesInZone(type, namePattern, null); - } - - - public Set findAuthoritiesByShortName(AuthorityType type, String shortNamePattern) - { - String fullNamePattern = getName(type, shortNamePattern); - return findAuthorities(type, fullNamePattern); - } - + public void addAuthority(String parentName, String childName) { addAuthority(Collections.singleton(parentName), childName); @@ -391,7 +377,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean public Set getAllRootAuthorities(AuthorityType type) { - return authorityDAO.getAllRootAuthorities(type); + return authorityDAO.findAuthorities(type, null, true, null, null); } public Set getContainedAuthorities(AuthorityType type, String name, boolean immediate) @@ -404,40 +390,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean return authorityDAO.getContainingAuthorities(type, name, immediate); } - public String getName(AuthorityType type, String shortName) - { - if (type.isFixedString()) - { - return type.getFixedString(); - } - else if (type.isPrefixed()) - { - return type.getPrefixString() + shortName; - } - else - { - return shortName; - } - } - - public String getShortName(String name) - { - AuthorityType type = AuthorityType.getAuthorityType(name); - if (type.isFixedString()) - { - return ""; - } - else if (type.isPrefixed()) - { - return name.substring(type.getPrefixString().length()); - } - else - { - return name; - } - - } - public void removeAuthority(String parentName, String childName) { authorityDAO.removeAuthority(parentName, childName); @@ -512,40 +464,35 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean public Set getAllRootAuthoritiesInZone(String zoneName, AuthorityType type) { - return authorityDAO.getAllRootAuthoritiesInZone(zoneName, type); + return authorityDAO.findAuthorities(type, null, true, null, zoneName); } - public Set findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone) + public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, + String displayNamePattern, String zoneName) { - String fullNamePattern = getName(type, shortNamePattern); - return findAuthoritiesInZone(type, fullNamePattern, zone); - } - - public Set findAuthoritiesInZone(AuthorityType type, String namePattern, String zone) - { - Set authorities = new HashSet(); - switch (type) + if (type == null || type == AuthorityType.GROUP || type == AuthorityType.USER) { - case ADMIN: - case EVERYONE: - case GUEST: - throw new UnsupportedOperationException(); - case GROUP: - Set 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 authorityDAO.findAuthorities(type, parentAuthority, immediate, displayNamePattern, zoneName); + } + else + { + throw new UnsupportedOperationException(); } - return authorities; } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.security.AuthorityService#getName(org.alfresco.service.cmr.security.AuthorityType, java.lang.String) + */ + public String getName(AuthorityType type, String shortName) + { + return authorityDAO.getName(type, shortName); + } + + /* (non-Javadoc) + * @see org.alfresco.service.cmr.security.AuthorityService#getShortName(java.lang.String) + */ + public String getShortName(String name) + { + return authorityDAO.getShortName(name); + } } diff --git a/source/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java b/source/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java index f925aa32df..da2fcd82ba 100644 --- a/source/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java +++ b/source/java/org/alfresco/repo/security/authority/AuthorityServiceTest.java @@ -268,25 +268,25 @@ public class AuthorityServiceTest extends TestCase } int size = end - 'a' + 1; before = System.nanoTime(); - Set matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__a*"); + Set matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__a*", null); 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*"); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__aa*", null); 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"); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*aa", null); 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"); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*a", null); after = System.nanoTime(); System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f)); assertEquals(size * size * zones.length, matches.size()); @@ -298,25 +298,25 @@ public class AuthorityServiceTest extends TestCase if (zone != null) { before = System.nanoTime(); - matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__a*", zone); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__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); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__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); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*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); + matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*a", zone); after = System.nanoTime(); System.out.println("GROUP___*a in " + ((after - before) / 1000000000.0f)); assertEquals(size * size, matches.size()); diff --git a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java index 8e436d9ad7..dce15a44e1 100644 --- a/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java +++ b/source/java/org/alfresco/repo/security/authority/SimpleAuthorityServiceImpl.java @@ -187,14 +187,7 @@ public class SimpleAuthorityServiceImpl implements AuthorityService } return authorities; } - - - public Set findAuthorities(AuthorityType type, String namePattern) - { - return Collections.emptySet(); - } - public void addAuthority(String parentName, String childName) { @@ -304,13 +297,6 @@ public class SimpleAuthorityServiceImpl implements AuthorityService } - public Set findAuthoritiesByShortName(AuthorityType type, - String shortNamePattern) - { - String fullNamePattern = getName(type, shortNamePattern); - return findAuthorities(type, fullNamePattern); - } - public Set getAllAuthoritiesInZone(String zoneName, AuthorityType type) { return Collections.emptySet(); @@ -351,18 +337,14 @@ public class SimpleAuthorityServiceImpl implements AuthorityService } - public Set findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone) - { - return Collections.emptySet(); - } - - public Set findAuthoritiesInZone(AuthorityType type, String namePattern, String zone) - { - return Collections.emptySet(); - } - public NodeRef getZone(String zoneName) { return null; } + + public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, + String displayNamePattern, String zoneName) + { + return Collections.emptySet(); + } } diff --git a/source/java/org/alfresco/repo/security/authority/script/ScriptAuthorityService.java b/source/java/org/alfresco/repo/security/authority/script/ScriptAuthorityService.java index 4d5710c545..5ff745c995 100644 --- a/source/java/org/alfresco/repo/security/authority/script/ScriptAuthorityService.java +++ b/source/java/org/alfresco/repo/security/authority/script/ScriptAuthorityService.java @@ -51,39 +51,35 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension * Search the root groups, those without a parent group. * @return The root groups (empty if there are no root groups) */ - public ScriptGroup[] searchRootGroupsInZone(String shortNamePattern, String zone) - { - Set groups = new LinkedHashSet(0); - Set authorities = authorityService.findAuthoritiesByShortNameInZone(AuthorityType.GROUP, shortNamePattern, zone); - for (String authority : authorities) - { - ScriptGroup group = new ScriptGroup(authority, authorityService); - if (group.isRootGroup()) - { - groups.add(group); - } - } - return groups.toArray(new ScriptGroup[groups.size()]); - } + public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone) + { + Set groups = new LinkedHashSet(0); + Set authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, true, displayNamePattern, + zone); + for (String authority : authorities) + { + ScriptGroup group = new ScriptGroup(authority, authorityService); + groups.add(group); + } + return groups.toArray(new ScriptGroup[groups.size()]); + } /** * Search the root groups, those without a parent group. * @return The root groups (empty if there are no root groups) */ - public ScriptGroup[] searchRootGroups(String shortNamePattern) - { - Set groups = new LinkedHashSet(); - Set authorities = authorityService.findAuthoritiesByShortName(AuthorityType.GROUP, shortNamePattern); - for (String authority : authorities) - { - ScriptGroup group = new ScriptGroup(authority, authorityService); - if (group.isRootGroup()) - { - groups.add(group); - } - } - return groups.toArray(new ScriptGroup[groups.size()]); - } + public ScriptGroup[] searchRootGroups(String displayNamePattern) + { + Set groups = new LinkedHashSet(); + Set authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, true, displayNamePattern, + null); + for (String authority : authorities) + { + ScriptGroup group = new ScriptGroup(authority, authorityService); + groups.add(group); + } + return groups.toArray(new ScriptGroup[groups.size()]); + } /** * Search the root groups, those without a parent group. Searches in all zones. @@ -182,7 +178,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension } Set groups = new LinkedHashSet(); - Set authorities = authorityService.findAuthoritiesByShortName(AuthorityType.GROUP, filter); + Set authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, false, filter, null); for(String authority : authorities) { ScriptGroup group = new ScriptGroup(authority, authorityService); @@ -211,7 +207,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension } Set groups = new LinkedHashSet(); - Set authorities = authorityService.findAuthoritiesByShortNameInZone(AuthorityType.GROUP, filter, zone); + Set authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, false, filter, zone); for(String authority : authorities) { ScriptGroup group = new ScriptGroup(authority, authorityService); diff --git a/source/java/org/alfresco/service/cmr/security/AuthorityService.java b/source/java/org/alfresco/service/cmr/security/AuthorityService.java index 9e4c52a0aa..7845cc79a5 100644 --- a/source/java/org/alfresco/service/cmr/security/AuthorityService.java +++ b/source/java/org/alfresco/service/cmr/security/AuthorityService.java @@ -134,27 +134,7 @@ public interface AuthorityService */ @Auditable(parameters = {"type"}) public Set getAllAuthorities(AuthorityType type); - - - /** - * Find authorities by pattern matching (* and ?) against the authority name. - * @param type - the authority type - * @param namePattern - the pattern which will be matched against the shortName. - * @return the names of the authorities matching the pattern and type. - */ - @Auditable(parameters = {"type"}) - public Set findAuthoritiesByShortName(AuthorityType type, String shortNamePattern); - - /** - * Find authorities by pattern matching (* and ?) against the full authority name. - * @param type - the authority type - * @param namePattern - the pattern which will be matched against the full authority name. - * @return the names of the authorities matching the pattern and type. - */ - @Auditable(parameters = {"type"}) - public Set findAuthorities(AuthorityType type, String namePattern); - - + /** * Get all root authorities by type. Root authorities are ones that were * created without an authority as the parent authority; @@ -419,23 +399,16 @@ public interface AuthorityService public Set 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 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. + * @param type + * @param parentAuthority if non-null, will look only for authorities who are a child of the named parent + * @param immediate if true then only search root groups if parentAuthority is null, or immediate children of parentAuthority if it is non-null. + * @param displayNamePattern + * @param zoneName - may be null to indicate all zones + * @return */ @Auditable(parameters = {"type"}) - public Set findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone); -} + public Set findAuthorities(AuthorityType type, String parentAuthority, boolean immediate, + String displayNamePattern, String zoneName); +} \ No newline at end of file