Path: blob/master/test/jdk/sun/net/www/protocol/http/WebGet.java
41159 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.BufferedReader;24import java.io.IOException;25import java.io.InputStream;26import java.io.InputStreamReader;27import java.net.Authenticator;28import java.net.PasswordAuthentication;29import java.net.URL;30import java.security.Security;31import javax.security.auth.callback.Callback;32import javax.security.auth.callback.CallbackHandler;33import javax.security.auth.callback.NameCallback;34import javax.security.auth.callback.PasswordCallback;35import javax.security.auth.callback.UnsupportedCallbackException;3637public class WebGet {3839static String user = System.getProperty("user");40static String pass = System.getProperty("pass");41static String kuser = System.getProperty("kuser");42static String kpass = System.getProperty("kpass");43static String showhint = System.getProperty("showhint");4445static class MyAuthenticator extends Authenticator {46public MyAuthenticator () {47super ();48}4950public PasswordAuthentication getPasswordAuthentication ()51{52// scheme is the only key for Negotiate53if(getRequestingScheme().equalsIgnoreCase("negotiate") ||54getRequestingScheme().equalsIgnoreCase("kerberos")) {55if(showhint != null)56System.out.println("::::: PROVIDING Kerberos PASSWORD AND USERNAME " + kuser +":"+kpass+" :::::");57return (new PasswordAuthentication (kuser, kpass.toCharArray()));58} else {59if(showhint != null)60System.out.println("::::: PROVIDING PASSWORD AND USERNAME " + user +":"+pass+" :::::");61return (new PasswordAuthentication (user, pass.toCharArray()));62}63}64}6566/**67* Creates a new instance of WebGet68*/69static void url(String urls) throws Exception {70Authenticator.setDefault (new MyAuthenticator ());71//Security.setProperty("auth.login.defaultCallbackHandler", "WebGet$Handler");72URL url = new URL(urls);73InputStream ins = url.openConnection().getInputStream();74BufferedReader reader = new BufferedReader(new InputStreamReader(ins));75String str;76while((str = reader.readLine()) != null)77System.out.println(str);78}7980/**81* @param args 1. url82* 2. if given, means there should be error83*/84public static void main(String[] args) throws Exception {85url(args[0]);86}87}888990