Class CachedEncryptionKeyProvider
java.lang.Object
de.otto.kafka.messaging.e2ee.vault.CachedEncryptionKeyProvider
- All Implemented Interfaces:
EncryptionKeyProvider
This class is intended to be used as a 2nd-Level-Cache for the vault access. Meaning the results
of all method calls should be cached with a 1st-Level-Cache.
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.otto.kafka.messaging.e2ee.EncryptionKeyProvider
EncryptionKeyProvider.KeyVersion -
Constructor Summary
ConstructorsConstructorDescriptionCachedEncryptionKeyProvider(EncryptionKeyProvider realEncryptionKeyProvider, SecondLevelCacheStorage cacheStorage, Clock clock, Duration cachingDuration) CachedEncryptionKeyProvider(EncryptionKeyProvider realEncryptionKeyProvider, SecondLevelCacheStorage cacheStorage, Duration cachingDuration) -
Method Summary
Modifier and TypeMethodDescriptionbooleanisEncryptedTopic(String kafkaTopicName) retrieveKeyForDecryption(String topic, int version) retrieveKeyForDecryption(String topic, int version, String encryptionKeyAttributeName) retrieveKeyForEncryption(String topic)
-
Constructor Details
-
CachedEncryptionKeyProvider
public CachedEncryptionKeyProvider(EncryptionKeyProvider realEncryptionKeyProvider, SecondLevelCacheStorage cacheStorage, Duration cachingDuration) - Parameters:
realEncryptionKeyProvider- the VaultEncryptionKeyProvidercacheStorage- the 2nd-level cache storagecachingDuration- the cache duration for the encryption keys. The decryption keys will never expire.
-
CachedEncryptionKeyProvider
public CachedEncryptionKeyProvider(EncryptionKeyProvider realEncryptionKeyProvider, SecondLevelCacheStorage cacheStorage, Clock clock, Duration cachingDuration) - Parameters:
realEncryptionKeyProvider- the VaultEncryptionKeyProvidercacheStorage- the 2nd-level cache storagecachingDuration- the cache duration for the encryption keys. The decryption keys will never expire.clock- a clock (used in unit tests)
-
-
Method Details
-
retrieveKeyForEncryption
- Specified by:
retrieveKeyForEncryptionin interfaceEncryptionKeyProvider- Parameters:
topic- the name of the topic to encrypt- Returns:
- a key for encryption or
nullif encryption is not needed
-
retrieveKeyForDecryption
- Specified by:
retrieveKeyForDecryptionin interfaceEncryptionKeyProvider- Parameters:
topic- the name of the topic to decryptversion- the version of the key- Returns:
- base64 and URL-Encoded encoded key
-
retrieveKeyForDecryption
public String retrieveKeyForDecryption(String topic, int version, String encryptionKeyAttributeName) - Specified by:
retrieveKeyForDecryptionin interfaceEncryptionKeyProvider- Parameters:
topic- the name of the topic to decryptversion- the version of the keyencryptionKeyAttributeName- the name of the encryption key within the vault. Whennullthen the default value must be used.- Returns:
- base64 and URL-Encoded encoded key
-
isEncryptedTopic
- Specified by:
isEncryptedTopicin interfaceEncryptionKeyProvider- Parameters:
kafkaTopicName- the name of the topic- Returns:
truewhen the topic can contain encrypted payloads
-