Reputation: 15158
I'm creating an application in Java (& using Mysql as DBMS).
My app. has users and each user can be permitted or not permitted for each feature of app.
there are 8 different static permissions.
How can I store these permissions for each user?
Is it a good idea to store it like Unix file mode bits (e.g. 0775)?
Thanks
Upvotes: 1
Views: 987
Reputation: 1486
3 of the many many approaches:
1) database : define roles like admin, manager etc. so that they can have viewing, writing roles. the tables will contain the users and the roles assigned to them.
2) xml files for storing the names and the roles. (Tomcat is a good example. u can store the roles in conf.xml)
3) if u want to chuck out db and xml.. simple bit operations can also help u. http://vipan.com/htdocs/bitwisehelp.html
this site explains how to use permissions using bit operations.
Upvotes: 2
Reputation: 900
You could do it in the database.
ID
FIRSTNAME
LASTNAME
USER_ID
RIGHT_ID
ID
NAME
Upvotes: 1
Reputation: 6657
You can store in values in bit format like
for Permission 1 you can store value as 00000001 For Permission 2 you can store value as 00000010
and so on
And you use bitwise And(&
) operation for mapping or validating the permissions of the users
Upvotes: 2