code: private Membership findMembershipByUserGroupAndType(Session session, String userName, String groupId, String type)
        throws Exception
     {
        MembershipImpl membership = getFromCache(userName, groupId, type);
        if (membership != null)
        {
           return membership;
        }
  
        try
        {
           Node groupNode = utils.getGroupNode(session, groupId);
  
           Node refUserNode = groupNode.getNode(JCROrganizationServiceImpl.JOS_MEMBERSHIP).getNode(userName);
           Node refTypeNode =
              refUserNode.getNode(type.equals(MembershipTypeHandler.ANY_MEMBERSHIP_TYPE)
                 ? JCROrganizationServiceImpl.JOS_MEMBERSHIP_TYPE_ANY : type);
  
           String id = utils.composeMembershipId(groupNode, refUserNode, refTypeNode);
  
           membership = new MembershipImpl();
           membership.setGroupId(groupId);
           membership.setUserName(userName);
           membership.setMembershipType(type);
           membership.setId(id);
  
           putInCache(membership);
  
           return membership;
        }
        catch (PathNotFoundException e)
        {
           return null;
        }
     }
docs: Use this method to search for a specific membership type of an user in a group.