1
votes

I have successfully added "Class"-level ACL's, to only allow authorized users access my model:

.../server/ModelObj.js

"acls": [
  {
    "accessType": "*",
    "principalType": "ROLE",
    "principalId": "$unauthenticated",
    "permission": "DENY"
  }
]

This is great, but my applications needs ACL's on a even lower level - object level.

When a User, which belongs to a Role, creates a new object, the object must only be accessible by other users, who have the same role.

Is this the way to go around the problem in Loopback, or do they provide a different way?

Thanks in advance, Jesper.

2

2 Answers

0
votes

I think you may have to implement this using a custom role resolver. The idea is to create a role and a custom resolver and determine a user's access to the given model at runtime. Here's a partial example (note that you would need to create the role, and members, etc as well).

// perhaps in a boot script?
app.models.Role.registerResolver('teamMember', function(role, context, cb) {
  if (context.modelName === 'ModelObj') {
    context.model.findById(context.modelId, function(err, instance) {
      if (err) { /* handle it... */ return cb(err); }
      // check the instance for something to determine access
      // execute callback with switch for access (or not)
      cb(null, true);
    }
  }
});
0
votes

This week I started a loopback mixin to support acls on object-level. We needed dynamic acls on a instance-level that may change over time. We saw your question and made a search to find some plugin/mixin/middleware that someone could be made to support this, but we didn't found nothing.

If you are still interested on this I will be very happy to have your feedback, as I want to make this mixin to work anywhere and not only on our product.

My plan is to have a first version this week. Since monday I made a simple, synchronous acl library on object-level. Later I added support as loopback-mixin and support for resolvers that could obtain data to make a decission. I want to add support for make a layer of 'sugar', where a simple property can make acls. So if you have a model with property "stock", nobody can call method 'buy' if stock is less than 1.

Thanks!