Finally, I defined a Permission class to connect all the elements to form a complete permissions to determine the component. code show as below. When the user inherits this class, it is necessary to finish both method getDenyrule, getAccepttrule.
When we perform permission judgment, you can call Haspermission (User User, HashMap OldData, Input Input). Then, three parameters are users, data, input, respectively. In order to determine the person, the data is the original data, when updating the operation, OldData is old data, INPUT is introduced in the previous part, which is a universal input method. Input POST or GET mode than the web, you can convert into an Input class, or you can create a new input computer manually, as a collection of operations, and its data.
During the Permission class, the judgment of Denyrule and AcceptRule, as long as there is a DenyRule rule that meets the requirements, it is considered that the user has no permissions, and if the user is not excluded by Denyru, it is considered that as long as one rule meets the requirements. The user has permission.
Because I am more lazy, the implementation of Permission has not been written yet.
In summary, use this permission component to do the following work:
1. Write the implementation of the User.
2. Write the implementation of Group.
3. Write the implementation of the Role.
4. Write the implementation of Permission. (I will put a universal up for a while)
5. Write n Rule (corresponding to your system to perform permission judgment).
6. Call the permission.haspermission judge in the program.
====================== permission.java ====================================================================== ======
Package org.fswan.Permission;
Import java.util.arraylist;
Import java.util.hashmap;
Import org.fswan.input;
/ **
* Permissions judgment class
* /
Public Abstract Class Permission
{
Public string permission;
Public String Subpermission;
Protected arraylist prop;
Public Boolean Haspermission (user user, hashmap olddata, input input)
{
Rule [] rules = getDenyrule ();
Boolean Accept = TRUE;
For (int i = 0; i { IF (! Rules [i] .pass (this, user, olddata, input)) { Accept = false; Break; } } IF (Accept) Return False; Rules = getAcceptrule (); For (int i = 0; i { IF (! Rules [i] .pass (this, user, olddata, input)) Return false;} Return True; } Public String getPermissionname () { IF (SUBPERMIERMIERMISSION == Null) Return Permission; Return Permission ":" Subpermission; } Public ArrayList getPermissionItem () { Return Prop; } Public abstract rule [] getDenyrule (); Public abstract rule [] getacceptrule (); }