We are trying to use hibernate Converter to encrypt / decrypt data stored via hibernate for few columns
@Convert(attributeName="myattr",converter=DataEncryptionConverter.class)
private String actualValue;
The plan is to implement reusable Converter based on data type (String, Date etc).
However the plan is to maintain a config template that indicates if the field encryption should be turned on / off
Approach
@Converter
public class DataEncryptionConverter implements AttributeConverter<String,String>{
private static Logger logger = LoggerFactory.getLogger(DataEncryptionConverter.class);
@Override
public String convertToDatabaseColumn(String arg0) {
logger.info("convertToDatabase>input:"+arg0);
if(attributeName matches (TemplateList)) {
//check if the attributeName is part of approved TemplateList where data needs to be encrypted
return encryptData(arg0);
}
else {
return arg0;
}
}
@Override
public String convertToEntityAttribute(String arg0) {
logger.info("convertToEntity>input:"+arg0);
if(attributeName matches (TemplateList)) {
//check if the attributeName is part of approved TemplateList where data needs was encrypted
return deCryptData(arg0);
}
else {
return arg0;
}
}
}
So, is there any way to retrieve the attributeName that is set as part of @Converter ?