Path: blob/master/src/java.security.sasl/share/classes/com/sun/security/sasl/Provider.java
41161 views
/*1* Copyright (c) 2003, 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*/24package com.sun.security.sasl;2526import java.security.AccessController;27import java.security.PrivilegedAction;28import java.security.NoSuchAlgorithmException;29import java.security.InvalidParameterException;30import java.security.ProviderException;31import static sun.security.util.SecurityConstants.PROVIDER_VER;3233/**34* The SASL provider.35* Provides client support for36* - EXTERNAL37* - PLAIN38* - CRAM-MD539* - DIGEST-MD540* - NTLM41* And server support for42* - CRAM-MD543* - DIGEST-MD544* - NTLM45*/4647public final class Provider extends java.security.Provider {4849private static final long serialVersionUID = 8622598936488630849L;5051private static final String info = "Sun SASL provider" +52"(implements client mechanisms for: " +53"DIGEST-MD5, EXTERNAL, PLAIN, CRAM-MD5, NTLM;" +54" server mechanisms for: DIGEST-MD5, CRAM-MD5, NTLM)";5556private static final class ProviderService57extends java.security.Provider.Service {58ProviderService(java.security.Provider p, String type, String algo,59String cn) {60super(p, type, algo, cn, null, null);61}6263@Override64public Object newInstance(Object ctrParamObj)65throws NoSuchAlgorithmException {66String type = getType();67if (ctrParamObj != null) {68throw new InvalidParameterException69("constructorParameter not used with " + type + " engines");70}7172String algo = getAlgorithm();73try {74// DIGEST-MD5, NTLM uses same impl class for client and server75if (algo.equals("DIGEST-MD5")) {76return new com.sun.security.sasl.digest.FactoryImpl();77}78if (algo.equals("NTLM")) {79return new com.sun.security.sasl.ntlm.FactoryImpl();80}81if (type.equals("SaslClientFactory")) {82if (algo.equals("EXTERNAL") || algo.equals("PLAIN") ||83algo.equals("CRAM-MD5")) {84return new com.sun.security.sasl.ClientFactoryImpl();85}86} else if (type.equals("SaslServerFactory")) {87if (algo.equals("CRAM-MD5")) {88return new com.sun.security.sasl.ServerFactoryImpl();89}90}91} catch (Exception ex) {92throw new NoSuchAlgorithmException("Error constructing " +93type + " for " + algo + " using SunSASL", ex);94}95throw new ProviderException("No impl for " + algo +96" " + type);97}98}99100@SuppressWarnings("removal")101public Provider() {102super("SunSASL", PROVIDER_VER, info);103104final Provider p = this;105AccessController.doPrivileged(new PrivilegedAction<Void>() {106public Void run() {107// Client mechanisms108putService(new ProviderService(p, "SaslClientFactory",109"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));110putService(new ProviderService(p, "SaslClientFactory",111"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));112putService(new ProviderService(p, "SaslClientFactory",113"EXTERNAL", "com.sun.security.sasl.ClientFactoryImpl"));114putService(new ProviderService(p, "SaslClientFactory",115"PLAIN", "com.sun.security.sasl.ClientFactoryImpl"));116putService(new ProviderService(p, "SaslClientFactory",117"CRAM-MD5", "com.sun.security.sasl.ClientFactoryImpl"));118119// Server mechanisms120putService(new ProviderService(p, "SaslServerFactory",121"CRAM-MD5", "com.sun.security.sasl.ServerFactoryImpl"));122putService(new ProviderService(p, "SaslServerFactory",123"DIGEST-MD5", "com.sun.security.sasl.digest.FactoryImpl"));124putService(new ProviderService(p, "SaslServerFactory",125"NTLM", "com.sun.security.sasl.ntlm.FactoryImpl"));126return null;127}128});129}130}131132133