Web 应用程序中的模糊用户管理
我对 Web 应用程序中的角色管理有点困惑。
假设:用户属于一个角色,一个角色拥有一个或多个权限,权限可以是:查看页面options.html。
如果角色由权限组成(查看此页面、查看该页面等),我们应该如何检查用户允许在代码中查看哪个页面?
我想到了两个选择:
a)角色级别:如果用户是该角色的成员,则显示页面...
b)权限级别:如果用户有permissionToViewThatPage,则显示页面...
如果a)是可行的方法,那么为什么我们需要权限?
管理员角色有权查看该页面,稍后有人会更改权限。
在我们的代码中,我们询问用户是否是管理员角色的成员,但我们不检查权限。
问题:
如何在源代码(JSP/JSF、ASP.NET)中管理用户角色/权限?
I'm a bit confused about role management in web applications.
Assumption: user belongs to a role, one role has one or more permissions, and permission could be: view page options.html.
If role consists of permissions (view this page, view that page, etc..), how should we check which page is user allowed to see in our code?
Two options have crossed my mind:
a)Role level: If user is member of thatRole then show page ...
b)Permission level: if user has permissionToViewThatPage then show page...
If a) is the way to go, then why do we need permissions?
Admin role has the permission to view that page, and later on someone comes and changes permission.
In our code we ask if user is member of the admin role, but we don't check the permission.
Question:
How do you manage user roles/permissions in your source code (JSP/JSF, ASP.NET)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不使用角色,那么维护用户就会变得很麻烦,因为当需求发生变化时您必须更改每个用户。如果您不使用页面或功能级别权限,那么维护代码就会变得很麻烦,因为当需求发生变化时您必须更改代码。
最好的选择是让页面上的功能在需要时需要权限,让用户属于一个或多个角色,然后找到一种将角色与权限相匹配的方法。
If you don't use roles, then maintaining users becomes cumbersome because you have to change each individual when requirements change. If you don't use page or feature level permissions, then maintaining code becomes cumbersome because you have to change the code when requirements change.
The best option is to have the features on your page require permissions where needed, have the users belong to one or more roles, then have a way to match the roles with the permissions.
b).如果您不打算使用您定义的权限,那么您是对的,那么您就不需要它们。但考虑到您当前的设置,您应该只需要权限。处理管理问题的最佳方法是授予管理员角色所有权限,而不是为用户添加单独的角色检查。
b). You are right if you are not going to use the permissions you have defined then you don't need them. But given your current setup you should just permissions. The best way to handle your admin issue is to grant the Admin role all permissions rather than adding a separate role check for the user.
基本区别是权限分配给角色,角色分配给特定用户。这个概念背后的基本思想是在不知道实际代码的情况下使访问管理尽可能动态。
The basic distinction is that permissions are assigned to roles, and roles are assigned to specific users. The basic idea behind this concept is to make access management as dynamic as possible without knowing the actual code.