final Set<String> nIds = new HashSet<String>();
// workaround for failure of Node#getWeakReferences
// traverse the tree below groups-path and collect membership manually.
log.info("Traversing groups tree to collect membership.");
ItemVisitor visitor = new TraversingItemVisitor.Default() {
@Override
protected void entering(Property property, int level) throws RepositoryException {
PropertyImpl pMember = (PropertyImpl) property;
NodeImpl nGroup = (NodeImpl) pMember.getParent();
if (P_MEMBERS.equals(pMember.getQName()) && nGroup.isNodeType(NT_REP_GROUP)) {
// Found membership information in members property
for (Value value : property.getValues()) {
String v = value.getString();
if (v.equals(authorizableNodeIdentifier)) {
pIds.add(nGroup.getIdentifier());
}
}
} else {
// Found membership information in members node
while (nGroup.isNodeType(NT_REP_MEMBERS)) {
nGroup = (NodeImpl) nGroup.getParent();
}
if (nGroup.isNodeType(NT_REP_GROUP) && !NameConstants.JCR_UUID.equals(pMember.getQName())) {
String v = pMember.getString();
if (v.equals(authorizableNodeIdentifier)) {
nIds.add(nGroup.getIdentifier());
}
}
}
}
};
if (session.nodeExists(groupsPath)) {
Node groupsNode = session.getNode(groupsPath);
visitor.visit(groupsNode);
} // else: no groups exist -> nothing to do.
// Based on the user's setting return either of the found membership informations
return select(pIds, nIds);
}