2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, 2010, 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;
|
|
34 |
|
|
35 |
/**
|
|
36 |
* Defines the Sun NativeGSS provider for plugging in the
|
|
37 |
* native GSS mechanisms to Java GSS.
|
|
38 |
*
|
|
39 |
* List of supported mechanisms depends on the local
|
|
40 |
* machine configuration.
|
|
41 |
*
|
|
42 |
* @author Yu-Ching Valerie Peng
|
|
43 |
*/
|
|
44 |
|
|
45 |
public final class SunNativeProvider extends Provider {
|
|
46 |
|
|
47 |
private static final long serialVersionUID = -238911724858694204L;
|
|
48 |
|
|
49 |
private static final String NAME = "SunNativeGSS";
|
|
50 |
private static final String INFO = "Sun Native GSS provider";
|
|
51 |
private static final String MF_CLASS =
|
|
52 |
"sun.security.jgss.wrapper.NativeGSSFactory";
|
|
53 |
private static final String LIB_PROP = "sun.security.jgss.lib";
|
|
54 |
private static final String DEBUG_PROP = "sun.security.nativegss.debug";
|
|
55 |
private static HashMap MECH_MAP;
|
|
56 |
static final Provider INSTANCE = new SunNativeProvider();
|
|
57 |
static boolean DEBUG;
|
|
58 |
static void debug(String message) {
|
|
59 |
if (DEBUG) {
|
|
60 |
if (message == null) {
|
|
61 |
throw new NullPointerException();
|
|
62 |
}
|
|
63 |
System.out.println(NAME + ": " + message);
|
|
64 |
}
|
|
65 |
}
|
|
66 |
|
|
67 |
static {
|
|
68 |
MECH_MAP =
|
|
69 |
AccessController.doPrivileged(new PrivilegedAction<HashMap>() {
|
|
70 |
public HashMap run() {
|
|
71 |
DEBUG = Boolean.parseBoolean
|
|
72 |
(System.getProperty(DEBUG_PROP));
|
|
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 |
}
|
5300
|
80 |
String gssLibs[] = new String[0];
|
|
81 |
String defaultLib = System.getProperty(LIB_PROP);
|
|
82 |
if (defaultLib == null || defaultLib.trim().equals("")) {
|
2
|
83 |
String osname = System.getProperty("os.name");
|
|
84 |
if (osname.startsWith("SunOS")) {
|
5300
|
85 |
gssLibs = new String[]{ "libgss.so" };
|
2
|
86 |
} else if (osname.startsWith("Linux")) {
|
5300
|
87 |
gssLibs = new String[]{
|
|
88 |
"libgssapi.so",
|
|
89 |
"libgssapi_krb5.so",
|
|
90 |
};
|
2
|
91 |
}
|
5300
|
92 |
} else {
|
|
93 |
gssLibs = new String[]{ defaultLib };
|
2
|
94 |
}
|
5300
|
95 |
for (String libName: gssLibs) {
|
|
96 |
if (GSSLibStub.init(libName)) {
|
|
97 |
debug("Loaded GSS library: " + libName);
|
|
98 |
Oid[] mechs = GSSLibStub.indicateMechs();
|
|
99 |
HashMap<String, String> map =
|
|
100 |
new HashMap<String, String>();
|
|
101 |
for (int i = 0; i < mechs.length; i++) {
|
|
102 |
debug("Native MF for " + mechs[i]);
|
|
103 |
map.put("GssApiMechanism." + mechs[i],
|
|
104 |
MF_CLASS);
|
|
105 |
}
|
|
106 |
return map;
|
2
|
107 |
}
|
|
108 |
}
|
|
109 |
return null;
|
|
110 |
}
|
|
111 |
});
|
|
112 |
}
|
|
113 |
|
|
114 |
public SunNativeProvider() {
|
|
115 |
/* We are the Sun NativeGSS provider */
|
|
116 |
super(NAME, 1.0, INFO);
|
|
117 |
|
|
118 |
if (MECH_MAP != null) {
|
|
119 |
AccessController.doPrivileged(new PutAllAction(this, MECH_MAP));
|
|
120 |
}
|
|
121 |
}
|
|
122 |
}
|