FileDocCategorySizeDatePackage
Authenticator.javaAPI DocJavaMail 1.4.36002Tue Nov 17 10:38:12 GMT 2009javax.mail

Authenticator

public abstract class Authenticator extends Object
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.

see
java.net.Authenticator
see
javax.mail.Session#getInstance(java.util.Properties, javax.mail.Authenticator)
see
javax.mail.Session#getDefaultInstance(java.util.Properties, javax.mail.Authenticator)
see
javax.mail.Session#requestPasswordAuthentication
see
javax.mail.PasswordAuthentication
author
Bill Foote
author
Bill Shannon

Fields Summary
private InetAddress
requestingSite
private int
requestingPort
private String
requestingProtocol
private String
requestingPrompt
private String
requestingUserName
Constructors Summary
Methods Summary
protected final java.lang.StringgetDefaultUserName()

return
the default user name given by the requestor

	return requestingUserName;
    
protected javax.mail.PasswordAuthenticationgetPasswordAuthentication()
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.

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

	return null;
    
protected final intgetRequestingPort()

return
the port for the requested connection

	return requestingPort;
    
protected final java.lang.StringgetRequestingPrompt()

return
the prompt string given by the requestor

	return requestingPrompt;
    
protected final java.lang.StringgetRequestingProtocol()
Give the protocol that's requesting the connection. Often this will be based on a URLName.

return
the protcol
see
javax.mail.URLName#getProtocol

	return requestingProtocol;
    
protected final java.net.InetAddressgetRequestingSite()

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

	return requestingSite;
    
final javax.mail.PasswordAuthenticationrequestPasswordAuthentication(java.net.InetAddress addr, int port, java.lang.String protocol, java.lang.String prompt, java.lang.String defaultUserName)
Ask the authenticator for a password.

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


	reset();
	requestingSite = addr;
	requestingPort = port;
	requestingProtocol = protocol;
	requestingPrompt = prompt;
	requestingUserName = defaultUserName;
	return getPasswordAuthentication();
    
private voidreset()

	requestingSite = null;
	requestingPort = -1;
	requestingProtocol = null;
	requestingPrompt = null;
	requestingUserName = null;