public IEnumerable <AzRecord> GetAcesWithInherits(Guid subjectId, Guid actionId, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
        {
            if (objectId == null)
            {
                return(GetAces(subjectId, actionId, null));
            }

            var result = new List <AzRecord>();
            var aces   = service.GetAces(CoreContext.TenantManager.GetCurrentTenant().TenantId, default);

            result.AddRange(FilterAces(aces, subjectId, actionId, objectId));

            var inherits             = new List <AzRecord>();
            var secObjProviderHelper = new AzObjectSecurityProviderHelper(objectId, secObjProvider);

            while (secObjProviderHelper.NextInherit())
            {
                inherits.AddRange(FilterAces(aces, subjectId, actionId, secObjProviderHelper.CurrentObjectId));
            }

            inherits.AddRange(FilterAces(aces, subjectId, actionId, null));

            result.AddRange(DistinctAces(inherits));
            return(result);
        }
Exemplo n.º 2
0
        public IEnumerable <Ace> GetAcl(ISubject subject, IAction action, ISecurityObjectId objectId, ISecurityObjectProvider secObjProvider)
        {
            if (subject == null)
            {
                throw new ArgumentNullException("subject");
            }
            if (action == null)
            {
                throw new ArgumentNullException("action");
            }
            if (objectId == null)
            {
                throw new ArgumentNullException("objectId");
            }

            var allAces      = new List <Ace>();
            var fullObjectId = AzObjectIdHelper.GetFullObjectId(objectId);

            allAces.AddRange(GetAcl(subject, action, fullObjectId));

            bool inherit = GetObjectAcesInheritance(objectId);

            if (inherit)
            {
                var providerHelper = new AzObjectSecurityProviderHelper(objectId, secObjProvider);
                while (providerHelper.NextInherit())
                {
                    allAces.AddRange(GetAcl(subject, action, AzObjectIdHelper.GetFullObjectId(providerHelper.CurrentObjectId)));
                }
                allAces.AddRange(GetAcl(subject, action));
            }

            var aces    = new List <Ace>();
            var aclKeys = new List <string>();

            foreach (var ace in allAces)
            {
                var key = string.Format("{0}{1:D}", ace.ActionId, ace.Reaction);
                if (!aclKeys.Contains(key))
                {
                    aces.Add(ace);
                    aclKeys.Add(key);
                }
            }

            return(aces);
        }