extends Authenticator : Authenticator « java.net « Java by API






extends Authenticator

  

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;

public class MainClass {

  public static void main(String args[]) throws Exception {

    Authenticator.setDefault(new DialogAuthenticator());

    URL u = new URL("secure url");
    InputStream in = u.openStream();
    in = new BufferedInputStream(in);
    Reader r = new InputStreamReader(in);
    int c;
    while ((c = r.read()) != -1) {
      System.out.print((char) c);
    }
  }

}

class DialogAuthenticator extends Authenticator {

  public DialogAuthenticator() {
  }

  public PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("username", "password".toCharArray());
  }

}

   
    
  








Related examples in the same category

1.Authenticator: setDefault(Authenticator a)