该类无引入包和继承类
该类的类头注释如下:
/** * The class Authenticator represents an object that knows how to obtain * authentication for a network connection. Usually, it will do this * by prompting the user for information. * <p> * Applications use this class by overriding { @link * #getPasswordAuthentication()} in a sub-class. This method will * typically use the various getXXX() accessor methods to get information * about the entity requesting authentication. It must then acquire a * username and password either by interacting with the user or through * some other non-interactive means. The credentials are then returned * as a { @link PasswordAuthentication} return value. * <p> * An instance of this concrete sub-class is then registered * with the system by calling { @link #setDefault(Authenticator)}. * When authentication is required, the system will invoke one of the * requestPasswordAuthentication() methods which in turn will call the * getPasswordAuthentication() method of the registered object. * <p> * All methods that request authentication have a default implementation * that fails. * * @see java.net.Authenticator#setDefault(java.net.Authenticator) * @see java.net.Authenticator#getPasswordAuthentication() * * @author Bill Foote * @since 1.2 */
大意如下:
该类用来获得网络连接的认证信息,一般情况下该类通过提示用户输入信息来完成该操作
应用程序通过覆写getPasswordAuthentication方法来使用该类。
该方法经常使用多种getXXX()访问器获取请求验证实体的信息
然后其必须通过与用户交互方式或者一些不需要与用户交互的方式来获得用户名和密码
授权将以getPasswordAuthentication的返回值返回
接下来通过调用setDefault方法向系统注册该子类的实例
当系统接收到验证请求时,系统将会调用其中一个(已注册的)requestPasswordAuthentication方法,这些方法将依次调用注册对象的 getPasswordAuthentication() 方法。
所有验证请求都有默认的失败实现
该类含有如下的成员变量:
系统默认的链接验证口
private static Authenticator theAuthenticator;
请求主机名
private String requestingHost;
请求主机地址
private InetAddress