author | weijun |
Thu, 13 Jun 2019 10:06:07 +0800 | |
changeset 55354 | 74f0622db875 |
parent 51398 | 3c389a284345 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
55354
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
2 |
* Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.jgss.wrapper; |
|
27 |
||
28 |
import java.util.HashMap; |
|
29 |
import java.security.Provider; |
|
30 |
import java.security.AccessController; |
|
31 |
import java.security.PrivilegedAction; |
|
32 |
import org.ietf.jgss.Oid; |
|
33 |
import sun.security.action.PutAllAction; |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
33992
diff
changeset
|
34 |
import static sun.security.util.SecurityConstants.PROVIDER_VER; |
2 | 35 |
|
36 |
/** |
|
37 |
* Defines the Sun NativeGSS provider for plugging in the |
|
38 |
* native GSS mechanisms to Java GSS. |
|
39 |
* |
|
40 |
* List of supported mechanisms depends on the local |
|
41 |
* machine configuration. |
|
42 |
* |
|
43 |
* @author Yu-Ching Valerie Peng |
|
44 |
*/ |
|
45 |
||
46 |
public final class SunNativeProvider extends Provider { |
|
47 |
||
48 |
private static final long serialVersionUID = -238911724858694204L; |
|
49 |
||
50 |
private static final String NAME = "SunNativeGSS"; |
|
51 |
private static final String INFO = "Sun Native GSS provider"; |
|
52 |
private static final String MF_CLASS = |
|
53 |
"sun.security.jgss.wrapper.NativeGSSFactory"; |
|
50508
6aa873a6dae9
8194073: Invalid SunNativeProvider.INSTANCE initialization
valeriep
parents:
47216
diff
changeset
|
54 |
private static final HashMap<String, String> MECH_MAP; |
6aa873a6dae9
8194073: Invalid SunNativeProvider.INSTANCE initialization
valeriep
parents:
47216
diff
changeset
|
55 |
static final Provider INSTANCE; |
2 | 56 |
static boolean DEBUG; |
57 |
static void debug(String message) { |
|
58 |
if (DEBUG) { |
|
59 |
if (message == null) { |
|
60 |
throw new NullPointerException(); |
|
61 |
} |
|
62 |
System.out.println(NAME + ": " + message); |
|
63 |
} |
|
64 |
} |
|
65 |
||
66 |
static { |
|
67 |
MECH_MAP = |
|
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
68 |
AccessController.doPrivileged( |
55354
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
69 |
new PrivilegedAction<>() { |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
9035
diff
changeset
|
70 |
public HashMap<String, String> run() { |
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50508
diff
changeset
|
71 |
DEBUG = Boolean.parseBoolean( |
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50508
diff
changeset
|
72 |
System.getProperty("sun.security.nativegss.debug")); |
2 | 73 |
try { |
74 |
System.loadLibrary("j2gss"); |
|
75 |
} catch (Error err) { |
|
76 |
debug("No j2gss library found!"); |
|
77 |
if (DEBUG) err.printStackTrace(); |
|
78 |
return null; |
|
79 |
} |
|
55354
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
80 |
String[] gssLibs; |
51398
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50508
diff
changeset
|
81 |
String defaultLib |
3c389a284345
8209416: Refactoring GetPropertyAction calls in security libs
weijun
parents:
50508
diff
changeset
|
82 |
= System.getProperty("sun.security.jgss.lib"); |
5300 | 83 |
if (defaultLib == null || defaultLib.trim().equals("")) { |
2 | 84 |
String osname = System.getProperty("os.name"); |
85 |
if (osname.startsWith("SunOS")) { |
|
5300 | 86 |
gssLibs = new String[]{ "libgss.so" }; |
2 | 87 |
} else if (osname.startsWith("Linux")) { |
5300 | 88 |
gssLibs = new String[]{ |
89 |
"libgssapi.so", |
|
90 |
"libgssapi_krb5.so", |
|
8388
bc5ae489cd71
7016698: test sun/security/krb5/runNameEquals.sh failed on Ubuntu
weijun
parents:
5506
diff
changeset
|
91 |
"libgssapi_krb5.so.2", |
5300 | 92 |
}; |
17435 | 93 |
} else if (osname.contains("OS X")) { |
94 |
gssLibs = new String[]{ |
|
95 |
"libgssapi_krb5.dylib", |
|
96 |
"/usr/lib/sasl2/libgssapiv2.2.so", |
|
97 |
}; |
|
55354
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
98 |
} else if (osname.contains("Windows")) { |
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
99 |
// Full path needed, DLL is in jre/bin |
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
100 |
gssLibs = new String[]{ System.getProperty("java.home") |
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
101 |
+ "\\bin\\sspi_bridge.dll" }; |
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
102 |
} else { |
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
103 |
gssLibs = new String[0]; |
2 | 104 |
} |
5300 | 105 |
} else { |
106 |
gssLibs = new String[]{ defaultLib }; |
|
2 | 107 |
} |
5300 | 108 |
for (String libName: gssLibs) { |
23585
e4412d1b53d3
8031003: [Parfait] warnings from jdk/src/share/native/sun/security/jgss/wrapper: JNI exception pending
valeriep
parents:
22121
diff
changeset
|
109 |
if (GSSLibStub.init(libName, DEBUG)) { |
5300 | 110 |
debug("Loaded GSS library: " + libName); |
111 |
Oid[] mechs = GSSLibStub.indicateMechs(); |
|
55354
74f0622db875
6722928: Support SSPI as a native GSS-API provider
weijun
parents:
51398
diff
changeset
|
112 |
HashMap<String,String> map = new HashMap<>(); |
5300 | 113 |
for (int i = 0; i < mechs.length; i++) { |
114 |
debug("Native MF for " + mechs[i]); |
|
115 |
map.put("GssApiMechanism." + mechs[i], |
|
116 |
MF_CLASS); |
|
117 |
} |
|
118 |
return map; |
|
2 | 119 |
} |
120 |
} |
|
121 |
return null; |
|
122 |
} |
|
123 |
}); |
|
50508
6aa873a6dae9
8194073: Invalid SunNativeProvider.INSTANCE initialization
valeriep
parents:
47216
diff
changeset
|
124 |
// initialize INSTANCE after MECH_MAP is constructed |
6aa873a6dae9
8194073: Invalid SunNativeProvider.INSTANCE initialization
valeriep
parents:
47216
diff
changeset
|
125 |
INSTANCE = new SunNativeProvider(); |
2 | 126 |
} |
127 |
||
128 |
public SunNativeProvider() { |
|
129 |
/* We are the Sun NativeGSS provider */ |
|
40416
5d91b2fd668c
8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents:
33992
diff
changeset
|
130 |
super(NAME, PROVIDER_VER, INFO); |
2 | 131 |
|
132 |
if (MECH_MAP != null) { |
|
133 |
AccessController.doPrivileged(new PutAllAction(this, MECH_MAP)); |
|
134 |
} |
|
135 |
} |
|
136 |
} |