Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/windows/classes/sun/net/www/protocol/http/NTLMAuthentication.java
+++ new/src/windows/classes/sun/net/www/protocol/http/ntlm/NTLMAuthentication.java
1 1 /*
2 2 * Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation. Sun designates this
8 8 * particular file as subject to the "Classpath" exception as provided
9 9 * by Sun in the LICENSE file that accompanied this code.
10 10 *
11 11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 14 * version 2 for more details (a copy is included in the LICENSE file that
15 15 * accompanied this code).
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 *
17 17 * You should have received a copy of the GNU General Public License version
18 18 * 2 along with this work; if not, write to the Free Software Foundation,
19 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 20 *
21 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 23 * have any questions.
24 24 */
25 25
26 -package sun.net.www.protocol.http;
26 +package sun.net.www.protocol.http.ntlm;
27 27
28 28 import java.io.IOException;
29 29 import java.net.InetAddress;
30 30 import java.net.PasswordAuthentication;
31 31 import java.net.UnknownHostException;
32 32 import java.net.URL;
33 33 import sun.net.www.HeaderParser;
34 +import sun.net.www.protocol.http.AuthenticationInfo;
35 +import sun.net.www.protocol.http.AuthScheme;
36 +import sun.net.www.protocol.http.HttpURLConnection;
34 37
35 38 /**
36 39 * NTLMAuthentication:
37 40 *
38 41 * @author Michael McMahon
39 42 */
40 43
41 -class NTLMAuthentication extends AuthenticationInfo {
44 +public class NTLMAuthentication extends AuthenticationInfo {
42 45
43 46 private static final long serialVersionUID = 100L;
44 47
45 48 private String hostname;
46 49 private static String defaultDomain; /* Domain to use if not specified by user */
47 50
48 51 static {
49 52 defaultDomain = java.security.AccessController.doPrivileged(
50 53 new sun.security.action.GetPropertyAction("http.auth.ntlm.domain",
51 54 "domain"));
52 55 };
53 56
54 57 private void init0() {
55 58
56 59 hostname = java.security.AccessController.doPrivileged(
57 60 new java.security.PrivilegedAction<String>() {
58 61 public String run() {
59 62 String localhost;
60 63 try {
61 64 localhost = InetAddress.getLocalHost().getHostName().toUpperCase();
62 65 } catch (UnknownHostException e) {
63 66 localhost = "localhost";
64 67 }
65 68 return localhost;
66 69 }
67 70 });
68 71 int x = hostname.indexOf ('.');
69 72 if (x != -1) {
70 73 hostname = hostname.substring (0, x);
71 74 }
72 75 }
73 76
74 77 String username;
75 78 String ntdomain;
76 79 String password;
77 80
78 81 /**
79 82 * Create a NTLMAuthentication:
80 83 * Username may be specified as domain<BACKSLASH>username in the application Authenticator.
81 84 * If this notation is not used, then the domain will be taken
82 85 * from a system property: "http.auth.ntlm.domain".
83 86 */
84 87 public NTLMAuthentication(boolean isProxy, URL url, PasswordAuthentication pw) {
85 88 super(isProxy ? PROXY_AUTHENTICATION : SERVER_AUTHENTICATION,
86 89 AuthScheme.NTLM,
87 90 url,
88 91 "");
89 92 init (pw);
90 93 }
91 94
92 95 private void init (PasswordAuthentication pw) {
93 96 this.pw = pw;
94 97 if (pw != null) {
95 98 String s = pw.getUserName();
96 99 int i = s.indexOf ('\\');
97 100 if (i == -1) {
98 101 username = s;
99 102 ntdomain = defaultDomain;
100 103 } else {
101 104 ntdomain = s.substring (0, i).toUpperCase();
102 105 username = s.substring (i+1);
103 106 }
104 107 password = new String (pw.getPassword());
105 108 } else {
106 109 /* credentials will be acquired from OS */
107 110 username = null;
108 111 ntdomain = null;
109 112 password = null;
110 113 }
111 114 init0();
112 115 }
113 116
114 117 /**
115 118 * Constructor used for proxy entries
116 119 */
117 120 public NTLMAuthentication(boolean isProxy, String host, int port,
118 121 PasswordAuthentication pw) {
119 122 super(isProxy?PROXY_AUTHENTICATION:SERVER_AUTHENTICATION,
↓ open down ↓ |
68 lines elided |
↑ open up ↑ |
120 123 AuthScheme.NTLM,
121 124 host,
122 125 port,
123 126 "");
124 127 init (pw);
125 128 }
126 129
127 130 /**
128 131 * @return true if this authentication supports preemptive authorization
129 132 */
130 - boolean supportsPreemptiveAuthorization() {
133 + @Override
134 + public boolean supportsPreemptiveAuthorization() {
131 135 return false;
132 136 }
133 137
134 138 /**
135 139 * @return true if NTLM supported transparently (no password needed, SSO)
136 140 */
137 - static boolean supportsTransparentAuth() {
141 + public static boolean supportsTransparentAuth() {
138 142 return true;
139 143 }
140 144
141 145 /**
142 - * @return the name of the HTTP header this authentication wants set
143 - */
144 - String getHeaderName() {
145 - if (type == SERVER_AUTHENTICATION) {
146 - return "Authorization";
147 - } else {
148 - return "Proxy-authorization";
149 - }
150 - }
151 -
152 - /**
153 146 * Not supported. Must use the setHeaders() method
154 147 */
155 - String getHeaderValue(URL url, String method) {
148 + @Override
149 + public String getHeaderValue(URL url, String method) {
156 150 throw new RuntimeException ("getHeaderValue not supported");
157 151 }
158 152
159 153 /**
160 154 * Check if the header indicates that the current auth. parameters are stale.
161 155 * If so, then replace the relevant field with the new value
162 156 * and return true. Otherwise return false.
163 157 * returning true means the request can be retried with the same userid/password
164 158 * returning false means we have to go back to the user to ask for a new
165 159 * username password.
166 160 */
167 - boolean isAuthorizationStale (String header) {
161 + @Override
162 + public boolean isAuthorizationStale (String header) {
168 163 return false; /* should not be called for ntlm */
169 164 }
170 165
171 166 /**
172 167 * Set header(s) on the given connection.
173 168 * @param conn The connection to apply the header(s) to
174 169 * @param p A source of header values for this connection, not used because
175 170 * HeaderParser converts the fields to lower case, use raw instead
176 171 * @param raw The raw header field.
177 172 * @return true if all goes well, false if no headers were set.
178 173 */
179 - synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
174 + @Override
175 + public synchronized boolean setHeaders(HttpURLConnection conn, HeaderParser p, String raw) {
180 176
181 177 try {
182 - NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj;
178 + NTLMAuthSequence seq = (NTLMAuthSequence)conn.authObj();
183 179 if (seq == null) {
184 180 seq = new NTLMAuthSequence (username, password, ntdomain);
185 - conn.authObj = seq;
181 + conn.authObj(seq);
186 182 }
187 183 String response = "NTLM " + seq.getAuthHeader (raw.length()>6?raw.substring(5):null);
188 184 conn.setAuthenticationProperty(getHeaderName(), response);
189 185 return true;
190 186 } catch (IOException e) {
191 187 return false;
192 188 }
193 189 }
194 190
195 191 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX