编码用户层次java
我正在设计一些包含具有不同权限的不同用户的软件,这些软件与它们在我的程序中的底层操作系统无关。
有针对这种事情的设计模式吗?
理想情况下,我希望能够像在 UNIX 中一样创建具有多个组的用户。 例如 用户A属于用户组A和用户组C 用户B属于用户组A和用户组B
I am designing some software that contains different users with different privileges, these are not related to the underlying os they are within my program.
Is there a design pattern for this sort of thing?
Ideally i would like it possible to create users with multiple groups as you can in unix.
For example
user A is in user group A and user group C
user B is in user group A and user group B
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的方法是拥有一个包含所有可能权限的数据库,然后为用户分配适当的权限。在编写任何需要权限的操作之前,请使用诸如
boolean isAuthorized(User user, PrivilegeTypeprivilege)
之类的方便方法进行测试。Java中有很多身份验证和授权框架。我个人更喜欢 Apache Shiro,因为它简单且学习曲线小。
希望这有帮助。
The easiest would be to have a database of all possible privileges and then assign appropriate privileges to users. Before you write any action that requires a privilege, have a handy method something like
boolean isAuthorized(User user, PrivilegeType privilege)
to test.There are many authentication and authorization frameworks in Java. I personally prefer Apache Shiro for it's simplicity and small learning curve.
Hope this helps.