author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 8815 | 9a3f042d307e |
permissions | -rw-r--r-- |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
4 |
* |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
10 |
* |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
15 |
* accompanied this code). |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
16 |
* |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
20 |
* |
5506 | 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. |
|
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
24 |
*/ |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
25 |
package sun.net.www.protocol.http; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
26 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
27 |
import java.net.URL; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
28 |
import java.net.PasswordAuthentication; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
29 |
import java.lang.reflect.Constructor; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
30 |
import java.lang.reflect.Method; |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
31 |
import sun.util.logging.PlatformLogger; |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
32 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
33 |
/** |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
34 |
* Proxy class for loading NTLMAuthentication, so as to remove static |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
35 |
* dependancy. |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
36 |
*/ |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
37 |
class NTLMAuthenticationProxy { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
38 |
private static Method supportsTA; |
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
3866
diff
changeset
|
39 |
private static final String clazzStr = "sun.net.www.protocol.http.ntlm.NTLMAuthentication"; |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
40 |
private static final String supportsTAStr = "supportsTransparentAuth"; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
41 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
42 |
static final NTLMAuthenticationProxy proxy = tryLoadNTLMAuthentication(); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
43 |
static final boolean supported = proxy != null ? true : false; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
44 |
static final boolean supportsTransparentAuth = supported ? supportsTransparentAuth(supportsTA) : false; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
45 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
46 |
private final Constructor<? extends AuthenticationInfo> threeArgCtr; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
47 |
private final Constructor<? extends AuthenticationInfo> fiveArgCtr; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
48 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
49 |
private NTLMAuthenticationProxy(Constructor<? extends AuthenticationInfo> threeArgCtr, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
50 |
Constructor<? extends AuthenticationInfo> fiveArgCtr) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
51 |
this.threeArgCtr = threeArgCtr; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
52 |
this.fiveArgCtr = fiveArgCtr; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
53 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
54 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
55 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
56 |
AuthenticationInfo create(boolean isProxy, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
57 |
URL url, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
58 |
PasswordAuthentication pw) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
59 |
try { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
60 |
return threeArgCtr.newInstance(isProxy, url, pw); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
61 |
} catch (ReflectiveOperationException roe) { |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
62 |
finest(roe); |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
63 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
64 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
65 |
return null; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
66 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
67 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
68 |
AuthenticationInfo create(boolean isProxy, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
69 |
String host, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
70 |
int port, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
71 |
PasswordAuthentication pw) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
72 |
try { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
73 |
return fiveArgCtr.newInstance(isProxy, host, port, pw); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
74 |
} catch (ReflectiveOperationException roe) { |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
75 |
finest(roe); |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
76 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
77 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
78 |
return null; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
79 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
80 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
81 |
/* Returns true if the NTLM implementation supports transparent |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
82 |
* authentication (try with the current users credentials before |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
83 |
* prompting for username and password, etc). |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
84 |
*/ |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
85 |
private static boolean supportsTransparentAuth(Method method) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
86 |
try { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
87 |
return (Boolean)method.invoke(null); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
88 |
} catch (ReflectiveOperationException roe) { |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
89 |
finest(roe); |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
90 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
91 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
92 |
return false; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
93 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
94 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
95 |
/** |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
96 |
* Loads the NTLM authentiation implementation through reflection. If |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
97 |
* the class is present, then it must have the required constructors and |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
98 |
* method. Otherwise, it is considered an error. |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
99 |
*/ |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
100 |
@SuppressWarnings("unchecked") |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
101 |
private static NTLMAuthenticationProxy tryLoadNTLMAuthentication() { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
102 |
Class<? extends AuthenticationInfo> cl; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
103 |
Constructor<? extends AuthenticationInfo> threeArg, fiveArg; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
104 |
try { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
105 |
cl = (Class<? extends AuthenticationInfo>)Class.forName(clazzStr, true, null); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
106 |
if (cl != null) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
107 |
threeArg = cl.getConstructor(boolean.class, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
108 |
URL.class, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
109 |
PasswordAuthentication.class); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
110 |
fiveArg = cl.getConstructor(boolean.class, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
111 |
String.class, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
112 |
int.class, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
113 |
PasswordAuthentication.class); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
114 |
supportsTA = cl.getDeclaredMethod(supportsTAStr); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
115 |
return new NTLMAuthenticationProxy(threeArg, |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
116 |
fiveArg); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
117 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
118 |
} catch (ClassNotFoundException cnfe) { |
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
119 |
finest(cnfe); |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
120 |
} catch (ReflectiveOperationException roe) { |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
121 |
throw new AssertionError(roe); |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
122 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
123 |
|
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
124 |
return null; |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
125 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
126 |
|
3866
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
127 |
static void finest(Exception e) { |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
128 |
PlatformLogger logger = HttpURLConnection.getHttpLogger(); |
34cd368bd2dd
6882384: Update http protocol handler to use PlatformLogger
chegar
parents:
3859
diff
changeset
|
129 |
logger.finest("NTLMAuthenticationProxy: " + e); |
3859
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
130 |
} |
8b82336dedb3
6882594: Remove static dependancy on NTLM authentication
chegar
parents:
diff
changeset
|
131 |
} |