Java Code Examples for org.apache.solr.client.solrj.impl.SolrHttpClientBuilder#setDefaultCredentialsProvider()

The following examples show how to use org.apache.solr.client.solrj.impl.SolrHttpClientBuilder#setDefaultCredentialsProvider() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KerberosHttpClientBuilder.java    From nifi with Apache License 2.0 5 votes vote down vote up
public SolrHttpClientBuilder getBuilder(SolrHttpClientBuilder builder) {

        //Enable only SPNEGO authentication scheme.

        builder.setAuthSchemeRegistryProvider(() -> {
            Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create()
                    .register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false))
                    .build();
            return authProviders;
        });
        // Get the credentials from the JAAS configuration rather than here
        Credentials useJaasCreds = new Credentials() {
            public String getPassword() {
                return null;
            }
            public Principal getUserPrincipal() {
                return null;
            }
        };

        HttpClientUtil.setCookiePolicy(SolrPortAwareCookieSpecFactory.POLICY_NAME);

        builder.setCookieSpecRegistryProvider(() -> {
            SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();

            Lookup<CookieSpecProvider> cookieRegistry = RegistryBuilder.<CookieSpecProvider> create()
                    .register(SolrPortAwareCookieSpecFactory.POLICY_NAME, cookieFactory).build();

            return cookieRegistry;
        });

        builder.setDefaultCredentialsProvider(() -> {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(AuthScope.ANY, useJaasCreds);
            return credentialsProvider;
        });
        HttpClientUtil.addRequestInterceptor(bufferedEntityInterceptor);
        return builder;
    }
 
Example 2
Source File: SdcSolrHttpClientBuilder.java    From datacollector with Apache License 2.0 4 votes vote down vote up
static SolrHttpClientBuilder create() {
  SolrHttpClientBuilder solrHttpClientBuilder = SolrHttpClientBuilder.create();

  final String useSubjectCredentialsProperty = USE_SUBJECT_CREDENTIALS_PROPERTY;
  String useSubjectCredentialsValue = System.getProperty(useSubjectCredentialsProperty);

  if (useSubjectCredentialsValue == null) {
    System.setProperty(useSubjectCredentialsProperty, FALSE);
  } else if (!useSubjectCredentialsValue.toLowerCase(Locale.ROOT).equals(FALSE)) {
    LOG.warn(String.format(
        "System Property: %s set to: %s not false. SPNego authentication may not be successful.",
        useSubjectCredentialsProperty,
        useSubjectCredentialsValue
    ));
  }

  solrHttpClientBuilder.setAuthSchemeRegistryProvider(() -> RegistryBuilder.<AuthSchemeProvider>create().register(AuthSchemes.SPNEGO,
      new SPNegoSchemeFactory(true)
  ).build());

  SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();
  solrHttpClientBuilder.setCookieSpecRegistryProvider(() -> RegistryBuilder.<CookieSpecProvider>create().register(SolrPortAwareCookieSpecFactory.POLICY_NAME,
      cookieFactory
  ).build());

  Credentials jassCredentials = new Credentials() {
    public String getPassword() {
      return null;
    }

    public Principal getUserPrincipal() {
      return null;
    }
  };

  CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
  credentialsProvider.setCredentials(AuthScope.ANY, jassCredentials);
  solrHttpClientBuilder.setDefaultCredentialsProvider(() -> credentialsProvider);

  return solrHttpClientBuilder;
}