jpa - Hide / remap field values in Hibernate entity based on user permissions -


in spring 2.6 / jpa 1 / hibernate 3.3 application need "hide" entity field data based on current user's permissions.

e.g. on entity "document" there's field "title" maps title column in doc table. depending on user's permission title should either read "confidential" if he/she not allowed read title or should contain correct value fetched database. same applies lot of other properties.

the problem cannot apply presentation model or filtering in ui. because entity objects passed layer takes care of post-processing , displaying data in ui , real data (i.e. real value of "title") should not passed layer in terms of being publicly accessible. entity object should "sealed" without real value being accessible through api - entity may store it's state internally of course.

a naive approach fetch list of document objects, iterate on , set title "confidential" if user not allowed. of course, change entity when gets send persistence layer, on merge value of title ("confidential") written database - should not happen @ case of course.

so either, i'll have write custom insert/update statements these entities (lots of work) , / or write custom loader logic exchanges data in entity - again don't know how store , track original state of entity when comes merging. also, fail when using jpql/hql , not em methods loading.

so, questions are:

  • what options have "remap" value in entity based on current user while not breaking update / merge mechanism?
  • could interceptors (either hibernate or spring / aop style) out here? again: how handle merge?

thanks, dwight

one option springs mind write spring aspect apply across appropriate layer of app (service layer?) switch values out entities cross layer boundary. on way out, change value "my secret value" "confidential", , remember old value , entity came from. then, if/when entity passed in, set "my secret value" place. on side of boundary, entities have proper values, secret values never leave boundary , can never compromised.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -