Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Solr client using Solrj Api with Kerberized Solr

I am trying to create a solr client using solrj api for kerberised solr. And as per the documentation of solrj, it is required to set HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); in code.

But the solrj api jar do not have the function setConfigurer inside the HttpClientUtil class. I am using the below dependency from maven.

<dependency>
    <groupId>org.apache.solr</groupId>
    <artifactId>solr-solrj</artifactId>
    <version>7.2.1</version>
</dependency>

Is it possible to create solr client using new HttpSolrClient.Builder and enable kerberisation to read the jaas.config file to do the authentication and authorization.

Currently i am creating the solr client like below;

new HttpSolrClient.Builder("solrUrlString").build()

But i do not see a option to enable Krb5HttpClientConfigurer in the above way

like image 547
Amit Kumar Avatar asked Feb 22 '18 08:02

Amit Kumar


1 Answers

The "HttpClientUtil.setConfigurer" method was depreciated from "solr-solrj" version 6.0.0 and finally removed from version 7.0.0 onwards.

But still the documentation of solrj has not been updated with the new way to create the Kerberized Solr client.

Figured out the way to do it in version 7.0.0 onwards:

        Builder solrClientBuilder = new HttpSolrClient.Builder("https://<hostname>/solr/<collectionName>");
        Krb5HttpClientBuilder krbBuilder = new Krb5HttpClientBuilder();
        SolrHttpClientBuilder krb5HttpClientBuilder = krbBuilder.getHttpClientBuilder(java.util.Optional.empty());
        HttpClientUtil.setHttpClientBuilder(krb5HttpClientBuilder);
        ModifiableSolrParams params = new ModifiableSolrParams();
        params.set(HttpClientUtil.PROP_FOLLOW_REDIRECTS, false);
        CloseableHttpClient httpClient = HttpClientUtil.createClient(params);

        SolrClient client = solrClientBuilder.withHttpClient(httpClient).build();
like image 60
Amit Kumar Avatar answered Dec 08 '22 23:12

Amit Kumar