我想为我的 SolrCloud
设置身份验证。我在java中使用SolrJ6.5.0
。我的 CloudSolrClient 是通过直接使用 Zookeeper 主机定义的:
CloudSolrClient serverCloud = new CloudSolrClient.Builder().
withZkHost(connectionStr).build();
我看到有用的代码Deepak Shrivastava和 Brian 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;
}
关于java - 使用 Zookeeper 主机字符串对 Solr Cloud 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48475745/