jdk/src/jdk.security.jgss/share/classes/com/sun/security/sasl/gsskerb/JdkSASL.java
author serb
Thu, 17 Aug 2017 13:51:01 -0700
changeset 47179 49b3d270f821
parent 40416 5d91b2fd668c
permissions -rw-r--r--
8185683: Inaccessible and unused classes can be removed from java.desktop module Reviewed-by: prr, kcr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     1
/*
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 33991
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     4
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    10
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    15
 * accompanied this code).
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    16
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    20
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    23
 * questions.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    24
 */
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    25
package com.sun.security.sasl.gsskerb;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    26
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    27
import java.security.AccessController;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    28
import java.security.PrivilegedAction;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    29
import java.security.Provider;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    30
import java.security.NoSuchAlgorithmException;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    31
import java.security.InvalidParameterException;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    32
import java.security.ProviderException;
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 33991
diff changeset
    33
import static sun.security.util.SecurityConstants.PROVIDER_VER;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 33991
diff changeset
    34
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    35
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    36
/**
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    37
 * The JdkSASL provider class -
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    38
 * provides client and server support for GSSAPI/Kerberos v5
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    39
 */
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    40
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    41
public final class JdkSASL extends Provider {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    42
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    43
    private static final long serialVersionUID = 8622590901641830849L;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    44
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    45
    private static final String info = "JDK SASL provider" +
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    46
        "(implements client and server mechanisms for GSSAPI)";
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    47
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    48
    private static final class ProviderService extends Provider.Service {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    49
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    50
        ProviderService(Provider p, String type, String algo, String cn) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    51
            super(p, type, algo, cn, null, null);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    52
        }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    53
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    54
        @Override
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    55
        public Object newInstance(Object ctrParamObj)
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    56
            throws NoSuchAlgorithmException {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    57
            String type = getType();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    58
            if (ctrParamObj != null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    59
                throw new InvalidParameterException
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    60
                    ("constructorParameter not used with " + type + " engines");
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    61
            }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    62
            String algo = getAlgorithm();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    63
            // GSSAPI uses same impl class for client and server
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    64
            try {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    65
                if (algo.equals("GSSAPI")) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    66
                    return new com.sun.security.sasl.gsskerb.FactoryImpl();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    67
                }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    68
            } catch (Exception ex) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    69
                throw new NoSuchAlgorithmException("Error constructing " +
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    70
                     type + " for " + algo + " using JdkSASL", ex);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    71
            }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    72
            throw new ProviderException("No impl for " + algo +
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    73
                " " + type);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    74
        }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    75
    }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    76
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    77
    public JdkSASL() {
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 33991
diff changeset
    78
        super("JdkSASL", PROVIDER_VER, info);
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    79
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    80
        final Provider p = this;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    81
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    82
            public Void run() {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    83
                putService(new ProviderService(p, "SaslClientFactory",
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    84
                           "GSSAPI", "com.sun.security.sasl.gsskerb.FactoryImpl"));
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    85
                putService(new ProviderService(p, "SaslServerFactory",
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    86
                           "GSSAPI", "com.sun.security.sasl.gsskerb.FactoryImpl"));
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    87
                return null;
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    88
            }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    89
        });
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    90
    }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents:
diff changeset
    91
}