Class JKSKeyProvider

  • All Implemented Interfaces:
    KeyProvider

    public class JKSKeyProvider
    extends Object
    implements KeyProvider
    The class JKSKeyProvider is a class that is implemented to retrieve X509Certificates and Private Keys from user data store.

    • Constructor Detail

      • JKSKeyProvider

        public JKSKeyProvider()
        Constructor
      • JKSKeyProvider

        public JKSKeyProvider​(String keyStoreFilePropName,
                              String keyStorePassFilePropName,
                              String keyStoreTypePropName,
                              String privateKeyPassFilePropName)
        Constructor
    • Method Detail

      • setKey

        public void setKey​(String storepass,
                           String keypass)
        Set the key to access key store database. This method will only need to be calles once if the key could not be obtained by other means.
        Specified by:
        setKey in interface KeyProvider
        Parameters:
        storepass - password for the key store
        keypass - password for the certificate
      • getX509Certificate

        public X509Certificate getX509Certificate​(String certAlias)
        Return java.security.cert.X509Certificate for the specified certAlias.
        Specified by:
        getX509Certificate in interface KeyProvider
        Parameters:
        certAlias - Certificate alias name
        Returns:
        X509Certificate which matches the certAlias, return null if the certificate could not be found.
      • getPublicKey

        public PublicKey getPublicKey​(String keyAlias)
        Return java.security.PublicKey for the specified keyAlias
        Specified by:
        getPublicKey in interface KeyProvider
        Parameters:
        keyAlias - Key alias name
        Returns:
        PublicKey which matches the keyAlias, return null if the PublicKey could not be found.
      • getPrivateKey

        public PrivateKey getPrivateKey​(String certAlias)
        Return java.security.PrivateKey for the specified certAlias.
        Specified by:
        getPrivateKey in interface KeyProvider
        Parameters:
        certAlias - Certificate alias name
        Returns:
        PrivateKey which matches the certAlias, return null if the private key could not be found.
      • getSecretKey

        public SecretKey getSecretKey​(String certAlias)
        Description copied from interface: KeyProvider
        Retrieves the secret key for the given certificate alias.
        Specified by:
        getSecretKey in interface KeyProvider
        Parameters:
        certAlias - the certificate alieas
        Returns:
        the secret key or returns null if the key does not exist or this key provider does not support secret keys
      • getPrivateKey

        public PrivateKey getPrivateKey​(String certAlias,
                                        String encryptedKeyPass)
        Return the PrivateKey for the specified certAlias and encrypted private key password.
        Specified by:
        getPrivateKey in interface KeyProvider
        Parameters:
        certAlias - Certificate alias name
        encryptedKeyPass - The encrypted keypass to use when getting the private certificate
        Returns:
        PrivateKey which matches the certAlias, return null if the private key could not be found.
      • getCertificateAlias

        public String getCertificateAlias​(Certificate cert)
        Get the alias name of the first keystore entry whose certificate matches the given certificate.
        Specified by:
        getCertificateAlias in interface KeyProvider
        Parameters:
        cert - Certificate
        Returns:
        the (alias) name of the first entry with matching certificate, or null if no such entry exists in this keystore. If the keystore has not been loaded properly, return null as well.
      • getPrivateKeyPass

        public String getPrivateKeyPass()
        Get the private key password
        Returns:
        the private key password
      • setCertificateEntry

        public void setCertificateEntry​(String certAlias,
                                        Certificate cert)
                                 throws SAMLException
        Set the Certificate with name certAlias in the leystore
        Parameters:
        certAlias - Certificate's name Alias
        cert - Certificate
        Throws:
        SAMLException
      • getCertificate

        public Certificate getCertificate​(String certAlias)
        Get the Certificate named certAlias.
        Parameters:
        certAlias - Certificate's name Alias
        Returns:
        the Certificate, If the keystore doesn't contain such certAlias, return null.
      • getCertificate

        public Certificate getCertificate​(PublicKey publicKey)
        Return Certificate for the specified PublicKey.
        Specified by:
        getCertificate in interface KeyProvider
        Parameters:
        publicKey - Certificate public key
        Returns:
        Certificate which matches the PublicKey, return null if the Certificate could not be found.
      • containsKey

        public boolean containsKey​(String alias)
        Description copied from interface: KeyProvider
        Whether the key alias exists in the keystore.
        Specified by:
        containsKey in interface KeyProvider
        Parameters:
        alias - the key alias
        Returns:
        whether the key alias exists