loopback icon indicating copy to clipboard operation
loopback copied to clipboard

$owner and ACL doesn't seem to work

Open ghislaindj opened this issue 12 years ago • 6 comments

I've got this ACL in my user.json model :
{ "accessType": "READ", "permission": "ALLOW", "principalType": "ROLE", "principalId": "$owner", "property": "findById" }

However, I've got a 401 when I try to reach /users/:myUserID

In fact, it seems that I'm considered as the owner of the resource, what am I doing wrong ?

ghislaindj avatar Sep 09 '14 08:09 ghislaindj

@ghislaindj I'm not good at English but I will try to explain to you. The $owner keyword check the access_token with the primary key on /users/{pk} or it check with the belongsTo relation model. Did you call "/users/login" and set "access_token" on the top of the explorer? Your code works fine for me.

veekungx avatar Sep 09 '14 13:09 veekungx

I haven't put it, but I'm of course authenticated (i've got an access token after login, and I've set the access token in swagger for example)

ghislaindj avatar Sep 09 '14 13:09 ghislaindj

need your "user.json" for better solutions

veekungx avatar Sep 09 '14 15:09 veekungx

{ "name": "user", "plural": "users", "base": "User", "properties": { "firstName": { "type": "string", "required": true }, "lastName": { "type": "string", "required": true }, "gender": { "type": "string" }, "newsletter": { "type": "boolean", "default": false }, "picture": { "type": "string" } }, "validations": [], "relations": { "accessTokens": { "type": "hasMany", "model": "accessToken", "foreignKey": "userId" }, "identities": { "type": "hasMany", "model": "userIdentity", "foreignKey": "userId" }, "credentials": { "type": "hasMany", "model": "userCredential", "foreignKey": "userId" } }, "acls": [ { "accessType": "READ", "permission": "ALLOW", "principalType": "ROLE", "principalId": "$owner", "property": "findById" }, { "accessType": "EXECUTE", "permission": "ALLOW", "principalType": "ROLE", "principalId": "$everyone" }, { "permission": "ALLOW", "principalType": "ROLE", "principalId": "$owner", "property": "upsert" } ], "methods": [], "options": { "mongodb": { "collection": "users" } } }

ghislaindj avatar Sep 09 '14 15:09 ghislaindj

@ghislaindj I have examined your user.json work fine for me.

I'm not sure these can help you fix the problem.

  1. I ever got the same problem as you when I was using loopback version below 2.8.9.
  2. Now I'm using loopback v2.9.1 and the GET /users/{pk} allow access with "$owner" by default the module maybe slightly different you can check it with "slc version" and update with "slc update"
  3. the relation object to "accessToken" not need if you base the user model from "User".

Here my 'user.json' and GET /users/{pk} allow access by default with "$owner"

{
  "name": "user",
  "base": "User",
  "properties": {
    "name": {
      "type": "string"
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": []
}

I tested with your "user.json" but I don't know why the model extend from "User" based not working well with the same name.

{
 "name" : "user",
 "base" : "User",
}

but if I create model with other name ex."Customer" It worked as it could be.

{
    "name": "Customer",
    "base": "User",
}

Here a little addition info about Built-in user model http://docs.strongloop.com/display/LB/User

PS. the documents might slightly a bit out of date I think LB are working on it.

veekungx avatar Sep 09 '14 16:09 veekungx

Hi @veekungx ,

I've juste updated slc to the 2.9.1 version and the npm package as well, and it does work very well ! It seems that there was a problem with the 2.8.x version, but it's corrected !

Thanks a lot @veekungx !

ghislaindj avatar Sep 10 '14 06:09 ghislaindj