Search in sources :

Example 21 with AuthScope

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

the class HttpSender method setProxyAuth.

private void setProxyAuth(HttpState state) {
    if (param.isUseProxyChain() && param.isUseProxyChainAuth()) {
        String realm = param.getProxyChainRealm();
        state.setProxyCredentials(new AuthScope(param.getProxyChainName(), param.getProxyChainPort(), realm.isEmpty() ? AuthScope.ANY_REALM : realm), new NTCredentials(param.getProxyChainUserName(), param.getProxyChainPassword(), "", realm));
    }
}
Also used : AuthScope(org.apache.commons.httpclient.auth.AuthScope) NTCredentials(org.apache.commons.httpclient.NTCredentials)

Example 22 with AuthScope

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

the class UriUtils method getInputStreamFromUrl.

public static InputStream getInputStreamFromUrl(String url, String user, String password) {
    try {
        Pair<String, Integer> hostAndPort = validateUrl(url);
        HttpClient httpclient = new HttpClient(new MultiThreadedHttpConnectionManager());
        if ((user != null) && (password != null)) {
            httpclient.getParams().setAuthenticationPreemptive(true);
            Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
            httpclient.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
            s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
        }
        // Execute the method.
        GetMethod method = new GetMethod(url);
        int statusCode = httpclient.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            s_logger.error("Failed to read from URL: " + url);
            return null;
        }
        return method.getResponseBodyAsStream();
    } catch (Exception ex) {
        s_logger.error("Failed to read from URL: " + url);
        return null;
    }
}
Also used : HttpClient(org.apache.commons.httpclient.HttpClient) MultiThreadedHttpConnectionManager(org.apache.commons.httpclient.MultiThreadedHttpConnectionManager) AuthScope(org.apache.commons.httpclient.auth.AuthScope) GetMethod(org.apache.commons.httpclient.methods.GetMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) URISyntaxException(java.net.URISyntaxException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 23 with AuthScope

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

the class HttpTemplateDownloader method checkCredentials.

private void checkCredentials(String user, String password) {
    try {
        Pair<String, Integer> hostAndPort = UriUtils.validateUrl(downloadUrl);
        if ((user != null) && (password != null)) {
            client.getParams().setAuthenticationPreemptive(true);
            Credentials defaultcreds = new UsernamePasswordCredentials(user, password);
            client.getState().setCredentials(new AuthScope(hostAndPort.first(), hostAndPort.second(), AuthScope.ANY_REALM), defaultcreds);
            s_logger.info("Added username=" + user + ", password=" + password + "for host " + hostAndPort.first() + ":" + hostAndPort.second());
        } else {
            s_logger.info("No credentials configured for host=" + hostAndPort.first() + ":" + hostAndPort.second());
        }
    } catch (IllegalArgumentException iae) {
        errorString = iae.getMessage();
        status = TemplateDownloader.Status.UNRECOVERABLE_ERROR;
        inited = false;
    }
}
Also used : 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 24 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project java-apns by notnoop.

the class TlsTunnelBuilder method AuthenticateProxy.

private Socket AuthenticateProxy(ConnectMethod method, ProxyClient client, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword) throws IOException {
    if ("ntlm".equalsIgnoreCase(method.getProxyAuthState().getAuthScheme().getSchemeName())) {
        // If Auth scheme is NTLM, set NT credentials with blank host and domain name
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new NTCredentials(proxyUsername, proxyPassword, "", ""));
    } else {
        // If Auth scheme is Basic/Digest, set regular Credentials
        client.getState().setProxyCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUsername, proxyPassword));
    }
    ProxyClient.ConnectResponse response = client.connect();
    Socket socket = response.getSocket();
    if (socket == null) {
        method = response.getConnectMethod();
        throw new ProtocolException("Proxy Authentication failed. Socket not created: " + method.getStatusLine());
    }
    return socket;
}
Also used : ProtocolException(java.net.ProtocolException) ProxyClient(org.apache.commons.httpclient.ProxyClient) AuthScope(org.apache.commons.httpclient.auth.AuthScope) Socket(java.net.Socket) NTCredentials(org.apache.commons.httpclient.NTCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 25 with AuthScope

use of org.apache.commons.httpclient.auth.AuthScope in project intellij-community by JetBrains.

the class BaseRepositoryImpl method configureHttpClient.

protected void configureHttpClient(HttpClient client) {
    client.getParams().setConnectionManagerTimeout(3000);
    client.getParams().setSoTimeout(TaskSettings.getInstance().CONNECTION_TIMEOUT);
    if (isUseProxy()) {
        HttpConfigurable proxy = HttpConfigurable.getInstance();
        client.getHostConfiguration().setProxy(proxy.PROXY_HOST, proxy.PROXY_PORT);
        if (proxy.PROXY_AUTHENTICATION && proxy.getProxyLogin() != null) {
            AuthScope authScope = new AuthScope(proxy.PROXY_HOST, proxy.PROXY_PORT);
            Credentials credentials = getCredentials(proxy.getProxyLogin(), proxy.getPlainProxyPassword(), proxy.PROXY_HOST);
            client.getState().setProxyCredentials(authScope, credentials);
        }
    }
    if (isUseHttpAuthentication()) {
        client.getParams().setCredentialCharset("UTF-8");
        client.getParams().setAuthenticationPreemptive(true);
        client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(getUsername(), getPassword()));
    } else {
        client.getState().clearCredentials();
        client.getParams().setAuthenticationPreemptive(false);
    }
}
Also used : HttpConfigurable(com.intellij.util.net.HttpConfigurable) AuthScope(org.apache.commons.httpclient.auth.AuthScope)

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