jdk/src/java.base/share/classes/javax/net/ssl/TrustManagerFactory.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 32647 53b8fd1f3840
child 33241 27eb2d6abda9
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
     2
 * Copyright (c) 1999, 2015, 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: 474
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: 474
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: 474
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 474
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 474
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 javax.net.ssl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import sun.security.jca.GetInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class acts as a factory for trust managers based on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * source of trust material. Each trust manager manages a specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * type of trust material for use by secure sockets. The trust
32647
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    37
 * material is based on a KeyStore and/or provider-specific sources.
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    38
 *
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    39
 * <p> Every implementation of the Java platform is required to support the
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    40
 * following standard {@code TrustManagerFactory} algorithm:
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    41
 * <ul>
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    42
 * <li><tt>PKIX</tt></li>
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    43
 * </ul>
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    44
 * This algorithm is described in the <a href=
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    45
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#TrustManagerFactory">
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    46
 * TrustManagerFactory section</a> of the
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    47
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    48
 * Consult the release documentation for your implementation to see if any
53b8fd1f3840 8015388: Required algorithms for JDK 9
mullan
parents: 30033
diff changeset
    49
 * other algorithms are supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * @see TrustManager
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class TrustManagerFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // The provider implementation (delegate)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private TrustManagerFactorySpi factorySpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // The name of the trust management algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    private String algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Obtains the default TrustManagerFactory algorithm name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * <p>The default TrustManager can be changed at runtime by setting
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    68
     * the value of the {@code ssl.TrustManagerFactory.algorithm}
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    69
     * security property to the desired algorithm name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *
14775
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    71
     * @see java.security.Security security properties
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    72
     * @return the default algorithm name as specified by the
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    73
     * {@code ssl.TrustManagerFactory.algorithm} security property, or an
2ed01c760aea 8004064: Downgrade normative references to ${java.home}/lib/security/java.security
mullan
parents: 14514
diff changeset
    74
     * implementation-specific default if no such property exists.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32647
diff changeset
    76
    public static final String getDefaultAlgorithm() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        String type;
30033
b9c86c17164a 8078468: Update security libraries to use diamond with anonymous classes
darcy
parents: 25859
diff changeset
    78
        type = AccessController.doPrivileged(new PrivilegedAction<>() {
14514
46a8ed03c7fc 8003587: Warning cleanup in package javax.net.ssl
xuelei
parents: 5506
diff changeset
    79
            @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            public String run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                return Security.getProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                    "ssl.TrustManagerFactory.algorithm");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (type == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            type = "SunX509";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Creates a TrustManagerFactory object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @param factorySpi the delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param provider the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param algorithm the algorithm
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    protected TrustManagerFactory(TrustManagerFactorySpi factorySpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            Provider provider, String algorithm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.factorySpi = factorySpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.algorithm = algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Returns the algorithm name of this <code>TrustManagerFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * <p>This is the same name that was specified in one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>getInstance</code> calls that created this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <code>TrustManagerFactory</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return the algorithm name of this <code>TrustManagerFactory</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *          object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public final String getAlgorithm() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        return this.algorithm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Returns a <code>TrustManagerFactory</code> object that acts as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * factory for trust managers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * A new TrustManagerFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * TrustManagerFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Provider that supports the specified algorithm is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param algorithm the standard name of the requested trust management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *          algorithm.  See the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *  "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *          Java Secure Socket Extension Reference Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *          for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @return the new <code>TrustManagerFactory</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @exception NoSuchAlgorithmException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *          TrustManagerFactorySpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *          specified algorithm.
474
8fcc864c9258 6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
xuelei
parents: 2
diff changeset
   144
     * @exception NullPointerException if algorithm is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static final TrustManagerFactory getInstance(String algorithm)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                ("TrustManagerFactory", TrustManagerFactorySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        return new TrustManagerFactory((TrustManagerFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Returns a <code>TrustManagerFactory</code> object that acts as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * factory for trust managers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p> A new KeyManagerFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * KeyManagerFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param algorithm the standard name of the requested trust management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *          algorithm.  See the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *  "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *          Java Secure Socket Extension Reference Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *          for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @return the new <code>TrustManagerFactory</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @throws NoSuchAlgorithmException if a TrustManagerFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @throws NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @throws IllegalArgumentException if the provider name is null or empty.
474
8fcc864c9258 6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
xuelei
parents: 2
diff changeset
   187
     * @throws NullPointerException if algorithm is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public static final TrustManagerFactory getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            String provider) throws NoSuchAlgorithmException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                ("TrustManagerFactory", TrustManagerFactorySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return new TrustManagerFactory((TrustManagerFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns a <code>TrustManagerFactory</code> object that acts as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * factory for trust managers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <p> A new TrustManagerFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * TrustManagerFactorySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param algorithm the standard name of the requested trust management
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *          algorithm.  See the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *  "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *          Java Secure Socket Extension Reference Guide </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *          for information about standard algorithm names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param provider an instance of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @return the new <code>TrustManagerFactory</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @throws NoSuchAlgorithmException if a TrustManagerFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @throws IllegalArgumentException if the provider is null.
474
8fcc864c9258 6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
xuelei
parents: 2
diff changeset
   225
     * @throws NullPointerException if algorithm is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    public static final TrustManagerFactory getInstance(String algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Provider provider) throws NoSuchAlgorithmException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        GetInstance.Instance instance = GetInstance.getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                ("TrustManagerFactory", TrustManagerFactorySpi.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                algorithm, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        return new TrustManagerFactory((TrustManagerFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                instance.provider, algorithm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Returns the provider of this <code>TrustManagerFactory</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @return the provider of this <code>TrustManagerFactory</code> object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Initializes this factory with a source of certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * authorities and related trust material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * The provider typically uses a KeyStore as a basis for making
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * trust decisions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * For more flexible initialization, please see
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * {@link #init(ManagerFactoryParameters)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param ks the key store, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @throws KeyStoreException if this operation fails
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public final void init(KeyStore ks) throws KeyStoreException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        factorySpi.engineInit(ks);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Initializes this factory with a source of provider-specific
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * trust material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * In some cases, initialization parameters other than a keystore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * may be needed by a provider.  Users of that particular provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * are expected to pass an implementation of the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * <CODE>ManagerFactoryParameters</CODE> as defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * provider.  The provider can then call the specified methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * the <CODE>ManagerFactoryParameters</CODE> implementation to obtain the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * needed information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param spec an implementation of a provider-specific parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *          specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @throws InvalidAlgorithmParameterException if an error is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *          encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public final void init(ManagerFactoryParameters spec) throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            InvalidAlgorithmParameterException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        factorySpi.engineInit(spec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns one trust manager for each type of trust material.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
474
8fcc864c9258 6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
xuelei
parents: 2
diff changeset
   292
     * @throws IllegalStateException if the factory is not initialized.
8fcc864c9258 6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
xuelei
parents: 2
diff changeset
   293
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @return the trust managers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public final TrustManager[] getTrustManagers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return factorySpi.engineGetTrustManagers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
}