This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi all, I'm new to LightSpeed and I have a question. I recently joined a project that is using lightspeed. I'm working on adding encryption to an existing object. Given that we want the data to be decrypted when the Object is loaded in the appliation, it seems to make the most sense to add the encryption before the persist and the decryption after the db load using the lifecycle callbacks. My issue is that the current data that needs encrypted and decrypted resides in a Value Object, not a class that extends the Entity<TId>. For instance, here is a snippit of my model structure.
public class Organisation : : Entity<Guid> ... [ValueObject] ... }
public class CreditCard : ValidateableEntity public string Number }
I can't put my lifecycle in my orginzation as I need access to the private members of _number and _securityCode within my credit card object. Any ideas how to get around this?
Thanks, Todd
|
|
|
Hi Todd, One possible plan of attack here is to use transient fields in the value object to hold the decrypted values, and to use setter logic to keep the transient decrypted and persistent encrypted fields in sync. I am thinking of something like: public class CreditCard However we actually recommend that value objects be immutable -- that is, rather than modifying the Number and SecurityCode properties, you would create a new CreditCard and set Organisation.CreditCard to that new object. I believe this is important for dirtiness detection (i.e. so LightSpeed knows that the Organisation data has changed and the Organisation needs to be included in a SaveChanges). See "Creating Model Classes" in the help file for an example (near the bottom). You could then have Encrypt and Decrypt methods on CreditCard, and call them from the Organisation lifecycle callback; though to be honest I would still go with the "transient field" approach simply because it avoids the possibility of confusion e.g. if you encrypt the Number field for saving, and then later on a maintenance programmer comes along and tries to use the CreditCard.Number after the save as if it were still a decrypted value. |
|