private ADObjectId ValidateUser(SecurityPrincipalIdParameter principalId) { if (principalId == null) { return(null); } IEnumerable <ADRecipient> objects = principalId.GetObjects <ADRecipient>(null, base.TenantGlobalCatalogSession); ADObjectId result; using (IEnumerator <ADRecipient> enumerator = objects.GetEnumerator()) { if (!enumerator.MoveNext()) { base.WriteError(new ManagementObjectNotFoundException(Strings.ErrorUserNotFound(principalId.ToString())), ErrorCategory.ObjectNotFound, null); } ADObjectId adobjectId = (ADObjectId)enumerator.Current.Identity; if (enumerator.MoveNext()) { base.WriteError(new ManagementObjectAmbiguousException(Strings.ErrorUserNotUnique(principalId.ToString())), ErrorCategory.InvalidData, null); } this.WriteWarning(Strings.AccountPrivilegeWarning); result = adobjectId; } return(result); }
public List <SecurityIdentifier> ConvertGuidsToSid(string[] rawGuids) { List <Guid> list = new List <Guid>(); foreach (string input in rawGuids) { Guid guid; if (!Guid.TryParse(input, out guid)) { throw new FaultException(string.Format("Guid {0} is invalid", guid)); } list.Add(guid); } if (list != null && list.Any <Guid>()) { IRecipientSession session = (IRecipientSession)this.CreateAdSession(); List <SecurityIdentifier> list2 = new List <SecurityIdentifier>(); foreach (Guid guid2 in list) { SecurityPrincipalIdParameter securityPrincipalIdParameter = new SecurityPrincipalIdParameter(guid2.ToString()); IEnumerable <ADRecipient> objects = securityPrincipalIdParameter.GetObjects <ADRecipient>(null, session); using (IEnumerator <ADRecipient> enumerator2 = objects.GetEnumerator()) { if (enumerator2.MoveNext()) { ADRecipient adrecipient = enumerator2.Current; list2.Add(adrecipient.MasterAccountSid ?? ((IADSecurityPrincipal)adrecipient).Sid); if (enumerator2.MoveNext()) { throw new Exception(Strings.ErrorUserNotUnique(guid2.ToString())); } } } } return(list2); } return(new List <SecurityIdentifier>()); }