Class KeyStoreCallbackHandler

All Implemented Interfaces:
CallbackHandler, org.springframework.beans.factory.InitializingBean

public class KeyStoreCallbackHandler extends AbstractWsPasswordCallbackHandler implements org.springframework.beans.factory.InitializingBean
Callback handler that uses Java Security KeyStores to handle cryptographic callbacks. Allows for specific key stores to be set for various cryptographic operations.
Since:
2.3.0
Author:
Tareq Abed Rabbo, Arjen Poutsma, Jamin Hitchcock
See Also:
  • Constructor Details

    • KeyStoreCallbackHandler

      public KeyStoreCallbackHandler()
  • Method Details

    • handleDecrypt

      protected void handleDecrypt(org.apache.wss4j.common.ext.WSPasswordCallback callback) throws IOException, UnsupportedCallbackException
      Invoked when the callback has a WSPasswordCallback.DECRYPT usage.

      This method is invoked when WSS4J needs a password to get the private key of the identifier (username) from the keystore. WSS4J uses this private key to decrypt the session (symmetric) key. Because the encryption method uses the public key to encrypt the session key it needs no password (a public key is usually not protected by a password).

      Default implementation throws an UnsupportedCallbackException.

      Overrides:
      handleDecrypt in class AbstractWsPasswordCallbackHandler
      Throws:
      IOException
      UnsupportedCallbackException
    • handleSecretKey

      protected void handleSecretKey(org.apache.wss4j.common.ext.WSPasswordCallback callback) throws IOException, UnsupportedCallbackException
      Invoked when the callback has a WSPasswordCallback.SECRET_KEY usage.

      Default implementation throws an UnsupportedCallbackException.

      Overrides:
      handleSecretKey in class AbstractWsPasswordCallbackHandler
      Throws:
      IOException
      UnsupportedCallbackException
    • setKeyStore

      public void setKeyStore(KeyStore keyStore)
      Sets the key store to use if a symmetric key name is embedded.
    • setPrivateKeyPassword

      public void setPrivateKeyPassword(String privateKeyPassword)
      Sets the password used to retrieve private keys from the keystore. This property is required for decryption based on private keys, and signing.
    • setSymmetricKeyPassword

      public void setSymmetricKeyPassword(String symmetricKeyPassword)
      Sets the password used to retrieve keys from the symmetric keystore. If this property is not set, it defaults to the private key password.
      See Also:
    • afterPropertiesSet

      public void afterPropertiesSet() throws Exception
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
      Throws:
      Exception
    • loadDefaultKeyStore

      protected void loadDefaultKeyStore()
      Loads the key store indicated by system properties. Delegates to KeyStoreUtils.loadDefaultKeyStore().