jdk/src/java.base/share/classes/java/security/Provider.java
author jjg
Thu, 11 May 2017 10:48:00 -0700
changeset 45124 144479e89cdb
parent 40416 5d91b2fd668c
child 45434 4582657c7260
permissions -rw-r--r--
8179592: Update tables in java.base to be HTML 5-friendly. Reviewed-by: mchung, darcy, martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
     2
 * Copyright (c) 1996, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import static java.util.Locale.ENGLISH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.lang.ref.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.lang.reflect.*;
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    33
import java.util.function.BiConsumer;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    34
import java.util.function.BiFunction;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
    35
import java.util.function.Function;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class represents a "provider" for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * Java Security API, where a provider implements some or all parts of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Java Security. Services that a provider may implement include:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    44
 * <li>Algorithms (such as DSA, RSA, or SHA-256).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <li>Key generation, conversion, and management facilities (such as for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * algorithm-specific keys).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    49
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>Some provider implementations may encounter unrecoverable internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * errors during their operation, for example a failure to communicate with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * security token. A {@link ProviderException} should be used to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * such errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    56
 * <p>Please note that a provider can be used to implement any security
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    57
 * service in Java that uses a pluggable architecture with a choice
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    58
 * of implementations that fit underneath.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    59
 *
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    60
 * <p>The service type {@code Provider} is reserved for use by the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * security framework. Services of this type cannot be added, removed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * or modified by applications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * The following attributes are automatically placed in each Provider object:
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    64
 * <table class="plain">
18592
80cdfecea074 8019539: Fix doclint errors in java.security and its subpackages
juh
parents: 18579
diff changeset
    65
 * <caption><b>Attributes Automatically Placed in a Provider Object</b></caption>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    66
 * <thead>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <tr><th>Name</th><th>Value</th>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    68
 * </thead>
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    69
 * <tbody>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    70
 * <tr><td>{@code Provider.id name}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    71
 *     <td>{@code String.valueOf(provider.getName())}</td>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    72
 * <tr><td>{@code Provider.id version}</td>
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
    73
 *     <td>{@code String.valueOf(provider.getVersionStr())}</td>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    74
 * <tr><td>{@code Provider.id info}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    75
 *     <td>{@code String.valueOf(provider.getInfo())}</td>
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    76
 * <tr><td>{@code Provider.id className}</td>
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
    77
 *     <td>{@code provider.getClass().getName()}</td>
45124
144479e89cdb 8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents: 40416
diff changeset
    78
 * </tbody>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
    81
 * <p>Each provider has a name and a version string. A provider normally
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    82
 * identifies itself with a file named {@code java.security.Provider}
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    83
 * in the resource directory {@code META-INF/services}.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    84
 * Security providers are looked up via the {@link ServiceLoader} mechanism
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    85
 * using the {@link ClassLoader#getSystemClassLoader application class loader}.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    86
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    87
 * <p>Providers may be configured such that they are automatically
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    88
 * installed and made available at runtime via the
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    89
 * {@link Security#getProviders() Security.getProviders()} method.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    90
 * The mechanism for configuring and installing security providers is
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    91
 * implementation-specific.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    92
 *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    93
 * @implNote
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    94
 * The JDK implementation supports static registration of the security
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    95
 * providers via the {@code conf/security/java.security} file in the Java
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    96
 * installation directory. These providers are automatically installed by
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    97
 * the JDK runtime, see <a href =
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    98
 * "../../../technotes/guides/security/crypto/CryptoSpec.html#Provider">The Provider Class</a>
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
    99
 * in the "Java Cryptography Architecture API Specification &amp; Reference"
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   100
 * for information about how a particular type of provider, the cryptographic
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   101
 * service provider, works and is installed.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   102
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @author Benjamin Renaud
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
public abstract class Provider extends Properties {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    // Declare serialVersionUID to be compatible with JDK1.1
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   109
    private static final long serialVersionUID = -4298000515446427739L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private static final sun.security.util.Debug debug =
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   112
        sun.security.util.Debug.getInstance("provider", "Provider");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * The provider name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * A description of the provider and its services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private String info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * The provider version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private double version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   135
    /**
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   136
     * The provider version string.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   137
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   138
     * @serial
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   139
     */
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   140
    private String versionStr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private transient Set<Map.Entry<Object,Object>> entrySet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private transient int entrySetCallCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private transient boolean initialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   147
    private static Object newInstanceUtil(final Class<?> clazz,
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   148
        final Class<?> ctrParamClz, final Object ctorParamObj)
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   149
        throws Exception {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   150
        if (ctrParamClz == null) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   151
            Constructor<?> con = clazz.getConstructor();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   152
            return con.newInstance();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   153
        } else {
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   154
            // Looking for the constructor with a params first and fallback
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   155
            // to one without if not found. This is to support the enhanced
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   156
            // SecureRandom where both styles of constructors are supported.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   157
            // Before jdk9, there was no params support (only getInstance(alg))
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   158
            // and an impl only had the params-less constructor. Since jdk9,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   159
            // there is getInstance(alg,params) and an impl can contain
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   160
            // an Impl(params) constructor.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   161
            try {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   162
                Constructor<?> con = clazz.getConstructor(ctrParamClz);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   163
                return con.newInstance(ctorParamObj);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   164
            } catch (NoSuchMethodException nsme) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   165
                // For pre-jdk9 SecureRandom implementations, they only
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   166
                // have params-less constructors which still works when
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   167
                // the input ctorParamObj is null.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   168
                //
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   169
                // For other primitives using params, ctorParamObj should not
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   170
                // be null and nsme is thrown, just like before.
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   171
                if (ctorParamObj == null) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   172
                    try {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   173
                        Constructor<?> con = clazz.getConstructor();
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   174
                        return con.newInstance();
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   175
                    } catch (NoSuchMethodException nsme2) {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   176
                        nsme.addSuppressed(nsme2);
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   177
                        throw nsme;
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   178
                    }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   179
                } else {
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   180
                    throw nsme;
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   181
                }
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
   182
            }
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   183
        }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   184
    }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   185
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   186
    private static double parseVersionStr(String s) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   187
        try {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   188
            int firstDotIdx = s.indexOf('.');
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   189
            int nextDotIdx = s.indexOf('.', firstDotIdx + 1);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   190
            if (nextDotIdx != -1) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   191
                s = s.substring(0, nextDotIdx);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   192
            }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   193
            int endIdx = s.indexOf('-');
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   194
            if (endIdx > 0) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   195
                s = s.substring(0, endIdx);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   196
            }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   197
            endIdx = s.indexOf('+');
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   198
            if (endIdx > 0) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   199
                s = s.substring(0, endIdx);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   200
            }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   201
            return Double.parseDouble(s);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   202
        } catch (NullPointerException | NumberFormatException e) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   203
            return 0d;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   204
        }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   205
    }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   206
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Constructs a provider with the specified name, version number,
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   209
     * and information. Calling this constructor is equivalent to call the
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   210
     * {@link #Provider(String, String, String)} with {@code name}
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   211
     * name, {@code Double.toString(version)}, and {@code info}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @param name the provider name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @param version the provider version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param info a description of the provider and its services.
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   218
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   219
     * @deprecated use {@link #Provider(String, String, String)} instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   221
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected Provider(String name, double version, String info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        this.version = version;
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   225
        this.versionStr = Double.toString(version);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   226
        this.info = info;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   227
        putId();
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   228
        initialized = true;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   229
    }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   230
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   231
    /**
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   232
     * Constructs a provider with the specified name, version string,
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   233
     * and information.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   234
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   235
     * <p>The version string contains a version number optionally followed
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   236
     * by other information separated by one of the characters of '+', '-'.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   237
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   238
     * The format for the version number is:
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   239
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   240
     * <blockquote><pre>
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   241
     *     ^[0-9]+(\.[0-9]+)*
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   242
     * </pre></blockquote>
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   243
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   244
     * <p>In order to return the version number in a double, when there are
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   245
     * more than two components (separated by '.' as defined above), only
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   246
     * the first two components are retained. The resulting string is then
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   247
     * passed to {@link Double#valueOf(String)} to generate version number,
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   248
     * i.e. {@link #getVersion}.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   249
     * <p>If the conversion failed, value 0 will be used.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   250
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   251
     * @param name the provider name.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   252
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   253
     * @param versionStr the provider version string.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   254
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   255
     * @param info a description of the provider and its services.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   256
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   257
     * @since 9
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   258
     */
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   259
    protected Provider(String name, String versionStr, String info) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   260
        this.name = name;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   261
        this.versionStr = versionStr;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   262
        this.version = parseVersionStr(versionStr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        putId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   269
     * Apply the supplied configuration argument to this provider instance
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   270
     * and return the configured provider. Note that if this provider cannot
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   271
     * be configured in-place, a new provider will be created and returned.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   272
     * Therefore, callers should always use the returned provider.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   273
     *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   274
     * @implSpec
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   275
     * The default implementation throws {@code UnsupportedOperationException}.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   276
     * Subclasses should override this method only if a configuration argument
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   277
     * is supported.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   278
     *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   279
     * @param configArg the configuration information for configuring this
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   280
     *         provider.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   281
     *
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   282
     * @throws UnsupportedOperationException if a configuration argument is
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   283
     *         not supported.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   284
     * @throws NullPointerException if the supplied configuration argument is
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   285
               null.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   286
     * @throws InvalidParameterException if the supplied configuration argument
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   287
     *         is invalid.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   288
     * @return a provider configured with the supplied configuration argument.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   289
     *
32931
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   290
     * @since 9
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   291
     */
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   292
    public Provider configure(String configArg) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   293
        throw new UnsupportedOperationException("configure is not supported");
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   294
    }
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   295
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   296
    /**
32931
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   297
     * Check if this provider instance has been configured.
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   298
     *
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   299
     * @implSpec
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   300
     * The default implementation returns true.
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   301
     * Subclasses should override this method if the provider instance requires
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   302
     * an explicit {@code configure} call after being constructed.
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   303
     *
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   304
     * @return true if no further configuration is needed, false otherwise.
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   305
     *
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   306
     * @since 9
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   307
     */
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   308
    public boolean isConfigured() {
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   309
        return true;
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   310
    }
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   311
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   312
2ba4f06f8684 8130648: JCK test api/java_security/AuthProvider/ProviderTests_login starts failing after JDK-7191662
valeriep
parents: 32649
diff changeset
   313
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Returns the name of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @return the name of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Returns the version number for this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @return the version number for this provider.
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   326
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   327
     * @deprecated use {@link #getVersionStr} instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     */
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   329
    @Deprecated(since="9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public double getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return version;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   335
     * Returns the version string for this provider.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   336
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   337
     * @return the version string for this provider.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   338
     *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   339
     * @since 9
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   340
     */
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   341
    public String getVersionStr() {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   342
        return versionStr;
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   343
    }
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   344
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   345
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Returns a human-readable description of the provider and its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * services.  This may return an HTML page, with relevant links.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @return a description of the provider and its services.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    public String getInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        return info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   356
     * Returns a string with the name and the version string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * of this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   359
     * @return the string with the name and the version string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * for this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public String toString() {
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   363
        return name + " version " + versionStr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * override the following methods to ensure that provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * information can only be changed if the caller has the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * permissions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Clears this provider so that it no longer contains the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * used to look up facilities implemented by the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   376
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   377
     * method is called with the string {@code "clearProviderProperties."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   378
     * (where {@code name} is the provider name) to see if it's ok to clear
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   379
     * this provider.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   382
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   383
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *          denies access to clear this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   388
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public synchronized void clear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        check("clearProviderProperties."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            debug.println("Remove " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        implClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * Reads a property list (key and element pairs) from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   400
     * @param inStream the input stream.
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
   401
     * @exception IOException if an error occurred when reading from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     *               input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see java.util.Properties#load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   405
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public synchronized void load(InputStream inStream) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            debug.println("Load " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        Properties tempProperties = new Properties();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        tempProperties.load(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        implPutAll(tempProperties);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * Copies all of the mappings from the specified Map to this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * These mappings will replace any properties that this provider had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * for any of the keys currently in the specified Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   423
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public synchronized void putAll(Map<?,?> t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            debug.println("Put all " + name + " provider properties");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        implPutAll(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * Returns an unmodifiable Set view of the property entries contained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * in this Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see   java.util.Map.Entry
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   439
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    public synchronized Set<Map.Entry<Object,Object>> entrySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        if (entrySet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            if (entrySetCallCount++ == 0)  // Initial call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                entrySet = Collections.unmodifiableMap(this).entrySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                return super.entrySet();   // Recursive call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        // This exception will be thrown if the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // Collections.unmodifiableMap.entrySet() is changed such that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        // no longer calls entrySet() on the backing Map.  (Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        // entrySet implementation depends on this "implementation detail",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        // which is unlikely to change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        if (entrySetCallCount != 2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            throw new RuntimeException("Internal error.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        return entrySet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Returns an unmodifiable Set view of the property keys contained in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   466
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public Set<Object> keySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        return Collections.unmodifiableSet(super.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Returns an unmodifiable Collection view of the property values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * contained in this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   478
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public Collection<Object> values() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return Collections.unmodifiableCollection(super.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   485
     * Sets the {@code key} property to have the specified
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   486
     * {@code value}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   488
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   489
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   490
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   491
     * provider's property values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   494
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   495
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *          denies access to set property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   500
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    public synchronized Object put(Object key, Object value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        check("putProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            debug.println("Set " + name + " provider property [" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                          key + "/" + value +"]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return implPut(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   511
     * If the specified key is not already associated with a value (or is mapped
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   512
     * to {@code null}) associates it with the given value and returns
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   513
     * {@code null}, else returns the current value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   514
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   515
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   516
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   517
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   518
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   519
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   520
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   521
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   522
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   523
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   524
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   525
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   526
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   527
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   528
    public synchronized Object putIfAbsent(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   529
        check("putProviderProperty."+name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   530
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   531
            debug.println("Set " + name + " provider property [" +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   532
                          key + "/" + value +"]");
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   533
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   534
        return implPutIfAbsent(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   535
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   536
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   537
    /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   538
     * Removes the {@code key} property (and its corresponding
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   539
     * {@code value}).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   541
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   542
     * method is called with the string {@code "removeProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   543
     * where {@code name} is the provider name, to see if it's ok to remove this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   544
     * provider's properties.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   547
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
   548
     *          java.lang.SecurityManager#checkSecurityAccess} method
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *          denies access to remove this provider's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   553
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public synchronized Object remove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        check("removeProviderProperty."+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            debug.println("Remove " + name + " provider property " + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return implRemove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   562
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   563
     * Removes the entry for the specified key only if it is currently
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   564
     * mapped to the specified value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   565
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   566
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   567
     * method is called with the string {@code "removeProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   568
     * where {@code name} is the provider name, to see if it's ok to remove this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   569
     * provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   570
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   571
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   572
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   573
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   574
     *          denies access to remove this provider's properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   575
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   576
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   577
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   578
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   579
    public synchronized boolean remove(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   580
        check("removeProviderProperty."+name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   581
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   582
            debug.println("Remove " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   583
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   584
        return implRemove(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   585
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   586
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   587
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   588
     * Replaces the entry for the specified key only if currently
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   589
     * mapped to the specified value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   590
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   591
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   592
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   593
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   594
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   595
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   596
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   597
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   598
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   599
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   600
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   601
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   602
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   603
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   604
    public synchronized boolean replace(Object key, Object oldValue,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   605
            Object newValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   606
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   607
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   608
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   609
            debug.println("Replace " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   610
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   611
        return implReplace(key, oldValue, newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   612
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   613
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   614
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   615
     * Replaces the entry for the specified key only if it is
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   616
     * currently mapped to some value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   617
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   618
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   619
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   620
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   621
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   622
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   623
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   624
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   625
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   626
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   627
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   628
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   629
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   630
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   631
    public synchronized Object replace(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   632
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   633
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   634
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   635
            debug.println("Replace " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   636
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   637
        return implReplace(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   638
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   639
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   640
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   641
     * Replaces each entry's value with the result of invoking the given
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   642
     * function on that entry, in the order entries are returned by an entry
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   643
     * set iterator, until all entries have been processed or the function
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   644
     * throws an exception.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   645
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   646
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   647
     * method is called with the string {@code "putProviderProperty."+name},
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   648
     * where {@code name} is the provider name, to see if it's ok to set this
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   649
     * provider's property values.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   650
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   651
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   652
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   653
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   654
     *          denies access to set property values.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   655
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   656
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   657
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   658
    @Override
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   659
    public synchronized void replaceAll(BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   660
            ? super Object, ? extends Object> function) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   661
        check("putProviderProperty." + name);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   662
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   663
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   664
            debug.println("ReplaceAll " + name + " provider property ");
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   665
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   666
        implReplaceAll(function);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   667
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   668
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   669
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   670
     * Attempts to compute a mapping for the specified key and its
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   671
     * current mapped value (or {@code null} if there is no current
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   672
     * mapping).
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   673
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   674
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   675
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   676
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   677
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   678
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   679
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   680
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   681
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   682
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   683
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   684
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   685
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   686
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   687
    @Override
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   688
    public synchronized Object compute(Object key, BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   689
            ? super Object, ? extends Object> remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   690
        check("putProviderProperty." + name);
40404
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
   691
        check("removeProviderProperty." + name);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   692
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   693
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   694
            debug.println("Compute " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   695
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   696
        return implCompute(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   697
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   698
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   699
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   700
     * If the specified key is not already associated with a value (or
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   701
     * is mapped to {@code null}), attempts to compute its value using
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   702
     * the given mapping function and enters it into this map unless
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   703
     * {@code null}.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   704
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   705
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   706
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   707
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   708
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   709
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   710
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   711
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   712
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   713
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   714
     *          denies access to set property values and remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   715
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   716
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   717
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   718
    @Override
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   719
    public synchronized Object computeIfAbsent(Object key, Function<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   720
            ? extends Object> mappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   721
        check("putProviderProperty." + name);
40404
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
   722
        check("removeProviderProperty." + name);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   723
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   724
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   725
            debug.println("ComputeIfAbsent " + name + " provider property " +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   726
                    key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   727
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   728
        return implComputeIfAbsent(key, mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   729
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   730
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   731
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   732
     * If the value for the specified key is present and non-null, attempts to
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   733
     * compute a new mapping given the key and its current mapped value.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   734
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   735
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   736
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   737
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   738
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   739
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   740
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   741
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   742
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   743
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   744
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   745
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   746
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   747
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   748
    @Override
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   749
    public synchronized Object computeIfPresent(Object key, BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   750
            ? super Object, ? extends Object> remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   751
        check("putProviderProperty." + name);
40404
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
   752
        check("removeProviderProperty." + name);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   753
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   754
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   755
            debug.println("ComputeIfPresent " + name + " provider property " +
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   756
                    key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   757
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   758
        return implComputeIfPresent(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   759
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   760
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   761
    /**
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   762
     * If the specified key is not already associated with a value or is
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   763
     * associated with null, associates it with the given value. Otherwise,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   764
     * replaces the value with the results of the given remapping function,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   765
     * or removes if the result is null. This method may be of use when
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   766
     * combining multiple mapped values for a key.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   767
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   768
     * <p>If a security manager is enabled, its {@code checkSecurityAccess}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   769
     * method is called with the strings {@code "putProviderProperty."+name}
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   770
     * and {@code "removeProviderProperty."+name}, where {@code name} is the
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   771
     * provider name, to see if it's ok to set this provider's property values
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   772
     * and remove this provider's properties.
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   773
     *
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   774
     * @throws  SecurityException
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   775
     *          if a security manager exists and its {@link
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   776
     *          java.lang.SecurityManager#checkSecurityAccess} method
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   777
     *          denies access to set property values or remove properties.
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   778
     *
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   779
     * @since 1.8
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   780
     */
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   781
    @Override
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   782
    public synchronized Object merge(Object key, Object value,  BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   783
            ? super Object, ? extends Object>  remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   784
        check("putProviderProperty." + name);
40404
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
   785
        check("removeProviderProperty." + name);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   786
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   787
        if (debug != null) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   788
            debug.println("Merge " + name + " provider property " + key);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   789
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   790
        return implMerge(key, value, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   791
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   792
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   794
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    public Object get(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return super.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   799
    /**
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   800
     * @since 1.8
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   801
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   802
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   803
    public synchronized Object getOrDefault(Object key, Object defaultValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   804
        checkInitialized();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   805
        return super.getOrDefault(key, defaultValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   806
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   807
21979
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   808
    /**
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   809
     * @since 1.8
3dcd1bc15edd 8029550: javadoc since tag for recent Hashtable updates
ascarpino
parents: 21340
diff changeset
   810
     */
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   811
    @Override
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   812
    public synchronized void forEach(BiConsumer<? super Object, ? super Object> action) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   813
        checkInitialized();
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   814
        super.forEach(action);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   815
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   816
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   818
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    public Enumeration<Object> keys() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return super.keys();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    // let javadoc show doc from superclass
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   825
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public Enumeration<Object> elements() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        return super.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    // let javadoc show doc from superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    public String getProperty(String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        return super.getProperty(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    private void checkInitialized() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        if (!initialized) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            throw new IllegalStateException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    private void check(String directive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
        SecurityManager security = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        if (security != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
            security.checkSecurityAccess(directive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    // legacy properties changed since last call to any services method?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    private transient boolean legacyChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    // serviceMap changed since last call to getServices()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    private transient boolean servicesChanged;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    // Map<String,String>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    private transient Map<String,String> legacyStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    // Map<ServiceKey,Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    // used for services added via putService(), initialized on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
    private transient Map<ServiceKey,Service> serviceMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    // Map<ServiceKey,Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    // used for services added via legacy methods, init on demand
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    private transient Map<ServiceKey,Service> legacyMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
    // Set<Service>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    // Unmodifiable set of all services. Initialized on demand.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    private transient Set<Service> serviceSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    // register the id attributes for this provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    // this is to ensure that equals() and hashCode() do not incorrectly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    // report to different provider objects as the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    private void putId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        // note: name and info may be null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        super.put("Provider.id name", String.valueOf(name));
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   877
        super.put("Provider.id version", String.valueOf(versionStr));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        super.put("Provider.id info", String.valueOf(info));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        super.put("Provider.id className", this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   882
   /**
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   883
    * Reads the {@code ObjectInputStream} for the default serializable fields.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   884
    * If the serialized field {@code versionStr} is found in the STREAM FIELDS,
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   885
    * its String value will be used to populate both the version string and
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   886
    * version number. If {@code versionStr} is not found, but {@code version}
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   887
    * is, then its double value will be used to populate both fields.
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   888
    *
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   889
    * @param in the {@code ObjectInputStream} to read
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   890
    * @serial
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   891
    */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                throws IOException, ClassNotFoundException {
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
   894
        Map<Object,Object> copy = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        for (Map.Entry<Object,Object> entry : super.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            copy.put(entry.getKey(), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        defaults = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        in.defaultReadObject();
40416
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   900
        if (this.versionStr == null) {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   901
            // set versionStr based on version when not found in serialized bytes
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   902
            this.versionStr = Double.toString(this.version);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   903
        } else {
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   904
            // otherwise, set version based on versionStr
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   905
            this.version = parseVersionStr(this.versionStr);
5d91b2fd668c 8130181: Deprecate java.security.Provider(String, double, String), add Provider(Strin
valeriep
parents: 40404
diff changeset
   906
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        implClear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        initialized = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        putAll(copy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   912
    private boolean checkLegacy(Object key) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   913
        String keyString = (String)key;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   914
        if (keyString.startsWith("Provider.")) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   915
            return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   916
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   917
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   918
        legacyChanged = true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   919
        if (legacyStrings == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
   920
            legacyStrings = new LinkedHashMap<>();
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   921
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   922
        return true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   923
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   924
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * Copies all of the mappings from the specified Map to this provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * Internal method to be called AFTER the security check has been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     */
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   930
    private void implPutAll(Map<?,?> t) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
   931
        for (Map.Entry<?,?> e : t.entrySet()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            implPut(e.getKey(), e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
    private Object implRemove(Object key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (key instanceof String) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   938
            if (!checkLegacy(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   941
            legacyStrings.remove((String)key);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        return super.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   946
    private boolean implRemove(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   947
        if (key instanceof String && value instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   948
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   949
                return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   950
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   951
            legacyStrings.remove((String)key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   952
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   953
        return super.remove(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   954
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   955
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   956
    private boolean implReplace(Object key, Object oldValue, Object newValue) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   957
        if ((key instanceof String) && (oldValue instanceof String) &&
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   958
                (newValue instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   959
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   960
                return false;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   961
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   962
            legacyStrings.replace((String)key, (String)oldValue,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   963
                    (String)newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   964
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   965
        return super.replace(key, oldValue, newValue);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   966
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   967
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   968
    private Object implReplace(Object key, Object value) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if ((key instanceof String) && (value instanceof String)) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   970
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   971
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   972
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   973
            legacyStrings.replace((String)key, (String)value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   974
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   975
        return super.replace(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   976
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   977
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   978
    @SuppressWarnings("unchecked") // Function must actually operate over strings
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   979
    private void implReplaceAll(BiFunction<? super Object, ? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   980
            ? extends Object> function) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   981
        legacyChanged = true;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   982
        if (legacyStrings == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
   983
            legacyStrings = new LinkedHashMap<>();
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   984
        } else {
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   985
            legacyStrings.replaceAll((BiFunction<? super String, ? super String,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   986
                    ? extends String>) function);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   987
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   988
        super.replaceAll(function);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   989
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   990
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
   991
    @SuppressWarnings("unchecked") // Function must actually operate over strings
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   992
    private Object implMerge(Object key, Object value, BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
   993
            ? super Object, ? extends Object> remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   994
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   995
            if (!checkLegacy(key)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   998
            legacyStrings.merge((String)key, (String)value,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
   999
                    (BiFunction<? super String, ? super String, ? extends String>) remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1000
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1001
        return super.merge(key, value, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1002
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1003
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
  1004
    @SuppressWarnings("unchecked") // Function must actually operate over strings
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1005
    private Object implCompute(Object key, BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1006
            ? super Object, ? extends Object> remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1007
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1008
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1009
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1010
            }
40404
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
  1011
            legacyStrings.compute((String) key,
167b711cf138 8156192: Provider#compute and #merge methods expect wrong permission & #compute ClassCastException even with wrong permission.
ascarpino
parents: 39759
diff changeset
  1012
                    (BiFunction<? super String,? super String, ? extends String>) remappingFunction);
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1013
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1014
        return super.compute(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1015
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1016
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
  1017
    @SuppressWarnings("unchecked") // Function must actually operate over strings
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1018
    private Object implComputeIfAbsent(Object key, Function<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1019
            ? extends Object> mappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1020
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1021
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1022
                return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            }
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1024
            legacyStrings.computeIfAbsent((String) key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1025
                    (Function<? super String, ? extends String>) mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1026
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1027
        return super.computeIfAbsent(key, mappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1028
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1029
23062
ece6b5d8a71b 8036747: Fix unchecked lint warnings in java.security.Provider
darcy
parents: 22117
diff changeset
  1030
    @SuppressWarnings("unchecked") // Function must actually operate over strings
38448
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1031
    private Object implComputeIfPresent(Object key, BiFunction<? super Object,
1008868d499d 8155575: Provider.java contains very long lines because of lambda
snikandrova
parents: 37880
diff changeset
  1032
            ? super Object, ? extends Object> remappingFunction) {
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1033
        if (key instanceof String) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1034
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1035
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1036
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1037
            legacyStrings.computeIfPresent((String) key,
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1038
                    (BiFunction<? super String, ? super String, ? extends String>) remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1039
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1040
        return super.computeIfPresent(key, remappingFunction);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1041
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1042
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1043
    private Object implPut(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1044
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1045
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1046
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1047
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1048
            legacyStrings.put((String)key, (String)value);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        return super.put(key, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
21340
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1053
    private Object implPutIfAbsent(Object key, Object value) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1054
        if ((key instanceof String) && (value instanceof String)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1055
            if (!checkLegacy(key)) {
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1056
                return null;
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1057
            }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1058
            legacyStrings.putIfAbsent((String)key, (String)value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1059
        }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1060
        return super.putIfAbsent(key, value);
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1061
    }
17142dadfffe 8025763: Provider does not override new Hashtable methods
ascarpino
parents: 18592
diff changeset
  1062
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    private void implClear() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        if (legacyStrings != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            legacyStrings.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        if (legacyMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            legacyMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            serviceMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        legacyChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        servicesChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        super.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        putId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    // used as key in the serviceMap and legacyMap HashMaps
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    private static class ServiceKey {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        private final String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        private final String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        private final String originalAlgorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        private ServiceKey(String type, String algorithm, boolean intern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            this.originalAlgorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            algorithm = algorithm.toUpperCase(ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            this.algorithm = intern ? algorithm.intern() : algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            return type.hashCode() + algorithm.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
            if (obj instanceof ServiceKey == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            ServiceKey other = (ServiceKey)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            return this.type.equals(other.type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                && this.algorithm.equals(other.algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        boolean matches(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            return (this.type == type) && (this.originalAlgorithm == algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * Ensure all the legacy String properties are fully parsed into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * service objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    private void ensureLegacyParsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if ((legacyChanged == false) || (legacyStrings == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        if (legacyMap == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1120
            legacyMap = new LinkedHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            legacyMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        for (Map.Entry<String,String> entry : legacyStrings.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            parseLegacyPut(entry.getKey(), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        removeInvalidServices(legacyMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        legacyChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Remove all invalid services from the Map. Invalid services can only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * occur if the legacy properties are inconsistent or incomplete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    private void removeInvalidServices(Map<ServiceKey,Service> map) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1136
        for (Iterator<Map.Entry<ServiceKey, Service>> t =
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1137
                map.entrySet().iterator(); t.hasNext(); ) {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1138
            Service s = t.next().getValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            if (s.isValid() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                t.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
    private String[] getTypeAndAlgorithm(String key) {
24685
215fa91e1b4c 8044461: Cleanup new Boolean and single character strings
rriggs
parents: 23926
diff changeset
  1146
        int i = key.indexOf('.');
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        if (i < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                debug.println("Ignoring invalid entry in provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                        + name + ":" + key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        String type = key.substring(0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        String alg = key.substring(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        return new String[] {type, alg};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31270
diff changeset
  1159
    private static final String ALIAS_PREFIX = "Alg.Alias.";
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31270
diff changeset
  1160
    private static final String ALIAS_PREFIX_LOWER = "alg.alias.";
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 31270
diff changeset
  1161
    private static final int ALIAS_LENGTH = ALIAS_PREFIX.length();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    private void parseLegacyPut(String name, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        if (name.toLowerCase(ENGLISH).startsWith(ALIAS_PREFIX_LOWER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            // e.g. put("Alg.Alias.MessageDigest.SHA", "SHA-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            // aliasKey ~ MessageDigest.SHA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            String stdAlg = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            String aliasKey = name.substring(ALIAS_LENGTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            String[] typeAndAlg = getTypeAndAlgorithm(aliasKey);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            if (typeAndAlg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            String aliasAlg = typeAndAlg[1].intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            legacyMap.put(new ServiceKey(type, aliasAlg, true), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            s.addAlias(aliasAlg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            String[] typeAndAlg = getTypeAndAlgorithm(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            if (typeAndAlg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            int i = typeAndAlg[1].indexOf(' ');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            if (i == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                // e.g. put("MessageDigest.SHA-1", "sun.security.provider.SHA");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                String stdAlg = typeAndAlg[1].intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                String className = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                    s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                s.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            } else { // attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                // e.g. put("MessageDigest.SHA-1 ImplementedIn", "Software");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                String attributeValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                String type = getEngineName(typeAndAlg[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                String attributeString = typeAndAlg[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                String stdAlg = attributeString.substring(0, i).intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                String attributeName = attributeString.substring(i + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                // kill additional spaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                while (attributeName.startsWith(" ")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    attributeName = attributeName.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                attributeName = attributeName.intern();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                ServiceKey key = new ServiceKey(type, stdAlg, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                Service s = legacyMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    s = new Service(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                    s.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                    s.algorithm = stdAlg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                    legacyMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                s.addAttribute(attributeName, attributeValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * Get the service describing this Provider's implementation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     * specified type of this algorithm or alias. If no such
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * implementation exists, this method returns null. If there are two
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * matching services, one added to this provider using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * {@link #putService putService()} and one added via {@link #put put()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * the service added via {@link #putService putService()} is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @param type the type of {@link Service service} requested
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1239
     * (for example, {@code MessageDigest})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @param algorithm the case insensitive algorithm name (or alternate
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1241
     * alias) of the service requested (for example, {@code SHA-1})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @return the service describing this Provider's matching service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * or null if no such service exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
     * @throws NullPointerException if type or algorithm is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    public synchronized Service getService(String type, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        // avoid allocating a new key object if possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        ServiceKey key = previousKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        if (key.matches(type, algorithm) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            key = new ServiceKey(type, algorithm, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            previousKey = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            Service service = serviceMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            if (service != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                return service;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        ensureLegacyParsed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        return (legacyMap != null) ? legacyMap.get(key) : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    // ServiceKey from previous getService() call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
    // by re-using it if possible we avoid allocating a new object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    // and the toUpperCase() call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
    // re-use will occur e.g. as the framework traverses the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    // list and queries each provider with the same values until it finds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
    // a matching service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    private static volatile ServiceKey previousKey =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                                            new ServiceKey("", "", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
     * Get an unmodifiable Set of all services supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
     * this Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * @return an unmodifiable Set of all services supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * this Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    public synchronized Set<Service> getServices() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        checkInitialized();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        if (legacyChanged || servicesChanged) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
            serviceSet = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (serviceSet == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            ensureLegacyParsed();
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
  1293
            Set<Service> set = new LinkedHashSet<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            if (serviceMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                set.addAll(serviceMap.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            if (legacyMap != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                set.addAll(legacyMap.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            serviceSet = Collections.unmodifiableSet(set);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
            servicesChanged = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        return serviceSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * Add a service. If a service of the same type with the same algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     * name exists and it was added using {@link #putService putService()},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
     * it is replaced by the new service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * This method also places information about this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     * in the provider's Hashtable values in the format described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
     * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
     * Java Cryptography Architecture API Specification &amp; Reference </a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * <p>Also, if there is a security manager, its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1316
     * {@code checkSecurityAccess} method is called with the string
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1317
     * {@code "putProviderProperty."+name}, where {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * the provider name, to see if it's ok to set this provider's property
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1319
     * values. If the default implementation of {@code checkSecurityAccess}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
     * is used (that is, that method is not overriden), then this results in
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1321
     * a call to the security manager's {@code checkPermission} method with
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1322
     * a {@code SecurityPermission("putProviderProperty."+name)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * @param s the Service to add
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * @throws SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1328
     *      if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1329
     *      java.lang.SecurityManager#checkSecurityAccess} method denies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     *      access to set property values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * @throws NullPointerException if s is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
    protected synchronized void putService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        check("putProviderProperty." + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            debug.println(name + ".putService(): " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
        if (s.getProvider() != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                    ("service.getProvider() must match this Provider object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        if (serviceMap == null) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1348
            serviceMap = new LinkedHashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        servicesChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
        ServiceKey key = new ServiceKey(type, algorithm, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
        // remove existing service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
        implRemoveService(serviceMap.get(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        serviceMap.put(key, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            serviceMap.put(new ServiceKey(type, alias, true), s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
        putPropertyStrings(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * Put the string properties for this Service in this Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    private void putPropertyStrings(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
        // use super() to avoid permission check and other processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        super.put(type + "." + algorithm, s.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            super.put(ALIAS_PREFIX + type + "." + alias, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        for (Map.Entry<UString,String> entry : s.attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
            String key = type + "." + algorithm + " " + entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            super.put(key, entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
     * Remove the string properties for this Service from this Provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
    private void removePropertyStrings(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // use super() to avoid permission check and other processing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        super.remove(type + "." + algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            super.remove(ALIAS_PREFIX + type + "." + alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        for (Map.Entry<UString,String> entry : s.attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
            String key = type + "." + algorithm + " " + entry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
            super.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     * Remove a service previously added using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     * {@link #putService putService()}. The specified service is removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     * this provider. It will no longer be returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     * {@link #getService getService()} and its information will be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     * from this provider's Hashtable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     * <p>Also, if there is a security manager, its
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1407
     * {@code checkSecurityAccess} method is called with the string
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1408
     * {@code "removeProviderProperty."+name}, where {@code name} is
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * the provider name, to see if it's ok to remove this provider's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * properties. If the default implementation of
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1411
     * {@code checkSecurityAccess} is used (that is, that method is not
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * overriden), then this results in a call to the security manager's
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1413
     * {@code checkPermission} method with a
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1414
     * {@code SecurityPermission("removeProviderProperty."+name)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * permission.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * @param s the Service to be removed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * @throws  SecurityException
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1420
     *          if a security manager exists and its {@link
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1421
     *          java.lang.SecurityManager#checkSecurityAccess} method denies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     *          access to remove this provider's properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * @throws NullPointerException if s is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    protected synchronized void removeService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        check("removeProviderProperty." + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            debug.println(name + ".removeService(): " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
        if (s == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        implRemoveService(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
    private void implRemoveService(Service s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        if ((s == null) || (serviceMap == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        String type = s.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        String algorithm = s.getAlgorithm();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
        ServiceKey key = new ServiceKey(type, algorithm, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        Service oldService = serviceMap.get(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        if (s != oldService) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        servicesChanged = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        serviceMap.remove(key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        for (String alias : s.getAliases()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            serviceMap.remove(new ServiceKey(type, alias, false));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        removePropertyStrings(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
    // Wrapped String that behaves in a case insensitive way for equals/hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    private static class UString {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        final String string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        final String lowerString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        UString(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            this.string = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            this.lowerString = s.toLowerCase(ENGLISH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            return lowerString.hashCode();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            if (obj instanceof UString == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            UString other = (UString)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            return lowerString.equals(other.lowerString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            return string;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
    // describe relevant properties of a type of engine
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    private static class EngineDescription {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        final String name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        final boolean supportsParameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        final String constructorParameterClassName;
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1492
        private volatile Class<?> constructorParameterClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        EngineDescription(String name, boolean sp, String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            this.name = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            this.supportsParameter = sp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            this.constructorParameterClassName = paramName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1499
        Class<?> getConstructorParameterClass() throws ClassNotFoundException {
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1500
            Class<?> clazz = constructorParameterClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
            if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                clazz = Class.forName(constructorParameterClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                constructorParameterClass = clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
    // built in knowledge of the engine types shipped as part of the JDK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
    private static final Map<String,EngineDescription> knownEngines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
    private static void addEngine(String name, boolean sp, String paramName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        EngineDescription ed = new EngineDescription(name, sp, paramName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        // also index by canonical name to avoid toLowerCase() for some lookups
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        knownEngines.put(name.toLowerCase(ENGLISH), ed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        knownEngines.put(name, ed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
    static {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1520
        knownEngines = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        // JCA
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        addEngine("AlgorithmParameterGenerator",        false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        addEngine("AlgorithmParameters",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        addEngine("KeyFactory",                         false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
        addEngine("KeyPairGenerator",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        addEngine("KeyStore",                           false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        addEngine("MessageDigest",                      false, null);
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
  1528
        addEngine("SecureRandom",                       false,
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
  1529
                "java.security.SecureRandomParameters");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        addEngine("Signature",                          true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        addEngine("CertificateFactory",                 false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        addEngine("CertPathBuilder",                    false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
        addEngine("CertPathValidator",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
        addEngine("CertStore",                          false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                            "java.security.cert.CertStoreParameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        // JCE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
        addEngine("Cipher",                             true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        addEngine("ExemptionMechanism",                 false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
        addEngine("Mac",                                true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        addEngine("KeyAgreement",                       true,  null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        addEngine("KeyGenerator",                       false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        addEngine("SecretKeyFactory",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        // JSSE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
        addEngine("KeyManagerFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
        addEngine("SSLContext",                         false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
        addEngine("TrustManagerFactory",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        // JGSS
23926
ebade3f50c1f 8039853: Provider.Service.newInstance() does not work with current JDK JGSS Mechanisms
weijun
parents: 23735
diff changeset
  1548
        addEngine("GssApiMechanism",                    false, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        // SASL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        addEngine("SaslClientFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        addEngine("SaslServerFactory",                  false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        // POLICY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
        addEngine("Policy",                             false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                            "java.security.Policy$Parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
        // CONFIGURATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        addEngine("Configuration",                      false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                            "javax.security.auth.login.Configuration$Parameters");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        // XML DSig
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        addEngine("XMLSignatureFactory",                false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        addEngine("KeyInfoFactory",                     false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        addEngine("TransformService",                   false, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        // Smart Card I/O
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        addEngine("TerminalFactory",                    false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                            "java.lang.Object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
    // get the "standard" (mixed-case) engine name for arbitary case engine name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    // if there is no known engine by that name, return s
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
    private static String getEngineName(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
        // try original case first, usually correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        EngineDescription e = knownEngines.get(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        if (e == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            e = knownEngines.get(s.toLowerCase(ENGLISH));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
        return (e == null) ? s : e.name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
     * The description of a security service. It encapsulates the properties
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * of a service and contains a factory method to obtain new implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * instances of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
     * <p>Each service has a provider that offers the service, a type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
     * an algorithm name, and the name of the class that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
     * service. Optionally, it also includes a list of alternate algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
     * names for this service (aliases) and attributes, which are a map of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * (name, value) String pairs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     * <p>This class defines the methods {@link #supportsParameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
     * supportsParameter()} and {@link #newInstance newInstance()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
     * which are used by the Java security framework when it searches for
25542
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1592
     * suitable services and instantiates them. The valid arguments to those
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
     * methods depend on the type of service. For the service types defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
     * within Java SE, see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
     * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     * for the valid values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * Note that components outside of Java SE can define additional types of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     * services and their behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
     * <p>Instances of this class are immutable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    public static class Service {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        private String type, algorithm, className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        private final Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        private List<String> aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        private Map<UString,String> attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
        // Reference to the cached implementation Class object
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1613
        private volatile Reference<Class<?>> classRef;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        // flag indicating whether this service has its attributes for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        // supportedKeyFormats or supportedKeyClasses set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        // if null, the values have not been initialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        // if TRUE, at least one of supportedFormats/Classes is non null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        private volatile Boolean hasKeyAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        // supported encoding formats
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
        private String[] supportedFormats;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
        // names of the supported key (super) classes
22117
1efafbb25acb 8031302: Fix raw types lint warnings in java.security
darcy
parents: 21979
diff changeset
  1625
        private Class<?>[] supportedClasses;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        // whether this service has been registered with the Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
        private boolean registered;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1630
        private static final Class<?>[] CLASS0 = new Class<?>[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
        // this constructor and these methods are used for parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        // the legacy string properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        private Service(Provider provider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            aliases = Collections.<String>emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
            attributes = Collections.<UString,String>emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
        private boolean isValid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
            return (type != null) && (algorithm != null) && (className != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        private void addAlias(String alias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            if (aliases.isEmpty()) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1647
                aliases = new ArrayList<>(2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
            aliases.add(alias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
        void addAttribute(String type, String value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            if (attributes.isEmpty()) {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1654
                attributes = new HashMap<>(8);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
            attributes.put(new UString(type), value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
         * Construct a new service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
         * @param provider the provider that offers this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
         * @param type the type of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
         * @param algorithm the algorithm name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
         * @param className the name of the class implementing this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
         * @param aliases List of aliases or null if algorithm has no aliases
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
         * @param attributes Map of attributes or null if this implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
         *                   has no attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
         * @throws NullPointerException if provider, type, algorithm, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
         * className is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        public Service(Provider provider, String type, String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                String className, List<String> aliases,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                Map<String,String> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            if ((provider == null) || (type == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                    (algorithm == null) || (className == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            this.type = getEngineName(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
            if (aliases == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                this.aliases = Collections.<String>emptyList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
            } else {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1687
                this.aliases = new ArrayList<>(aliases);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                this.attributes = Collections.<UString,String>emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
            } else {
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1692
                this.attributes = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                for (Map.Entry<String,String> entry : attributes.entrySet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    this.attributes.put(new UString(entry.getKey()), entry.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        /**
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1700
         * Get the type of this service. For example, {@code MessageDigest}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
         * @return the type of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
        public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
            return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
         * Return the name of the algorithm of this service. For example,
18579
b678846778ad 8019360: Cleanup of the javadoc <code> tag in java.security.*
juh
parents: 10336
diff changeset
  1710
         * {@code SHA-1}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
         * @return the algorithm of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
        public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
            return algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
         * Return the Provider of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
         * @return the Provider of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
        public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
            return provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
         * Return the name of the class implementing this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
         * @return the name of the class implementing this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
        public final String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            return className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        // internal only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
        private final List<String> getAliases() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            return aliases;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
         * Return the value of the specified attribute or null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
         * attribute is not set for this Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
         * @param name the name of the requested attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
         * @return the value of the specified attribute or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
         *         attribute is not present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
         * @throws NullPointerException if name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
        public final String getAttribute(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            return attributes.get(new UString(name));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
         * Return a new instance of the implementation described by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
         * service. The security provider framework uses this method to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
         * construct implementations. Applications will typically not need
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
         * to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
         * <p>The default implementation uses reflection to invoke the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
         * standard constructor for this type of service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         * Security providers can override this method to implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         * instantiation in a different way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         * For details and the values of constructorParameter that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
         * valid for the various types of services see the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
         * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
         * Java Cryptography Architecture API Specification &amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
         * Reference</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
         * @param constructorParameter the value to pass to the constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
         * or null if this type of service does not use a constructorParameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
         * @return a new implementation of this service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
         * @throws InvalidParameterException if the value of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
         * constructorParameter is invalid for this type of service.
25542
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1782
         * @throws NoSuchAlgorithmException if instantiation failed for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
         * any other reason.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        public Object newInstance(Object constructorParameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            if (registered == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                if (provider.getService(type, algorithm) != this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                    throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
                        ("Service not registered with Provider "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
                        + provider.getName() + ": " + this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                registered = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            }
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1795
            Class<?> ctrParamClz;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                EngineDescription cap = knownEngines.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
                if (cap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
                    // unknown engine type, use generic code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                    // this is the code path future for non-core
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                    // optional packages
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1802
                    ctrParamClz = constructorParameter == null?
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1803
                        null : constructorParameter.getClass();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1804
                } else {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1805
                    ctrParamClz = cap.constructorParameterClassName == null?
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1806
                        null : Class.forName(cap.constructorParameterClassName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
                    if (constructorParameter != null) {
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1808
                        if (ctrParamClz == null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                            throw new InvalidParameterException
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1810
                                ("constructorParameter not used with " + type
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1811
                                + " engines");
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1812
                        } else {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1813
                            Class<?> argClass = constructorParameter.getClass();
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1814
                            if (ctrParamClz.isAssignableFrom(argClass) == false) {
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1815
                                throw new InvalidParameterException
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1816
                                    ("constructorParameter must be instanceof "
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1817
                                    + cap.constructorParameterClassName.replace('$', '.')
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1818
                                    + " for engine type " + type);
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1819
                            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                }
37796
256c45c4af5d 8051408: NIST SP 800-90A SecureRandom implementations
weijun
parents: 32931
diff changeset
  1823
                // constructorParameter can be null if not provided
31270
e6470b24700d 7191662: JCE providers should be located via ServiceLoader
valeriep
parents: 30033
diff changeset
  1824
                return newInstanceUtil(getImplClass(), ctrParamClz, constructorParameter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
            } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                    ("Error constructing implementation (algorithm: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    + algorithm + ", provider: " + provider.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                    + ", class: " + className + ")", e.getCause());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                throw new NoSuchAlgorithmException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                    ("Error constructing implementation (algorithm: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    + algorithm + ", provider: " + provider.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                    + ", class: " + className + ")", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
        // return the implementation Class object for this service
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1841
        private Class<?> getImplClass() throws NoSuchAlgorithmException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
            try {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1843
                Reference<Class<?>> ref = classRef;
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1844
                Class<?> clazz = (ref == null) ? null : ref.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                if (clazz == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                    ClassLoader cl = provider.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                    if (cl == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                        clazz = Class.forName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
                        clazz = cl.loadClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                    }
25542
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1852
                    if (!Modifier.isPublic(clazz.getModifiers())) {
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1853
                        throw new NoSuchAlgorithmException
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1854
                            ("class configured for " + type + " (provider: " +
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1855
                            provider.getName() + ") is not public.");
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1856
                    }
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 28059
diff changeset
  1857
                    classRef = new WeakReference<>(clazz);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                return clazz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                throw new NoSuchAlgorithmException
25542
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1862
                    ("class configured for " + type + " (provider: " +
05badfb785b2 8035004: Provider provides less service
mullan
parents: 24685
diff changeset
  1863
                    provider.getName() + ") cannot be found.", e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
         * Test whether this Service can use the specified parameter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
         * Returns false if this service cannot use the parameter. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
         * true if this service can use the parameter, if a fast test is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
         * infeasible, or if the status is unknown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
         * <p>The security provider framework uses this method with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
         * some types of services to quickly exclude non-matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
         * implementations for consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
         * Applications will typically not need to call it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
         * <p>For details and the values of parameter that are valid for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
         * various types of services see the top of this class and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
         * <a href="../../../technotes/guides/security/crypto/CryptoSpec.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
         * Java Cryptography Architecture API Specification &amp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
         * Reference</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
         * Security providers can override it to implement their own test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
         * @param parameter the parameter to test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
         *
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
  1887
         * @return false if this service cannot use the specified
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
         * parameter; true if it can possibly use the parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
         * @throws InvalidParameterException if the value of parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
         * invalid for this type of service or if this method cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
         * used with this type of service
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        public boolean supportsParameter(Object parameter) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
            EngineDescription cap = knownEngines.get(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
            if (cap == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                // unknown engine type, return true by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
            if (cap.supportsParameter == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                throw new InvalidParameterException("supportsParameter() not "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    + "used with " + type + " engines");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            // allow null for keys without attributes for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
            if ((parameter != null) && (parameter instanceof Key == false)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                throw new InvalidParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                    ("Parameter must be instanceof Key for engine " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            if (hasKeyAttributes() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
            if (parameter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
            Key key = (Key)parameter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            if (supportsKeyFormat(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
            if (supportsKeyClass(key)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        /**
37880
60ec48925dc6 8156661: Handful of typos in javadoc
igerasim
parents: 37796
diff changeset
  1926
         * Return whether this service has its supported properties for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
         * keys defined. Parses the attributes if not yet initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
        private boolean hasKeyAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            Boolean b = hasKeyAttributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
            if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                    String s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                    s = getAttribute("SupportedKeyFormats");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                    if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                        supportedFormats = s.split("\\|");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                    s = getAttribute("SupportedKeyClasses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                    if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                        String[] classNames = s.split("\\|");
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1941
                        List<Class<?>> classList =
7970
af1579474d16 7008728: diamond conversion of basic security, permissions, authentication
smarks
parents: 5506
diff changeset
  1942
                            new ArrayList<>(classNames.length);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                        for (String className : classNames) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1944
                            Class<?> clazz = getKeyClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                            if (clazz != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                                classList.add(clazz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                        supportedClasses = classList.toArray(CLASS0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                    boolean bool = (supportedFormats != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                        || (supportedClasses != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                    b = Boolean.valueOf(bool);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                    hasKeyAttributes = b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
            return b.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        // get the key class object of the specified name
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1961
        private Class<?> getKeyClass(String name) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                return Class.forName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                ClassLoader cl = provider.getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
                if (cl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
                    return cl.loadClass(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
                // ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
        private boolean supportsKeyFormat(Key key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            if (supportedFormats == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            String format = key.getFormat();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            if (format == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
            for (String supportedFormat : supportedFormats) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                if (supportedFormat.equals(format)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        private boolean supportsKeyClass(Key key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            if (supportedClasses == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            }
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1998
            Class<?> keyClass = key.getClass();
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 9035
diff changeset
  1999
            for (Class<?> clazz : supportedClasses) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                if (clazz.isAssignableFrom(keyClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
         * Return a String representation of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
         * @return a String representation of this service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            String aString = aliases.isEmpty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
                ? "" : "\r\n  aliases: " + aliases.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            String attrs = attributes.isEmpty()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                ? "" : "\r\n  attributes: " + attributes.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            return provider.getName() + ": " + type + "." + algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                + " -> " + className + aString + attrs + "\r\n";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
}