java - 使用 Zookeeper 主机字符串对 Solr Cloud 进行身份验证

标签 java http authentication solr solrcloud

我想为我的 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;
}

关于java - 使用 Zookeeper 主机字符串对 Solr Cloud 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48475745/

相关文章:

java - 我想从 firestore 检索当前登录的用户数据,但它在我想显示数据的地方显示空白

c# - 维基百科查询返回错误 403

flutter - 如何根据 Gmail 或 Facebook 登录显示个人资料图片?

authentication - Active Directory 能否使用 MD5 散列密码对用户进行身份验证

php - 无法将输入的 $username 插入表中

java - 如何使用 java 中的反射确定泛型类型的构造函数参数数量?

java - String.hashCode() 的 int 值是唯一的吗?

java - 使用 Gson 将 JSON 转换为 POJO : JsonSyntaxException

ios - 解码从 HTTP API 请求接收到的数据

http - 有没有SMTP转HTTP的免费服务(Email转POST)?