001: /*
002: * Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.security.jgss.wrapper;
027:
028: import java.util.HashMap;
029: import java.security.Provider;
030: import java.security.AccessController;
031: import java.security.PrivilegedAction;
032: import org.ietf.jgss.Oid;
033: import sun.security.action.PutAllAction;
034:
035: /**
036: * Defines the Sun NativeGSS provider for plugging in the
037: * native GSS mechanisms to Java GSS.
038: *
039: * List of supported mechanisms depends on the local
040: * machine configuration.
041: *
042: * @author Yu-Ching Valerie Peng
043: * @version 1.13, 05/05/07
044: */
045:
046: public final class SunNativeProvider extends Provider {
047:
048: private static final long serialVersionUID = -238911724858694204L;
049:
050: private static final String NAME = "SunNativeGSS";
051: private static final String INFO = "Sun Native GSS provider";
052: private static final String MF_CLASS = "sun.security.jgss.wrapper.NativeGSSFactory";
053: private static final String LIB_PROP = "sun.security.jgss.lib";
054: private static final String DEBUG_PROP = "sun.security.nativegss.debug";
055: private static HashMap MECH_MAP;
056: static final Provider INSTANCE = new SunNativeProvider();
057: static boolean DEBUG;
058:
059: static void debug(String message) {
060: if (DEBUG) {
061: if (message == null) {
062: throw new NullPointerException();
063: }
064: System.out.println(NAME + ": " + message);
065: }
066: }
067:
068: static {
069: MECH_MAP = AccessController
070: .doPrivileged(new PrivilegedAction<HashMap>() {
071: public HashMap run() {
072: DEBUG = Boolean.parseBoolean(System
073: .getProperty(DEBUG_PROP));
074: try {
075: System.loadLibrary("j2gss");
076: } catch (Error err) {
077: debug("No j2gss library found!");
078: if (DEBUG)
079: err.printStackTrace();
080: return null;
081: }
082: String gssLib = System.getProperty(LIB_PROP);
083: if (gssLib == null || gssLib.trim().equals("")) {
084: String osname = System
085: .getProperty("os.name");
086: if (osname.startsWith("SunOS")) {
087: gssLib = "libgss.so";
088: } else if (osname.startsWith("Linux")) {
089: gssLib = "libgssapi.so";
090: }
091: }
092: if (GSSLibStub.init(gssLib)) {
093: debug("Loaded GSS library: " + gssLib);
094: Oid[] mechs = GSSLibStub.indicateMechs();
095: HashMap<String, String> map = new HashMap<String, String>();
096: for (int i = 0; i < mechs.length; i++) {
097: debug("Native MF for " + mechs[i]);
098: map.put("GssApiMechanism." + mechs[i],
099: MF_CLASS);
100: }
101: return map;
102: }
103: return null;
104: }
105: });
106: }
107:
108: public SunNativeProvider() {
109: /* We are the Sun NativeGSS provider */
110: super (NAME, 1.0, INFO);
111:
112: if (MECH_MAP != null) {
113: AccessController.doPrivileged(new PutAllAction(this,
114: MECH_MAP));
115: }
116: }
117: }
|