# Authenticator

public abstract class **Authenticator** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
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.


Applications use this class by overriding `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#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 `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html` return value.


An instance of this concrete sub-class is then registered
with the system by calling `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#setDefault(java.net.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.


All methods that request authentication have a default implementation
that fails.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#setDefault(java.net.Authenticator)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getPasswordAuthentication()`

### Nested Class Summary

|---|---|---|---|
| enum | [Authenticator.RequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.RequestorType.html) || The type of the entity requesting authentication. |

### Public Constructor Summary

|---|---|
|   | [Authenticator](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#Authenticator())() |

### Public Method Summary

|---|---|
| static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html) | [requestPasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#requestPasswordAuthentication(java.lang.String,%20java.net.InetAddress,%20int,%20java.lang.String,%20java.lang.String,%20java.lang.String,%20java.net.URL,%20java.net.Authenticator.RequestorType))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme, [URL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URL.html) url, [Authenticator.RequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.RequestorType.html) reqType) Ask the authenticator that has been registered with the system for a password. |
| static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html) | [requestPasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#requestPasswordAuthentication(java.net.InetAddress,%20int,%20java.lang.String,%20java.lang.String,%20java.lang.String))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme) Ask the authenticator that has been registered with the system for a password. |
| static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html) | [requestPasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#requestPasswordAuthentication(java.lang.String,%20java.net.InetAddress,%20int,%20java.lang.String,%20java.lang.String,%20java.lang.String))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme) Ask the authenticator that has been registered with the system for a password. |
| synchronized static void | [setDefault](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#setDefault(java.net.Authenticator))([Authenticator](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html) a) Sets the authenticator that will be used by the networking code when a proxy or an HTTP server asks for authentication. |

### Protected Method Summary

|---|---|
| [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html) | [getPasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getPasswordAuthentication())() Called when password authorization is needed. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getRequestingHost](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingHost())() Gets the `hostname` of the site or proxy requesting authentication, or `null` if not available. |
| final int | [getRequestingPort](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingPort())() Gets the port number for the requested connection. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getRequestingPrompt](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingPrompt())() Gets the prompt string given by the requestor. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getRequestingProtocol](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingProtocol())() Give the protocol that's requesting the connection. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getRequestingScheme](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingScheme())() Gets the scheme of the requestor (the HTTP scheme for an HTTP firewall, for example). |
| final [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) | [getRequestingSite](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingSite())() Gets the `InetAddress` of the site requesting authorization, or `null` if not available. |
| [URL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URL.html) | [getRequestingURL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingURL())() Returns the URL that resulted in this request for authentication. |
| [Authenticator.RequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.RequestorType.html) | [getRequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestorType())() Returns whether the requestor is a Proxy or a Server. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**Authenticator**
()

<br />

## Public Methods

#### public static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html)
**requestPasswordAuthentication**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme, [URL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URL.html) url, [Authenticator.RequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.RequestorType.html) reqType)

Ask the authenticator that has been registered with the system
for a password.


First, if there is a security manager, its `checkPermission`
method is called with a
`NetPermission("requestPasswordAuthentication")` permission.
This may result in a java.lang.SecurityException.

##### Parameters

| host | The hostname of the site requesting authentication. |
| addr | The InetAddress of the site requesting authorization, or null if not known. |
| port | the port for the requested connection |
| protocol | The protocol that's requesting the connection (`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingProtocol()`) |
| prompt | A prompt string for the user |
| scheme | The authentication scheme |
| url | The requesting URL that caused the authentication |
| reqType | The type (server or proxy) of the entity requesting authentication. |
|---|---|

##### Returns

- The username/password, or null if one can't be gotten.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkPermission` method doesn't allow the password authentication request. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html`

#### public static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html)
**requestPasswordAuthentication**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme)

Ask the authenticator that has been registered with the system
for a password.


First, if there is a security manager, its `checkPermission`
method is called with a
`NetPermission("requestPasswordAuthentication")` permission.
This may result in a java.lang.SecurityException.

##### Parameters

| addr | The InetAddress of the site requesting authorization, or null if not known. |
| port | the port for the requested connection |
| protocol | The protocol that's requesting the connection (`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingProtocol()`) |
| prompt | A prompt string for the user |
| scheme | The authentication scheme |
|---|---|

##### Returns

- The username/password, or null if one can't be gotten.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkPermission` method doesn't allow the password authentication request. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html`

#### public static [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html)
**requestPasswordAuthentication**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) protocol, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) prompt, [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) scheme)

Ask the authenticator that has been registered with the system
for a password. This is the preferred method for requesting a password
because the hostname can be provided in cases where the InetAddress
is not available.


First, if there is a security manager, its `checkPermission`
method is called with a
`NetPermission("requestPasswordAuthentication")` permission.
This may result in a java.lang.SecurityException.

##### Parameters

| host | The hostname of the site requesting authentication. |
| addr | The InetAddress of the site requesting authentication, or null if not known. |
| port | the port for the requested connection. |
| protocol | The protocol that's requesting the connection (`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html#getRequestingProtocol()`) |
| prompt | A prompt string for the user which identifies the authentication realm. |
| scheme | The authentication scheme |
|---|---|

##### Returns

- The username/password, or null if one can't be gotten.

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkPermission` method doesn't allow the password authentication request. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html`

#### public static synchronized void
**setDefault**
([Authenticator](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.html) a)

Sets the authenticator that will be used by the networking code
when a proxy or an HTTP server asks for authentication.


First, if there is a security manager, its `checkPermission`
method is called with a
`NetPermission("setDefaultAuthenticator")` permission.
This may result in a java.lang.SecurityException.

##### Parameters

| a | The authenticator to be set. If a is `null` then any previously set authenticator is removed. |
|---|---|

##### Throws

| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkPermission` method doesn't allow setting the default authenticator. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkPermission(java.security.Permission)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetPermission.html`

## Protected Methods

#### protected [PasswordAuthentication](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PasswordAuthentication.html)
**getPasswordAuthentication**
()

Called when password authorization is needed. Subclasses should
override the default implementation, which returns null.

##### Returns

- The PasswordAuthentication collected from the user, or null if none is provided.

#### protected final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getRequestingHost**
()

Gets the `hostname` of the
site or proxy requesting authentication, or `null`
if not available.

##### Returns

- the hostname of the connection requiring authentication, or null if it's not available.

#### protected final int
**getRequestingPort**
()

Gets the port number for the requested connection.

##### Returns

- an `int` indicating the port for the requested connection.

#### protected final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getRequestingPrompt**
()

Gets the prompt string given by the requestor.

##### Returns

- the prompt string given by the requestor (realm for http requests)

#### protected final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getRequestingProtocol**
()

Give the protocol that's requesting the connection. Often this
will be based on a URL, but in a future JDK it could be, for
example, "SOCKS" for a password-protected SOCKS5 firewall.

##### Returns

- the protocol, optionally followed by "/version", where version is a version number.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URL.html#getProtocol()`

#### protected final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getRequestingScheme**
()

Gets the scheme of the requestor (the HTTP scheme
for an HTTP firewall, for example).

##### Returns

- the scheme of the requestor

#### protected final [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html)
**getRequestingSite**
()

Gets the `InetAddress` of the
site requesting authorization, or `null`
if not available.

##### Returns

- the InetAddress of the site requesting authorization, or null if it's not available.

#### protected [URL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/URL.html)
**getRequestingURL**
()

Returns the URL that resulted in this
request for authentication.

##### Returns

- the requesting URL

#### protected [Authenticator.RequestorType](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Authenticator.RequestorType.html)
**getRequestorType**
()

Returns whether the requestor is a Proxy or a Server.

##### Returns

- the authentication type of the requestor