code: private MembershipsByUserWrapper findMembershipsByUser(Session session, String userName) throws Exception
     {
        Node userNode;
        try
        {
           userNode = utils.getUserNode(session, userName);
        }
        catch (PathNotFoundException e)
        {
           return new MembershipsByUserWrapper(new ArrayList<Membership>(), new ArrayList<Node>());
        }
  
        List<Membership> memberships = new ArrayList<Membership>();
        List<Node> refUserNodes = new ArrayList<Node>();
  
        PropertyIterator refUserProps = userNode.getReferences();
        while (refUserProps.hasNext())
        {
           Node refUserNode = refUserProps.nextProperty().getParent();
           Node groupNode = refUserNode.getParent().getParent();
  
           memberships.addAll(findMembershipsByUserAndGroup(session, refUserNode, groupNode));
           refUserNodes.add(refUserNode);
        }
  
        return new MembershipsByUserWrapper(memberships, refUserNodes);
     }
docs: Use this method to find all the memberships of an user in any group.