Hi there, I have posted this message at General Java itermediate but it seems that there is no one who is able to answer me there so i just tot that i would try out here. I would just like to ask anyone out there who has ever programmed an application that allows an administrator(through a web interface) to control which page or option or field of a form are available and whether they are read only , editable or not, whether a user has the rights to delete or not based on the authorizations a person is given. I am sure there are applications out there that have been developed with such features but how messy or complicated were they?
to programme an application with page control(controls which page a user can see or not) is not too difficult but to not only control that page access and also the visibility of those fields in that page and its properties such as editable or not, i think it might be quite a headache
if i were to store all these access control list information in a database, how would the information be organized ?
i have come across applications that store references to elements to a form in a page as a "page.form.element" string so that at first glance, it becomes immediately recognizable in the database to a human to which element in the form does this permission belong to and the application also uses this string(the identifier) to match its permissions according to the the user rights.
is there already a design pattern out there already for this issue? I hope seasoned developers might be able to give me some pointers or shed some light into this issue cos i think a lot of people might faced the same task and go about it in different ways, some better than the others , some worse
As for how to store what roles can see what elements, you could assign a category to each element, or better each <div> section of a page, and then assign one or more categories to each role. These assignments could be stored in a DB and loaded in a HashMap at runtime.
At some point, you will have to bite the bullet and manually ID each <DIV> section, but it's not really that much work...
Hello Fletcher, Thanks for your input it definitely gave me something to chew on. but a couple of follow up questions.
I won't go near the JSP end, but on the database end this kind of thing is common:
User many-to-many Role
Role many-to-many Resource
User, Role and Resource are all just string names for things.
You can build APIs to say "does this user have access to this resource" or "give me all resources for this user". Avoid checking user against role so you can introduce new roles with new combinations of resources without touching the code.
In the database when you do many-to-many you build a little association table in between with the keys of the other two tables, eg RoleKey & ResourceKey. You can add more information to this table to allow or deny specific permissions, eg Create Retrieve Update Delete Execute etc. If you can navigate from user to resource through two different role paths, the common rule is to use the more restrictive path. So if I have one role that allows execute access to "change employee salary" and another role that denies access, the more restrictive wins and I can't do it.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad: