簡體   English   中英

使用Zookeeper主機字符串對Solr Cloud進行身份驗證

[英]Authentication of Solr Cloud using zookeeper host string

我想為我的SolrCloud設置身份驗證。 我在Java中使用SolrJ6.5.0 我的CloudSolrClient是通過直接使用Zookeeper主機定義的:

 CloudSolrClient serverCloud = new CloudSolrClient.Builder().
                               withZkHost(connectionStr).build();

我看到了Deepak ShrivastavaBrian teggart用來驗證solr的有用代碼。

@Deepak Shrivastava使用HttpSolrClient而@Brian teggart使用AuthScope

我有zookeeper主機連接字符串而不是solr core url,所以我不能使用這些代碼。

如何為我的solrCloud設置身份驗證?

我也對此問題進行了一周的研究。 您可以嘗試以下方法:

public HttpClient httpClient() {
    CredentialsProvider provider = new BasicCredentialsProvider();
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("solr username", "solr password");
    provider.setCredentials(AuthScope.ANY, credentials);
    return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
}

public CloudSolrClient solrClient(HttpClient httpClient) {
    CloudSolrClient solrClient = new CloudSolrClient.Builder()
            .withZkHost("your zkHost").withHttpClient(httpClient()).build();
    solrClient.setDefaultCollection("your collection");
    return solrClient;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM