- java.lang.Object
-
- java.net.Authenticator
-
public abstract class Authenticator extends Object
Authenticatorクラスは、ネットワーク接続に必要な認証を取得するためのオブジェクトを表します。 通常は、ユーザーに情報の入力を求めることにより、認証を行います。アプリケーションは、サブクラスで
getPasswordAuthentication()をオーバーライドすることでこのクラスを使用します。 このメソッドは、通常、さまざまなgetXXX()アクセス用メソッドを使用して、認証を要求しているエンティティに関する情報を取得します。 次に、ユーザーとの対話、またはその他の対話以外の方法で、ユーザー名とパスワードを取得する必要があります。 その後、PasswordAuthenticationの戻り値として、資格が返されます。次に、
setDefault(Authenticator)を呼び出すことで、この具象サブクラスのインスタンスがシステムに登録されます。 認証が必要な場合、システムはrequestPasswordAuthentication()メソッドの1つを呼び出し、これが登録されたオブジェクトのgetPasswordAuthentication()メソッドを呼び出します。認証を要求するメソッドはすべて、失敗に終わるデフォルト実装を持っています。
- 導入されたバージョン:
- 1.2
- 関連項目:
setDefault(java.net.Authenticator),getPasswordAuthentication()
-
-
ネストされたクラスのサマリー
ネストされたクラス 修飾子と型 クラス 説明 static classAuthenticator.RequestorType認証を要求しているエンティティのタイプ。
-
コンストラクタのサマリー
コンストラクタ コンストラクタ 説明 Authenticator()
-
メソッドのサマリー
すべてのメソッド staticメソッド インスタンス・メソッド 具象メソッド 修飾子と型 メソッド 説明 static AuthenticatorgetDefault()デフォルトの認証プロバイダを取得します。protected PasswordAuthenticationgetPasswordAuthentication()パスワード認証が必要な場合に呼び出されます。protected StringgetRequestingHost()認証を要求しているサイトまたはプロキシのhostnameを取得します。入手できない場合は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(Authenticator authenticator, String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)与えられたauthenticatorにパスワードを尋ねます。static PasswordAuthenticationrequestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)システムに登録されているオーセンティケータに、パスワードを要求します。PasswordAuthenticationrequestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)このオーセンティケータにパスワードを要求してください。static voidsetDefault(Authenticator a)オーセンティケータを設定します。このオーセンティケータは、プロキシ・サーバーまたはHTTPサーバーからオーセンティケータを要求されたときに、ネットワーク・コードが使います。
-
-
-
メソッドの詳細
-
setDefault
public static void setDefault(Authenticator a)
オーセンティケータを設定します。このオーセンティケータは、プロキシ・サーバーまたはHTTPサーバーからオーセンティケータを要求されたときに、ネットワーク・コードが使います。まず、セキュリティ・マネージャが存在する場合は、その
checkPermissionメソッドがNetPermission("setDefaultAuthenticator")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。- パラメータ:
a- 設定されるオーセンティケータ。 aがnullの場合、以前に設定されたオーセンティケータは削除されます。- 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがデフォルト・オーセンティケータの設定を許可しない場合。- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
getDefault
public static Authenticator getDefault()
デフォルトの認証プロバイダを取得します。 まず、セキュリティ・マネージャが存在する場合は、そのcheckPermissionメソッドがNetPermission("requestPasswordAuthentication")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。 デフォルトのオーセンティケータが設定されている場合は、それが返されます。 それ以外の場合はnullが返されます。- 戻り値:
- デフォルト認証者が設定されている場合は、それ以外の場合は
nullです。 - 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがパスワード認証のリクエストを許可しない場合。- 導入されたバージョン:
- 9
- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String scheme)
システムに登録されているオーセンティケータに、パスワードを要求します。まず、セキュリティ・マネージャが存在する場合は、その
checkPermissionメソッドがNetPermission("requestPasswordAuthentication")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。- パラメータ:
addr- 認証を要求しているサイトのInetAddress。不明の場合はnull。port- 要求された接続に使うポート番号protocol- 接続を要求しているプロトコル(getRequestingProtocol())。prompt- ユーザーに表示されるプロンプト文字列scheme- 認証スキーム- 戻り値:
- ユーザー名またはパスワード。取得できない場合はnull。
- 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがパスワード認証要求を許可しない場合。- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme)
システムに登録されているオーセンティケータに、パスワードを要求します。 InetAddressが使用できない場合はホスト名が提供されるので、この方法でパスワードを要求することをお薦めします。まず、セキュリティ・マネージャが存在する場合は、その
checkPermissionメソッドがNetPermission("requestPasswordAuthentication")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。- パラメータ:
host- 認証を要求しているサイトのホスト名。addr- 認証を要求しているサイトのInetAddress。InetAddressが不明の場合はnull。port- 要求された接続に使うポート番号。protocol- 接続を要求しているプロトコル(getRequestingProtocol())。prompt- 認証領域を識別する、ユーザーに表示されるプロンプト文字列。scheme- 認証スキーム- 戻り値:
- ユーザー名またはパスワード。取得できない場合はnull。
- 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがパスワード認証要求を許可しない場合。- 導入されたバージョン:
- 1.4
- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
システムに登録されているオーセンティケータに、パスワードを要求します。まず、セキュリティ・マネージャが存在する場合は、その
checkPermissionメソッドがNetPermission("requestPasswordAuthentication")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。- パラメータ:
host- 認証を要求しているサイトのホスト名。addr- 認証を要求しているサイトのInetAddress。不明の場合はnull。port- 要求された接続に使うポート番号protocol- 接続を要求しているプロトコル(getRequestingProtocol())。prompt- ユーザーに表示されるプロンプト文字列scheme- 認証スキームurl- 認証を発生させた要求元のURL。reqType- 認証を要求しているエンティティのタイプ(サーバーまたはプロキシ)。- 戻り値:
- ユーザー名またはパスワード。取得できない場合はnull。
- 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがパスワード認証要求を許可しない場合。- 導入されたバージョン:
- 1.5
- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
requestPasswordAuthentication
public static PasswordAuthentication requestPasswordAuthentication(Authenticator authenticator, String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
与えられたauthenticatorにパスワードを尋ねます。 指定されたauthenticatorがヌルの場合、setDefaultを使用してシステムに登録されているオーセンティケータが使用されていればそれが使用されます。まず、セキュリティ・マネージャが存在する場合は、その
checkPermissionメソッドがNetPermission("requestPasswordAuthentication")アクセス権で呼び出されます。 この結果、java.lang.SecurityExceptionになることがあります。- パラメータ:
authenticator- オーセンティケータ、またはnull。host- 認証を要求しているサイトのホスト名。addr- 認証を要求しているサイトのInetAddress。不明の場合はnull。port- 要求された接続に使うポート番号protocol- 接続を要求しているプロトコル(getRequestingProtocol())。prompt- ユーザーに表示されるプロンプト文字列scheme- 認証スキームurl- 認証を発生させた要求元のURL。reqType- 認証を要求しているエンティティのタイプ(サーバーまたはプロキシ)。- 戻り値:
- ユーザー名/パスワード、または取得できない場合は
null。 - 例外:
SecurityException- セキュリティ・マネージャが存在し、そのcheckPermissionメソッドがパスワード認証要求を許可しない場合。- 導入されたバージョン:
- 9
- 関連項目:
SecurityManager.checkPermission(java.security.Permission)、NetPermission
-
requestPasswordAuthenticationInstance
public PasswordAuthentication requestPasswordAuthenticationInstance(String host, InetAddress addr, int port, String protocol, String prompt, String scheme, URL url, Authenticator.RequestorType reqType)
このオーセンティケータにパスワードを要求してください。- パラメータ:
host- 認証を要求しているサイトのホスト名。addr- 認証を要求しているサイトのInetAddress。不明の場合はnull。port- 要求された接続に使うポート番号protocol- 接続を要求しているプロトコル(getRequestingProtocol())。prompt- ユーザーに表示されるプロンプト文字列scheme- 認証スキームurl- 認証を発生させた要求元のURL。reqType- 認証を要求しているエンティティのタイプ(サーバーまたはプロキシ)。- 戻り値:
- ユーザー名またはパスワード。取得できない場合はnull
- 導入されたバージョン:
- 9
-
getRequestingHost
protected final String getRequestingHost()
認証を要求しているサイトまたはプロキシのhostnameを取得します。入手できない場合はnullが返されます。- 戻り値:
- 認証を要求している接続のホスト名。使用できない場合はnull。
- 導入されたバージョン:
- 1.4
-
getRequestingSite
protected final InetAddress getRequestingSite()
許可を要求しているサイトのInetAddressを取得します。入手できない場合はnullが返されます。- 戻り値:
- 認証を要求しているサイトのInetAddress。InetAddressが使用できない場合はnull。
-
getRequestingPort
protected final int getRequestingPort()
要求された接続に使うポート番号を取得します。- 戻り値:
- 要求された接続のポートを示す
int。
-
getRequestingProtocol
protected final String getRequestingProtocol()
接続を要求しているプロトコルを返します。 多くの場合、プロトコルはURLを基にしています。しかし将来のJDKでは、たとえば、パスワードで保護されたSOCKS5ファイアウォールには「SOCKS」と指定するようになる予定です。- 戻り値:
- プロトコル。バージョン番号を表す「/version」が後ろに付くこともある。
- 関連項目:
URL.getProtocol()
-
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
- 導入されたバージョン:
- 1.5
-
getRequestorType
protected Authenticator.RequestorType getRequestorType()
要求者がプロキシかサーバーかを返します。- 戻り値:
- 要求者の認証タイプ
- 導入されたバージョン:
- 1.5
-
-