新聞中心
Authenticator

專注于為中小企業(yè)提供網(wǎng)站設(shè)計(jì)、成都網(wǎng)站設(shè)計(jì)服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)漢陰免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上千多家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
java.lang.Object
|---java.net.Authenticator
public abstract class Authenticator
extends Object
Authenticator 類表示一個(gè)知道如何獲得網(wǎng)絡(luò)連接身份驗(yàn)證的對象。 通常,它會(huì)通過提示用戶輸入信息來做到這一點(diǎn)。
應(yīng)用程序通過覆蓋子類中的 getPasswordAuthentication() 來使用此類。 此方法通常會(huì)使用各種 getXXX() 訪問器方法來獲取有關(guān)請求身份驗(yàn)證的實(shí)體的信息。 然后,它必須通過與用戶交互或通過其他一些非交互方式來獲取用戶名和密碼。 然后將憑據(jù)作為 PasswordAuthentication 返回值返回。
然后通過調(diào)用 setDefault(java.net.Authenticator) 向系統(tǒng)注冊這個(gè)具體子類的實(shí)例。 當(dāng)需要身份驗(yàn)證時(shí),系統(tǒng)將調(diào)用其中一個(gè) requestPasswordAuthentication() 方法,該方法又將調(diào)用注冊對象的 getPasswordAuthentication() 方法。
所有請求身份驗(yàn)證的方法都有一個(gè)失敗的默認(rèn)實(shí)現(xiàn)。
嵌套類摘要
| 修飾符和類型 | 類 | 描述 |
|---|---|---|
| static class | Authenticator.RequestorType | 請求身份驗(yàn)證的實(shí)體的類型。 |
構(gòu)造函數(shù)摘要
| 構(gòu)造函數(shù) | 描述 |
|---|---|
| Authenticator() |
方法總結(jié)
| 修飾符和類型 | 方法 | 描述 |
|---|---|---|
| protected PasswordAuthentication | getPasswordAuthentication() | 需要密碼授權(quán)時(shí)調(diào)用。 |
| protected String | getRequestingHost() | 獲取請求身份驗(yàn)證的站點(diǎn)或代理的主機(jī)名,如果不可用,則為 null。 |
| protected int | getRequestingPort() | 獲取所請求連接的端口號。 |
| protected String | getRequestingPrompt() | 獲取請求者給出的提示字符串。 |
| protected String | getRequestingProtocol() | 給出請求連接的協(xié)議。 |
| protected String | getRequestingScheme() | 獲取請求者的方案(例如 HTTP 防火墻的 HTTP 方案)。 |
| protected InetAddress | getRequestingSite() | 獲取請求授權(quán)的站點(diǎn)的 InetAddress,如果不可用,則為 null。 |
| protected URL | getRequestingURL() | 返回導(dǎo)致此身份驗(yàn)證請求的 URL。 |
| protected Authenticator.RequestorType | getRequestorType() | 返回請求者是代理還是服務(wù)器。 |
| static PasswordAuthentication | requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme) | 向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。 |
| static PasswordAuthentication | requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType) | 向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。 |
| static PasswordAuthentication | requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme) | 向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。 |
| static void | setDefault(Authenticator a) | 設(shè)置當(dāng)代理或 HTTP 服務(wù)器請求身份驗(yàn)證時(shí)網(wǎng)絡(luò)代碼將使用的身份驗(yàn)證器。 |
| 從類 java.lang.Object 繼承的方法 |
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
構(gòu)造函數(shù)詳細(xì)信息
Authenticator
public Authenticator()
方法詳情
setDefault
public static void setDefault(Authenticator a)
設(shè)置當(dāng)代理或 HTTP 服務(wù)器請求身份驗(yàn)證時(shí)網(wǎng)絡(luò)代碼將使用的身份驗(yàn)證器。
首先,如果有安全管理器,則使用 NetPermission("setDefaultAuthenticator") 權(quán)限調(diào)用其 checkPermission 方法。 這可能會(huì)導(dǎo)致 java.lang.SecurityException。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| a | 要設(shè)置的身份驗(yàn)證器。 如果 a 為 null,則刪除任何先前設(shè)置的身份驗(yàn)證器。 |
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| SecurityException | 如果存在安全管理器并且其 checkPermission 方法不允許設(shè)置默認(rèn)身份驗(yàn)證器。 |
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)
向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。
首先,如果存在安全管理器,則使用 NetPermission("requestPasswordAuthentication") 權(quán)限調(diào)用其 checkPermission 方法。 這可能會(huì)導(dǎo)致 java.lang.SecurityException。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| addr | 請求授權(quán)的站點(diǎn)的 InetAddress,如果未知,則為 null。 |
| port | 請求連接的端口 |
| protocol | 請求連接的協(xié)議 (getRequestingProtocol()) |
| prompt | 用戶的提示字符串 |
| scheme | 認(rèn)證方案 |
返回:
用戶名/密碼,如果無法獲取,則返回 null。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| SecurityException | 如果存在安全管理器并且其 checkPermission 方法不允許密碼身份驗(yàn)證請求。 |
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)
向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。 這是請求密碼的首選方法,因?yàn)樵?InetAddress 不可用的情況下可以提供主機(jī)名。
首先,如果存在安全管理器,則使用 NetPermission("requestPasswordAuthentication") 權(quán)限調(diào)用其 checkPermission 方法。 這可能會(huì)導(dǎo)致 java.lang.SecurityException。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| host | 請求身份驗(yàn)證的站點(diǎn)的主機(jī)名。 |
| addr | 請求身份驗(yàn)證的站點(diǎn)的 InetAddress,如果未知,則為 null。 |
| port | 請求連接的端口。 |
| protocol | 請求連接的協(xié)議 (getRequestingProtocol()) |
| prompt | 用于標(biāo)識身份驗(yàn)證領(lǐng)域的用戶提示字符串。 |
| scheme | 認(rèn)證方案 |
返回:
用戶名/密碼,如果無法獲取,則返回 null。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| SecurityException | 如果存在安全管理器并且其 checkPermission 方法不允許密碼身份驗(yàn)證請求。 |
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
向已在系統(tǒng)中注冊的身份驗(yàn)證器詢問密碼。
首先,如果存在安全管理器,則使用 NetPermission("requestPasswordAuthentication") 權(quán)限調(diào)用其 checkPermission 方法。 這可能會(huì)導(dǎo)致 java.lang.SecurityException。
參數(shù):
| 參數(shù)名稱 | 參數(shù)描述 |
|---|---|
| host | 請求身份驗(yàn)證的站點(diǎn)的主機(jī)名。 |
| addr | 請求授權(quán)的站點(diǎn)的 InetAddress,如果未知,則為 null。 |
| port | 請求連接的端口 |
| protocol | 請求連接的協(xié)議 (getRequestingProtocol()) |
| prompt | 用戶的提示字符串 |
| scheme | 認(rèn)證方案 |
| url | 導(dǎo)致身份驗(yàn)證的請求 URL |
| reqType | 請求身份驗(yàn)證的實(shí)體的類型(服務(wù)器或代理)。 |
返回:
用戶名/密碼,如果無法獲取,則返回 null。
Throws:
| Throw名稱 | Throw描述 |
|---|---|
| SecurityException | 如果存在安全管理器并且其 checkPermission 方法不允許密碼身份驗(yàn)證請求。 |
getRequestingHost
protected final String getRequestingHost()
獲取請求身份驗(yàn)證的站點(diǎn)或代理的主機(jī)名,如果不可用,則為 null。
返回:
需要身份驗(yàn)證的連接的主機(jī)名,如果不可用,則為 null。
getRequestingSite
protected final InetAddress getRequestingSite()
獲取請求授權(quán)的站點(diǎn)的 InetAddress,如果不可用,則為 null。
返回:
請求授權(quán)的站點(diǎn)的 InetAddress,如果不可用,則返回 null。
getRequestingPort
protected final int getRequestingPort()
獲取所請求連接的端口號。
返回:
一個(gè) int 指示所請求連接的端口。
getRequestingProtocol
protected final String getRequestingProtocol()
給出請求連接的協(xié)議。 通常這將基于 URL,但在未來的 JDK 中,它可能是例如“SOCKS”,用于受密碼保護(hù)的 SOCKS5 防火墻。
返回:
協(xié)議,可選擇后跟“/version”,其中 version 是版本號。
getRequestingPrompt
protected final String getRequestingPrompt()
獲取請求者給出的提示字符串。
返回:
請求者給出的提示字符串(http請求的領(lǐng)域)
getRequestingScheme
protected final String getRequestingScheme()
獲取請求者的方案(例如 HTTP 防火墻的 HTTP 方案)。
返回:
請求者的計(jì)劃
getPasswordAuthentication
protected PasswordAuthentication getPasswordAuthentication()
需要密碼授權(quán)時(shí)調(diào)用。 子類應(yīng)該覆蓋默認(rèn)實(shí)現(xiàn),它返回 null。
返回:
從用戶收集的 PasswordAuthentication,如果沒有提供,則返回 null。
getRequestingURL
protected URL getRequestingURL()
返回導(dǎo)致此身份驗(yàn)證請求的 URL。
返回:
請求的 URL
getRequestorType
protected Authenticator.RequestorType getRequestorType()
返回請求者是代理還是服務(wù)器。
返回:
請求者的身份驗(yàn)證類型
網(wǎng)站題目:創(chuàng)新互聯(lián)鴻蒙OS教程:鴻蒙OSAuthenticator
標(biāo)題網(wǎng)址:http://m.fisionsoft.com.cn/article/cdheioe.html


咨詢
建站咨詢
