blob: beaf3a21167da7a8622a2e34f9064e375de4be5d [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24import java.io.BufferedReader;
25import java.io.IOException;
26import java.io.InputStream;
27import java.io.InputStreamReader;
28import java.net.Authenticator;
29import java.net.PasswordAuthentication;
30import java.net.URL;
31import java.security.Security;
32import javax.security.auth.callback.Callback;
33import javax.security.auth.callback.CallbackHandler;
34import javax.security.auth.callback.NameCallback;
35import javax.security.auth.callback.PasswordCallback;
36import javax.security.auth.callback.UnsupportedCallbackException;
37
38public class WebGet {
39
40 static String user = System.getProperty("user");
41 static String pass = System.getProperty("pass");
42 static String kuser = System.getProperty("kuser");
43 static String kpass = System.getProperty("kpass");
44 static String showhint = System.getProperty("showhint");
45
46 static class MyAuthenticator extends Authenticator {
47 public MyAuthenticator () {
48 super ();
49 }
50
51 public PasswordAuthentication getPasswordAuthentication ()
52 {
53 // scheme is the only key for Negotiate
54 if(getRequestingScheme().equalsIgnoreCase("negotiate") ||
55 getRequestingScheme().equalsIgnoreCase("kerberos")) {
56 if(showhint != null)
57 System.out.println("::::: PROVIDING Kerberos PASSWORD AND USERNAME " + kuser +":"+kpass+" :::::");
58 return (new PasswordAuthentication (kuser, kpass.toCharArray()));
59 } else {
60 if(showhint != null)
61 System.out.println("::::: PROVIDING PASSWORD AND USERNAME " + user +":"+pass+" :::::");
62 return (new PasswordAuthentication (user, pass.toCharArray()));
63 }
64 }
65 }
66
67 /**
68 * Creates a new instance of WebGet
69 */
70 static void url(String urls) throws Exception {
71 Authenticator.setDefault (new MyAuthenticator ());
72 //Security.setProperty("auth.login.defaultCallbackHandler", "WebGet$Handler");
73 URL url = new URL(urls);
74 InputStream ins = url.openConnection().getInputStream();
75 BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
76 String str;
77 while((str = reader.readLine()) != null)
78 System.out.println(str);
79 }
80
81 /**
82 * @param args 1. url
83 * 2. if given, means there should be error
84 */
85 public static void main(String[] args) throws Exception {
86 url(args[0]);
87 }
88}