mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-1999: Refactored AuthorityService.findAuthorities to support search options required by Alfresco Explorer client in efficient manner
- optional parentAuthority argument - when set will only search for authorities under a given group - optional immediate flag - when false means do a recursive search. When true means only return first level. When true and parentAuthority is null means root groups. - search expression - which is tested against the short name and the display name - reworked all existing calls for new semantics - this method is for UI search only - not for existence checking! - removed some ill-informed calls git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19203 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -707,10 +707,7 @@
|
|||||||
org.alfresco.service.cmr.security.AuthorityService.getAuthorities=ACL_ALLOW
|
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.getAuthoritiesForUser=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||||
org.alfresco.service.cmr.security.AuthorityService.getAllAuthorities=ACL_ALLOW
|
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.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.getAllRootAuthorities=ACL_ALLOW
|
||||||
org.alfresco.service.cmr.security.AuthorityService.createAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
|
org.alfresco.service.cmr.security.AuthorityService.createAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||||
org.alfresco.service.cmr.security.AuthorityService.addAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
|
org.alfresco.service.cmr.security.AuthorityService.addAuthority=ACL_METHOD.ROLE_ADMINISTRATOR
|
||||||
|
@@ -50,14 +50,6 @@ public interface AuthorityDAO
|
|||||||
*/
|
*/
|
||||||
void deleteAuthority(String name);
|
void deleteAuthority(String name);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all root authorities.
|
|
||||||
*
|
|
||||||
* @param type
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
Set<String> getAllRootAuthorities(AuthorityType type);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get contained authorities.
|
* Get contained authorities.
|
||||||
*
|
*
|
||||||
@@ -135,14 +127,35 @@ public interface AuthorityDAO
|
|||||||
void setAuthorityDisplayName(String authorityName, String authorityDisplayName);
|
void setAuthorityDisplayName(String authorityName, String authorityDisplayName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find authorities by pattern.
|
* Find authorities by display name pattern.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type
|
||||||
* @param namePattern
|
* @param parentAuthority if non-null, will look only for authorities who are a child of the named parent
|
||||||
* @param zones - may be null to indicate all zones
|
* @param immediate if <code>true</code> 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
|
* @return
|
||||||
*/
|
*/
|
||||||
public Set<String> findAuthorities(AuthorityType type, String namePattern, Set<String> zones);
|
public Set<String> 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
|
* Gets or creates an authority zone node with the specified name
|
||||||
@@ -196,12 +209,4 @@ public interface AuthorityDAO
|
|||||||
* @param zones
|
* @param zones
|
||||||
*/
|
*/
|
||||||
public void removeAuthorityFromZones(String authorityName, Set<String> zones);
|
public void removeAuthorityFromZones(String authorityName, Set<String> zones);
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all root authorities in a zone
|
|
||||||
* @param zoneName
|
|
||||||
* @param type (optional)
|
|
||||||
* @return the set of authority names
|
|
||||||
*/
|
|
||||||
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type);
|
|
||||||
}
|
}
|
||||||
|
@@ -23,13 +23,11 @@ import java.util.Collection;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.alfresco.error.AlfrescoRuntimeException;
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
@@ -244,11 +242,6 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
userAuthorityCache.clear();
|
userAuthorityCache.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAllRootAuthorities(AuthorityType type)
|
|
||||||
{
|
|
||||||
return getAllRootAuthoritiesUnderContainer(getAuthorityContainer(), type);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getAllAuthorities(AuthorityType type)
|
public Set<String> getAllAuthorities(AuthorityType type)
|
||||||
{
|
{
|
||||||
Set<String> authorities = new TreeSet<String>();
|
Set<String> authorities = new TreeSet<String>();
|
||||||
@@ -279,10 +272,19 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> findAuthorities(AuthorityType type, String namePattern, Set<String> zones)
|
|
||||||
|
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,
|
||||||
|
String displayNamePattern, String zoneName)
|
||||||
{
|
{
|
||||||
String regExpString = SearchLanguageConversion.convert(SearchLanguageConversion.DEF_LUCENE, SearchLanguageConversion.DEF_REGEX, namePattern);
|
Pattern pattern = displayNamePattern == null ? null : Pattern.compile(SearchLanguageConversion.convert(
|
||||||
Pattern pattern = Pattern.compile(regExpString, Pattern.CASE_INSENSITIVE);
|
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<String> authorities = new TreeSet<String>();
|
Set<String> authorities = new TreeSet<String>();
|
||||||
SearchParameters sp = new SearchParameters();
|
SearchParameters sp = new SearchParameters();
|
||||||
sp.addStore(this.storeRef);
|
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(
|
query.append("TYPE:\"").append(ContentModel.TYPE_PERSON).append("\" AND @").append(
|
||||||
LuceneQueryParser.escape("{" + ContentModel.PROP_USERNAME.getNamespaceURI() + "}"
|
LuceneQueryParser.escape("{" + ContentModel.PROP_USERNAME.getNamespaceURI() + "}"
|
||||||
+ ISO9075.encode(ContentModel.PROP_USERNAME.getLocalName()))).append(":\"").append(
|
+ ISO9075.encode(ContentModel.PROP_USERNAME.getLocalName()))).append(":\"").append(
|
||||||
namePattern).append("\"");
|
displayNamePattern).append("\"");
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
query.append(") OR (");
|
query.append(") OR (");
|
||||||
@@ -305,28 +307,39 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
}
|
}
|
||||||
if (type != AuthorityType.USER)
|
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() + "}"
|
LuceneQueryParser.escape("{" + ContentModel.PROP_AUTHORITY_NAME.getNamespaceURI() + "}"
|
||||||
+ ISO9075.encode(ContentModel.PROP_AUTHORITY_NAME.getLocalName()))).append(":\"").append(
|
+ ISO9075.encode(ContentModel.PROP_AUTHORITY_NAME.getLocalName()))).append(":\"");
|
||||||
namePattern).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)
|
if (type == null)
|
||||||
{
|
{
|
||||||
query.append("))");
|
query.append("))");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (zones != null)
|
if (parentAuthority != null)
|
||||||
{
|
{
|
||||||
query.append(" AND PATH:(");
|
query.append(" AND PATH:\"/sys:system/sys:authorities/cm:").append(ISO9075.encode(parentAuthority));
|
||||||
Iterator<String> i = zones.iterator();
|
if (!immediate)
|
||||||
while (i.hasNext())
|
{
|
||||||
{
|
query.append('/');
|
||||||
query.append("\"/sys:system/sys:zones/cm:").append(ISO9075.encode(i.next())).append("/*\"");
|
}
|
||||||
if (i.hasNext())
|
query.append("/*\"");
|
||||||
{
|
}
|
||||||
query.append(" ");
|
if (zoneName != null)
|
||||||
}
|
{
|
||||||
}
|
query.append(" AND PATH:\"/sys:system/sys:zones/cm:").append(ISO9075.encode(zoneName)).append("/*\"");
|
||||||
query.append(")");
|
|
||||||
}
|
}
|
||||||
sp.setQuery(query.toString());
|
sp.setQuery(query.toString());
|
||||||
sp.setMaxItems(100);
|
sp.setMaxItems(100);
|
||||||
@@ -372,7 +385,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<String> authorities = new TreeSet<String>();
|
Set<String> authorities = new TreeSet<String>();
|
||||||
findAuthorities(type, null, nodeRef, authorities, false, !immediate, false);
|
findAuthorities(type, nodeRef, authorities, false, !immediate, false);
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -435,7 +448,41 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAuthorityNameIfMatches(Set<String> 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<String> authorities, String authorityName, AuthorityType type,
|
||||||
|
Pattern pattern)
|
||||||
{
|
{
|
||||||
if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type))
|
if (type == null || AuthorityType.getAuthorityType(authorityName).equals(type))
|
||||||
{
|
{
|
||||||
@@ -445,11 +492,18 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Matcher m = pattern.matcher(authorityName);
|
if (pattern.matcher(getShortName(authorityName)).matches())
|
||||||
if (m.matches())
|
|
||||||
{
|
{
|
||||||
authorities.add(authorityName);
|
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)
|
if (ref != null)
|
||||||
{
|
{
|
||||||
findAuthorities(type, null, ref, authorities, parents, recursive, false);
|
findAuthorities(type, ref, authorities, parents, recursive, false);
|
||||||
}
|
}
|
||||||
else if (!localType.equals(AuthorityType.USER))
|
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<String> authorities, boolean parents, boolean recursive, boolean includeNode)
|
private void findAuthorities(AuthorityType type, NodeRef nodeRef, Set<String> authorities, boolean parents, boolean recursive, boolean includeNode)
|
||||||
{
|
{
|
||||||
if (includeNode)
|
if (includeNode)
|
||||||
{
|
{
|
||||||
@@ -486,7 +540,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
.getProperty(nodeRef, dictionaryService.isSubClass(nodeService.getType(nodeRef),
|
.getProperty(nodeRef, dictionaryService.isSubClass(nodeService.getType(nodeRef),
|
||||||
ContentModel.TYPE_AUTHORITY_CONTAINER) ? ContentModel.PROP_AUTHORITY_NAME
|
ContentModel.TYPE_AUTHORITY_CONTAINER) ? ContentModel.PROP_AUTHORITY_NAME
|
||||||
: ContentModel.PROP_USERNAME));
|
: 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
|
// 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)
|
for (ChildAssociationRef car : cars)
|
||||||
{
|
{
|
||||||
findAuthorities(type, pattern, car.getParentRef(), authorities, true, recursive, true);
|
findAuthorities(type, car.getParentRef(), authorities, true, recursive, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -511,10 +565,10 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
{
|
{
|
||||||
String childName = car.getQName().getLocalName();
|
String childName = car.getQName().getLocalName();
|
||||||
AuthorityType childType = AuthorityType.getAuthorityType(childName);
|
AuthorityType childType = AuthorityType.getAuthorityType(childName);
|
||||||
addAuthorityNameIfMatches(authorities, childName, type, pattern);
|
addAuthorityNameIfMatches(authorities, childName, type, null);
|
||||||
if (recursive && childType != AuthorityType.USER)
|
if (recursive && childType != AuthorityType.USER)
|
||||||
{
|
{
|
||||||
findAuthorities(type, pattern, car.getChildRef(), authorities, false, true, false);
|
findAuthorities(type, car.getChildRef(), authorities, false, true, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -779,13 +833,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type)
|
private Set<String> getRootAuthoritiesUnderContainer(NodeRef container, AuthorityType type, Pattern pattern)
|
||||||
{
|
|
||||||
NodeRef zone = getZone(zoneName);
|
|
||||||
return zone == null ? Collections.<String> emptySet() : getAllRootAuthoritiesUnderContainer(zone, type);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Set<String> getAllRootAuthoritiesUnderContainer(NodeRef container, AuthorityType type)
|
|
||||||
{
|
{
|
||||||
if (type != null && type.equals(AuthorityType.USER))
|
if (type != null && type.equals(AuthorityType.USER))
|
||||||
{
|
{
|
||||||
@@ -795,7 +843,7 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
|
|||||||
Set<String> authorities = new TreeSet<String>();
|
Set<String> authorities = new TreeSet<String>();
|
||||||
for (ChildAssociationRef childRef : childRefs)
|
for (ChildAssociationRef childRef : childRefs)
|
||||||
{
|
{
|
||||||
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, null);
|
addAuthorityNameIfMatches(authorities, childRef.getQName().getLocalName(), type, pattern);
|
||||||
}
|
}
|
||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
@@ -297,20 +297,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
|
||||||
{
|
|
||||||
return findAuthoritiesInZone(type, namePattern, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public Set<String> findAuthoritiesByShortName(AuthorityType type, String shortNamePattern)
|
|
||||||
{
|
|
||||||
String fullNamePattern = getName(type, shortNamePattern);
|
|
||||||
return findAuthorities(type, fullNamePattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAuthority(String parentName, String childName)
|
public void addAuthority(String parentName, String childName)
|
||||||
{
|
{
|
||||||
addAuthority(Collections.singleton(parentName), childName);
|
addAuthority(Collections.singleton(parentName), childName);
|
||||||
@@ -391,7 +377,7 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
|
|
||||||
public Set<String> getAllRootAuthorities(AuthorityType type)
|
public Set<String> getAllRootAuthorities(AuthorityType type)
|
||||||
{
|
{
|
||||||
return authorityDAO.getAllRootAuthorities(type);
|
return authorityDAO.findAuthorities(type, null, true, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getContainedAuthorities(AuthorityType type, String name, boolean immediate)
|
public Set<String> getContainedAuthorities(AuthorityType type, String name, boolean immediate)
|
||||||
@@ -404,40 +390,6 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
return authorityDAO.getContainingAuthorities(type, name, immediate);
|
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)
|
public void removeAuthority(String parentName, String childName)
|
||||||
{
|
{
|
||||||
authorityDAO.removeAuthority(parentName, childName);
|
authorityDAO.removeAuthority(parentName, childName);
|
||||||
@@ -512,40 +464,35 @@ public class AuthorityServiceImpl implements AuthorityService, InitializingBean
|
|||||||
|
|
||||||
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type)
|
public Set<String> getAllRootAuthoritiesInZone(String zoneName, AuthorityType type)
|
||||||
{
|
{
|
||||||
return authorityDAO.getAllRootAuthoritiesInZone(zoneName, type);
|
return authorityDAO.findAuthorities(type, null, true, null, zoneName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone)
|
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,
|
||||||
|
String displayNamePattern, String zoneName)
|
||||||
{
|
{
|
||||||
String fullNamePattern = getName(type, shortNamePattern);
|
if (type == null || type == AuthorityType.GROUP || type == AuthorityType.USER)
|
||||||
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:
|
return authorityDAO.findAuthorities(type, parentAuthority, immediate, displayNamePattern, zoneName);
|
||||||
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;
|
else
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -268,25 +268,25 @@ public class AuthorityServiceTest extends TestCase
|
|||||||
}
|
}
|
||||||
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, null, false, "__*__a*", null);
|
||||||
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 * zones.length, matches.size());
|
assertEquals(size * size * zones.length, matches.size());
|
||||||
|
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__aa*");
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__aa*", null);
|
||||||
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 * zones.length, matches.size());
|
assertEquals(size * zones.length, matches.size());
|
||||||
|
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__*aa");
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*aa", null);
|
||||||
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 * zones.length, matches.size());
|
assertEquals(size * zones.length, matches.size());
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
|
|
||||||
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, "GROUP___*__*a");
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*a", null);
|
||||||
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 * zones.length, matches.size());
|
assertEquals(size * size * zones.length, matches.size());
|
||||||
@@ -298,25 +298,25 @@ public class AuthorityServiceTest extends TestCase
|
|||||||
if (zone != null)
|
if (zone != null)
|
||||||
{
|
{
|
||||||
before = System.nanoTime();
|
before = System.nanoTime();
|
||||||
matches = pubAuthorityService.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__a*", zone);
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__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.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__aa*", zone);
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__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.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*aa", zone);
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*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.findAuthoritiesInZone(AuthorityType.GROUP, "GROUP___*__*a", zone);
|
matches = pubAuthorityService.findAuthorities(AuthorityType.GROUP, null, false, "__*__*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());
|
||||||
|
@@ -188,13 +188,6 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
|||||||
return authorities;
|
return authorities;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Set<String> findAuthorities(AuthorityType type, String namePattern)
|
|
||||||
{
|
|
||||||
return Collections.<String>emptySet();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addAuthority(String parentName, String childName)
|
public void addAuthority(String parentName, String childName)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -304,13 +297,6 @@ public class SimpleAuthorityServiceImpl implements AuthorityService
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> findAuthoritiesByShortName(AuthorityType type,
|
|
||||||
String shortNamePattern)
|
|
||||||
{
|
|
||||||
String fullNamePattern = getName(type, shortNamePattern);
|
|
||||||
return findAuthorities(type, fullNamePattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type)
|
public Set<String> getAllAuthoritiesInZone(String zoneName, AuthorityType type)
|
||||||
{
|
{
|
||||||
return Collections.<String>emptySet();
|
return Collections.<String>emptySet();
|
||||||
@@ -351,18 +337,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();
|
|
||||||
}
|
|
||||||
|
|
||||||
public NodeRef getZone(String zoneName)
|
public NodeRef getZone(String zoneName)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,
|
||||||
|
String displayNamePattern, String zoneName)
|
||||||
|
{
|
||||||
|
return Collections.emptySet();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -51,39 +51,35 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
|
|||||||
* Search the root groups, those without a parent group.
|
* Search the root groups, those without a parent group.
|
||||||
* @return The root groups (empty if there are no root groups)
|
* @return The root groups (empty if there are no root groups)
|
||||||
*/
|
*/
|
||||||
public ScriptGroup[] searchRootGroupsInZone(String shortNamePattern, String zone)
|
public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone)
|
||||||
{
|
{
|
||||||
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>(0);
|
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>(0);
|
||||||
Set<String> authorities = authorityService.findAuthoritiesByShortNameInZone(AuthorityType.GROUP, shortNamePattern, zone);
|
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, true, displayNamePattern,
|
||||||
for (String authority : authorities)
|
zone);
|
||||||
{
|
for (String authority : authorities)
|
||||||
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
{
|
||||||
if (group.isRootGroup())
|
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
||||||
{
|
groups.add(group);
|
||||||
groups.add(group);
|
}
|
||||||
}
|
return groups.toArray(new ScriptGroup[groups.size()]);
|
||||||
}
|
}
|
||||||
return groups.toArray(new ScriptGroup[groups.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search the root groups, those without a parent group.
|
* Search the root groups, those without a parent group.
|
||||||
* @return The root groups (empty if there are no root groups)
|
* @return The root groups (empty if there are no root groups)
|
||||||
*/
|
*/
|
||||||
public ScriptGroup[] searchRootGroups(String shortNamePattern)
|
public ScriptGroup[] searchRootGroups(String displayNamePattern)
|
||||||
{
|
{
|
||||||
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
||||||
Set<String> authorities = authorityService.findAuthoritiesByShortName(AuthorityType.GROUP, shortNamePattern);
|
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, true, displayNamePattern,
|
||||||
for (String authority : authorities)
|
null);
|
||||||
{
|
for (String authority : authorities)
|
||||||
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
{
|
||||||
if (group.isRootGroup())
|
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
||||||
{
|
groups.add(group);
|
||||||
groups.add(group);
|
}
|
||||||
}
|
return groups.toArray(new ScriptGroup[groups.size()]);
|
||||||
}
|
}
|
||||||
return groups.toArray(new ScriptGroup[groups.size()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search the root groups, those without a parent group. Searches in all zones.
|
* Search the root groups, those without a parent group. Searches in all zones.
|
||||||
@@ -182,7 +178,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
||||||
Set<String> authorities = authorityService.findAuthoritiesByShortName(AuthorityType.GROUP, filter);
|
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, false, filter, null);
|
||||||
for(String authority : authorities)
|
for(String authority : authorities)
|
||||||
{
|
{
|
||||||
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
||||||
@@ -211,7 +207,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
|
|||||||
}
|
}
|
||||||
|
|
||||||
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
Set<ScriptGroup> groups = new LinkedHashSet<ScriptGroup>();
|
||||||
Set<String> authorities = authorityService.findAuthoritiesByShortNameInZone(AuthorityType.GROUP, filter, zone);
|
Set<String> authorities = authorityService.findAuthorities(AuthorityType.GROUP, null, false, filter, zone);
|
||||||
for(String authority : authorities)
|
for(String authority : authorities)
|
||||||
{
|
{
|
||||||
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
ScriptGroup group = new ScriptGroup(authority, authorityService);
|
||||||
|
@@ -135,26 +135,6 @@ public interface AuthorityService
|
|||||||
@Auditable(parameters = {"type"})
|
@Auditable(parameters = {"type"})
|
||||||
public Set<String> getAllAuthorities(AuthorityType type);
|
public Set<String> 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<String> 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<String> findAuthorities(AuthorityType type, String namePattern);
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all root authorities by type. Root authorities are ones that were
|
* Get all root authorities by type. Root authorities are ones that were
|
||||||
* created without an authority as the parent authority;
|
* created without an authority as the parent authority;
|
||||||
@@ -419,23 +399,16 @@ public interface AuthorityService
|
|||||||
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.
|
* Find authorities by pattern matching (* and ?) against the authority name.
|
||||||
* @param type - the authority type
|
* @param type
|
||||||
* @param shortNamePattern - the pattern which will be matched against the shortName.
|
* @param parentAuthority if non-null, will look only for authorities who are a child of the named parent
|
||||||
* @param zone
|
* @param immediate if <code>true</code> then only search root groups if parentAuthority is null, or immediate children of parentAuthority if it is non-null.
|
||||||
* @return the names of the authorities matching the pattern and type.
|
* @param displayNamePattern
|
||||||
|
* @param zoneName - may be null to indicate all zones
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
@Auditable(parameters = {"type"})
|
@Auditable(parameters = {"type"})
|
||||||
public Set<String> findAuthoritiesByShortNameInZone(AuthorityType type, String shortNamePattern, String zone);
|
public Set<String> findAuthorities(AuthorityType type, String parentAuthority, boolean immediate,
|
||||||
|
String displayNamePattern, String zoneName);
|
||||||
}
|
}
|
Reference in New Issue
Block a user