Search in sources :

Example 1 with PasswordEntry

use of org.commonjava.maven.galley.auth.PasswordEntry in project galley by Commonjava.

the class HttpImpl method createContext.

@Override
public HttpClientContext createContext(final HttpLocation location) {
    final HttpClientContext ctx = HttpClientContext.create();
    if (location != null) {
        final CredentialsProvider creds = new BasicCredentialsProvider();
        final AuthScope as = new AuthScope(location.getHost(), location.getPort());
        if (location.getUser() != null) {
            final String password = passwords.getPassword(new PasswordEntry(location, PasswordEntry.USER_PASSWORD));
            creds.setCredentials(as, new UsernamePasswordCredentials(location.getUser(), password));
        }
        if (location.getProxyHost() != null && location.getProxyUser() != null) {
            final String password = passwords.getPassword(new PasswordEntry(location, PasswordEntry.PROXY_PASSWORD));
            creds.setCredentials(new AuthScope(location.getProxyHost(), getProxyPort(location)), new UsernamePasswordCredentials(location.getProxyUser(), password));
        }
        ctx.setCredentialsProvider(creds);
    }
    return ctx;
}
Also used : BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) AuthScope(org.apache.http.auth.AuthScope) HttpClientContext(org.apache.http.client.protocol.HttpClientContext) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) CredentialsProvider(org.apache.http.client.CredentialsProvider) PasswordEntry(org.commonjava.maven.galley.auth.PasswordEntry) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials)

Aggregations

AuthScope (org.apache.http.auth.AuthScope)1 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)1 CredentialsProvider (org.apache.http.client.CredentialsProvider)1 HttpClientContext (org.apache.http.client.protocol.HttpClientContext)1 BasicCredentialsProvider (org.apache.http.impl.client.BasicCredentialsProvider)1 PasswordEntry (org.commonjava.maven.galley.auth.PasswordEntry)1