Example usage for org.apache.solr.client.solrj.impl SolrPortAwareCookieSpecFactory SolrPortAwareCookieSpecFactory

List of usage examples for org.apache.solr.client.solrj.impl SolrPortAwareCookieSpecFactory SolrPortAwareCookieSpecFactory

Introduction

In this page you can find the example usage for org.apache.solr.client.solrj.impl SolrPortAwareCookieSpecFactory SolrPortAwareCookieSpecFactory.

Prototype

public SolrPortAwareCookieSpecFactory() 

Source Link

Usage

From source file:com.streamsets.pipeline.solr.impl.SdcSolrHttpClientBuilder.java

License:Apache License

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(//from   w  ww .j  a  v a 2  s  .  c om
                "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;
}

From source file:org.apache.nifi.processors.solr.KerberosHttpClientConfigurer.java

License:Apache License

public void configure(DefaultHttpClient httpClient, SolrParams config) {
    super.configure(httpClient, config);
    logger.info("Setting up SPNego auth...");

    //Enable only SPNEGO authentication scheme.
    final AuthSchemeRegistry registry = new AuthSchemeRegistry();
    registry.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true, false));
    httpClient.setAuthSchemes(registry);

    // Get the credentials from the JAAS configuration rather than here
    final Credentials useJaasCreds = new Credentials() {
        public String getPassword() {
            return null;
        }//from w ww.  j  a  v  a2 s.  com

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

    final SolrPortAwareCookieSpecFactory cookieFactory = new SolrPortAwareCookieSpecFactory();
    httpClient.getCookieSpecs().register(cookieFactory.POLICY_NAME, cookieFactory);
    httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, cookieFactory.POLICY_NAME);
    httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, useJaasCreds);
    httpClient.addRequestInterceptor(bufferedEntityInterceptor);
}