Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)

136785 jkaabimofrad: MNT-17824: Added a workaround for retrieving authorities (i.e. group or role) that were created with 'GROUP_' prefix before MNT-14958 fix.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@136810 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jamal Kaabi-Mofrad
2017-05-19 08:32:26 +00:00
parent 1ee1cbd533
commit 2d714be75d

View File

@@ -1029,30 +1029,37 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
public String getName(AuthorityType type, String shortName) public String getName(AuthorityType type, String shortName)
{ {
String authorityName = shortName;
if (type.isFixedString()) if (type.isFixedString())
{ {
authorityName = type.getFixedString(); return type.getFixedString();
} }
else if (type.isPrefixed()) else if (type.isPrefixed())
{ {
String prefix = type.getPrefixString(); final String prefix = type.getPrefixString();
final String authorityName = prefix + shortName;
if (shortName.startsWith(prefix)) if (shortName.startsWith(prefix))
{ {
String doublePrefixed = prefix + prefix; String doublePrefixed = prefix + prefix;
if (shortName.startsWith(doublePrefixed)) if (shortName.startsWith(doublePrefixed))
{ {
throw new AuthorityException("The authority name is double-prefixed"); throw new AuthorityException("The authority name [" + shortName + "] is double-prefixed");
}
// MNT-17824: We need this check, in case this method is invoked for retrieving an
// authority (rather than creating a new one), that was created with the shortName prefixed with 'GROUP_' before the MNT-14958 fix.
// As before MNT-14958, if the shortName starts with 'GROUP_', the authority name will end up as 'GROUP_GROUP_<anyName>'
else if (getAuthorityOrNull(authorityName, type) != null)
{
return authorityName;
} }
} }
else else
{ {
authorityName = prefix + shortName;
}
}
return authorityName; return authorityName;
} }
}
return shortName;
}
protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type) protected void addAuthorityNameIfMatches(Set<String> authorities, String authorityName, AuthorityType type)
{ {
@@ -1287,10 +1294,15 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
} }
private NodeRef getAuthorityOrNull(final String name) private NodeRef getAuthorityOrNull(final String name)
{
final AuthorityType authType = AuthorityType.getAuthorityType(name);
return getAuthorityOrNull(name, authType);
}
private NodeRef getAuthorityOrNull(final String name, final AuthorityType authType)
{ {
try try
{ {
final AuthorityType authType = AuthorityType.getAuthorityType(name);
switch (authType) switch (authType)
{ {
case USER: case USER:
@@ -1306,8 +1318,8 @@ public class AuthorityDAOImpl implements AuthorityDAO, NodeServicePolicies.Befor
NodeRef result = authorityLookupCache.get(cacheKey); NodeRef result = authorityLookupCache.get(cacheKey);
if (result == null) if (result == null)
{ {
List<ChildAssociationRef> results = nodeService.getChildAssocs(getAuthorityContainer(), List<ChildAssociationRef> results = nodeService.getChildAssocs(getAuthorityContainer(), ContentModel.ASSOC_CHILDREN,
ContentModel.ASSOC_CHILDREN, QName.createQName("cm", name, namespacePrefixResolver), false); QName.createQName("cm", name, namespacePrefixResolver), false);
result = results.isEmpty() ? NULL_NODEREF : results.get(0).getChildRef(); result = results.isEmpty() ? NULL_NODEREF : results.get(0).getChildRef();
authorityLookupCache.put(cacheKey, result); authorityLookupCache.put(cacheKey, result);
} }