What is meant by, "A user shouldn't decide whether it is an Admin or not. The Privileges or Security system should."

Posted by GlenPeterson on Programmers See other posts from Programmers or by GlenPeterson
Published on 2013-11-04T12:16:40Z Indexed on 2013/11/04 16:11 UTC
Read the original article Hit count: 315

The example used in the question pass bare minimum data to a function touches on the best way to determine whether the user is an administrator or not. One common answer was:

user.isAdmin()

This prompted a comment which was repeated several times and up-voted many times:

A user shouldn't decide whether it is an Admin or not. The Privileges or Security system should. Something being tightly coupled to a class doesn't mean it is a good idea to make it part of that class.

I replied,

The user isn't deciding anything. The User object/table stores data about each user. Actual users don't get to change everything about themselves.

But this was not productive. Clearly there is an underlying difference of perspective which is making communication difficult. Can someone explain to me why user.isAdmin() is bad, and paint a brief sketch of what it looks like done "right"?

Really, I fail to see the advantage of separating security from the system that it protects. Any security text will say that security needs to be designed into a system from the beginning and considered at every stage of development, deployment, maintenance, and even end-of-life. It is not something that can be bolted on the side. But 17 up-votes so far on this comment says that I'm missing something important.

© Programmers or respective owner

Related posts about design

Related posts about separation-of-concerns