Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/jgss/wrapper/SunNativeProvider.java
38923 views
/*1* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.jgss.wrapper;2627import java.util.HashMap;28import java.security.Provider;29import java.security.AccessController;30import java.security.PrivilegedAction;31import org.ietf.jgss.Oid;32import sun.security.action.PutAllAction;3334/**35* Defines the Sun NativeGSS provider for plugging in the36* native GSS mechanisms to Java GSS.37*38* List of supported mechanisms depends on the local39* machine configuration.40*41* @author Yu-Ching Valerie Peng42*/4344public final class SunNativeProvider extends Provider {4546private static final long serialVersionUID = -238911724858694204L;4748private static final String NAME = "SunNativeGSS";49private static final String INFO = "Sun Native GSS provider";50private static final String MF_CLASS =51"sun.security.jgss.wrapper.NativeGSSFactory";52private static final String LIB_PROP = "sun.security.jgss.lib";53private static final String DEBUG_PROP = "sun.security.nativegss.debug";54private static HashMap<String, String> MECH_MAP;55static final Provider INSTANCE = new SunNativeProvider();56static boolean DEBUG;57static void debug(String message) {58if (DEBUG) {59if (message == null) {60throw new NullPointerException();61}62System.out.println(NAME + ": " + message);63}64}6566static {67MECH_MAP =68AccessController.doPrivileged(69new PrivilegedAction<HashMap<String, String>>() {70public HashMap<String, String> run() {71DEBUG = Boolean.parseBoolean72(System.getProperty(DEBUG_PROP));73try {74System.loadLibrary("j2gss");75} catch (Error err) {76debug("No j2gss library found!");77if (DEBUG) err.printStackTrace();78return null;79}80String gssLibs[] = new String[0];81String defaultLib = System.getProperty(LIB_PROP);82if (defaultLib == null || defaultLib.trim().equals("")) {83String osname = System.getProperty("os.name");84if (osname.startsWith("SunOS")) {85gssLibs = new String[]{ "libgss.so" };86} else if (osname.startsWith("Linux")) {87gssLibs = new String[]{88"libgssapi.so",89"libgssapi_krb5.so",90"libgssapi_krb5.so.2",91};92} else if (osname.contains("OS X")) {93gssLibs = new String[]{94"libgssapi_krb5.dylib",95"/usr/lib/sasl2/libgssapiv2.2.so",96};97}98} else {99gssLibs = new String[]{ defaultLib };100}101for (String libName: gssLibs) {102if (GSSLibStub.init(libName, DEBUG)) {103debug("Loaded GSS library: " + libName);104Oid[] mechs = GSSLibStub.indicateMechs();105HashMap<String, String> map =106new HashMap<String, String>();107for (int i = 0; i < mechs.length; i++) {108debug("Native MF for " + mechs[i]);109map.put("GssApiMechanism." + mechs[i],110MF_CLASS);111}112return map;113}114}115return null;116}117});118}119120public SunNativeProvider() {121/* We are the Sun NativeGSS provider */122super(NAME, 1.8d, INFO);123124if (MECH_MAP != null) {125AccessController.doPrivileged(new PutAllAction(this, MECH_MAP));126}127}128}129130131