// Token: 0x06000B8C RID: 2956 RVA: 0x00024868 File Offset: 0x00022A68
        internal static ADObject GetRawRoleAssignee(RoleAssigneeIdParameter user, IConfigurationSession configSession, IRecipientSession recipientSession)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (recipientSession == null)
            {
                throw new ArgumentNullException("recipientSession");
            }
            if (configSession == null)
            {
                throw new ArgumentNullException("configSession");
            }
            IEnumerable <ADObject>       enumerable = user.GetObjects <RoleAssignmentPolicy>(null, configSession).Cast <ADObject>();
            EnumerableWrapper <ADObject> wrapper    = EnumerableWrapper <ADObject> .GetWrapper(enumerable);

            if (!wrapper.HasElements())
            {
                SecurityIdentifier securityIdentifier = SecurityPrincipalIdParameter.TryParseToSID(user.RawIdentity);
                if (null != securityIdentifier)
                {
                    ADRecipient adrecipient = recipientSession.FindBySid(securityIdentifier);
                    if (adrecipient != null)
                    {
                        enumerable = new ADObject[]
                        {
                            adrecipient
                        };
                        wrapper = EnumerableWrapper <ADObject> .GetWrapper(enumerable);
                    }
                }
                else
                {
                    enumerable = user.GetObjects <ADRecipient>(null, recipientSession).Cast <ADObject>();
                    wrapper    = EnumerableWrapper <ADObject> .GetWrapper(enumerable);
                }
            }
            ADObject result = null;

            using (IEnumerator <ADObject> enumerator = wrapper.GetEnumerator())
            {
                if (!enumerator.MoveNext())
                {
                    throw new ManagementObjectNotFoundException(Strings.ErrorPolicyUserOrSecurityGroupNotFound(user.ToString()));
                }
                result = enumerator.Current;
                if (enumerator.MoveNext())
                {
                    throw new ManagementObjectAmbiguousException(Strings.ErrorPolicyUserOrSecurityGroupNotUnique(user.ToString()));
                }
            }
            return(result);
        }
        public bool MoveNext()
        {
            if (this.mainEnum == null)
            {
                EnumerableWrapper <T> wrapper = EnumerableWrapper <T> .GetWrapper(this.conditionalEnumerable);

                if (wrapper.HasElements())
                {
                    this.mainEnum         = wrapper.GetEnumerator();
                    this.secondEnumerable = null;
                }
                else
                {
                    this.mainEnum = this.secondEnumerable.GetEnumerator();
                    this.conditionalEnumerable = null;
                }
            }
            return(this.mainEnum.MoveNext());
        }
        private static bool CollectionsAreEqual <T>(
            T actual,
            T expected)
        {
            var actualEnumerable = new EnumerableWrapper(actual);

            if (!actualEnumerable.IsValid)
            {
                return(false);
            }

            var expectedEnumerable = new EnumerableWrapper(expected);

            if (!expectedEnumerable.IsValid)
            {
                return(false);
            }

            var actualEnumerator   = actualEnumerable.GetEnumerator();
            var expectedEnumerator = expectedEnumerable.GetEnumerator();

            var actualHasNext   = actualEnumerator.MoveNext();
            var expectedHasNext = expectedEnumerator.MoveNext();

            while (actualHasNext && expectedHasNext)
            {
                if (!ValuesAreEqual(
                        actualEnumerator.Current,
                        expectedEnumerator.Current))
                {
                    return(false);
                }

                actualHasNext   = actualEnumerator.MoveNext();
                expectedHasNext = expectedEnumerator.MoveNext();
            }

            return(actualHasNext == expectedHasNext);
        }
Example #4
0
        // Token: 0x06000A29 RID: 2601 RVA: 0x00021A8C File Offset: 0x0001FC8C
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            IEnumerable <T> enumerable = null;
            List <T>        list       = new List <T>();

            notFoundReason = null;
            int num  = 0;
            int num2 = 0;

            if (base.InternalADObjectId != null)
            {
                enumerable = base.GetADObjectIdObjects <T>(base.InternalADObjectId, rootId, subTreeSession, optionalData);
            }
            EnumerableWrapper <T> wrapper = EnumerableWrapper <T> .GetWrapper(enumerable);

            if (wrapper.HasElements())
            {
                using (IEnumerator <T> enumerator = wrapper.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        T item = enumerator.Current;
                        if (ServerIdParameter.HasRole((ADObjectId)item.Identity, this.RoleRestriction, (IConfigDataProvider)session) || (this.AllowLegacy && !ServerIdParameter.HasRole((ADObjectId)item.Identity, ServerRole.All, (IConfigDataProvider)session)))
                        {
                            list.Add(item);
                        }
                        else if (!ServerIdParameter.HasRole((ADObjectId)item.Identity, ServerRole.All, (IConfigDataProvider)session))
                        {
                            num2++;
                        }
                        else
                        {
                            num++;
                        }
                    }
                    goto IL_21B;
                }
            }
            if (!string.IsNullOrEmpty(this.CommonName) && this.ServerId != null)
            {
                ADObjectId[] matchingIdentities = this.ServerId.GetMatchingIdentities((IConfigDataProvider)session);
                foreach (ADObjectId rootId2 in matchingIdentities)
                {
                    enumerable = base.GetObjectsInOrganization <T>(this.CommonName, rootId2, session, optionalData);
                    foreach (T item2 in enumerable)
                    {
                        if (ServerIdParameter.HasRole((ADObjectId)item2.Identity, this.RoleRestriction, (IConfigDataProvider)session) || (this.AllowLegacy && !ServerIdParameter.HasRole((ADObjectId)item2.Identity, ServerRole.All, (IConfigDataProvider)session)))
                        {
                            list.Add(item2);
                        }
                        else if (!ServerIdParameter.HasRole((ADObjectId)item2.Identity, ServerRole.All, (IConfigDataProvider)session))
                        {
                            num2++;
                        }
                        else
                        {
                            num++;
                        }
                    }
                }
            }
IL_21B:
            if (list.Count == 0)
            {
                if (num2 != 0)
                {
                    notFoundReason = new LocalizedString?(Strings.ExceptionLegacyObjects(this.ToString()));
                }
                if (num != 0)
                {
                    notFoundReason = new LocalizedString?(Strings.ExceptionRoleNotFoundObjects(this.ToString()));
                }
            }
            return(list);
        }