简体   繁体   中英

Authentication of Solr Cloud using zookeeper host string

I want to set authentication for my SolrCloud . I use SolrJ6.5.0 in java. My CloudSolrClient is defined by directly using Zookeeper host:

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

I saw useful codes of Deepak Shrivastava and Brian teggart for authenticating solr.

@Deepak Shrivastava used HttpSolrClient and @Brian teggart used AuthScope .

I have zookeeper host connection string instead of solr core url, so I cannot use these codes.

How can I set authentication for my solrCloud ?

I have also research this issue for a week. You can try the following:

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM