Esempio n. 1
0
        /// <summary>
        /// Inserts a list of <see cref="AccessRuleItem" />s to the specified <paramref name="item" />.
        /// </summary>
        /// <param name="objectType">The type of the shared object to be inserted.</param>
        /// <param name="objectId">The primary key for the shared object to be inserted.</param>
        /// <param name="rule">The ACEs (Access Control Entries) to insert.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ValidationResult> AddAccessRuleAsync(AccessObjectType objectType, int objectId, AccessRuleItem rule, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            if (await AccessRules.Where(objectType, objectId, rule.User?.Id).AnyAsync(cancellationToken))
            {
                return(ValidationResult.Failed("Duplicated ACE entry."));
            }
            AccessRules.Add(new SecurityAccessRule
            {
                ObjectType = objectType,
                ObjectId   = objectId,
                UserId     = rule.User?.Id,
                Permission = rule.Permission,
                Visibility = rule.Visibility
            });
            await SaveChangesAsync(cancellationToken);

            return(ValidationResult.Success);
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the rule.
        /// </summary>
        /// <param name="accessRule">The access rule.</param>
        public virtual void AddRule(IAccessRule accessRule)
        {
            if (AccessRules == null)
            {
                AccessRules = new List <AccessRule>();
            }

            AccessRules.Add((AccessRule)accessRule);
        }
Esempio n. 3
0
        private void GetAccessRules()
        {
            try
            {
                ActiveDirectorySecurity Sec = DirEntry.ObjectSecurity;
                foreach (ActiveDirectoryAccessRule ADRule in Sec.GetAccessRules(true, true, typeof(NTAccount)))
                {
                    ADCertificateTemplateAccessRule CurrRule = new ADCertificateTemplateAccessRule(ADRule);

                    if (AccessRules.FirstOrDefault(p => p.Identity.Matches(CurrRule.Identity)) == null)
                    {
                        AccessRules.Add(CurrRule);
                    }
                    else
                    {
                        AccessRules.ForEach(p => p.MergeIf(CurrRule));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new CertificateTemplateAccessRuleException(this, ex);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Add a new rule to the request
 /// </summary>
 /// <param name="rule">The rule to add to the request</param>
 public void AddRule(AccessRight rule)
 {
     AccessRules.Add(rule);
 }