angela created SLING-8605:
-----------------------------
Summary: AclUtil.createLocalRestrictions should use
JackrabbitAccessControlList.isMultiValueRestriction(String)
Key: SLING-8605
URL: https://issues.apache.org/jira/browse/SLING-8605
Project: Sling
Issue Type: Bug
Components: Repoinit
Reporter: angela
today the {{AclUtil.createLocalRestrictions}} looks at the length of the value
array to determine if a given restriction is intended to be multivalued or not.
this may lead to an unexpected exception in cases where a single value is
defined for a restriction that is defined to be multivalued. instead of looking
at the length of the array, the code should make use of
{{JackrabbitAccessControlList.isMultiValueRestriction}} in order to find out if
a given restriction is multivalued or not.
here the proposed change (also using the 'checkState' method that is part of
the patch for SLING-8604:
{code}
private static LocalRestrictions
createLocalRestrictions(List<RestrictionClause> list,
JackrabbitAccessControlList jacl, Session s) throws RepositoryException {
Map<String,Value> restrictions = new HashMap<>();
Map<String,Value[]> mvrestrictions = new HashMap<>();
if(list != null && !list.isEmpty()){
ValueFactory vf = s.getValueFactory();
for(RestrictionClause rc : list){
String restrictionName = rc.getName();
int type = jacl.getRestrictionType(restrictionName);
boolean isMvRestriction =
jacl.isMultiValueRestriction(restrictionName);
Value[] values = new Value[rc.getValues().size()];
for(int i=0;i<values.length;i++) {
values[i] = vf.createValue(rc.getValues().get(i),type);
}
if("rep:glob".equals(restrictionName) && values.length == 0) {
// SLING-7280 - special case for rep:glob which supports an
empty string
// to mean "no values"
restrictions.put(restrictionName, vf.createValue(""));
} else if (isMvRestriction) {
mvrestrictions.put(restrictionName, values);
} else {
checkState(values.length == 1, "Expected just one value for
single valued restriction with name " + restrictionName);
restrictions.put(restrictionName, values[0]);
}
}
}
return new LocalRestrictions(restrictions,mvrestrictions);
}
{code}
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)