Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From your architecture, I am guessing that you have the security filters setup already (I believe it's called OncePerRequestFilter in Spring?). The way I have approached this in the past is use my security filters to get the "Role" of the client (assuming you can have roles assigned for each client which map to specific permissions/restrictions on each resource object). Now based on the "Role" I have custom JSON serializer/deserializer strategies (I used GSON for this inclusion/exclusion type adapters. You can read more <a href="https://stackoverflow.com/questions/11271375/gson-custom-seralizer-for-one-variable-of-many-in-an-object-using-typeadapter">here (Gson custom seralizer for one variable (of many) in an object using TypeAdapter)</a> ) that will take care of what resource fields should/should not be populated/serialized. This way, you will continue to use the same resource object and TypeAdapter for each resource object which will determine the serialization/deserialization of the resource object based on the role of the client.</p> <p>One more idea that comes to my mind is method interceptors (Spring AOP). Although I have never tried it with method interceptors, I think it should still work in the sense that you will intercept the method right BEFORE it returns (and after the business logic is done) and look at the role of the client making the request. Based on that role, you can determine what fields to null out (most serializers (atleast gson) do not serialize null fields) and not serialize, before converting it to json (or whatever your return type might be) and sending it over to the client</p> <p>I hope this helps. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COWell, i tried that with Spring AOP interceptors. I even created a seperate library that contains interceptor and common annotation library to mark fields as restricted for some roles. What i am not certains is, from the rest api point of view, authentication and authorization is based on other apps, (my UI app or another system) but from my UI app point of view, security is based on user and roles retrieved from api on login (Users, Managers, Super Users etc.). Is it right to introduce security concepts of UI to the REST api in some HTTP header way?
      singulars
    2. COA very good question and my personal opinion would be that it depends on the implementation. The way I handled it before was EACH CLIENT has a role or some kind of identifier as to what is their origin. For example, your UI APP client can have a role of "TRUSTED_CLIENT" which means that there will be further authorization needed based on the "role" of whosoever is trying to access your api THROUGH that UI APP client (based on their login, as you mentioned, they can be super users, managers, users etc.)
      singulars
    3. COThe other systems (other clients), you can have a "TRUSTED_THIRD_PARTY_CLIENT" role which means that you will look at the "scope" to which this client has access to, rather than going one step deeper as to what granular role does the user have who is trying to make this api call through this third party client. My point being, it seems that you will need 2 levels of authorization based on what kind of client is making the call. And this will have to be handled at your security filter layer itself.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload