Skip to main content
Tweeted twitter.com/StackCodeReview/status/1025531907260538882
added 119 characters in body
Source Link
jrswgtr
  • 131
  • 3

It would be best if I could somehow override Doctrine behavior so I wouldn't have to touch the entity classes at all.

It would be best if I could somehow override Doctrine behavior so I wouldn't have to touch the entity classes at all.

added 15 characters in body; added 9 characters in body
Source Link
jrswgtr
  • 131
  • 3

I am building an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML and Javascript for the purpose of AJAX calls. However, for security reasons I don't want the original ID's exposed.

Instead of encrypting an ID every time it is displayed or being sent to the client, I figured it would be better to encrypt the ID of every entity once, when. When they are loaded. I tried to encrypt the $id field of entities on postLoad and decrypt them again at preUpdate. That works fine, until relations come around. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided it would be better to not touch the $id field of the entities and create an additional field. The field will only be used when the entity is loaded and will not be persisted. Instead of adding the field and get/set methods to each entity, I decided to create an interface and abstract class. The interface is to use for checking the object later on. The abstract class is to implement the methods.

I am building an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML for the purpose of AJAX calls. However, for security reasons I don't want the original ID's exposed.

Instead of encrypting an ID every time it is displayed, I figured it would be better to encrypt the ID of every entity once, when they are loaded. I tried to encrypt the $id field of entities on postLoad and decrypt them again at preUpdate. That works fine, until relations come around. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided it would be better to not touch the $id field of the entities and create an additional field. The field will only be used when the entity is loaded and will not be persisted. Instead of adding the field and get/set methods to each entity, I decided to create an interface and abstract class. The interface is to use for checking the object later on. The abstract class is to implement the methods.

I am building an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML and Javascript for the purpose of AJAX calls. However, for security reasons I don't want the original ID's exposed.

Instead of encrypting an ID every time it is displayed or being sent to the client, I figured it would be better to encrypt the ID of every entity once. When they are loaded. I tried to encrypt the $id field of entities on postLoad and decrypt them again at preUpdate. That works fine, until relations come around. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided to not touch the $id field of the entities and create an additional field. The field will only be used when the entity is loaded and will not be persisted. Instead of adding the field and get/set methods to each entity, I decided to create an interface and abstract class. The interface is to use for checking the object later on. The abstract class is to implement the methods.

added 141 characters in body
Source Link
jrswgtr
  • 131
  • 3

I am working onbuilding an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML for the purpose of AJAX calls. However, for security reasons I don't want the original ID's exposed.

Instead of needing to encryptencrypting an ID every time it is displayed, I figured it would be better to encrypt the ID of every entity once, when they are loaded. I tried to encrypt the ID's$id field of entities on postLoad and decrypt them again at preUpdate. That works fine, until you need to work with relations come around. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided it would be better to not touch the ID$id field of the entities and create an additional field. The field will only be used when the entity is loaded and will not persistbe persisted. Instead of adding the field and get/set methods to each entity, I decided to create an interface and abstract class. The interface is to use for checking the object later on. The abstract class is to implement the methods.

This is the interface defining the methods that are needed. I also defined getId() here. This is so I can be sure that getId() is available by checking the objects against this interface.

The Doctrine listener class encrypts the ID of the entity and sets the field when the entity is loaded. Read more about Doctrine event listeners. I use NzoUrlEncryptor because I also use it for routing purposes. It could however be any encryption tool.

I am working on an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML for the purpose of AJAX calls. However for security reasons I don't want the original ID's exposed.

Instead of needing to encrypt an ID every time it is displayed, I figured it would be better to encrypt the ID of every entity once they are loaded. I tried to encrypt the ID's of entities on postLoad and decrypt them again at preUpdate. That works fine, until you need to work with relations. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided it would be better to not touch the ID field of the entities and create an additional field. The field will only be used when the entity is loaded and will not persist. Instead adding the field and get/set methods to each entity I decided to create an interface and abstract class. The interface to use for checking the object later on. The abstract class to implement the methods.

This is the interface defining the methods that are needed.

The listener class encrypts the ID of the entity and sets the field when the entity is loaded. I use NzoUrlEncryptor because I also use it for routing purposes. It could however be any encryption tool.

I am building an application that is becoming some kind of social media platform. I need to work a lot with the entities ID's in the HTML for the purpose of AJAX calls. However, for security reasons I don't want the original ID's exposed.

Instead of encrypting an ID every time it is displayed, I figured it would be better to encrypt the ID of every entity once, when they are loaded. I tried to encrypt the $id field of entities on postLoad and decrypt them again at preUpdate. That works fine, until relations come around. Doctrine simply finds no relations because the ID of the current entity is ecrypted (duh).

I decided it would be better to not touch the $id field of the entities and create an additional field. The field will only be used when the entity is loaded and will not be persisted. Instead of adding the field and get/set methods to each entity, I decided to create an interface and abstract class. The interface is to use for checking the object later on. The abstract class is to implement the methods.

This is the interface defining the methods that are needed. I also defined getId() here. This is so I can be sure that getId() is available by checking the objects against this interface.

The Doctrine listener class encrypts the ID of the entity and sets the field when the entity is loaded. Read more about Doctrine event listeners. I use NzoUrlEncryptor because I also use it for routing purposes. It could however be any encryption tool.

annotations in code
Source Link
jrswgtr
  • 131
  • 3
Loading
Source Link
jrswgtr
  • 131
  • 3
Loading