package nxm.net.lib;

import java.net.Authenticator;
import java.net.InetAddress;
import java.net.PasswordAuthentication;

/** Set the authenticator used for {@link HttpRequester}
 *  that requires HTTP authentication.
 *
 *  @author Jeanette McCall
 *  @since NeXtMidas 3.9.2
 */
public class MyAuthenticator extends Authenticator {
  private static String user;
  private static String pass;
  /** PasswordAuthentication data holder for the username and password */
  public static PasswordAuthentication pa = null;

  /** MyAuthenticator Constructor
   *  @param puser username for authenticator
   *  @param ppass password for authenticator
   */
  public MyAuthenticator(String puser,String ppass) {
    super();
    user=puser;
    pass=ppass;
    pa = new PasswordAuthentication(user,pass.toCharArray());
  }
  protected PasswordAuthentication getPasswordAuthentication() {
    return pa;
  }
  /** Get the current PasswordAuthentication data holder
   *  @param host     Hostname of the requesting site
   *  @param addr     InetAddress of the requesting site
   *  @param port     Port number for the requesting connection
   *  @param protocol Protocol that's requesting the connection
   *  @param prompt   Prompt for the user
   *  @param scheme   Authentication scheme
   *  @return the current PasswordAuthentication data holder
   */
  public static PasswordAuthentication requestPasswordAuthentication(String host,InetAddress addr,int port,String protocol,String prompt,
                                                                     String scheme) {
    return pa;
  }
  /** Get the current PasswordAuthentication data holder
   *  @param addr     InetAddress of the requesting site
   *  @param port     Port number for the requesting connection
   *  @param protocol Protocol that's requesting the connection
   *  @param prompt   Prompt for the user
   *  @param scheme   Authentication scheme
   *  @return the current PasswordAuthentication data holder
   */
  public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr,int port,String protocol,String prompt,
                                                                    String scheme) {
    return pa;
  }
}
