Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/share/classes/sun/net/www/protocol/http/NTLMAuthenticationProxy.java
+++ new/src/share/classes/sun/net/www/protocol/http/NTLMAuthenticationProxy.java
1 1 /*
2 2 * Copyright 2009 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).
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 package sun.net.www.protocol.http;
26 26
27 27 import java.net.URL;
28 28 import java.net.PasswordAuthentication;
↓ open down ↓ |
28 lines elided |
↑ open up ↑ |
29 29 import java.lang.reflect.Constructor;
30 30 import java.lang.reflect.Method;
31 31 import sun.util.logging.PlatformLogger;
32 32
33 33 /**
34 34 * Proxy class for loading NTLMAuthentication, so as to remove static
35 35 * dependancy.
36 36 */
37 37 class NTLMAuthenticationProxy {
38 38 private static Method supportsTA;
39 - private static final String clazzStr = "sun.net.www.protocol.http.NTLMAuthentication";
39 + private static final String clazzStr = "sun.net.www.protocol.http.ntlm.NTLMAuthentication";
40 40 private static final String supportsTAStr = "supportsTransparentAuth";
41 41
42 42 static final NTLMAuthenticationProxy proxy = tryLoadNTLMAuthentication();
43 43 static final boolean supported = proxy != null ? true : false;
44 44 static final boolean supportsTransparentAuth = supported ? supportsTransparentAuth(supportsTA) : false;
45 45
46 46 private final Constructor<? extends AuthenticationInfo> threeArgCtr;
47 47 private final Constructor<? extends AuthenticationInfo> fiveArgCtr;
48 48
49 49 private NTLMAuthenticationProxy(Constructor<? extends AuthenticationInfo> threeArgCtr,
50 50 Constructor<? extends AuthenticationInfo> fiveArgCtr) {
51 51 this.threeArgCtr = threeArgCtr;
52 52 this.fiveArgCtr = fiveArgCtr;
53 53 }
54 54
55 55
56 56 AuthenticationInfo create(boolean isProxy,
57 57 URL url,
58 58 PasswordAuthentication pw) {
59 59 try {
60 60 return threeArgCtr.newInstance(isProxy, url, pw);
61 61 } catch (ReflectiveOperationException roe) {
62 62 finest(roe);
63 63 }
64 64
65 65 return null;
66 66 }
67 67
68 68 AuthenticationInfo create(boolean isProxy,
69 69 String host,
70 70 int port,
71 71 PasswordAuthentication pw) {
72 72 try {
73 73 return fiveArgCtr.newInstance(isProxy, host, port, pw);
74 74 } catch (ReflectiveOperationException roe) {
75 75 finest(roe);
76 76 }
77 77
78 78 return null;
79 79 }
80 80
81 81 /* Returns true if the NTLM implementation supports transparent
82 82 * authentication (try with the current users credentials before
83 83 * prompting for username and password, etc).
84 84 */
85 85 private static boolean supportsTransparentAuth(Method method) {
86 86 try {
87 87 return (Boolean)method.invoke(null);
88 88 } catch (ReflectiveOperationException roe) {
89 89 finest(roe);
90 90 }
91 91
92 92 return false;
93 93 }
94 94
95 95 /**
96 96 * Loads the NTLM authentiation implementation through reflection. If
97 97 * the class is present, then it must have the required constructors and
98 98 * method. Otherwise, it is considered an error.
99 99 */
100 100 @SuppressWarnings("unchecked")
101 101 private static NTLMAuthenticationProxy tryLoadNTLMAuthentication() {
102 102 Class<? extends AuthenticationInfo> cl;
103 103 Constructor<? extends AuthenticationInfo> threeArg, fiveArg;
104 104 try {
105 105 cl = (Class<? extends AuthenticationInfo>)Class.forName(clazzStr, true, null);
106 106 if (cl != null) {
107 107 threeArg = cl.getConstructor(boolean.class,
108 108 URL.class,
109 109 PasswordAuthentication.class);
110 110 fiveArg = cl.getConstructor(boolean.class,
111 111 String.class,
112 112 int.class,
113 113 PasswordAuthentication.class);
114 114 supportsTA = cl.getDeclaredMethod(supportsTAStr);
115 115 return new NTLMAuthenticationProxy(threeArg,
116 116 fiveArg);
117 117 }
118 118 } catch (ClassNotFoundException cnfe) {
119 119 finest(cnfe);
120 120 } catch (ReflectiveOperationException roe) {
121 121 throw new AssertionError(roe);
122 122 }
123 123
124 124 return null;
125 125 }
126 126
127 127 static void finest(Exception e) {
128 128 PlatformLogger logger = HttpURLConnection.getHttpLogger();
129 129 logger.finest("NTLMAuthenticationProxy: " + e);
130 130 }
131 131 }
↓ open down ↓ |
82 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX