Example usage for org.apache.http.auth NTCredentials NTCredentials

List of usage examples for org.apache.http.auth NTCredentials NTCredentials

Introduction

In this page you can find the example usage for org.apache.http.auth NTCredentials NTCredentials.

Prototype

public NTCredentials(final String userName, final String password, final String workstation,
        final String domain) 

Source Link

Document

Constructor.

Usage

From source file:org.miloss.fgsms.bueller.Bueller.java

protected Credentials transformCredentials(String[] info) {
    if (info.length == 2) {
        return new UsernamePasswordCredentials(info[0], Utility.DE(info[1]));
    }//from  ww  w  .  j  a v a  2s. co  m
    if (info.length == 3) {
        TransportAuthenticationStyle tas = TransportAuthenticationStyle.valueOf(info[2]);
        switch (tas) {
            case HTTP_NTLM:
                String data = info[0];
                String[] t = data.split("\\\\");
                String username = t[1];
                String domain = t[0];
                return new NTCredentials(username, Utility.DE(info[1]), SLACommon.GetHostName(), domain);
            case HTTP_DIGEST:
            case HTTP_BASIC:
            default:
                return new UsernamePasswordCredentials(info[0], Utility.DE(info[1]));
        }
    }
    return null;
}

From source file:com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientImpl.java

private Credentials _getProxyCredentials() {
    if ("ntlm".equalsIgnoreCase(_proxyAuthType)) {
        return new NTCredentials(_proxyLogin, _proxyPassword, _proxyWorkstation, _proxyDomain);
    }/*w ww.  j a  v a 2 s.co m*/

    return new UsernamePasswordCredentials(_proxyLogin, _proxyPassword);
}

From source file:org.apache.maven.wagon.providers.http.AbstractHttpClientWagon.java

protected CloseableHttpResponse execute(HttpUriRequest httpMethod) throws HttpException, IOException {
    setHeaders(httpMethod);//  w w  w  . j  a v  a 2s.c  o  m
    String userAgent = getUserAgent(httpMethod);
    if (userAgent != null) {
        httpMethod.setHeader(HTTP.USER_AGENT, userAgent);
    }

    RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
    // WAGON-273: default the cookie-policy to browser compatible
    requestConfigBuilder.setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);

    Repository repo = getRepository();
    ProxyInfo proxyInfo = getProxyInfo(repo.getProtocol(), repo.getHost());
    if (proxyInfo != null) {
        HttpHost proxy = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
        requestConfigBuilder.setProxy(proxy);
    }

    HttpMethodConfiguration config = httpConfiguration == null ? null
            : httpConfiguration.getMethodConfiguration(httpMethod);

    if (config != null) {
        ConfigurationUtils.copyConfig(config, requestConfigBuilder);
    } else {
        requestConfigBuilder.setSocketTimeout(getReadTimeout());
    }

    localContext.setRequestConfig(requestConfigBuilder.build());

    if (config != null && config.isUsePreemptive()) {
        HttpHost targetHost = new HttpHost(repo.getHost(), repo.getPort(), repo.getProtocol());
        AuthScope targetScope = getBasicAuthScope().getScope(targetHost);

        if (credentialsProvider.getCredentials(targetScope) != null) {
            BasicScheme targetAuth = new BasicScheme();
            targetAuth.processChallenge(new BasicHeader(AUTH.WWW_AUTH, "BASIC preemptive"));
            authCache.put(targetHost, targetAuth);
        }
    }

    if (proxyInfo != null) {
        if (proxyInfo.getHost() != null) {
            HttpHost proxyHost = new HttpHost(proxyInfo.getHost(), proxyInfo.getPort());
            AuthScope proxyScope = getProxyBasicAuthScope().getScope(proxyHost);

            String proxyUsername = proxyInfo.getUserName();
            String proxyPassword = proxyInfo.getPassword();
            String proxyNtlmHost = proxyInfo.getNtlmHost();
            String proxyNtlmDomain = proxyInfo.getNtlmDomain();

            if (proxyUsername != null && proxyPassword != null) {
                Credentials creds;
                if (proxyNtlmHost != null || proxyNtlmDomain != null) {
                    creds = new NTCredentials(proxyUsername, proxyPassword, proxyNtlmHost, proxyNtlmDomain);
                } else {
                    creds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
                }

                credentialsProvider.setCredentials(proxyScope, creds);
                BasicScheme proxyAuth = new BasicScheme();
                proxyAuth.processChallenge(new BasicHeader(AUTH.PROXY_AUTH, "BASIC preemptive"));
                authCache.put(proxyHost, proxyAuth);
            }
        }
    }

    return CLIENT.execute(httpMethod, localContext);
}

From source file:ti.modules.titanium.network.TiHTTPClient.java

public void open(String method, String url) {
    Log.d(TAG, "open request method=" + method + " url=" + url, Log.DEBUG_MODE);

    if (url == null) {
        Log.e(TAG, "Unable to open a null URL");
        throw new IllegalArgumentException("URL cannot be null");
    }//from   ww  w  .j  av a  2  s  . c  o  m

    // if the url is not prepended with either http or 
    // https, then default to http and prepend the protocol
    // to the url
    String lowerCaseUrl = url.toLowerCase();
    if (!lowerCaseUrl.startsWith("http://") && !lowerCaseUrl.startsWith("https://")) {
        url = "http://" + url;
    }

    if (autoEncodeUrl) {
        this.uri = TiUrl.getCleanUri(url);

    } else {
        this.uri = Uri.parse(url);
    }

    // If the original url does not contain any
    // escaped query string (i.e., does not look
    // pre-encoded), go ahead and reset it to the 
    // clean uri. Else keep it as is so the user's
    // escaping stays in effect.  The users are on their own
    // at that point.
    if (autoEncodeUrl && !url.matches(".*\\?.*\\%\\d\\d.*$")) {
        this.url = this.uri.toString();

    } else {
        this.url = url;
    }

    redirectedLocation = null;
    this.method = method;
    String hostString = uri.getHost();
    int port = PROTOCOL_DEFAULT_PORT;

    // The Android Uri doesn't seem to handle user ids with at-signs (@) in them
    // properly, even if the @ is escaped.  It will set the host (uri.getHost()) to
    // the part of the user name after the @.  For example, this Uri would get
    // the host set to appcelerator.com when it should be mickey.com:
    // http://testuser@appcelerator.com:password@mickey.com/xx
    // ... even if that first one is escaped to ...
    // http://testuser%40appcelerator.com:password@mickey.com/xx
    // Tests show that Java URL handles it properly, however.  So revert to using Java URL.getHost()
    // if we see that the Uri.getUserInfo has an at-sign in it.
    // Also, uri.getPort() will throw an exception as it will try to parse what it thinks is the port
    // part of the Uri (":password....") as an int.  So in this case we'll get the port number
    // as well from Java URL.  See Lighthouse ticket 2150.
    if (uri.getUserInfo() != null && uri.getUserInfo().contains("@")) {
        URL javaUrl;
        try {
            javaUrl = new URL(uri.toString());
            hostString = javaUrl.getHost();
            port = javaUrl.getPort();

        } catch (MalformedURLException e) {
            Log.e(TAG, "Error attempting to derive Java url from uri: " + e.getMessage(), e);
        }

    } else {
        port = uri.getPort();
    }

    Log.d(TAG, "Instantiating host with hostString='" + hostString + "', port='" + port + "', scheme='"
            + uri.getScheme() + "'", Log.DEBUG_MODE);

    host = new HttpHost(hostString, port, uri.getScheme());
    if (uri.getUserInfo() != null) {
        credentials = new UsernamePasswordCredentials(uri.getUserInfo());
    }
    if (credentials == null) {
        String userName = ((HTTPClientProxy) proxy).getUsername();
        String password = ((HTTPClientProxy) proxy).getPassword();
        String domain = ((HTTPClientProxy) proxy).getDomain();
        if (domain != null) {
            password = (password == null) ? "" : password;
            credentials = new NTCredentials(userName, password, TiPlatformHelper.getMobileId(), domain);
        } else {
            if (userName != null) {
                password = (password == null) ? "" : password;
                credentials = new UsernamePasswordCredentials(userName, password);
            }
        }
    }
    setReadyState(READY_STATE_OPENED);
    setRequestHeader("User-Agent", TITANIUM_USER_AGENT);
    // Causes Auth to Fail with twitter and other size apparently block X- as well
    // Ticket #729, ignore twitter for now
    if (!hostString.contains("twitter.com")) {
        setRequestHeader("X-Requested-With", "XMLHttpRequest");

    } else {
        Log.i(TAG, "Twitter: not sending X-Requested-With header", Log.DEBUG_MODE);
    }
}

From source file:org.apache.manifoldcf.authorities.authorities.sharepoint.SharePointAuthority.java

protected void getSharePointSession() throws ManifoldCFException {
    if (proxy == null) {
        // Set up server URL
        try {//  ww w  .j  av  a 2  s.  c  o m
            if (serverPortString == null || serverPortString.length() == 0) {
                if (serverProtocol.equals("https"))
                    this.serverPort = 443;
                else
                    this.serverPort = 80;
            } else
                this.serverPort = Integer.parseInt(serverPortString);
        } catch (NumberFormatException e) {
            throw new ManifoldCFException(e.getMessage(), e);
        }

        int proxyPort = 8080;
        if (proxyPortString != null && proxyPortString.length() > 0) {
            try {
                proxyPort = Integer.parseInt(proxyPortString);
            } catch (NumberFormatException e) {
                throw new ManifoldCFException(e.getMessage(), e);
            }
        }

        serverUrl = serverProtocol + "://" + serverName;
        if (serverProtocol.equals("https")) {
            if (serverPort != 443)
                serverUrl += ":" + Integer.toString(serverPort);
        } else {
            if (serverPort != 80)
                serverUrl += ":" + Integer.toString(serverPort);
        }

        fileBaseUrl = serverUrl + encodedServerLocation;

        int connectionTimeout = 60000;
        int socketTimeout = 900000;

        // Set up ssl if indicated

        connectionManager = new PoolingHttpClientConnectionManager();

        CredentialsProvider credentialsProvider = new BasicCredentialsProvider();

        SSLConnectionSocketFactory myFactory = null;
        if (keystoreData != null) {
            keystoreManager = KeystoreManagerFactory.make("", keystoreData);
            myFactory = new SSLConnectionSocketFactory(keystoreManager.getSecureSocketFactory(),
                    new BrowserCompatHostnameVerifier());
        }

        if (strippedUserName != null) {
            credentialsProvider.setCredentials(new AuthScope(serverName, serverPort),
                    new NTCredentials(strippedUserName, password, currentHost, ntlmDomain));
        }

        RequestConfig.Builder requestBuilder = RequestConfig.custom().setCircularRedirectsAllowed(true)
                .setSocketTimeout(socketTimeout).setStaleConnectionCheckEnabled(true)
                .setExpectContinueEnabled(false).setConnectTimeout(connectionTimeout)
                .setConnectionRequestTimeout(socketTimeout);

        // If there's a proxy, set that too.
        if (proxyHost != null && proxyHost.length() > 0) {

            // Configure proxy authentication
            if (proxyUsername != null && proxyUsername.length() > 0) {
                if (proxyPassword == null)
                    proxyPassword = "";
                if (proxyDomain == null)
                    proxyDomain = "";

                credentialsProvider.setCredentials(new AuthScope(proxyHost, proxyPort),
                        new NTCredentials(proxyUsername, proxyPassword, currentHost, proxyDomain));
            }

            HttpHost proxy = new HttpHost(proxyHost, proxyPort);

            requestBuilder.setProxy(proxy);
        }

        HttpClientBuilder builder = HttpClients.custom().setConnectionManager(connectionManager)
                .setMaxConnTotal(1).disableAutomaticRetries().setDefaultRequestConfig(requestBuilder.build())
                .setDefaultSocketConfig(
                        SocketConfig.custom().setTcpNoDelay(true).setSoTimeout(socketTimeout).build())
                .setDefaultCredentialsProvider(credentialsProvider);
        if (myFactory != null)
            builder.setSSLSocketFactory(myFactory);
        builder.setRequestExecutor(new HttpRequestExecutor(socketTimeout))
                .setRedirectStrategy(new DefaultRedirectStrategy());
        httpClient = builder.build();

        proxy = new SPSProxyHelper(serverUrl, encodedServerLocation, serverLocation, serverUserName, password,
                org.apache.manifoldcf.connectorcommon.common.CommonsHTTPSender.class, "client-config.wsdd",
                httpClient, isClaimSpace);

    }
    sharepointSessionTimeout = System.currentTimeMillis() + SharePointExpirationInterval;
}

From source file:com.cws.esolutions.core.utils.NetworkUtils.java

/**
 * Creates an HTTP connection to a provided website and returns the data back
 * to the requestor.//from  w  w w . j av  a2 s. c om
 *
 * @param hostName - The fully qualified URL for the host desired. MUST be
 *     prefixed with http/https:// as necessary
 * @param methodType - GET or POST, depending on what is necessary
 * @return A object containing the response data
 * @throws UtilityException {@link com.cws.esolutions.core.utils.exception.UtilityException} if an error occurs processing
 */
public static final synchronized Object executeHttpConnection(final URL hostName, final String methodType)
        throws UtilityException {
    final String methodName = NetworkUtils.CNAME
            + "#executeHttpConnection(final URL hostName, final String methodType) throws UtilityException";

    if (DEBUG) {
        DEBUGGER.debug(methodName);
        DEBUGGER.debug("Value: {}", hostName);
        DEBUGGER.debug("Value: {}", methodType);
    }

    RequestConfig requestConfig = null;
    CloseableHttpClient httpClient = null;
    CredentialsProvider credsProvider = null;
    CloseableHttpResponse httpResponse = null;

    final HttpClientParams httpParams = new HttpClientParams();
    final HTTPConfig httpConfig = appBean.getConfigData().getHttpConfig();
    final ProxyConfig proxyConfig = appBean.getConfigData().getProxyConfig();

    if (DEBUG) {
        DEBUGGER.debug("HttpClient: {}", httpClient);
        DEBUGGER.debug("HttpClientParams: {}", httpParams);
        DEBUGGER.debug("HTTPConfig: {}", httpConfig);
        DEBUGGER.debug("ProxyConfig: {}", proxyConfig);
    }
    try {
        final URI requestURI = new URIBuilder().setScheme(hostName.getProtocol()).setHost(hostName.getHost())
                .setPort(hostName.getPort()).build();

        if (StringUtils.isNotEmpty(httpConfig.getTrustStoreFile())) {
            System.setProperty("javax.net.ssl.trustStoreType",
                    (StringUtils.isNotEmpty(httpConfig.getTrustStoreType()) ? httpConfig.getTrustStoreType()
                            : "jks"));
            System.setProperty("javax.net.ssl.trustStore", httpConfig.getTrustStoreFile());
            System.setProperty("javax.net.ssl.trustStorePassword",
                    PasswordUtils.decryptText(httpConfig.getTrustStorePass(), httpConfig.getTrustStoreSalt(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                            secBean.getConfigData().getSecurityConfig().getIterations(),
                            secBean.getConfigData().getSecurityConfig().getKeyBits(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionInstance(),
                            appBean.getConfigData().getSystemConfig().getEncoding()));
        }

        if (StringUtils.isNotEmpty(httpConfig.getKeyStoreFile())) {
            System.setProperty("javax.net.ssl.keyStoreType",
                    (StringUtils.isNotEmpty(httpConfig.getKeyStoreType()) ? httpConfig.getKeyStoreType()
                            : "jks"));
            System.setProperty("javax.net.ssl.keyStore", httpConfig.getKeyStoreFile());
            System.setProperty("javax.net.ssl.keyStorePassword",
                    PasswordUtils.decryptText(httpConfig.getKeyStorePass(), httpConfig.getKeyStoreSalt(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                            secBean.getConfigData().getSecurityConfig().getIterations(),
                            secBean.getConfigData().getSecurityConfig().getKeyBits(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                            secBean.getConfigData().getSecurityConfig().getEncryptionInstance(),
                            appBean.getConfigData().getSystemConfig().getEncoding()));
        }

        if (proxyConfig.isProxyServiceRequired()) {
            if (DEBUG) {
                DEBUGGER.debug("ProxyConfig: {}", proxyConfig);
            }

            if (StringUtils.isEmpty(proxyConfig.getProxyServerName())) {
                throw new UtilityException(
                        "Configuration states proxy usage is required, but no proxy is configured.");
            }

            if (proxyConfig.isProxyAuthRequired()) {
                List<String> authList = new ArrayList<String>();
                authList.add(AuthPolicy.BASIC);
                authList.add(AuthPolicy.DIGEST);
                authList.add(AuthPolicy.NTLM);

                if (DEBUG) {
                    DEBUGGER.debug("authList: {}", authList);
                }

                requestConfig = RequestConfig.custom()
                        .setConnectionRequestTimeout(
                                (int) TimeUnit.SECONDS.toMillis(httpConfig.getConnTimeout()))
                        .setConnectTimeout((int) TimeUnit.SECONDS.toMillis(httpConfig.getConnTimeout()))
                        .setContentCompressionEnabled(Boolean.TRUE)
                        .setProxy(new HttpHost(proxyConfig.getProxyServerName(),
                                proxyConfig.getProxyServerPort()))
                        .setProxyPreferredAuthSchemes(authList).build();

                if (DEBUG) {
                    DEBUGGER.debug("requestConfig: {}", requestConfig);
                }

                String proxyPwd = PasswordUtils.decryptText(proxyConfig.getProxyPassword(),
                        proxyConfig.getProxyPwdSalt(),
                        secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                        secBean.getConfigData().getSecurityConfig().getIterations(),
                        secBean.getConfigData().getSecurityConfig().getKeyBits(),
                        secBean.getConfigData().getSecurityConfig().getEncryptionAlgorithm(),
                        secBean.getConfigData().getSecurityConfig().getEncryptionInstance(),
                        appBean.getConfigData().getSystemConfig().getEncoding());

                if (DEBUG) {
                    DEBUGGER.debug("proxyPwd: {}", proxyPwd);
                }

                if (StringUtils.equals(NetworkUtils.PROXY_AUTH_TYPE_BASIC, proxyConfig.getProxyAuthType())) {
                    credsProvider = new SystemDefaultCredentialsProvider();
                    credsProvider.setCredentials(
                            new AuthScope(proxyConfig.getProxyServerName(), proxyConfig.getProxyServerPort()),
                            new UsernamePasswordCredentials(proxyConfig.getProxyUserId(), proxyPwd));
                } else if (StringUtils.equals(NetworkUtils.PROXY_AUTH_TYPE_NTLM,
                        proxyConfig.getProxyAuthType())) {
                    credsProvider = new SystemDefaultCredentialsProvider();
                    credsProvider.setCredentials(
                            new AuthScope(proxyConfig.getProxyServerName(), proxyConfig.getProxyServerPort()),
                            new NTCredentials(proxyConfig.getProxyUserId(), proxyPwd,
                                    InetAddress.getLocalHost().getHostName(),
                                    proxyConfig.getProxyAuthDomain()));
                }

                if (DEBUG) {
                    DEBUGGER.debug("httpClient: {}", httpClient);
                }
            }
        }

        synchronized (new Object()) {
            httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();

            if (StringUtils.equalsIgnoreCase(methodType, "POST")) {
                HttpPost httpMethod = new HttpPost(requestURI);
                httpMethod.setConfig(requestConfig);

                httpResponse = httpClient.execute(httpMethod);
            } else {
                HttpGet httpMethod = new HttpGet(requestURI);
                httpMethod.setConfig(requestConfig);

                httpResponse = httpClient.execute(httpMethod);
            }

            int responseCode = httpResponse.getStatusLine().getStatusCode();

            if (DEBUG) {
                DEBUGGER.debug("responseCode: {}", responseCode);
            }

            if (responseCode != 200) {
                ERROR_RECORDER.error("HTTP Response Code received NOT 200: " + responseCode);

                throw new UtilityException("HTTP Response Code received NOT 200: " + responseCode);
            }

            return httpResponse.getEntity().toString();
        }
    } catch (ConnectException cx) {
        throw new UtilityException(cx.getMessage(), cx);
    } catch (UnknownHostException ux) {
        throw new UtilityException(ux.getMessage(), ux);
    } catch (SocketException sx) {
        throw new UtilityException(sx.getMessage(), sx);
    } catch (IOException iox) {
        throw new UtilityException(iox.getMessage(), iox);
    } catch (URISyntaxException usx) {
        throw new UtilityException(usx.getMessage(), usx);
    } finally {
        if (httpResponse != null) {
            try {
                httpResponse.close();
            } catch (IOException iox) {
            } // dont do anything with it
        }
    }
}

From source file:com.groupon.odo.bmp.http.BrowserMobHttpClient.java

public void autoNTLMAuthorization(String domain, String username, String password) {
    authType = AuthType.NTLM;// w  w w  . j av a 2  s  .  c  o  m
    httpClient.getCredentialsProvider().setCredentials(new AuthScope(domain, -1),
            new NTCredentials(username, password, "workstation", domain));
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Implementation method for the CredentialsProvider interface.
 * <p>/*  ww w  .  j av a  2s .  co m*/
 * Based on sample code:
 * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a>
 *
 */
public Credentials getCredentials(AuthScope scope) {
    if (scope == null || scope.getScheme() == null) {
        return null;
    }
    Credentials credentials = mCredentialProvider.getCredentials(scope);
    if (credentials != null) {
        return credentials;
    }

    try {
        if (scope.getScheme().equals("ntlm")) {
            //if (authscheme instanceof NTLMScheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html>Host <b>" + scope.getHost() + ":" + scope.getPort()
                            + "</b> requires Windows authentication</html>",
                    true);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(),
                        pwDialog.getDomain());
            }
            pwDialog.dispose();
        } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) {
            //if (authscheme instanceof RFC2617Scheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>"
                            + " requires authentication for the realm:<br><b>" + scope.getRealm()
                            + "</b></center></html>",
                    false);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new UsernamePasswordCredentials(pwDialog.getUser(), pwDialog.getPassword());
            }
            pwDialog.dispose();
        } else {
            throw new IllegalArgumentException("Unsupported authentication scheme: " + scope.getScheme());
        }
        if (credentials != null) {
            mCredentialProvider.setCredentials(scope, credentials);
        }
        return credentials;
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Implementation method for the CredentialsProvider interface.
 * <p>//w w  w .j a va  2 s  . c  o m
 * Based on sample code:
 * <a href="http://svn.apache.org/viewvc/jakarta/commons/proper/httpclient/trunk/src/examples/InteractiveAuthenticationExample.java?view=markup">InteractiveAuthenticationExample</a>
 *
 */
public Credentials getCredentials(AuthScope scope) {
    if (scope == null || scope.getScheme() == null) {
        return null;
    }
    Credentials credentials = mCredentialProvider.getCredentials(scope);
    if (credentials != null) {
        return credentials;
    }
    try {
        if (scope.getScheme().equals("ntlm")) {
            //if (authscheme instanceof NTLMScheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html>Host <b>" + scope.getHost() + ":" + scope.getPort()
                            + "</b> requires Windows authentication</html>",
                    true);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new NTCredentials(pwDialog.getUser(), pwDialog.getPassword(), scope.getHost(),
                        pwDialog.getDomain());
            }
            pwDialog.dispose();
        } else if (scope.getScheme().equals("basic") || scope.getScheme().equals("digest")) {
            //if (authscheme instanceof RFC2617Scheme) {
            AuthenticationDialog pwDialog = new AuthenticationDialog(ownerFrame, "Authentication Required",
                    "<html><center>Host <b>" + scope.getHost() + ":" + scope.getPort() + "</b>"
                            + " requires authentication for the realm:<br><b>" + scope.getRealm()
                            + "</b></center></html>",
                    false);
            pwDialog.setVisible(true);
            if (pwDialog.getUser().length() > 0) {
                credentials = new UsernamePasswordCredentials(pwDialog.getUser(), pwDialog.getPassword());
            }
            pwDialog.dispose();
        } else {
            throw new IllegalArgumentException("Unsupported authentication scheme: " + scope.getScheme());
        }
        if (credentials != null) {
            mCredentialProvider.setCredentials(scope, credentials);
        }
        return credentials;
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}