Package io.axoniq.dataprotection.api
Class ReplacementValueProvider
- java.lang.Object
-
- io.axoniq.dataprotection.api.ReplacementValueProvider
-
public class ReplacementValueProvider extends Object
Class that represents the replacement value mechanism. It takes care of setting a value in the class when the decryption key is no longer there. The default behaviour of this class is very simple: forStringfields, it will use the value of thereplacementattribute in thePersonalDataannotation, which is the emptyStringby default. In all other cases, it will benull. Applications may define more fine grained behaviour by creating their own subclass and providing this when constructing aFieldEncrypterorFieldEncryptingSerializer.A method of this class is invoked when a key is missing upon decryption. However, we also see an invocation upon each encryption. This is to provide a partial, clear to be included in the storage. By default, nothing is stored. This allows functionality such as keeping the year of a full date even if the date itself gets deleted, or keeping the last 4 digits of a credit card number.
-
-
Constructor Summary
Constructors Constructor Description ReplacementValueProvider()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]partialValueForStorage(Class<?> clazz, Field field, Type fieldType, String groupName, String replacement, Object inputValue)Invoked as part of the encryption process.ObjectreplacementValue(Class<?> clazz, Field field, Type fieldType, String groupName, String replacement, byte[] storedPartialValue)Invoked when a field cannot be decrypted because the key is missing.
-
-
-
Method Detail
-
replacementValue
public Object replacementValue(Class<?> clazz, Field field, Type fieldType, String groupName, String replacement, byte[] storedPartialValue)
Invoked when a field cannot be decrypted because the key is missing. The default implementation returns the value ofreplacementiffieldTypeequalsString, andnullotherwise (or the default value iffieldTyperepresents a primitive).- Parameters:
clazz- the class of the object on which the field was found. This is not necessarily the same asfield.getDeclaringClass(), since the field may be declared on a superclass of the class of our current objectfield- the field we're decryptingfieldType- the generic type of value that we need. This is not always the same asfield.getGenericType(), since the module itself recurses into collections and arrays. So, if the field has typeList<String>, then thefieldTypewill beStringrather thanList<String>.groupName- thegroupNamefrom thePersonalDataorSerializedPersonalDataannotationreplacement- thereplacementfrom thePersonalDataorSerializedPersonalDataannotationstoredPartialValue- the clear partial value previously stored with the encrypted value; may benull- Returns:
- the object to be used as field value; may be
null
-
partialValueForStorage
public byte[] partialValueForStorage(Class<?> clazz, Field field, Type fieldType, String groupName, String replacement, Object inputValue)
Invoked as part of the encryption process. Provides a partial, clear value in the form of a byte array to be stored with the encrypted value. The default implementation always returns null.- Parameters:
clazz- the class of the object on which the field was found. This is not necessarily the same asfield.getDeclaringClass(), since the field may be declared on a superclass of the class of our current objectfield- the field we're decryptingfieldType- the generic type of value that we need. This is not always the same asfield.getGenericType(), since the module itself recurses into collections and arrays. So, if the field has typeList<String>, then thefieldTypewill beStringrather thanList<String>.groupName- thegroupNamefrom thePersonalDataorSerializedPersonalDataannotationreplacement- thereplacementfrom thePersonalDataorSerializedPersonalDataannotationinputValue- the input value- Returns:
- the byte array to be stored; may be
null
-
-