Skip to content

Instantly share code, notes, and snippets.

@jlucaspains
Created February 12, 2019 03:16
Show Gist options
  • Save jlucaspains/c27e3be8d71804c5cc657ab3d0dab730 to your computer and use it in GitHub Desktop.
Save jlucaspains/c27e3be8d71804c5cc657ab3d0dab730 to your computer and use it in GitHub Desktop.
public void DoSomething()
{
// explicit access checking
// HasRead is an extension method for UserPrincipal class
if(User.HasRead("App.ResourceName")
{
// do something if user has read access to App.Resource1
}
}
// maybe some action decorator for asp.net web api or mvc
// by extending the authorize attribute, this method is never
// called if user doesn't have proper access
[ResourceAuthorize("App.ResourceName", Action.Read)]
public IEnumerable<Item> GetAllItems()
{
return new List<Item>();
}
// requires write permission
[ResourceAuthorize("App.ResourceName", Action.Write)]
public void SaveItem(Item item)
{
_uow.Save(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment