author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 5506 | 202f599c92aa |
child 10596 | 39b3a979e600 |
permissions | -rw-r--r-- |
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
1 |
/* |
5506 | 2 |
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. |
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
4 |
* |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
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 |
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
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. |
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
10 |
* |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
15 |
* accompanied this code). |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
16 |
* |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
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. |
|
4157
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
24 |
*/ |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
25 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
26 |
package sun.net.www.protocol.http; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
27 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
28 |
import java.io.IOException; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
29 |
import java.lang.reflect.Constructor; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
30 |
import sun.util.logging.PlatformLogger; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
31 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
32 |
/** |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
33 |
* This abstract class is a bridge to connect NegotiteAuthentication and |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
34 |
* NegotiatorImpl, so that JAAS and JGSS calls can be made |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
35 |
*/ |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
36 |
public abstract class Negotiator { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
37 |
static Negotiator getNegotiator(HttpCallerInfo hci) { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
38 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
39 |
// These lines are equivalent to |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
40 |
// return new NegotiatorImpl(hci); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
41 |
// The current implementation will make sure NegotiatorImpl is not |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
42 |
// directly referenced when compiling, thus smooth the way of building |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
43 |
// the J2SE platform where HttpURLConnection is a bootstrap class. |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
44 |
// |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
45 |
// Makes NegotiatorImpl, and the security classes it references, a |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
46 |
// runtime dependency rather than a static one. |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
47 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
48 |
Class clazz; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
49 |
Constructor c; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
50 |
try { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
51 |
clazz = Class.forName("sun.net.www.protocol.http.spnego.NegotiatorImpl", true, null); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
52 |
c = clazz.getConstructor(HttpCallerInfo.class); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
53 |
} catch (ClassNotFoundException cnfe) { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
54 |
finest(cnfe); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
55 |
return null; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
56 |
} catch (ReflectiveOperationException roe) { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
57 |
// if the class is there then something seriously wrong if |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
58 |
// the constructor is not. |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
59 |
throw new AssertionError(roe); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
60 |
} |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
61 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
62 |
try { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
63 |
return (Negotiator) (c.newInstance(hci)); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
64 |
} catch (ReflectiveOperationException roe) { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
65 |
finest(roe); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
66 |
Throwable t = roe.getCause(); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
67 |
if (t != null && t instanceof Exception) |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
68 |
finest((Exception)t); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
69 |
return null; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
70 |
} |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
71 |
} |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
72 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
73 |
public abstract byte[] firstToken() throws IOException; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
74 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
75 |
public abstract byte[] nextToken(byte[] in) throws IOException; |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
76 |
|
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
77 |
private static void finest(Exception e) { |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
78 |
PlatformLogger logger = HttpURLConnection.getHttpLogger(); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
79 |
logger.finest("NegotiateAuthentication: " + e); |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
80 |
} |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
81 |
} |
558590fb3b49
6893238: Move NTLM and SPNEGO implementations into separate packages
chegar
parents:
diff
changeset
|
82 |