views:

91

answers:

2

All the security stuff I have worked with in the past in ASP.Net for the most part has been role based. This is easy enough to implement and ASP.Net is geared for this type of security model. However, I am looking for something a little more fine grained than simple role based security.

Essentially I want to be able to write code like this:

if(SecurityService.CanPerformOperation("SomeUpdateOperation")){
    // perform some update logic here
}

I would also need row level security access like this:

if(SecurityService.CanPerformOperation("SomeViewOperation", SomeEntityIdentifier)){
   // Allow user to see specific data
}

Again, fine grained access control. Is there anything like this already built? Some framework that I can drop into ASP.Net and start using, or am I going to have to build this myself?

+1  A: 

Have you looked at Authorization Manager (AzMan)? http://msdn.microsoft.com/en-us/library/bb897401.aspx

It was included with Server 2003 and has had a few updates in server 2008, and comes with an MMC admin tool.

You can store you data in an xml file or AD/ADAM partition using server the 2003 version, and in server 2008 they added SQL support.

This tool lets you link your security objects together in a hierarchical structure of roles, tasks & operations.

You can use this as a role based provider in Asp.net but they also include .net classes so you can access the authorization store contents directly.

squig
@squig, I looked at AzMan originally because it sounded too good to be true. Perhaps I didn't give it a close enough look, but it appeared to have two major "cons" that I saw. 1.) The ASP.Net AzMan providers supported only a very small subset of the overall hierarchy, thus making it no more useful than the normal providers, and 2.) It was tightly integrated with AD, which I wanted to avoid. If it is possible to use AzMan without all the AD integration then it might be worth it. At this point, I have my own providers that work pretty well for my needs.
Josh
A: 

I think you might be looking for Declarative security. Declarative security allows you to well, 'Declare' who can access what as attributes on the code here is a page on Role Based security also on MSDN. Here is an example:

[PrincipalPermissionAttribute(SecurityAction.Demand, Role="admins")]
public class foo
{
    [PrincipalPermissionAttribute(SecurityAction.Demand, Role="Domain Admins")]
    public void bar()
    {
      ....
    }
}
Mgetz
@Mgetz, I actually do use this attribute a lot, but more specifically what I was looking for was the ability to compose fine grained actions/operations up into roles. I specifically wanted to avoid using roles at all in my code. That way I can create arbitrary roles that are composed of any number of permissions and assign that role to a user. The user would then have access to that subset of permissions via their role. I have basically done this part using a custom RoleProvider, but I am surprised that nobody has done this already.
Josh