Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration to ignore exception when decryption fails? #17

Closed
vageeshb opened this issue Nov 5, 2018 · 2 comments
Closed

Add configuration to ignore exception when decryption fails? #17

vageeshb opened this issue Nov 5, 2018 · 2 comments

Comments

@vageeshb
Copy link

vageeshb commented Nov 5, 2018

Description:

Using this library on an existing data or document with a newly added Encrypted annotation on an existing field fails because the crypt function (Decoder) throws an exception while loading the data as it expects binary data.

Usecase:

  • Application with existing data wants to use this library
  • Application with existing non-encrypted document wants to encrypt the fields
  • Application with existing partially encrypted document wants to encrypt an existing field

Question:

  • Would it logical to allow a configuration option to ignore this exception?

Proposal:

  • Allow a configuration option to enable data passthrough on decoding failure
  • Handle the exception thrown by the Decoder Function and pass the data as-is if the non-binary
@agoston
Copy link
Owner

agoston commented Nov 7, 2018

That is an excellent point!
It already came up that sometimes, you have to do data migrations because of changes in @Encrypted annotations.

For now, the recommended practice is similar to what you would do for data migrations with spring-data-mongodb:

  • make a new collection. make a one-off script that reads all from the old version and writes it in new version. this can be done online, while your service is running, but during that time, you'll have to read both collections.
  • make a new @document, backed by the same collection. Make a one-off script that reads, e.g. via MongoTemplate, into the old format, and if that does not fail, convert in java into the new format and save it back.
  • if you feel really advanced, you could make a version field in your document and hook into the spring-data-mongodb event handlers like this library does, to call the proper type mapper as per the version field in the Document.

These ideas aside, it is indeed possible to add a config option for allowing non-binary data simply pass through in the Decoder. I would be most delighted if you could submit a pull request for that; if not, I can make this soon-ish.

@agoston
Copy link
Owner

agoston commented Nov 19, 2018

Fixed in release 2.1.0.

@agoston agoston closed this as completed Nov 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants