Package io.axoniq.dataprotection.api
Class FieldEncrypter
- java.lang.Object
-
- io.axoniq.dataprotection.api.FieldEncrypter
-
public final class FieldEncrypter extends Object
This class can take an object and encrypt and decrypt its fields, including the fields of any objects deeper in the object tree, according to the configuration of the various Axon Data Protection Module annotations. To accomplish this, it needs the capabilities of aCryptoEngine.
-
-
Constructor Summary
Constructors Constructor Description FieldEncrypter(CryptoEngine cryptoEngine)Deprecated.in favor of using theFieldEncrypter(CryptoEngine, Serializer)to construct an instance using a configuredSerializerinstance.FieldEncrypter(CryptoEngine cryptoEngine, ReplacementValueProvider replacementValueProvider)Deprecated.in favor of using theFieldEncrypter(CryptoEngine, Serializer, ReplacementValueProvider)to construct an instance using a configuredSerializerinstance.FieldEncrypter(CryptoEngine cryptoEngine, Serializer serializer)Instantiates a FieldEncrypter with the default rules for value replacement but a customSerializer.FieldEncrypter(CryptoEngine cryptoEngine, Serializer serializer, ReplacementValueProvider replacementValueProvider)Instantiates a FieldEncrypter with a customReplacementValueProviderand a customSerializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddecrypt(Object obj)Decrypts the fields of the object.voiddecrypt(Object obj, String keyId)Decrypts the fields of the object.voiddecrypt(Object obj, String keyId, Set<String> groups)Decrypts the fields of the object, restricting to certain groups.voiddecrypt(Object obj, Map<String,String> keyIds)Decrypts the fields of the object.voiddecrypt(Object obj, Map<String,String> keyIds, Set<String> groups)Decrypts the fields of the object, restricting to certain groups.voiddecrypt(Object obj, Set<String> groups)Decrypts the fields of the object, restricting to certain groups.voidencrypt(Object obj)Encrypts the fields of the object.voidencrypt(Object obj, String keyId)Encrypts the fields of the object.voidencrypt(Object obj, String keyId, Set<String> groups)Encrypts the fields of the object, restricting to certain groups.voidencrypt(Object obj, Map<String,String> keyIds)Encrypts the fields of the object.voidencrypt(Object obj, Map<String,String> keyIds, Set<String> groups)Encrypts the fields of the object, restricting to certain groups.voidencrypt(Object obj, Set<String> groups)Encrypts the fields of the object, restricting to certain groups.Set<String>getGroups()Read accessor for the groups property.booleanisModifyImmutableCollections()Read accessor for the modifyImmutableCollections property.voidreplace(Object obj)Directly replaces the values of the fields of the object by the value they would get if they would get crypto-deleted, without doing actual encryption or decryption.voidreplace(Object obj, Set<String> groups)Directly replaces the values of the fields of the object by the value they would get if they would get crypto-deleted, without doing actual encryption or decryption.voidsetGroups(Set<String> groups)Write accessor for the groups property.voidsetModifyImmutableCollections(boolean value)Write accessor for the modifyImmutableCollections property.booleanwillProcess(Object obj)Examines whether object may change under encryption/decryption.
-
-
-
Constructor Detail
-
FieldEncrypter
@Deprecated public FieldEncrypter(CryptoEngine cryptoEngine)
Deprecated.in favor of using theFieldEncrypter(CryptoEngine, Serializer)to construct an instance using a configuredSerializerinstance. Using this shorthand still works, but will use anXStreaminstance that allows everything. Although this works, XStream expects the types or wildcards for the types to be defined to ensure the application stays secure. As such, it is highly recommended to follow their recommended approach.Instantiates a FieldEncrypter with the default rules for value replacement and anXStreamSerializer.- Parameters:
cryptoEngine- theCryptoEngineto be used
-
FieldEncrypter
@Deprecated public FieldEncrypter(CryptoEngine cryptoEngine, ReplacementValueProvider replacementValueProvider)
Deprecated.in favor of using theFieldEncrypter(CryptoEngine, Serializer, ReplacementValueProvider)to construct an instance using a configuredSerializerinstance. Using this shorthand still works, but will use anXStreaminstance that allows everything. Although this works, XStream expects the types or wildcards for the types to be defined to ensure the application stays secure. As such, it is highly recommended to follow their recommended approach.Instantiates a FieldEncrypter with a customReplacementValueProviderand a defaultXStreamSerializer.- Parameters:
cryptoEngine- theCryptoEngineto be usedreplacementValueProvider- a (custom) replacement value provider
-
FieldEncrypter
public FieldEncrypter(CryptoEngine cryptoEngine, Serializer serializer)
Instantiates a FieldEncrypter with the default rules for value replacement but a customSerializer.- Parameters:
cryptoEngine- theCryptoEngineto be usedserializer- theSerializerto be used
-
FieldEncrypter
public FieldEncrypter(CryptoEngine cryptoEngine, Serializer serializer, ReplacementValueProvider replacementValueProvider)
Instantiates a FieldEncrypter with a customReplacementValueProviderand a customSerializer.- Parameters:
cryptoEngine- theCryptoEngineto be usedserializer- theSerializerto be usedreplacementValueProvider- a (custom) replacement value provider
-
-
Method Detail
-
encrypt
public void encrypt(Object obj)
Encrypts the fields of the object.- Parameters:
obj- the object to encrypt
-
encrypt
public void encrypt(Object obj, String keyId)
Encrypts the fields of the object.- Parameters:
obj- the object to encryptkeyId- the id of key to be preloaded in the encryption context with default group
-
encrypt
public void encrypt(Object obj, Map<String,String> keyIds)
Encrypts the fields of the object.- Parameters:
obj- the object to encryptkeyIds- a map of group/keyId pairs defining keys to be preloaded into the encryption context
-
encrypt
public void encrypt(Object obj, Set<String> groups)
Encrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to encryptgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
encrypt
public void encrypt(Object obj, String keyId, Set<String> groups)
Encrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to encryptkeyId- the id of key to be preloaded in the encryption context with default groupgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
encrypt
public void encrypt(Object obj, Map<String,String> keyIds, Set<String> groups)
Encrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to encryptkeyIds- a map of group/keyId pairs defining keys to be preloaded into the encryption contextgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
decrypt
public void decrypt(Object obj)
Decrypts the fields of the object.- Parameters:
obj- the object to decrypt
-
decrypt
public void decrypt(Object obj, String keyId)
Decrypts the fields of the object.- Parameters:
obj- the object to decryptkeyId- the id of key to be preloaded in the decryption context with default group
-
decrypt
public void decrypt(Object obj, Map<String,String> keyIds)
Decrypts the fields of the object.- Parameters:
obj- the object to decryptkeyIds- a map of group/keyId pairs defining keys to be preloaded into the decryption context
-
decrypt
public void decrypt(Object obj, Set<String> groups)
Decrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to decryptgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
decrypt
public void decrypt(Object obj, String keyId, Set<String> groups)
Decrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to decryptkeyId- the id of key to be preloaded in the decryption context with default groupgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
decrypt
public void decrypt(Object obj, Map<String,String> keyIds, Set<String> groups)
Decrypts the fields of the object, restricting to certain groups.- Parameters:
obj- the object to decryptkeyIds- a map of group/keyId pairs defining keys to be preloaded into the decryption contextgroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
replace
public void replace(Object obj)
Directly replaces the values of the fields of the object by the value they would get if they would get crypto-deleted, without doing actual encryption or decryption.- Parameters:
obj- the object to replace
-
replace
public void replace(Object obj, Set<String> groups)
Directly replaces the values of the fields of the object by the value they would get if they would get crypto-deleted, without doing actual encryption or decryption.- Parameters:
obj- the object to replacegroups- the field groups to process. This override the 'groups' property of the FieldEncrypter object.
-
willProcess
public boolean willProcess(Object obj)
Examines whether object may change under encryption/decryption. This is the case if the argument is non-nulland the object's class (or superclass) has one or more Axon Data Protection Module annotations.- Parameters:
obj- the object to examine- Returns:
trueif the object may get encrypted
-
isModifyImmutableCollections
public boolean isModifyImmutableCollections()
Read accessor for the modifyImmutableCollections property. This property determines whether the module will attempt to modify immutable collections such as those returned byCollections.unmodifiableList(List).trueby default.- Returns:
- the current modifyImmutableCollections setting
-
setModifyImmutableCollections
public void setModifyImmutableCollections(boolean value)
Write accessor for the modifyImmutableCollections property. This property determines whether the module will attempt to modify immutable collections such as those returned byCollections.unmodifiableList(List).trueby default.- Parameters:
value- the new value of the property
-
getGroups
public Set<String> getGroups()
Read accessor for the groups property. This property determines which field groups will be processed by default by the encrypt/decrypt methods. Initially, this value isnullwhich means that all groups will be processed.- Returns:
- the current value of the groups property. Reference is copied directly, no defensive cloning or immutable wrapping.
-
setGroups
public void setGroups(Set<String> groups)
Write accessor for the groups property. This property determines which field groups will be processed by default by the encrypt/decrypt methods. Initially, this value isnullwhich means that all groups will be processed.- Parameters:
groups- the new value of the groups property. Reference is copied directly, no defensive cloning.
-
-