code: private Collection<Membership> findMembershipsByUserAndGroup(Session session, String userName, String groupId) throws Exception
     {
        Node groupNode;
        Node refUserNode;
  
        try
        {
           groupNode = utils.getGroupNode(session, groupId);
           refUserNode = groupNode.getNode(JCROrganizationServiceImpl.JOS_MEMBERSHIP).getNode(userName);
        }
        catch (PathNotFoundException e)
        {
           return new ArrayList<Membership>();
        }
  
        return findMembershipsByUserAndGroup(session, refUserNode, groupNode);
     }
docs: Use this method to find all the memberships of an user in a group.