< prev index next >

src/java.base/share/classes/javax/net/ssl/SSLContext.java

Print this page
rev 15967 : [mq]: GetInstance


   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.net.ssl;
  27 
  28 import java.security.*;

  29 
  30 import sun.security.jca.GetInstance;
  31 
  32 /**
  33  * Instances of this class represent a secure socket protocol
  34  * implementation which acts as a factory for secure socket
  35  * factories or {@code SSLEngine}s. This class is initialized
  36  * with an optional set of key and trust managers and source of
  37  * secure random bytes.
  38  *
  39  * <p> Every implementation of the Java platform is required to support the
  40  * following standard {@code SSLContext} protocols:
  41  * <ul>
  42  * <li>{@code TLSv1}</li>
  43  * <li>{@code TLSv1.1}</li>
  44  * <li>{@code TLSv1.2}</li>
  45  * </ul>
  46  * These protocols are described in the <a href=
  47  * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
  48  * SSLContext section</a> of the


 134      * Provider that supports the specified protocol is returned.
 135      *
 136      * <p> Note that the list of registered providers may be retrieved via
 137      * the {@link Security#getProviders() Security.getProviders()} method.
 138      *
 139      * @implNote
 140      * The JDK Reference Implementation additionally uses the
 141      * {@code jdk.security.provider.preferred}
 142      * {@link Security#getProperty(String) Security} property to determine
 143      * the preferred provider order for the specified algorithm. This
 144      * may be different than the order of providers returned by
 145      * {@link Security#getProviders() Security.getProviders()}.
 146      *
 147      * @param protocol the standard name of the requested protocol.
 148      *          See the SSLContext section in the <a href=
 149      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 150      *          Java Cryptography Architecture Standard Algorithm Name
 151      *          Documentation</a>
 152      *          for information about standard protocol names.
 153      *
 154      * @return the new {@code SSLContext} object.
 155      *
 156      * @exception NoSuchAlgorithmException if no Provider supports a
 157      *          SSLContextSpi implementation for the
 158      *          specified protocol.
 159      * @exception NullPointerException if protocol is null.

 160      *
 161      * @see java.security.Provider
 162      */
 163     public static SSLContext getInstance(String protocol)
 164             throws NoSuchAlgorithmException {

 165         GetInstance.Instance instance = GetInstance.getInstance
 166                 ("SSLContext", SSLContextSpi.class, protocol);
 167         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 168                 protocol);
 169     }
 170 
 171     /**
 172      * Returns a {@code SSLContext} object that implements the
 173      * specified secure socket protocol.
 174      *
 175      * <p> A new SSLContext object encapsulating the
 176      * SSLContextSpi implementation from the specified provider
 177      * is returned.  The specified provider must be registered
 178      * in the security provider list.
 179      *
 180      * <p> Note that the list of registered providers may be retrieved via
 181      * the {@link Security#getProviders() Security.getProviders()} method.
 182      *
 183      * @param protocol the standard name of the requested protocol.
 184      *          See the SSLContext section in the <a href=
 185      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 186      *          Java Cryptography Architecture Standard Algorithm Name
 187      *          Documentation</a>
 188      *          for information about standard protocol names.
 189      *
 190      * @param provider the name of the provider.
 191      *
 192      * @return the new {@code SSLContext} object.



 193      *
 194      * @throws NoSuchAlgorithmException if a SSLContextSpi
 195      *          implementation for the specified protocol is not
 196      *          available from the specified provider.
 197      *
 198      * @throws NoSuchProviderException if the specified provider is not
 199      *          registered in the security provider list.
 200      *
 201      * @throws IllegalArgumentException if the provider name is null or empty.
 202      * @throws NullPointerException if protocol is null.
 203      *
 204      * @see java.security.Provider
 205      */
 206     public static SSLContext getInstance(String protocol, String provider)
 207             throws NoSuchAlgorithmException, NoSuchProviderException {

 208         GetInstance.Instance instance = GetInstance.getInstance
 209                 ("SSLContext", SSLContextSpi.class, protocol, provider);
 210         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 211                 protocol);
 212     }
 213 
 214     /**
 215      * Returns a {@code SSLContext} object that implements the
 216      * specified secure socket protocol.
 217      *
 218      * <p> A new SSLContext object encapsulating the
 219      * SSLContextSpi implementation from the specified Provider
 220      * object is returned.  Note that the specified Provider object
 221      * does not have to be registered in the provider list.
 222      *
 223      * @param protocol the standard name of the requested protocol.
 224      *          See the SSLContext section in the <a href=
 225      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 226      *          Java Cryptography Architecture Standard Algorithm Name
 227      *          Documentation</a>
 228      *          for information about standard protocol names.
 229      *
 230      * @param provider an instance of the provider.
 231      *
 232      * @return the new {@code SSLContext} object.


 233      *
 234      * @throws NoSuchAlgorithmException if a SSLContextSpi
 235      *          implementation for the specified protocol is not available
 236      *          from the specified Provider object.
 237      *
 238      * @throws IllegalArgumentException if the provider is null.
 239      * @throws NullPointerException if protocol is null.
 240      *
 241      * @see java.security.Provider
 242      */
 243     public static SSLContext getInstance(String protocol, Provider provider)
 244             throws NoSuchAlgorithmException {

 245         GetInstance.Instance instance = GetInstance.getInstance
 246                 ("SSLContext", SSLContextSpi.class, protocol, provider);
 247         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 248                 protocol);
 249     }
 250 
 251     /**
 252      * Returns the protocol name of this {@code SSLContext} object.
 253      *
 254      * <p>This is the same name that was specified in one of the
 255      * {@code getInstance} calls that created this
 256      * {@code SSLContext} object.
 257      *
 258      * @return the protocol name of this {@code SSLContext} object.
 259      */
 260     public final String getProtocol() {
 261         return this.protocol;
 262     }
 263 
 264     /**




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.net.ssl;
  27 
  28 import java.security.*;
  29 import java.util.Objects;
  30 
  31 import sun.security.jca.GetInstance;
  32 
  33 /**
  34  * Instances of this class represent a secure socket protocol
  35  * implementation which acts as a factory for secure socket
  36  * factories or {@code SSLEngine}s. This class is initialized
  37  * with an optional set of key and trust managers and source of
  38  * secure random bytes.
  39  *
  40  * <p> Every implementation of the Java platform is required to support the
  41  * following standard {@code SSLContext} protocols:
  42  * <ul>
  43  * <li>{@code TLSv1}</li>
  44  * <li>{@code TLSv1.1}</li>
  45  * <li>{@code TLSv1.2}</li>
  46  * </ul>
  47  * These protocols are described in the <a href=
  48  * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
  49  * SSLContext section</a> of the


 135      * Provider that supports the specified protocol is returned.
 136      *
 137      * <p> Note that the list of registered providers may be retrieved via
 138      * the {@link Security#getProviders() Security.getProviders()} method.
 139      *
 140      * @implNote
 141      * The JDK Reference Implementation additionally uses the
 142      * {@code jdk.security.provider.preferred}
 143      * {@link Security#getProperty(String) Security} property to determine
 144      * the preferred provider order for the specified algorithm. This
 145      * may be different than the order of providers returned by
 146      * {@link Security#getProviders() Security.getProviders()}.
 147      *
 148      * @param protocol the standard name of the requested protocol.
 149      *          See the SSLContext section in the <a href=
 150      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 151      *          Java Cryptography Architecture Standard Algorithm Name
 152      *          Documentation</a>
 153      *          for information about standard protocol names.
 154      *
 155      * @return the new {@code SSLContext} object
 156      *
 157      * @throws NoSuchAlgorithmException if no {@code Provider} supports a
 158      *         {@code SSLContextSpi} implementation for the
 159      *         specified protocol
 160      *
 161      * @throws NullPointerException if {@code protocol} is {@code null}
 162      *
 163      * @see java.security.Provider
 164      */
 165     public static SSLContext getInstance(String protocol)
 166             throws NoSuchAlgorithmException {
 167         Objects.requireNonNull(protocol, "null protocol name");
 168         GetInstance.Instance instance = GetInstance.getInstance
 169                 ("SSLContext", SSLContextSpi.class, protocol);
 170         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 171                 protocol);
 172     }
 173 
 174     /**
 175      * Returns a {@code SSLContext} object that implements the
 176      * specified secure socket protocol.
 177      *
 178      * <p> A new SSLContext object encapsulating the
 179      * SSLContextSpi implementation from the specified provider
 180      * is returned.  The specified provider must be registered
 181      * in the security provider list.
 182      *
 183      * <p> Note that the list of registered providers may be retrieved via
 184      * the {@link Security#getProviders() Security.getProviders()} method.
 185      *
 186      * @param protocol the standard name of the requested protocol.
 187      *          See the SSLContext section in the <a href=
 188      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 189      *          Java Cryptography Architecture Standard Algorithm Name
 190      *          Documentation</a>
 191      *          for information about standard protocol names.
 192      *
 193      * @param provider the name of the provider.
 194      *
 195      * @return the new {@code SSLContext} object
 196      *
 197      * @throws IllegalArgumentException if the provider name is
 198      *         {@code null} or empty
 199      *
 200      * @throws NoSuchAlgorithmException if a {@code SSLContextSpi}
 201      *         implementation for the specified protocol is not
 202      *         available from the specified provider
 203      *
 204      * @throws NoSuchProviderException if the specified provider is not
 205      *         registered in the security provider list
 206      *
 207      * @throws NullPointerException if {@code protocol} is {@code null}

 208      *
 209      * @see java.security.Provider
 210      */
 211     public static SSLContext getInstance(String protocol, String provider)
 212             throws NoSuchAlgorithmException, NoSuchProviderException {
 213         Objects.requireNonNull(protocol, "null protocol name");
 214         GetInstance.Instance instance = GetInstance.getInstance
 215                 ("SSLContext", SSLContextSpi.class, protocol, provider);
 216         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 217                 protocol);
 218     }
 219 
 220     /**
 221      * Returns a {@code SSLContext} object that implements the
 222      * specified secure socket protocol.
 223      *
 224      * <p> A new SSLContext object encapsulating the
 225      * SSLContextSpi implementation from the specified Provider
 226      * object is returned.  Note that the specified Provider object
 227      * does not have to be registered in the provider list.
 228      *
 229      * @param protocol the standard name of the requested protocol.
 230      *          See the SSLContext section in the <a href=
 231      * "{@docRoot}/../technotes/guides/security/StandardNames.html#SSLContext">
 232      *          Java Cryptography Architecture Standard Algorithm Name
 233      *          Documentation</a>
 234      *          for information about standard protocol names.
 235      *
 236      * @param provider an instance of the provider.
 237      *
 238      * @return the new {@code SSLContext} object
 239      *
 240      * @throws IllegalArgumentException if the provider is {@code null}
 241      *
 242      * @throws NoSuchAlgorithmException if a {@code SSLContextSpi}
 243      *         implementation for the specified protocol is not available
 244      *         from the specified {@code Provider} object
 245      *
 246      * @throws NullPointerException if {@code protocol} is {@code null}

 247      *
 248      * @see java.security.Provider
 249      */
 250     public static SSLContext getInstance(String protocol, Provider provider)
 251             throws NoSuchAlgorithmException {
 252         Objects.requireNonNull(protocol, "null protocol name");
 253         GetInstance.Instance instance = GetInstance.getInstance
 254                 ("SSLContext", SSLContextSpi.class, protocol, provider);
 255         return new SSLContext((SSLContextSpi)instance.impl, instance.provider,
 256                 protocol);
 257     }
 258 
 259     /**
 260      * Returns the protocol name of this {@code SSLContext} object.
 261      *
 262      * <p>This is the same name that was specified in one of the
 263      * {@code getInstance} calls that created this
 264      * {@code SSLContext} object.
 265      *
 266      * @return the protocol name of this {@code SSLContext} object.
 267      */
 268     public final String getProtocol() {
 269         return this.protocol;
 270     }
 271 
 272     /**


< prev index next >