Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic security for ASP.NET MVC

I'm designing an app in ASP.NET MVC, and the usual way to protect actions is by the attribute Authorize which protects an entire action.

[Authorize(Roles = "Managers")]
public AtionResult Info(int employeeId )

However, in our design the application is highly data driven. An action on one set of data might be allowed, and on another set of data not be allowed.

//OK
http://host/Employee/Info/102

//Not OK
http://host/Employee/Info/105

What pattern should we use for security for this design?

like image 332
C. Ross Avatar asked Mar 16 '26 06:03

C. Ross


1 Answers

You can create a derived Authorize attribute to do whatever you want.

public class DynamicSecurity : AuthorizeAttribute
{
    protected override bool AuthorizeCore(HttpContextBase httpContext)
    {
        //go to db
        return true;
    }
}
like image 164
John Farrell Avatar answered Mar 18 '26 05:03

John Farrell