tags:

views:

90

answers:

1

In my future web application there would be many user roles. Depending on user's role, webapp should restrict users's access to certain pieces of information. I need to implement following features:

  • depending on role, user should see only columns and rows (in data grid) that are available for current role and user
  • depending on role, user should view page in readonly or in editable mode
  • depending on role, user should have visible/hidden some controls on a web page

In my previous applications (that were pretty simple) such problem was solved using many conditionals operators in codebehind files and in markup files also. It was quite difficult to maintain such code.

I'm wondering are there any complex solution for maintaining role-based security for all levels of apllication (data, logic, view) without messing up code with IFs.

ps both, solutions for java and .net platforms are interesting

A: 

Regarding point 1: You can implement that by encapsulating your data access and filtering loaded rows to match the current user's account / the current user's role.

I've implemeented this and a similar mechanism for preventing write access to rows from other users in my data layer, which saves me of having to write read write access security checks in the business layer.

Adrian Grigore
And how did you implement it in DAO?not like: ?if (userRole == 'admin') {}if (userRole == 'role1') {}..if (userRole == 'role') {}still there is a problem how to render view depending on role
kilonet
My data layer is based on LinqToSQL and for the reads I ad a simply where clause to restrict results to rows belonging to that particular user. The writes are a bit more complicated and my approach would not work without Linq, but perhaps you could approach this by adding an additional where clause to your update / delete queries as well to restrict database operations by row owner.
Adrian Grigore