private void collectMembership(final Set<Group> groups, boolean includeIndirect) throws RepositoryException {
PropertyIterator refs = getMembershipReferences();
if (refs != null) {
while (refs.hasNext()) {
try {
NodeImpl n = (NodeImpl) refs.nextProperty().getParent();
if (n.isNodeType(NT_REP_GROUP)) {
Group group = userManager.createGroup(n);
// only retrieve indirect membership if the group is not
// yet present (detected eventual circular membership).
if (groups.add(group) && includeIndirect) {