|
1 /* |
|
2 * Copyright (c) 2009, 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. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 |
|
26 package sun.net.www.protocol.http; |
|
27 |
|
28 import java.net.Authenticator.RequestorType; |
|
29 import java.net.InetAddress; |
|
30 import java.net.URL; |
|
31 |
|
32 /** |
|
33 * Used in HTTP/Negotiate, to feed HTTP request info into JGSS as a HttpCaller, |
|
34 * so that special actions can be taken, including special callback handler, |
|
35 * special useSubjectCredsOnly value. |
|
36 * |
|
37 * This is an immutable class. It can be instantiated in two styles; |
|
38 * |
|
39 * 1. Un-schemed: Create at the beginning before the preferred scheme is |
|
40 * determined. This object can be fed into AuthenticationHeader to check |
|
41 * for the preference. |
|
42 * |
|
43 * 2. Schemed: With the scheme field filled, can be used in JGSS-API calls. |
|
44 */ |
|
45 final public class HttpCallerInfo { |
|
46 // All info that an Authenticator needs. |
|
47 final public URL url; |
|
48 final public String host, protocol, prompt, scheme; |
|
49 final public int port; |
|
50 final public InetAddress addr; |
|
51 final public RequestorType authType; |
|
52 |
|
53 /** |
|
54 * Create a schemed object based on an un-schemed one. |
|
55 */ |
|
56 public HttpCallerInfo(HttpCallerInfo old, String scheme) { |
|
57 this.url = old.url; |
|
58 this.host = old.host; |
|
59 this.protocol = old.protocol; |
|
60 this.prompt = old.prompt; |
|
61 this.port = old.port; |
|
62 this.addr = old.addr; |
|
63 this.authType = old.authType; |
|
64 this.scheme = scheme; |
|
65 } |
|
66 |
|
67 /** |
|
68 * Constructor an un-schemed object for site access. |
|
69 */ |
|
70 public HttpCallerInfo(URL url) { |
|
71 this.url= url; |
|
72 prompt = ""; |
|
73 host = url.getHost(); |
|
74 |
|
75 int p = url.getPort(); |
|
76 if (p == -1) { |
|
77 port = url.getDefaultPort(); |
|
78 } else { |
|
79 port = p; |
|
80 } |
|
81 |
|
82 InetAddress ia; |
|
83 try { |
|
84 ia = InetAddress.getByName(url.getHost()); |
|
85 } catch (Exception e) { |
|
86 ia = null; |
|
87 } |
|
88 addr = ia; |
|
89 |
|
90 protocol = url.getProtocol(); |
|
91 authType = RequestorType.SERVER; |
|
92 scheme = ""; |
|
93 } |
|
94 |
|
95 /** |
|
96 * Constructor an un-schemed object for proxy access. |
|
97 */ |
|
98 public HttpCallerInfo(URL url, String host, int port) { |
|
99 this.url= url; |
|
100 this.host = host; |
|
101 this.port = port; |
|
102 prompt = ""; |
|
103 addr = null; |
|
104 protocol = url.getProtocol(); |
|
105 authType = RequestorType.PROXY; |
|
106 scheme = ""; |
|
107 } |
|
108 } |