// Token: 0x06000DED RID: 3565 RVA: 0x00029C98 File Offset: 0x00027E98
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            notFoundReason = new LocalizedString?(LocalizedString.Empty);
            EnumerableWrapper <T> enumerableWrapper = EnumerableWrapper <T> .Empty;
            SecurityIdentifier    sid     = SecurityPrincipalIdParameter.TryParseToSID(base.RawIdentity);
            string userAccountNameFromSid = SecurityPrincipalIdParameter.GetUserAccountNameFromSid(sid, this.ToString(), null);

            if (!string.IsNullOrEmpty(userAccountNameFromSid))
            {
                enumerableWrapper = base.GetEnumerableWrapper <T>(enumerableWrapper, base.GetObjectsByAccountName <T>(userAccountNameFromSid, rootId, (IRecipientSession)session, optionalData));
                if (enumerableWrapper.HasElements())
                {
                    return(enumerableWrapper);
                }
            }
            enumerableWrapper = base.GetEnumerableWrapper <T>(enumerableWrapper, base.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason));
            if (enumerableWrapper.HasElements())
            {
                return(enumerableWrapper);
            }
            sid = SecurityPrincipalIdParameter.GetUserSidAsSAMAccount(this, null, null);
            userAccountNameFromSid = SecurityPrincipalIdParameter.GetUserAccountNameFromSid(sid, this.ToString(), null);
            if (!string.IsNullOrEmpty(userAccountNameFromSid))
            {
                enumerableWrapper = base.GetEnumerableWrapper <T>(EnumerableWrapper <T> .Empty, base.GetObjectsByAccountName <T>(userAccountNameFromSid, rootId, (IRecipientSession)session, optionalData));
            }
            return(enumerableWrapper);
        }
        // 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);
        }
        // Token: 0x06000DE8 RID: 3560 RVA: 0x000298FC File Offset: 0x00027AFC
        public override string ToString()
        {
            string text  = SecurityPrincipalIdParameter.MapSidToAlias(base.RawIdentity);
            string text2 = (!string.IsNullOrEmpty(text)) ? text : base.ToString();

            if (this.ReturnUrlTokenEncodedString && text2 != null)
            {
                text2 = UrlTokenConverter.UrlTokenEncode(text2);
            }
            return(text2);
        }
        // Token: 0x06000DF7 RID: 3575 RVA: 0x00029FF0 File Offset: 0x000281F0
        private IEnumerable <T> GetUserAccountFromSid <T>(SecurityIdentifier sid, string user, Task.TaskErrorLoggingDelegate logError, ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason) where T : IConfigurable, new()
        {
            notFoundReason = null;
            string userAccountNameFromSid = SecurityPrincipalIdParameter.GetUserAccountNameFromSid(sid, user, logError);

            if (!string.IsNullOrEmpty(userAccountNameFromSid))
            {
                SecurityPrincipalIdParameter securityPrincipalIdParameter = this.CreateSidParameter(userAccountNameFromSid);
                return(securityPrincipalIdParameter.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason));
            }
            return(null);
        }
        // Token: 0x06000DEA RID: 3562 RVA: 0x00029A2C File Offset: 0x00027C2C
        internal static IADSecurityPrincipal GetSecurityPrincipal(IRecipientSession session, SecurityPrincipalIdParameter user, Task.TaskErrorLoggingDelegate logError, Task.TaskVerboseLoggingDelegate logVerbose)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            if (logError == null)
            {
                throw new ArgumentNullException("logError");
            }
            if (logVerbose == null)
            {
                throw new ArgumentNullException("logVerbose");
            }
            ADRecipient adrecipient = null;

            logVerbose(Strings.CheckIfUserIsASID(user.ToString()));
            SecurityIdentifier securityIdentifier = SecurityPrincipalIdParameter.TryParseToSID(user.RawIdentity);

            if (null == securityIdentifier)
            {
                securityIdentifier = SecurityPrincipalIdParameter.GetUserSidAsSAMAccount(user, logError, logVerbose);
            }
            IEnumerable <ADRecipient> objects = user.GetObjects <ADRecipient>(null, session);

            foreach (ADRecipient adrecipient2 in objects)
            {
                if (adrecipient == null)
                {
                    adrecipient = adrecipient2;
                }
                else
                {
                    logError(new ManagementObjectAmbiguousException(Strings.ErrorUserNotUnique(user.ToString())), ErrorCategory.InvalidData, null);
                }
            }
            if (adrecipient == null && null != securityIdentifier)
            {
                adrecipient = new ADUser();
                adrecipient.propertyBag.SetField(IADSecurityPrincipalSchema.Sid, securityIdentifier);
            }
            if (adrecipient == null)
            {
                logError(new ManagementObjectNotFoundException(Strings.ErrorUserNotFound(user.ToString())), ErrorCategory.InvalidData, null);
            }
            return((IADSecurityPrincipal)adrecipient);
        }
        // Token: 0x06000DEB RID: 3563 RVA: 0x00029B48 File Offset: 0x00027D48
        internal static SecurityIdentifier GetUserSid(IRecipientSession session, SecurityPrincipalIdParameter user, Task.TaskErrorLoggingDelegate logError, Task.TaskVerboseLoggingDelegate logVerbose)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (logError == null)
            {
                throw new ArgumentNullException("logError");
            }
            if (logVerbose == null)
            {
                throw new ArgumentNullException("logVerbose");
            }
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }
            logVerbose(Strings.CheckIfUserIsASID(user.ToString()));
            SecurityIdentifier securityIdentifier = SecurityPrincipalIdParameter.TryParseToSID(user.RawIdentity);

            if (null != securityIdentifier)
            {
                return(securityIdentifier);
            }
            logVerbose(Strings.LookupUserAsDomainUser(user.ToString()));
            IEnumerable <ADRecipient> objects = user.GetObjects <ADRecipient>(null, session);

            using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    securityIdentifier = ((IADSecurityPrincipal)enumerator.Current).Sid;
                    if (enumerator.MoveNext())
                    {
                        logError(new ManagementObjectAmbiguousException(Strings.ErrorUserNotUnique(user.ToString())), ErrorCategory.InvalidData, null);
                    }
                    return(securityIdentifier);
                }
            }
            securityIdentifier = SecurityPrincipalIdParameter.GetUserSidAsSAMAccount(user, logError, logVerbose);
            if (null == securityIdentifier)
            {
                logError(new ManagementObjectNotFoundException(Strings.ErrorUserNotFound(user.ToString())), ErrorCategory.InvalidData, null);
            }
            return(securityIdentifier);
        }
Beispiel #7
0
        internal override IEnumerable <T> GetObjects <T>(ADObjectId rootId, IDirectorySession session, IDirectorySession subTreeSession, OptionalIdentityData optionalData, out LocalizedString?notFoundReason)
        {
            EnumerableWrapper <T> wrapper = EnumerableWrapper <T> .GetWrapper(base.GetObjects <T>(rootId, session, subTreeSession, optionalData, out notFoundReason));

            if (wrapper.HasElements())
            {
                return(wrapper);
            }
            SecurityPrincipalIdParameter securityPrincipalIdParameter = new SecurityPrincipalIdParameter(base.RawIdentity);
            OptionalIdentityData         optionalIdentityData         = (optionalData == null) ? new OptionalIdentityData() : optionalData.Clone();

            optionalIdentityData.AdditionalFilter = QueryFilter.AndTogether(new QueryFilter[]
            {
                optionalIdentityData.AdditionalFilter,
                RecipientIdParameter.GetRecipientTypeFilter(this.RecipientTypes)
            });
            return(securityPrincipalIdParameter.GetObjects <T>(rootId, session, subTreeSession, optionalIdentityData, out notFoundReason));
        }
        // Token: 0x06000DF0 RID: 3568 RVA: 0x00029D70 File Offset: 0x00027F70
        internal static SecurityIdentifier GetUserSidAsSAMAccount(SecurityPrincipalIdParameter user, Task.TaskErrorLoggingDelegate logError, Task.TaskVerboseLoggingDelegate logVerbose)
        {
            SecurityIdentifier securityIdentifier = null;

            if (logVerbose != null)
            {
                logVerbose(Strings.LookupUserAsSAMAccount(user.ToString()));
            }
            NTAccount ntaccount;

            try
            {
                ntaccount = new NTAccount(user.RawIdentity);
            }
            catch (ArgumentException)
            {
                if (logVerbose != null)
                {
                    logVerbose(Strings.UserNotSAMAccount(user.ToString()));
                }
                return(null);
            }
            try
            {
                securityIdentifier = (SecurityIdentifier)ntaccount.Translate(typeof(SecurityIdentifier));
            }
            catch (IdentityNotMappedException)
            {
            }
            catch (SystemException innerException)
            {
                if (logError != null)
                {
                    logError(new LocalizedException(Strings.ForeignForestTrustFailedException(user.ToString()), innerException), ErrorCategory.InvalidOperation, null);
                }
                return(null);
            }
            if (securityIdentifier == null)
            {
                securityIdentifier = SecurityPrincipalIdParameter.MapAliasToSid(user.RawIdentity);
            }
            return(securityIdentifier);
        }
 // Token: 0x06000DDF RID: 3551 RVA: 0x000297B4 File Offset: 0x000279B4
 public SecurityPrincipalIdParameter(SecurityIdentifier sid) : this(SecurityPrincipalIdParameter.GetFriendlyUserName(sid, null))
 {
     this.securityIdentifier = sid;
 }