Example usage for java.net Authenticator requestPasswordAuthentication

List of usage examples for java.net Authenticator requestPasswordAuthentication

Introduction

In this page you can find the example usage for java.net Authenticator requestPasswordAuthentication.

Prototype

public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol,
        String prompt, String scheme) 

Source Link

Document

Ask the authenticator that has been registered with the system for a password.

Usage

From source file:org.droidparts.http.worker.HttpURLConnectionWorker.java

private void setupBasicAuth() {
    if (passAuth != null) {
        Authenticator.setDefault(new FixedAuthenticator(passAuth));
        if (!AuthScope.ANY.equals(authScope)) {
            InetAddress host = null;
            if (authScope.getHost() != null) {
                try {
                    host = InetAddress.getByName(authScope.getHost());
                } catch (UnknownHostException e) {
                    L.e("Failed to setup basic auth.");
                    L.d(e);//from w ww  . j  av  a  2  s. c o  m
                    Authenticator.setDefault(null);
                    return;
                }
            }
            int port = (authScope.getPort() == AuthScope.ANY_PORT) ? 0 : authScope.getPort();
            Authenticator.requestPasswordAuthentication(host, port, null, authScope.getRealm(),
                    authScope.getScheme());
        }
    }
}