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(String host, InetAddress addr, int port,
        String protocol, String prompt, String scheme, URL url, RequestorType reqType) 

Source Link

Document

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

Usage

From source file:es.mityc.firmaJava.ts.AuthenticatorProxyCredentials.java

private void refreshAuthenticator() {
    String proxyHost = System.getProperty("http.proxyHost");
    int proxyPort = 80;
    try {/*  www.j  av  a  2  s .  c o m*/
        proxyPort = Integer.parseInt(System.getProperty("http.proxyPort"));
    } catch (NumberFormatException ex) {
    }
    try {
        pa = Authenticator.requestPasswordAuthentication(proxyHost, null, proxyPort, "HTTP", "", "http", null,
                RequestorType.PROXY);
    } catch (SecurityException ex) {
        pa = null;
    }
}

From source file:org.callimachusproject.test.WebResource.java

public void patch(String type, byte[] body) throws IOException {
    ByteArrayEntity entity = new ByteArrayEntity(body);
    entity.setContentType(type);/*from   w w w  . j  a v  a 2s. c  o m*/
    HttpPatch req = new HttpPatch(uri);
    req.setEntity(entity);
    DefaultHttpClient client = new DefaultHttpClient();
    URL url = req.getURI().toURL();
    int port = url.getPort();
    String host = url.getHost();
    PasswordAuthentication passAuth = Authenticator.requestPasswordAuthentication(url.getHost(),
            InetAddress.getByName(url.getHost()), port, url.getProtocol(), "", "digest", url,
            RequestorType.SERVER);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(passAuth.getUserName(),
            new String(passAuth.getPassword()));
    client.getCredentialsProvider().setCredentials(new AuthScope(host, port), credentials);
    client.execute(req, new ResponseHandler<Void>() {
        public Void handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
            StatusLine status = response.getStatusLine();
            int code = status.getStatusCode();
            if (code != 200 && code != 204) {
                Assert.assertEquals(status.getReasonPhrase(), 204, code);
            }
            return null;
        }
    });
}

From source file:org.apache.tools.ant.taskdefs.optional.net2.FTP2.java

@Nullable
private static PasswordAuthentication getPasswordAuthentication(String host, int port,
        @Nullable String defaultUserId, @Nullable String defaultPassword, RequestorType requestorType) {

    if (defaultUserId != null) {
        if (defaultPassword == null)
            throw new BuildException("Password missing");
        return new PasswordAuthentication(defaultUserId, defaultPassword.toCharArray());
    }/*from   ww w  .  ja va2s.  c om*/

    InetAddress addr;
    try {
        addr = InetAddress.getByName(host);
    } catch (UnknownHostException uhe) {
        throw new BuildException(uhe);
    }

    return Authenticator.requestPasswordAuthentication(host, // host
            addr, // addr
            port, // port
            "ftp", // protocol
            "FTP", // prompt
            null, // scheme
            null, // url
            requestorType // reqType
    );
}