May be used: convert to binary Integer.toBinaryString (int i)
First, the theoretical design of the system rights management strategy is based on bitwise processing methods to achieve competence. First, form a list of all privileges, and give an integer value of non-repetition, for example:
Operating authority number --- -
Product Management 0
Department set a
Products / Materials Information 2
Customer Information Management 3
4 Warehouse Management
... ... ... ...
Theoretically, there are N-operation. Thus, if the user A has the following permissions:
Warehouse management authority to set the value of the user A power_value = 2 ^ 4 +2 ^ 1 = 18, into the binary is 10010. Then according to the formula:
Int result = power_value & ((int) Math.pow (base, index)); (Note: Math.pow (2,4) that 2 ^ 4);
To determine whether the relevant authority, if the result = base ^ index is illustrated with the permissions. Here's an example.
If you want to verify whether the user A warehouse management authority, and can be calculated by bitwise.
int result = power_value & ((int) Math.pow (2,4));
The result is result = 10000 = 2 ^ 4; that user A has a warehouse management authority;
If you want to verify whether the user A product / raw material information management rights, then:
int result = power_result & ((int) Math.pow (2,2))
The result is result = 00000! = 2 ^ 2; that user A no products / materials information management rights.
Second, the rights of the access control database design to use at least three strategies to achieve the form of a database table:
Rights resource table (poweraction):
Name field type the name of the field is empty foreign key resource ID Id primary key resources, whether from increased url url Varchar (255) whether the resource name of the Action Varchar (255) whether any resource value Value Int
User rights table (user_power):
Name field type the name of the field is empty foreign key user ID UserId Varchar (20) whether the foreign key value Power_value Int No permission