Top Description Fields Constructors Methods
jakarta.mail

public abstract Class Authenticator

extends Object
Class Inheritance
Imports
java.net.InetAddress

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 creating a subclass, and registering an instance of that subclass with the session when it is created. When authentication is required, the system will invoke a method on the subclass (like getPasswordAuthentication). The subclass's method can query about the authentication being requested with a number of inherited methods (getRequestingXXX()), and form an appropriate message for the user.

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

Authors
Bill Foote, Bill Shannon
See Also
java.net.Authenticator, jakarta.mail.Session#getInstance(java.util.Properties, jakarta.mail.Authenticator), jakarta.mail.Session#getDefaultInstance(java.util.Properties, jakarta.mail.Authenticator), jakarta.mail.Session#requestPasswordAuthentication, jakarta.mail.PasswordAuthentication

Field Summary

Modifier and TypeField and Description
private int
private String
private String
private InetAddress
private String

Constructor Summary

AccessConstructor and Description
public
Authenticator()

Creates a default Authenticator.

Method Summary

Modifier and TypeMethod and Description
protected final String

Returns:

the default user name given by the requestor
getDefaultUserName
()

protected PasswordAuthentication

Returns:

The PasswordAuthentication collected from the user, or null if none is provided.
getPasswordAuthentication
()

Called when password authentication is needed.

protected final int

Returns:

the port for the requested connection
getRequestingPort
()

protected final String

Returns:

the prompt string given by the requestor
getRequestingPrompt
()

protected final String

Returns:

the protcol
getRequestingProtocol
()

Give the protocol that's requesting the connection.

protected final InetAddress

Returns:

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

pack-priv final synchronized PasswordAuthentication

Returns:

The username/password, or null if one can't be gotten.
requestPasswordAuthentication
(InetAddress
The InetAddress of the site requesting authorization, or null if not known.
addr
,
int
the port for the requested connection
port
,
String
The protocol that's requesting the connection java.net.Authenticator.getProtocol()
protocol
,
String
A prompt string for the user
prompt
,
String defaultUserName)

Ask the authenticator for a password.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

requestingPortback to summary
private int requestingPort
requestingPromptback to summary
private String requestingPrompt
requestingProtocolback to summary
private String requestingProtocol
requestingSiteback to summary
private InetAddress requestingSite
requestingUserNameback to summary
private String requestingUserName

Constructor Detail

Authenticatorback to summary
public Authenticator()

Creates a default Authenticator. There are no abstract methods, but to be useful the user must subclass.

See Also
getPasswordAuthentication()

Method Detail

getDefaultUserNameback to summary
protected final String getDefaultUserName()
Returns:String

the default user name given by the requestor

getPasswordAuthenticationback to summary
protected PasswordAuthentication getPasswordAuthentication()

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

Note that if this method uses a dialog to prompt the user for this information, the dialog needs to block until the user supplies the information. This method can not simply return after showing the dialog.

Returns:PasswordAuthentication

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

getRequestingPortback to summary
protected final int getRequestingPort()
Returns:int

the port for the requested connection

getRequestingPromptback to summary
protected final String getRequestingPrompt()
Returns:String

the prompt string given by the requestor

getRequestingProtocolback to summary
protected final String getRequestingProtocol()

Give the protocol that's requesting the connection. Often this will be based on a URLName.

Returns:String

the protcol

See Also
jakarta.mail.URLName#getProtocol
getRequestingSiteback to summary
protected final InetAddress getRequestingSite()
Returns:InetAddress

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

requestPasswordAuthenticationback to summary
pack-priv final synchronized PasswordAuthentication requestPasswordAuthentication(InetAddress addr, int port, String protocol, String prompt, String defaultUserName)

Ask the authenticator for a password.

Parameters
addr:InetAddress

The InetAddress of the site requesting authorization, or null if not known.

port:int

the port for the requested connection

protocol:String

The protocol that's requesting the connection java.net.Authenticator.getProtocol()

prompt:String

A prompt string for the user

Returns:PasswordAuthentication

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