Convert Declaractive PrincipalPermission to Programmatic.Demand

I currently have two roles:

[PrincipalPermission (SecurityAction.Demand, Role = "Domain \ AnotherRole")] [PrincipalPermission (SecurityAction.Demand, Role = "Domain \ AnotherRole")]

The problem is that this legacy code is domain specific, and I want to ultimately get the roles from the web.config file, so I can work on a virtual machine outside the domain.

I saw an example like this:

PrincipalPermission permCheck = new PrincipalPermission(
                                     null, 
                                     @"Domain\Admin"); 
permCheck.Demand();

Since this throws an exception if the user is not in the role, how to modify this example to allow either of the two roles? I could use several IPrincipal.IsInRole () and then throw my own exception, but there seems to be a way to use the .Demand method with multiple roles.

12/21: Ladislav :

PrincipalPermission ppAdmin = new PrincipalPermission(null, @"Domain\Admin");
PrincipalPermission ppAnother = new PrincipalPermission(null, @"Domain\AnotherRole");
(ppAdmin.Union(ppAnother)).Demand();

AzMan ( , ).

+3
1

PrincipalPermission Union . PrincipalPermissions Demand. (AzMan) (AuthorizationStoreRoleProvider). MMC.

+2

Source: https://habr.com/ru/post/1781358/


All Articles