public Collection<Group> getSharedGroups(String userName) {
        HashSet<String> groupNames;
        if (!provider.isSharingSupported()) {
            groupNames = new HashSet<>();
        } else {
            // assume this is a local user
            groupNames = new HashSet<>(provider.getSharedGroupNames(new JID(userName,
                XMPPServer.getInstance().getServerInfo().getXMPPDomain(), null)));
        }
        return new GroupCollection(groupNames);
    }
Returns an unmodifiable Collection of all shared groups in the system for a given userName.

@param userName the user to check
@return an unmodifiable Collection of all shared groups for the given userName.
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupManager.java