| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Threading.Tasks; |
| | | 6 | | using CoreWCF.IdentityModel.Claims; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Primitives.Tests.CustomSecurity |
| | | 9 | | { |
| | | 10 | | public abstract class MyTestServiceAuthorizationManagerBase : ServiceAuthorizationManager |
| | | 11 | | { |
| | | 12 | | protected Func<OperationContext, bool> Logic = (OperationContext operationContext) => |
| | | 13 | | { |
| | | 14 | | // Extract the action URI from the OperationContext. Match this against the claims |
| | | 15 | | // in the AuthorizationContext. |
| | | 16 | | string action = operationContext.RequestContext.RequestMessage.Headers.Action; |
| | | 17 | | // Iterate through the various claim sets in the AuthorizationContext. |
| | | 18 | | bool isWIndowIdentity = false; |
| | | 19 | | foreach (ClaimSet cs in operationContext.ServiceSecurityContext.AuthorizationContext.ClaimSets) |
| | | 20 | | { |
| | | 21 | | // Examine only those claim sets issued by System. |
| | | 22 | | if (cs.Issuer == ClaimSet.System) |
| | | 23 | | { |
| | | 24 | | foreach (Claim c in cs.FindClaims("http://tempuri.org/claims/allowedoperation", |
| | | 25 | | Rights.PossessProperty)) |
| | | 26 | | { |
| | | 27 | | // If the Claim resource matches the action URI then return true to allow access. |
| | | 28 | | if (action == c.Resource.ToString()) |
| | | 29 | | { |
| | | 30 | | return true; |
| | | 31 | | } |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | else if (cs.Issuer == ClaimSet.Windows) |
| | | 35 | | { |
| | | 36 | | isWIndowIdentity = true; // unconditionally for windows |
| | | 37 | | } |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | // If this point is reached, return false to deny access. |
| | | 41 | | return isWIndowIdentity || false; |
| | | 42 | | }; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public class MySyncTestServiceAuthorizationManager : MyTestServiceAuthorizationManagerBase |
| | | 46 | | { |
| | | 47 | | [Obsolete("Implementers should override CheckAccessCoreAsync.")] |
| | 2 | 48 | | protected override bool CheckAccessCore(OperationContext operationContext) => Logic(operationContext); |
| | | 49 | | } |
| | | 50 | | |
| | | 51 | | public class MyAsyncTestServiceAuthorizationManager : MyTestServiceAuthorizationManagerBase |
| | | 52 | | { |
| | | 53 | | protected override ValueTask<bool> CheckAccessCoreAsync(OperationContext operationContext) => new(Logic(operatio |
| | | 54 | | } |
| | | 55 | | } |