set Authenticator - Java java.net

Java examples for java.net:Authenticator

Description

set Authenticator

Demo Code


//package com.java2s;
import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class Main {
    public static void main(String[] argv) throws Exception {
        String domain = "java2s.com";
        String user = "java2s.com";
        String password = "java2s.com";
        setAuthenticator(domain, user, password);
    }//w  w w .j ava 2  s.  c o  m

    public static void setAuthenticator(final String domain,
            final String user, final String password) {
        Authenticator.setDefault(new Authenticator() {
            @Override
            public PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(domain + "\\" + user,
                        password.toCharArray());
            }
        });
    }
}

Related Tutorials