4 views
How did you determine whether a user belonged to a group while taking the role hierarchy into account?
Asked at
AI answer
I usually separate a user’s group membership from their set of permissions. If groups form a tree, you can account for both a user’s direct membership and membership in parent groups—for example, by traversing the chain of parents or retrieving all ancestors with a recursive query. For frequent checks, you can store this structure in a transitive-closure table or cache it, with invalidation when the hierarchy changes. It’s important to define the semantics explicitly: whether permissions are inherited downward or upward, how membership in multiple groups is handled, and whether explicit denials exist. Access checks should be performed on the server, rather than relying on the state of the UI.
Also asked at СБЕРКОРУС
Similar questions
- A user enters a username and password: what happens next, and how are they authenticated?
- How would you design an authentication system? What would you use as its foundation?
- What methods of combining tables or data in SQL do you know?
- How would you sort users by the `name` field?
- How would you implement user authentication? Where is the best place to store authentication data, and why?