Search in sources :

Example 51 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project maven-plugins by apache.

the class AbstractCheckDocumentationMojo method setupProxy.

/**
 * Setup proxy access if needed.
 */
private void setupProxy() {
    Proxy settingsProxy = settings.getActiveProxy();
    if (settingsProxy != null) {
        String proxyUsername = settingsProxy.getUsername();
        String proxyPassword = settingsProxy.getPassword();
        String proxyHost = settingsProxy.getHost();
        int proxyPort = settingsProxy.getPort();
        if (StringUtils.isNotEmpty(proxyHost)) {
            httpClient.getHostConfiguration().setProxy(proxyHost, proxyPort);
            getLog().info("Using proxy [" + proxyHost + "] at port [" + proxyPort + "].");
            if (StringUtils.isNotEmpty(proxyUsername)) {
                getLog().info("Using proxy user [" + proxyUsername + "].");
                Credentials creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
                httpClient.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), creds);
                httpClient.getParams().setAuthenticationPreemptive(true);
            }
        }
    }
}
Also used : Proxy(org.apache.maven.settings.Proxy) AuthScope(org.apache.commons.httpclient.auth.AuthScope) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 52 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project jaggery by wso2.

the class HostObjectUtil method getURL.

public static int getURL(String urlString, String username, String password) throws IOException {
    HttpMethod method = new GetMethod(urlString);
    URL url = new URL(urlString);
    MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
    HttpClient httpClient = new HttpClient(connectionManager);
    // We should not use method.setURI and set the complete URI here.
    // If we do so commons-httpclient will not use our custom socket factory.
    // Hence we set the path and query separatly
    method.setPath(url.getPath());
    method.setQueryString(url.getQuery());
    method.setRequestHeader("Host", url.getHost());
    method.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES);
    // If a username and a password is provided we support basic auth
    if ((username != null) && (password != null)) {
        Credentials creds = new UsernamePasswordCredentials(username, password);
        int port = url.getPort();
        httpClient.getState().setCredentials(new AuthScope(url.getHost(), port), creds);
    }
    return httpClient.executeMethod(method);
}
Also used : GetMethod(org.apache.commons.httpclient.methods.GetMethod) AuthScope(org.apache.commons.httpclient.auth.AuthScope) URL(java.net.URL)

Aggregations

AuthScope (org.apache.commons.httpclient.auth.AuthScope)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)34 Credentials (org.apache.commons.httpclient.Credentials)19 GetMethod (org.apache.commons.httpclient.methods.GetMethod)12 HttpClient (org.apache.commons.httpclient.HttpClient)11 URL (java.net.URL)10 IOException (java.io.IOException)5 NTCredentials (org.apache.commons.httpclient.NTCredentials)5 Protocol (org.apache.commons.httpclient.protocol.Protocol)5 ProtocolSocketFactory (org.apache.commons.httpclient.protocol.ProtocolSocketFactory)5 Header (org.apache.commons.httpclient.Header)4 AuthScheme (org.apache.commons.httpclient.auth.AuthScheme)4 AuthState (org.apache.commons.httpclient.auth.AuthState)4 EasySSLProtocolSocketFactory (org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)3 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)3 InputStream (java.io.InputStream)3 InputStreamReader (java.io.InputStreamReader)3 URISyntaxException (java.net.URISyntaxException)3 ArrayList (java.util.ArrayList)3