Path: blob/master/src/java.security.jgss/share/classes/sun/security/jgss/SunProvider.java
41159 views
/*1* Copyright (c) 2000, 2021, 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;2627import java.security.Provider;28import java.security.AccessController;29import java.security.PrivilegedAction;30import java.security.NoSuchAlgorithmException;31import java.security.InvalidParameterException;32import java.security.ProviderException;33import sun.security.jgss.krb5.Krb5MechFactory;34import sun.security.jgss.spnego.SpNegoMechFactory;35import static sun.security.util.SecurityConstants.PROVIDER_VER;3637/**38* Defines the Sun JGSS provider.39* Will merger this with the Sun security provider40* sun.security.provider.Sun when the JGSS src is merged with the JDK41* src.42*43* Mechanisms supported are:44*45* - Kerberos v5 as defined in RFC 1964.46* Oid is 1.2.840.113554.1.2.247*48* - SPNEGO as defined in RFC 247849* Oid is 1.3.6.1.5.5.250*51* [Dummy mechanism is no longer compiled:52* - Dummy mechanism. This is primarily useful to test a multi-mech53* environment.54* Oid is 1.3.6.1.4.1.42.2.26.1.2]55*56* @author Mayank Upadhyay57*/5859public final class SunProvider extends Provider {6061private static final long serialVersionUID = -238911724858694198L;6263private static final String INFO = "Sun " +64"(Kerberos v5, SPNEGO)";65// "(Kerberos v5, Dummy GSS-API Mechanism)";6667private static final class ProviderService extends Provider.Service {68ProviderService(Provider p, String type, String algo, String cn) {69super(p, type, algo, cn, null, null);70}7172@Override73public Object newInstance(Object ctrParamObj)74throws NoSuchAlgorithmException {75String type = getType();76if (ctrParamObj != null) {77throw new InvalidParameterException78("constructorParameter not used with " + type +79" engines");80}81String algo = getAlgorithm();82try {83if (type.equals("GssApiMechanism")) {84if (algo.equals("1.2.840.113554.1.2.2")) {85return new Krb5MechFactory();86} else if (algo.equals("1.3.6.1.5.5.2")) {87return new SpNegoMechFactory();88}89}90} catch (Exception ex) {91throw new NoSuchAlgorithmException92("Error constructing " + type + " for " +93algo + " using SunJGSS", ex);94}95throw new ProviderException("No impl for " + algo +96" " + type);97}98}99100@SuppressWarnings("removal")101public SunProvider() {102/* We are the Sun JGSS provider */103super("SunJGSS", PROVIDER_VER, INFO);104105final Provider p = this;106AccessController.doPrivileged(new PrivilegedAction<Void>() {107public Void run() {108putService(new ProviderService(p, "GssApiMechanism",109"1.2.840.113554.1.2.2",110"sun.security.jgss.krb5.Krb5MechFactory"));111putService(new ProviderService(p, "GssApiMechanism",112"1.3.6.1.5.5.2",113"sun.security.jgss.spnego.SpNegoMechFactory"));114return null;115}116});117}118}119120121