protected List getAccessTokens()

in src/main/java/org/apache/solr/mcf/ManifoldCFQParserPlugin.java [324:398]


    protected List<String> getAccessTokens(Map<String,String> domainMap)
      throws IOException
    {
      // We can make this more complicated later, with support for https etc., but this is enough to demonstrate how it all should work.
      StringBuilder urlBuffer = new StringBuilder(authorityBaseURL);
      urlBuffer.append("/UserACLs");
      int i = 0;
      for (String domain : domainMap.keySet())
      {
        if (i == 0)
          urlBuffer.append("?");
        else
          urlBuffer.append("&");
        // For backwards compatibility, handle the singleton case specially
        if (domainMap.size() == 1 && domain.length() == 0)
        {
          urlBuffer.append("username=").append(URLEncoder.encode(domainMap.get(domain),"utf-8"));
        }
        else
        {
          urlBuffer.append("username_").append(Integer.toString(i)).append("=").append(URLEncoder.encode(domainMap.get(domain),"utf-8")).append("&")
            .append("domain_").append(Integer.toString(i)).append("=").append(URLEncoder.encode(domain,"utf-8"));
        }
        i++;
      }
      String theURL = urlBuffer.toString();
        
      HttpGet method = new HttpGet(theURL);
      try
      {
        HttpResponse httpResponse = client.execute(method);
        int rval = httpResponse.getStatusLine().getStatusCode();
        if (rval != 200)
        {
          String response = EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
          throw new SolrException(SolrException.ErrorCode.SERVER_ERROR,"Couldn't fetch user's access tokens from ManifoldCF authority service: "+Integer.toString(rval)+"; "+response);
        }

        try(InputStream is = httpResponse.getEntity().getContent())
        {
          Charset charSet;
          try
            {
              ContentType ct = ContentType.get(httpResponse.getEntity());
              if (ct == null)
                charSet = StandardCharsets.UTF_8;
              else
                charSet = ct.getCharset();
            }catch (ParseException e){
                charSet = StandardCharsets.UTF_8;
            }

          try( Reader r = new InputStreamReader(is,charSet); BufferedReader br = new BufferedReader(r)) {
              // Read the tokens, one line at a time.  If any authorities are down, we have no current way to note that, but someday we will.
              List<String> tokenList = new ArrayList<>();
              while (true) {
                String line = br.readLine();
                if (line == null)
                  break;
                if (line.startsWith("TOKEN:")) {
                  tokenList.add(line.substring("TOKEN:".length()));
                } else {
                   // It probably says something about the state of the authority(s) involved, so log it
                  LOG.info("Saw authority response " + line);
                }
              }
              return tokenList;
          }
        }
      }
      finally
      {
        method.abort();
      }
    }