Package javax.net.ssl

Class TrustManagerFactory


  • public class TrustManagerFactory
    extends Object
    This class acts as a factory for trust managers based on a source of trust material. Each trust manager manages a specific type of trust material for use by secure sockets. The trust material is based on a KeyStore and/or provider specific sources.
    Since:
    1.4
    See Also:
    TrustManager
    • Method Detail

      • getDefaultAlgorithm

        public static final String getDefaultAlgorithm()
        Obtains the default TrustManagerFactory algorithm name.

        The default TrustManager can be changed at runtime by setting the value of the ssl.TrustManagerFactory.algorithm security property to the desired algorithm name.

        Returns:
        the default algorithm name as specified by the ssl.TrustManagerFactory.algorithm security property, or an implementation-specific default if no such property exists.
      • getAlgorithm

        public final String getAlgorithm()
        Returns the algorithm name of this TrustManagerFactory object.

        This is the same name that was specified in one of the getInstance calls that created this TrustManagerFactory object.

        Returns:
        the algorithm name of this TrustManagerFactory object
      • getInstance

        public static final TrustManagerFactory getInstance​(String algorithm)
                                                     throws NoSuchAlgorithmException
        Returns a TrustManagerFactory object that acts as a factory for trust managers.

        This method traverses the list of registered security Providers, starting with the most preferred Provider. A new TrustManagerFactory object encapsulating the TrustManagerFactorySpi implementation from the first Provider that supports the specified algorithm is returned.

        Parameters:
        algorithm - the standard name of the requested trust management algorithm. See the Java Secure Socket Extension Reference Guide for information about standard algorithm names.
        Returns:
        the new TrustManagerFactory object.
        Throws:
        NoSuchAlgorithmException - if no Provider supports a TrustManagerFactorySpi implementation for the specified algorithm.
        NullPointerException - if algorithm is null.
      • init

        public final void init​(@Nullable
                               KeyStore ks)
                        throws KeyStoreException
        Initializes this factory with a source of certificate authorities and related trust material.

        The provider typically uses a KeyStore as a basis for making trust decisions.

        Parameters:
        ks - the key store, or null
        Throws:
        KeyStoreException - if this operation fails
      • getTrustManagers

        public final TrustManager[] getTrustManagers()
        Returns one trust manager for each type of trust material.
        Returns:
        the trust managers
        Throws:
        IllegalStateException - if the factory is not initialized.