Package org.apache.http.impl.client

Examples of org.apache.http.impl.client.BasicCredentialsProvider


    public void openConnectionInternal()
    {
        repository.setUrl( getURL( repository ) );

        localContext = HttpClientContext.create();
        credentialsProvider = new BasicCredentialsProvider();
        authCache = new BasicAuthCache();
        localContext.setCredentialsProvider( credentialsProvider );
        localContext.setAuthCache( authCache );

        if ( authenticationInfo != null )
View Full Code Here


            eeMethod.setEntity(new StringEntity(data, ContentType.create(mediaType, "UTF-8")));
        }

        /* Set the username/password if any */
        if (username != null) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
                    new UsernamePasswordCredentials(username, password));
            context.setAttribute(ClientContext.CREDS_PROVIDER, credentialsProvider);
        }

        /* Add request headers if need be */
 
View Full Code Here

    String  host    = sm.getValue(HOST);
    String  port    = sm.getValue(PORT);
    String  username= sm.getValue(USERNAME);
    String  password= sm.getValue(PASSWORD);

        CredentialsProvider provider = new BasicCredentialsProvider();
        if (enabled) {
            if (!Lib.type.isInteger(port)) {
                Log.error(Geonet.GEONETWORK, "Proxy port is not an integer : "+ port);
            } else {
                final HttpHost proxy = new HttpHost(host, Integer.parseInt(port));
                client.setProxy(proxy);

                client.setDefaultCredentialsProvider(provider);
        if (username.trim().length() != 0) {
                    provider.setCredentials(new AuthScope(proxy), new UsernamePasswordCredentials(username, password));
        }
      }
    }

        return provider;
View Full Code Here

    }

    /** {@inheritDoc} */
    public void authenticate(HttpClientBuilder pBuilder, String pUser, String pPassword) {
        // Preparing the builder for the credentials
        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(
                new AuthScope(AuthScope.ANY),
                new UsernamePasswordCredentials(pUser, pPassword));
        pBuilder.setDefaultCredentialsProvider(credentialsProvider);
        if (preemptive) {
            pBuilder.addInterceptorFirst(new PreemptiveAuthInterceptor(new BasicScheme()));
View Full Code Here

    protected ClientHttpResponse doExecute(final HttpRequestBase httpMethod) throws IOException {
        return requestFactory.execute(httpMethod, new Function<HttpClientBuilder, Void>() {
            @Nullable
            @Override
            public Void apply(@Nonnull HttpClientBuilder input) {
                final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                if (credentials != null) {
                    final URI uri = httpMethod.getURI();
                    HttpHost hh = new HttpHost(
                            uri.getHost(),
                            uri.getPort(),
                            uri.getScheme());
                    credentialsProvider.setCredentials(new AuthScope(hh), credentials);

                    // Preemptive authentication
                    if (isPreemptiveBasicAuth()) {
                        // Create AuthCache instance
                        AuthCache authCache = new BasicAuthCache();
                        // Generate BASIC scheme object and add it to the local auth cache
                        BasicScheme basicAuth = new BasicScheme();
                        authCache.put(hh, basicAuth);

                        // Add AuthCache to the execution context
                        httpClientContext = HttpClientContext.create();
                        httpClientContext.setCredentialsProvider(credentialsProvider);
                        httpClientContext.setAuthCache(authCache);
                    } else {
                        input.setDefaultCredentialsProvider(credentialsProvider);
                    }
                } else {
                    input.setDefaultCredentialsProvider(credentialsProvider);
                }

                if (useProxy) {
                    final HttpHost proxy = new HttpHost(proxyHost, proxyPort);
                    input.setProxy(proxy);
                    if (proxyCredentials != null) {
                        credentialsProvider.setCredentials(new AuthScope(proxy), proxyCredentials);
                    }
                }
                input.setRedirectStrategy(new LaxRedirectStrategy());
                return null;
            }
View Full Code Here

        final Function<HttpClientBuilder, Void> setCredentials = new Function<HttpClientBuilder, Void>() {
            @Nullable
            @Override
            public Void apply(@Nonnull HttpClientBuilder input) {

                final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
                credentialsProvider.setCredentials(authScope, credentials);
                input.setDefaultCredentialsProvider(credentialsProvider);

                return null;
            }
        };
View Full Code Here

  @Test
  public void testBasicPreemptiveAuth() throws Exception
  {
    final DefaultHttpClient client = new DefaultHttpClient();
    final CountDownLatch count = new CountDownLatch(1);
    client.setCredentialsProvider(new BasicCredentialsProvider()
    {
      @Override
      public Credentials getCredentials(AuthScope authscope)
      {
        // Set flag that credentials have been used indicating preemptive authentication
View Full Code Here

        this.authCache = new BasicAuthCache();
    }

    public Executor auth(final AuthScope authScope, final Credentials creds) {
        if (this.credentialsProvider == null) {
            this.credentialsProvider = new BasicCredentialsProvider();
        }
        this.credentialsProvider.setCredentials(authScope, creds);
        return this;
    }
View Full Code Here

    @Test
    public void testBasicAuthenticationCredentialsCaching() throws Exception {
        this.localServer.register("*", new AuthHandler());

        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("test", "test"));
        final TestTargetAuthenticationStrategy authStrategy = new TestTargetAuthenticationStrategy();

        this.httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
View Full Code Here

    @Test
    public void testPreemptiveAuthentication() throws Exception {
        final CountingAuthHandler requestHandler = new CountingAuthHandler();
        this.localServer.register("*", requestHandler);

        final BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
        credsProvider.setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("test", "test"));

        this.httpclient = HttpClients.custom()
            .setDefaultCredentialsProvider(credsProvider)
            .build();
View Full Code Here

TOP

Related Classes of org.apache.http.impl.client.BasicCredentialsProvider

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.