public virtual bool AssertAll <TResource>(LinkCondition <TResource> condition)
 {
     if (condition == null)
     {
         throw new ArgumentNullException(nameof(condition));
     }
     return(!condition.Assertions.Any() || condition.Assertions.All(a => a((TResource)this.Resource)));
 }
Beispiel #2
0
        public static LinksPolicyBuilder <TResource> RequireRoutedLink <TResource>(this LinksPolicyBuilder <TResource> builder,
                                                                                   string id,
                                                                                   string routeName,
                                                                                   Func <TResource, object> getValues,
                                                                                   LinkCondition <TResource> condition = null)
        {
            Func <TResource, RouteValueDictionary> getRouteValues = r => new RouteValueDictionary();

            if (getValues != null)
            {
                getRouteValues = r => new RouteValueDictionary(getValues(r));
            }
            var req = new RouteLinkRequirement <TResource>()
            {
                Id             = id,
                RouteName      = routeName,
                GetRouteValues = getRouteValues,
                Condition      = condition ?? LinkCondition <TResource> .None
            };

            return(builder.Requires(req));
        }
Beispiel #3
0
        private static LinksPolicyBuilder <TResource> RequiresPagingLinks <TResource>(this LinksPolicyBuilder <TResource> builder,
                                                                                      string currentId,
                                                                                      string nextId,
                                                                                      string previousId,
                                                                                      LinkCondition <TResource> condition)
        {
            var req = new PagingLinksRequirement <TResource>()
            {
                CurrentId  = currentId,
                NextId     = nextId,
                PreviousId = previousId,
                Condition  = condition ?? LinkCondition <TResource> .None
            };

            return(builder.Requires(req));
        }
        public virtual async Task <bool> AuthorizeAsync <TResource>(RouteInfo route, RouteValueDictionary values, LinkCondition <TResource> condition)
        {
            if (route == null)
            {
                throw new ArgumentNullException(nameof(route));
            }
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            if (condition == null)
            {
                throw new ArgumentNullException(nameof(condition));
            }

            var authContext = new LinkAuthorizationContext <TResource>(
                condition.RequiresRouteAuthorization,
                condition.AuthorizationRequirements,
                condition.AuthorizationPolicyNames,
                route,
                values,
                (TResource)this.Resource,
                this.User);

            return(await authService.AuthorizeLink(authContext));
        }