public Collection<Group> getGroups(JID user) {
        HashSet<String> groupNames = getUserGroupsFromCache(user);
        if (groupNames == null) {
            synchronized (userBasedMutex.intern(user)) {
                groupNames = getUserGroupsFromCache(user);
                if (groupNames == null) {
                    groupNames = new HashSet<>(provider.getGroupNames(user));
                    saveUserGroupsInCache(user, groupNames);
                }
            }
        }
        return new GroupCollection(groupNames);
    }
Returns an iterator for all groups that the entity with the specified JID is a member of.

@param user the JID of the entity to get a list of groups for.
@return all groups that an entity belongs to.
xmppserver/src/main/java/org/jivesoftware/openfire/group/GroupManager.java