Name

Authenticator

Synopsis

This abstract class defines a customizable mechanism for requesting and performing password authentication when required in URL-based networking. The static setDefault( ) method establishes the systemwide Authenticator. An Authenticator implementation can obtain the required authentication information from the user however it wants (e.g., through a text- or a GUI-based interface). setDefault( ) can be called only once; subsequent calls are ignored. Calling setDefault( ) requires an appropriate NetPermission.

When an application or the Java runtime system requires password authentication (to read the contents of a specified URL, for example), it calls the static requestPasswordAuthentication( ) method, passing arguments that specify the host and port for which the password is required and a prompt that may be displayed to the user. This method looks up the default Authenticator for the system and calls its getPasswordAuthentication( ) method. Calling requestPasswordAuthentication( ) requires an appropriate NetPermission.

Authenticator is an abstract class; its default implementation of getPasswordAuthentication( ) always returns null. To create an Authenticator, you must override this method so that it prompts the user to enter a username and password and returns that information in the form of a PasswordAuthentication object. Your implementation of getPasswordAuthentication( ) may call the various getRequesting( ) methods to find out who is requesting ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.