001package ca.bc.webarts.widgets;
002
003import java.net.Authenticator;
004import java.net.PasswordAuthentication;
005
006
007/**
008 *  FirewallAuthenticator class *
009 *
010 * @author    tgutwin
011 */
012public class FirewallAuthenticator extends Authenticator
013{
014  public static final String DEFAULT_PROXY_SET = "true";
015  public static final String DEFAULT_PROXY_HOST = "bctcproxy1";
016  public static final String DEFAULT_PROXY_PORT = "80";
017  public static final String DEFAULT_PROXY_NOPROXY = "";
018  /**  The username to use for the proxy authentication. */
019  String proxyUsername = "";
020  /**  The password to use for the proxy authentication. */
021  String proxyPassword = "";
022  /**  The impl of the  PasswordAuthentication for the Authenticator. */
023  PasswordAuthentication pw = new PasswordAuthentication(
024      proxyUsername, proxyPassword.toCharArray() );
025
026
027  /**
028   *  Constructor for the FirewallAuthenticator object
029   *
030   * @param  pw  Description of the Parameter
031   */
032  public FirewallAuthenticator( PasswordAuthentication pw )
033  {
034    this.pw = pw;
035  }
036
037
038  /**
039   *  Constructor for the FirewallAuthenticator object
040   *
041   * @param  proxyUser  Description of the Parameter
042   * @param  proxyPass  Description of the Parameter
043   */
044  public FirewallAuthenticator( String proxyUser, String proxyPass )
045  {
046    if ( proxyUser != null && !proxyUser.equals( "" ) )
047    {
048      proxyUsername = proxyUser;
049    }
050    if ( proxyPass != null && !proxyPass.equals( "" ) )
051    {
052      proxyPassword = proxyPass;
053    }
054    this.pw = new PasswordAuthentication(
055        proxyUsername, proxyPassword.toCharArray() );
056  }
057
058
059  /**
060   *  Impl for Authenticator so an authorizing proxy will work.
061   *
062   * @return    The passwordAuthentication value
063   */
064  protected PasswordAuthentication getPasswordAuthentication()
065  {
066    return this.pw;
067  }
068}
069