0N/A/*
4944N/A * Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.jgss.wrapper;
0N/A
0N/Aimport java.util.HashMap;
0N/Aimport java.security.Provider;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport org.ietf.jgss.Oid;
0N/Aimport sun.security.action.PutAllAction;
0N/A
0N/A/**
0N/A * Defines the Sun NativeGSS provider for plugging in the
0N/A * native GSS mechanisms to Java GSS.
0N/A *
0N/A * List of supported mechanisms depends on the local
0N/A * machine configuration.
0N/A *
0N/A * @author Yu-Ching Valerie Peng
0N/A */
0N/A
0N/Apublic final class SunNativeProvider extends Provider {
0N/A
0N/A private static final long serialVersionUID = -238911724858694204L;
0N/A
0N/A private static final String NAME = "SunNativeGSS";
0N/A private static final String INFO = "Sun Native GSS provider";
0N/A private static final String MF_CLASS =
0N/A "sun.security.jgss.wrapper.NativeGSSFactory";
0N/A private static final String LIB_PROP = "sun.security.jgss.lib";
0N/A private static final String DEBUG_PROP = "sun.security.nativegss.debug";
0N/A private static HashMap MECH_MAP;
0N/A static final Provider INSTANCE = new SunNativeProvider();
0N/A static boolean DEBUG;
0N/A static void debug(String message) {
0N/A if (DEBUG) {
0N/A if (message == null) {
0N/A throw new NullPointerException();
0N/A }
0N/A System.out.println(NAME + ": " + message);
0N/A }
0N/A }
0N/A
0N/A static {
0N/A MECH_MAP =
0N/A AccessController.doPrivileged(new PrivilegedAction<HashMap>() {
0N/A public HashMap run() {
0N/A DEBUG = Boolean.parseBoolean
0N/A (System.getProperty(DEBUG_PROP));
0N/A try {
0N/A System.loadLibrary("j2gss");
0N/A } catch (Error err) {
0N/A debug("No j2gss library found!");
0N/A if (DEBUG) err.printStackTrace();
0N/A return null;
0N/A }
2310N/A String gssLibs[] = new String[0];
2310N/A String defaultLib = System.getProperty(LIB_PROP);
2310N/A if (defaultLib == null || defaultLib.trim().equals("")) {
0N/A String osname = System.getProperty("os.name");
0N/A if (osname.startsWith("SunOS")) {
2310N/A gssLibs = new String[]{ "libgss.so" };
0N/A } else if (osname.startsWith("Linux")) {
2310N/A gssLibs = new String[]{
2310N/A "libgssapi.so",
2310N/A "libgssapi_krb5.so",
3571N/A "libgssapi_krb5.so.2",
2310N/A };
4944N/A } else if (osname.contains("OS X")) {
4632N/A gssLibs = new String[]{
4632N/A "/usr/lib/sasl2/libgssapiv2.2.so",
4632N/A };
0N/A }
2310N/A } else {
2310N/A gssLibs = new String[]{ defaultLib };
0N/A }
2310N/A for (String libName: gssLibs) {
2310N/A if (GSSLibStub.init(libName)) {
2310N/A debug("Loaded GSS library: " + libName);
2310N/A Oid[] mechs = GSSLibStub.indicateMechs();
2310N/A HashMap<String, String> map =
2310N/A new HashMap<String, String>();
2310N/A for (int i = 0; i < mechs.length; i++) {
2310N/A debug("Native MF for " + mechs[i]);
2310N/A map.put("GssApiMechanism." + mechs[i],
2310N/A MF_CLASS);
2310N/A }
2310N/A return map;
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A });
0N/A }
0N/A
0N/A public SunNativeProvider() {
0N/A /* We are the Sun NativeGSS provider */
0N/A super(NAME, 1.0, INFO);
0N/A
0N/A if (MECH_MAP != null) {
0N/A AccessController.doPrivileged(new PutAllAction(this, MECH_MAP));
0N/A }
0N/A }
0N/A}