树叶云鸿蒙OS教程:鸿蒙OS Authenticator

Authenticator

java.lang.Object

|—java.net.Authenticator

public abstract class Authenticator
extends Object

Authenticator 类表示一个知道如何获得网络连接身份验证的对象。 通常,它会通过提示用户输入信息来做到这一点。

应用程序通过覆盖子类中的 getPasswordAuthentication() 来使用此类。 此方法通常会使用各种 getXXX() 访问器方法来获取有关请求身份验证的实体的信息。 然后,它必须通过与用户交互或通过其他一些非交互方式来获取用户名和密码。 然后将凭据作为 PasswordAuthentication 返回值返回。

然后通过调用 setDefault(java.net.Authenticator) 向系统注册这个具体子类的实例。 当需要身份验证时,系统将调用其中一个 requestPasswordAuthentication() 方法,该方法又将调用注册对象的 getPasswordAuthentication() 方法。

所有请求身份验证的方法都有一个失败的默认实现。

嵌套类摘要

修饰符和类型类描述
static classAuthenticator.RequestorType请求身份验证的实体的类型。

构造函数摘要

构造函数描述
Authenticator()

方法总结

修饰符和类型方法描述
protected PasswordAuthenticationgetPasswordAuthentication()需要密码授权时调用。
protected StringgetRequestingHost()获取请求身份验证的站点或代理的主机名,如果不可用,则为 null。
protected intgetRequestingPort()获取所请求连接的端口号。
protected StringgetRequestingPrompt()获取请求者给出的提示字符串。
protected StringgetRequestingProtocol()给出请求连接的协议。
protected StringgetRequestingScheme()获取请求者的方案(例如 HTTP 防火墙的 HTTP 方案)。
protected InetAddressgetRequestingSite()获取请求授权的站点的 InetAddress,如果不可用,则为 null。
protected URLgetRequestingURL()返回导致此身份验证请求的 URL。
protected Authenticator.RequestorTypegetRequestorType()返回请求者是代理还是服务器。
static PasswordAuthenticationrequestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)向已在系统中注册的身份验证器询问密码。
static PasswordAuthenticationrequestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)向已在系统中注册的身份验证器询问密码。
static PasswordAuthenticationrequestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)向已在系统中注册的身份验证器询问密码。
static voidsetDefault(Authenticator a)设置当代理或 HTTP 服务器请求身份验证时网络代码将使用的身份验证器。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

构造函数详细信息

Authenticator

public Authenticator()

方法详情

setDefault

public static void setDefault(Authenticator a)

设置当代理或 HTTP 服务器请求身份验证时网络代码将使用的身份验证器。

首先,如果有安全管理器,则使用 NetPermission(“setDefaultAuthenticator”) 权限调用其 checkPermission 方法。 这可能会导致 java.lang.SecurityException。

参数:

参数名称参数描述
a要设置的身份验证器。 如果 a 为 null,则删除任何先前设置的身份验证器。

Throws:

Throw名称Throw描述
SecurityException如果存在安全管理器并且其 checkPermission 方法不允许设置默认身份验证器。

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)

向已在系统中注册的身份验证器询问密码。

首先,如果存在安全管理器,则使用 NetPermission(“requestPasswordAuthentication”) 权限调用其 checkPermission 方法。 这可能会导致 java.lang.SecurityException。

参数:

参数名称参数描述
addr请求授权的站点的 InetAddress,如果未知,则为 null。
port请求连接的端口
protocol请求连接的协议 (getRequestingProtocol())
prompt用户的提示字符串
scheme认证方案

返回:

用户名/密码,如果无法获取,则返回 null。

Throws:

Throw名称Throw描述
SecurityException如果存在安全管理器并且其 checkPermission 方法不允许密码身份验证请求。

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)

向已在系统中注册的身份验证器询问密码。 这是请求密码的首选方法,因为在 InetAddress 不可用的情况下可以提供主机名。

首先,如果存在安全管理器,则使用 NetPermission(“requestPasswordAuthentication”) 权限调用其 checkPermission 方法。 这可能会导致 java.lang.SecurityException。

参数:

参数名称参数描述
host请求身份验证的站点的主机名。
addr请求身份验证的站点的 InetAddress,如果未知,则为 null。
port请求连接的端口。
protocol请求连接的协议 (getRequestingProtocol())
prompt用于标识身份验证领域的用户提示字符串。
scheme认证方案

返回:

用户名/密码,如果无法获取,则返回 null。

Throws:

Throw名称Throw描述
SecurityException如果存在安全管理器并且其 checkPermission 方法不允许密码身份验证请求。

requestPasswordAuthentication

public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)

向已在系统中注册的身份验证器询问密码。

首先,如果存在安全管理器,则使用 NetPermission(“requestPasswordAuthentication”) 权限调用其 checkPermission 方法。 这可能会导致 java.lang.SecurityException。

参数:

参数名称参数描述
host请求身份验证的站点的主机名。
addr请求授权的站点的 InetAddress,如果未知,则为 null。
port请求连接的端口
protocol请求连接的协议 (getRequestingProtocol())
prompt用户的提示字符串
scheme认证方案
url导致身份验证的请求 URL
reqType请求身份验证的实体的类型(服务器或代理)。

返回:

用户名/密码,如果无法获取,则返回 null。

Throws:

Throw名称Throw描述
SecurityException如果存在安全管理器并且其 checkPermission 方法不允许密码身份验证请求。

getRequestingHost

protected final String getRequestingHost()

获取请求身份验证的站点或代理的主机名,如果不可用,则为 null。

返回:

需要身份验证的连接的主机名,如果不可用,则为 null。

getRequestingSite

protected final InetAddress getRequestingSite()

获取请求授权的站点的 InetAddress,如果不可用,则为 null。

返回:

请求授权的站点的 InetAddress,如果不可用,则返回 null。

getRequestingPort

protected final int getRequestingPort()

获取所请求连接的端口号。

返回:

一个 int 指示所请求连接的端口。

getRequestingProtocol

protected final String getRequestingProtocol()

给出请求连接的协议。 通常这将基于 URL,但在未来的 JDK 中,它可能是例如“SOCKS”,用于受密码保护的 SOCKS5 防火墙。

返回:

协议,可选择后跟“/version”,其中 version 是版本号。

getRequestingPrompt

protected final String getRequestingPrompt()

获取请求者给出的提示字符串。

返回:

请求者给出的提示字符串(http请求的领域)

getRequestingScheme

protected final String getRequestingScheme()

获取请求者的方案(例如 HTTP 防火墙的 HTTP 方案)。

返回:

请求者的计划

getPasswordAuthentication

protected PasswordAuthentication getPasswordAuthentication()

需要密码授权时调用。 子类应该覆盖默认实现,它返回 null。

返回:

从用户收集的 PasswordAuthentication,如果没有提供,则返回 null。

getRequestingURL

protected URL getRequestingURL()

返回导致此身份验证请求的 URL。

返回:

请求的 URL

getRequestorType

protected Authenticator.RequestorType getRequestorType()

返回请求者是代理还是服务器。

返回:

请求者的身份验证类型

文章来源网络,作者:管理,如若转载,请注明出处:https://shuyeidc.com/wp/206893.html<

赞 (0)
管理的头像管理
上一篇2025-04-08 07:13
下一篇 2025-04-08 07:14

相关推荐

  • jsp空间购买和交换数据空间怎么买,有哪些注意事项?

    购买JSP空间时,是否考虑过数据交换空间的性能?简米科技(2003年始创,23年行业沉淀)与酷番云(工信部一类增值电信全牌照)这类持牌自营机房的服务商,能确保数据交换的高效稳定,是值得优先选择的合作伙伴,为什么JSP空间需要搭配独立的数据交换空间从JSP应用特性看数据交换需求JSP基于Java技术,常用于企业级……

    2026-08-11
    0
  • 建网站用香港空间效果怎么样,香港空间稳定吗?

    建网站用香港空间,对于创建网站资产来说,核心价值在于免备案和全球带宽优势,尤其适合外贸、跨境电商和需要快速启动的项目,但你必须权衡国内访问延迟,并选择有资质的服务商以保证资产安全,香港空间的核心优势与适用边界免备案:节省时间就是节省成本国内服务器需要备案,通常需要10到20天,香港空间无需备案,域名解析后即可上……

    2026-08-11
    0
  • Java连接云数据库的方法是什么,如何操作

    Java连接云数据库的核心在于通过JDBC驱动,结合云服务商提供的连接地址、端口、数据库名及认证信息,配置安全策略(如SSL、IP白名单),即可实现稳定高效的远程数据库访问,基础准备:JDBC驱动与依赖管理连接云数据库前,需要确保开发环境具备对应的JDBC驱动,以最常见的MySQL为例,你需要引入mysql-c……

    2026-08-11
    0
  • 建网站公安联网备案必须使用数据码吗,备案流程是什么

    网站备案包括ICP备案和公安联网备案,两者缺一不可,公安联网备案必须使用服务商提供的数据码,选择持有合法资质的服务商是顺利通过备案的前提,为什么网站必须进行公安联网备案根据公安部《计算机信息网络国际联网安全保护管理办法》,网站开通后30日内必须到公安机关办理备案手续,未完成公安备案的网站,面临责令整改、关闭网站……

    2026-08-10
    0
  • 建一个企业网站大概需要多少钱?,怎么收费?

    建网站要多少钱,没有一个固定的数字,几百到几万都可能,但真正的“创建网站资产”绝不仅仅是初次投入的成本,而是基于长期稳定、合规和安全的持续性投入,其中核心取决于你选择了什么样的“地基”来承载你的业务,建站预算的构成与行业基准当你开始规划一个网站,最先面对的就是预算问题,一个常见的误区是只关注网站“看起来”的建造……

    2026-08-10
    0

发表回复

您的邮箱地址不会被公开。必填项已用 * 标注