I 开发者_如何学JAVAam 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
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.
精彩评论