Java 日看一类(62)之net包中的Authenticator类

Java的Authenticator类用于处理网络连接的认证信息,通常通过提示用户输入或非交互方式获取用户名和密码。应用程序可通过覆写getPasswordAuthentication方法来使用。系统在接收到验证请求时会调用注册的Authenticator实例。类包含多个访问器方法获取请求信息,并有reset方法重置为默认值。Authenticator需要与密码授权函数结合使用,抽象并封装了链接验证步骤。
摘要由CSDN通过智能技术生成

该类无引入包和继承类


该类的类头注释如下:

/**
 * 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 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值