O'Reilly logo

Java 9 Cookbook by Nick Samoylov, Mohamed Sanaulla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The Authenticator object is used by the network calls to obtain the authentication information. Developers generally extend the java.net.Authenticator class and override its getPasswordAuthentication() method. The username and password are read either from the user input or from the configuration and are used by the extended class to create an instance of java.net.PasswordAuthentication

In the recipe, we created an extension of java.net.Authenticator, as follows:

public class UsernamePasswordAuthenticator   extends Authenticator{    private String username;    private String password;        public UsernamePasswordAuthenticator(){}        public UsernamePasswordAuthenticator ( String username,                                            String password){        this.username = username;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required