Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/net/www/protocol/http/WebGet.java
41159 views
1
/*
2
* Copyright (c) 2005, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.BufferedReader;
25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.io.InputStreamReader;
28
import java.net.Authenticator;
29
import java.net.PasswordAuthentication;
30
import java.net.URL;
31
import java.security.Security;
32
import javax.security.auth.callback.Callback;
33
import javax.security.auth.callback.CallbackHandler;
34
import javax.security.auth.callback.NameCallback;
35
import javax.security.auth.callback.PasswordCallback;
36
import javax.security.auth.callback.UnsupportedCallbackException;
37
38
public 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
}
89
90