filter - Security filtering entity collection with jax-rs and jersey -


i've been looking around on how filter results based on security roles. i've been looking @ filters seems filter out fields rather complete entity itself. let me try explain need. lets have 2 entity classes:

public class project {     private long id;     private string name;     private string description;     // getters , setters }   public class user {      private long id;      private string name;      private string email;      // getters , setters } 

resource:

@path("projects") @produces("application/json")  public class projectsresource {      @get     public list<project> getprojects() {         return getdetailedprojects();     } } 

also have 2 companies, each own projects. convenience lets call them company , company b.

what achieve 3 users using same resource different results based on security role.

user 1: super user, should everything

user 2: manager company a, should projects company a

user 3: manager company b, should projects company b

how should go doing this? doesn't seem right filtering in each resource.

i'm using jax-rs, role based security. users linked role grants them access projects specific company.

i think have parameterize getdetailedprojectsmethod accessing user.

to achieve can inject jersey securitycontextinto resource (from jersey documentation):

@path("basket") public shoppingbasketresource get(@context securitycontext sc) {     if (sc.isuserinrole("preferredcustomer") {         return new preferredcustomershoppingbasketresource();     } else {         return new shoppingbasketresource();     } } 

the securitycontext.getuserprincipal().getname()method allow hold of requesting user , map method parameter (or use plain).


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -