Hello all,
We're using the hook functionality to implement encryption of some document fields "transparently" to the caller.
Basically the process is:
1 : when onRecordBeforeCreate or onRecordBeforeUpdate event fires we apply encryption to some data fields and change the document before is created or updated
byte[] data = doc.field("data");
byte[] encrypted = encrypt(data);
doc.field("data", encrypted);
2 : when onRecordAfterRead fires we get the encrypted data from the document fields, decrypt them, and change the document fields again with the decrypted data.
byte[] encrypted = doc.field("data");
byte[] decrypted = decrypt(encrypted);
doc.field("data", decrypted);
The problem is that the event onRecordAfterRead is firing twice and in the first time the data decrypts correctly (because is encrypted) but on the second time the decryption fails because we already had decrypted it, and so the document "load" fails.
Is there some "bug" with this, or some way to avoid the event firing twice?