public PermissionResultCollection InquirePermission(string permissionName, IIdentity userIdentity, IEnumerable <string> userRoles, object contextObject, Dictionary <string, object> contextProperties)
        {
            if (!_permissionRulesLookup.ContainsKey(permissionName))
            {
                return(new PermissionResultCollection());   // There are no know rules for the requested permission, therefore the permission CANNOT be granted
            }
            PermissionRuleContextCollection ruleContextCollection = _permissionRulesLookup[permissionName];
            List <Task <bool?> >            taskList = new List <Task <bool?> >();
            PermissionRuleContextCollection invocationContextCollection = new PermissionRuleContextCollection();

            foreach (PermissionRuleContext configurationContext in ruleContextCollection.Items)
            {
                PermissionRuleContext invocationContext = new PermissionRuleContext(configurationContext, contextObject, contextProperties);
                invocationContextCollection.Add(invocationContext);
                Task <bool?> ruleTask = _coreRules.TaskFromPermissionRuleContext(invocationContext, userIdentity, userRoles);
                ruleTask.Start();
                taskList.Add(ruleTask);
            }

            Task.WaitAll(taskList.ToArray());

            PermissionResultCollection results = new PermissionResultCollection();

            foreach (Task <bool?> ruleTask in taskList)
            {
                PermissionRuleContext invocationContext = invocationContextCollection[(Guid)ruleTask.AsyncState];
                if (invocationContext == null)
                {
                    throw new InvalidOperationException("An unexpected contition occurred while processing the permission rules. Could not identify the proper rule context.");
                }

                results.Add(new PermissionResult(ruleTask.Result, invocationContext.RuleName));
            }

            return(results);
        }
        public bool InquirePermission(string permissionName, IIdentity userIdentity, IEnumerable <string> userRoles)
        {
            PermissionResultCollection results = InquirePermission(permissionName, userIdentity, userRoles, null, null);

            return(results.IsAuthorized);
        }
        public bool DoAssertPermission(string permissionName, IIdentity userIdentity, IEnumerable <string> userRoles, object contextObject, Dictionary <string, object> contextProperties)
        {
            PermissionResultCollection permissionResults = InquirePermission(permissionName, userIdentity, userRoles, contextObject, contextProperties);

            return(permissionResults.IsAuthorized);
        }