fix potential NPE in CugAccessControlManager
*/
package org.apache.jackrabbit.oak.spi.security.authorization.cug.impl;
-import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -61,6 +60,8 @@ import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
import static org.apache.jackrabbit.oak.api.Type.NAMES;
@@ -289,14 +290,14 @@ class CugAccessControlManager extends AbstractAccessControlManager implements Cu
if (property == null) {
return Collections.emptySet();
} else {
- return ImmutableList.copyOf(Iterables.transform(property.getValue(Type.STRINGS), principalName -> {
+ return StreamSupport.stream(property.getValue(Type.STRINGS).spliterator(), false).map(principalName -> {
Principal principal = principalManager.getPrincipal(principalName);
if (principal == null) {
log.debug("Unknown principal {}", principalName);
principal = new PrincipalImpl(principalName);
}
return principal;
- }));
+ }).collect(Collectors.toList());
}
}
@@ -329,8 +330,9 @@ class CugAccessControlManager extends AbstractAccessControlManager implements Cu
}
if (CugUtil.isSupportedPath(path, supportedPaths)) {
Tree cug = CugUtil.getCug(t);
- if (cug != null) {
- if (!Collections.disjoint(ImmutableSet.copyOf(principalNames), ImmutableSet.copyOf(cug.getProperty(REP_PRINCIPAL_NAMES).getValue(Type.STRINGS)))) {
+ PropertyState pNames = (cug == null) ? null : cug.getProperty(REP_PRINCIPAL_NAMES);
+ if (pNames != null) {
+ if (!Collections.disjoint(ImmutableSet.copyOf(principalNames), ImmutableSet.copyOf(pNames.getValue(Type.STRINGS)))) {
candidates.add(path);
}
Iterables.addAll(eval, nestedCugPaths(cug));
