code: private Collection<Membership> findMembershipsByUserAndGroup(Session session, Node refUserNode, Node groupNode) throws Exception
     {
        List<Membership> memberships = new ArrayList<Membership>();
  
        NodeIterator refTypes = refUserNode.getNodes();
        while (refTypes.hasNext())
        {
           Node refTypeNode = refTypes.nextNode();
  
           String id = utils.composeMembershipId(groupNode, refUserNode, refTypeNode);
           String groupId = utils.getGroupIds(groupNode).groupId;
  
           MembershipImpl membership = new MembershipImpl();
           membership.setUserName(refUserNode.getName());
           membership.setMembershipType((refTypeNode.getName().equals(JCROrganizationServiceImpl.JOS_MEMBERSHIP_TYPE_ANY)
              ? MembershipTypeHandler.ANY_MEMBERSHIP_TYPE : refTypeNode.getName()));
           membership.setGroupId(groupId);
           membership.setId(id);
  
           memberships.add(membership);
        }
  
        return memberships;
     }
docs: Use this method to find all the memberships of an user in a group.