Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

node.js - How to properly manage both roles and statuses as ACLs in Loopback?

In my app I need to combine two different access control mechanisms that should work together: roles and statuses.

So a user can have different roles like admin, guest, teammember etc. This is already implemented by using Roles, role mappings and ACLs.

However now I need to add another access control mechanism: user statuses.

There can be about 10 different statues like trial, onboarding, beta, banned etc with different business logic for access control. Users with different roles can have different statuses. One user can have only one status at the same time.

I'm trying to think of a way to implement such functionality and came to a thought that it could be implemented by adding the exact same mechanism as role but with a name status. So I would have a model called Status and a user model would have a field status_id, so that I will get a hasOne relationship and will not need a mapping model.

So the idea comes down to having another set of ACL rules along with the rules for roles that would look something like this:

  {
    model: '*',
    property: 'some_model_method',
    accessType: 'EXECUTE/READ/WRITE',
    principalType: 'STATUS', // "STATUS" instead of "ROLE"
    principalId: '$onboarded',
    permission: 'ALLOW'
  },

I haven't found any relevant information as for creating custom principalTypes but it feels like it should be possible.

However I'm not sure if this is the right approach to the problem. Is it scalable? Will it be easy to support such code in future? Is it flexible enough? Will I get the acl hell with this approach so that my acls lists will become huge for my models?

Or this all is just overcomplicating the problem and I only need another table called Status and a bunch of if-else statements in my code? Or maybe some sort of a state machine?

Honestly, multiple questions arise, so that's why I've decided to seek help from the community.

I need a piece of advice on how to implement such functionality when a user can have both role and status access control mechanisms.

How should I approach this problem architecturally in general and specifically in Loopback 3?

question from:https://stackoverflow.com/questions/65921617/how-to-properly-manage-both-roles-and-statuses-as-acls-in-loopback

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...