C # /. NET has built-in functions for resolution.
Requirements for access to the function are set through the PrincipalPermissionAttribute class or inside the code using PrincipalPermission . To prevent a method call if the current user is not a member of the Administrators role, the following attribute is used (sample from MSDN ):
[PrincipalPermission(SecurityAction.Demand, Role = "Administrators")] static void CheckAdministrator() { Console.WriteLine("User is an administrator"); }
Both of these checks correspond to the current identifier of the calling thread. So, you need to implement the IPrincipal interface IPrincipal that your users can be set as a stream identifier. You can then use the standard .NET PrincipalPermission to verify security. It works exactly the way you want - if the security requirement is not met, an exception is thrown.
source share