All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hr.com.vgv.verano.http.wire.apache.BasicAuth Maven / Gradle / Ivy

There is a newer version: 0.41
Show newest version
package hr.com.vgv.verano.http.wire.apache;

import java.net.URI;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;

public class BasicAuth implements ApacheContext
{
    private final String username;

    private final String password;

    public BasicAuth(String username, String password)
    {
        this.username = username;
        this.password = password;
    }

    @Override
    public final HttpClientBuilder apply(URI uri, HttpClientBuilder builder) {
        final CredentialsProvider provider = new BasicCredentialsProvider();
        provider.setCredentials(
            new AuthScope(uri.getHost(), uri.getPort()),
            new UsernamePasswordCredentials(this.username, this.password)
        );
        return builder.setDefaultCredentialsProvider(provider);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy