@Nonnull
    private Set<Group> getSharedGroups(@Nonnull final Group group) {
        final HashSet<Group> result = new HashSet<>();
        if (provider.isSharingSupported()) {
            if (group.getSharedWith() == SharedGroupVisibility.usersOfGroups) {
                final Set<String> groupNames = new HashSet<>(group.getSharedWithUsersInGroupNames());

                for ( String groupName : groupNames )
                {
                    try {
                        result.add(getGroup(groupName));
                    }
                    catch ( GroupNotFoundException e )
                    {
                        Log.debug("While iterating over subgroups of group '{}', an unrecognized spefgroup was found: '{}'", group.getName(), groupName, e);
                    }
                }
            }
        }

        return result;
    }
Find the unique set of groups with which the provided group is shared,
directly or indirectly. An indirect share is defined as a scenario where
the group is shared by a group that's shared with another group.

@param group The group for which to return all groups that it is shared with (cannot be null).
@return A set of groups with which all members of 'group' are shared with (never null).
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupManager.java