Authorization design-pattern / practice?

Posted by Lawtonfogle on Programmers See other posts from Programmers or by Lawtonfogle
Published on 2014-08-22T19:31:46Z Indexed on 2014/08/22 22:32 UTC
Read the original article Hit count: 291

On one end, you have users. On the other end, you have activities. I was wondering if there is a best practice to relate the two.

The simplest way I can think of is to have every activity have a role, and assign every user every role they need. The problem is that this gets really messy in practice as soon as you go beyond a trivial system.

A way I recently designed was to have users who have roles, and roles have privileges, and activities require some combinations of privileges. For the trivial case, this is more complex, but I think it will scale better. But after I implemented it, I felt like it was overkill for the system I had.

Another option would be to have users, who have roles, and activities require you to have a certain role to perform with many activities sharing roles. A more complex variant of this would given activities many possible roles, which you only needed one of. And an even more complex variant would be to allow logical statements of role ownership to use an activity (i.e. Must have A and (B exclusive or C) and must not have D).

I could continue to list more, but I think this already gives a picture. And many of these have trade offs. But in software design, there are oftentimes solutions, while perhaps not perfect in every possible case, are clearly top of the pack to an extent it isn't even considered opinion based (i.e. how to store passwords, plain text is worse, hashing better, hashing and salt even better, despite the increased complexity of each level) (i.e. 2, Smart UI designs for applications are bad, even if it is subjective as to what the best design is).

So, is there a best practice for authorization design that is not purely opinion based/subjective?

© Programmers or respective owner

Related posts about design

Related posts about design-patterns