loopback icon indicating copy to clipboard operation
loopback copied to clipboard

How to use ACL' property?

Open Spark-star opened this issue 12 years ago • 6 comments

I'm a newer to loopback! when I used acl to deny someone modify model's specified property like this: { "principalType": "ROLE", "principalId": "admin", "permission": "DENY", "accessType": "READ", "property":"title" }

"admin" is a role I added, "title" is a model's(Post) property, when I access the route GET " /post", the response data also have "title" property? why? If I won't somebody modify this property ,how can I do?

Spark-star avatar Sep 20 '14 07:09 Spark-star

the "property" is the name of the model remote method (ex. find create upsert count) more info here http://docs.strongloop.com/display/LB/Model+definition+JSON+file#ModeldefinitionJSONfile-ACLs

if you set ACL like this

{
    "principalType": "ROLE",
    "principalId": "admin",
    "permission": "DENY",
    "accessType": "READ",
    "property":"find"
}

It means the user that have "admin" role can't call "GET /model"

http://docs.strongloop.com/display/LB/Defining+remote+hooks the last example on the link show you how to prevent password from being sent to client

and It will be useful for you in the future http://docs.strongloop.com/display/LB/Model+hooks

If you don't want to any body modify the value of title one of lastest two links above can help you solved. I'm not sure which one.

veekungx avatar Sep 20 '14 07:09 veekungx

THX, I find "property" could be a property on a model in the loopback document. I find it on the http://docs.strongloop.com/display/LB/Model+definition+JSON+file . "property Specifies a property/method/relation on a given model. It further constrains where the ACL applies."

Spark-star avatar Sep 20 '14 08:09 Spark-star

I can't use "principalId": "$owner", it doesn't work. Please tell me why ?

bluestaralone avatar Sep 22 '14 11:09 bluestaralone

@bluestaralone The $owner role is used to check if a target model instance is owned by the logged in user. The target model needs to have a belongsTo relation to the user model.

raymondfeng avatar Sep 22 '14 15:09 raymondfeng

@raymondfeng: what if the target model is extended from User built-in model, do I need to do implement any relation? If it's required, what should correct definition for this relation?

projectxmaker avatar Sep 22 '14 16:09 projectxmaker

@raymondfeng: It's ok now, but i can't find records that belong to a logged user. (method GET, remote method /Books) => db.Books.find(); it said that "Authorization Required"

bluestaralone avatar Sep 23 '14 01:09 bluestaralone