/// <summary> // Evaluate current requirement against given user and typed resource. /// </summary> /// <param name="context">authorization data context</param> /// <param name="resource">resource object</param> /// <returns>true if allowed</returns> protected override bool Evaluate(AuthZyinContext <TData> context, TResource resource) { if (context?.Data == null) { throw new ArgumentNullException("JsonPath requirement needs the data to be set in context"); } if (resource == null) { throw new ArgumentNullException("JsonPath based requirement needs the resource object"); } var dataJObject = context.GetDataAsJObject(); var resourceJObj = resource.GetResourceAsJObject(); if (dataJObject == null || resourceJObj == null) { return(false); } // Create evluation context and delegate real evlauation to the evaluators var evaluatorContext = new EvaluatorContext( dataJObject, this.DataJPath, resourceJObj, this.ResourceJPath, this.Direction); return(EvaluatorMap[this.Operator].Evaluate(evaluatorContext)); }
public OrRequirementTest() { var policies = new List <(string name, AuthorizationPolicy policy)> { ("nullpolicy", null), }; var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity()); this.context = new AuthZyinContext <TestCustomData>(policies, claimsPrincipal); }
/// <summary> // Evaluate current requirement against given user and typed resource. /// </summary> /// <param name="context">authorization data context</param> /// <param name="resource">resource object</param> /// <returns>true if allowed</returns> protected override bool Evaluate(AuthZyinContext <TData> context, ValueWrapperResource <TValue> resource) { if (resource != null) { throw new InvalidOperationException("Unexpected resource passed to JsonPathConstantRequirement evaluation"); } // Call base and replace the resource with the dummy resource wrapping around the const value return(base.Evaluate(context, this.valueWrapperResource)); }
protected override bool Evaluate(AuthZyinContext <TestCustomData> context, T resource) { return(result); }