掃二維碼與項目經(jīng)理溝通
我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流

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

我們在微信上24小時期待你的聲音
解答本文疑問/技術(shù)咨詢/運營咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流