protected void EnsureGroupMailboxData(StoreSession session)
        {
            this.ClearExpiredCacheData();
            if (this.groupsCache.ContainsKey(session.MailboxGuid))
            {
                return;
            }
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.IgnoreInvalid, session.GetADSessionSettings(), 466, "EnsureGroupMailboxData", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\WorkingSet\\Publisher\\WorkingSetPublisher.cs");
            ADUser            adUser;

            if (session.MailboxOwner.ObjectId != null)
            {
                adUser = tenantOrRootOrgRecipientSession.FindADUserByObjectId(session.MailboxOwner.ObjectId);
            }
            else
            {
                adUser = (tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(session.MailboxOwner.LegacyDn) as ADUser);
            }
            WorkingSetPublisher.GroupMailboxData groupMailboxData = new WorkingSetPublisher.GroupMailboxData
            {
                TargetUsers = this.CalculateTargetUsers(adUser, tenantOrRootOrgRecipientSession, session),
                TimeStamp   = DateTime.UtcNow
            };
            if (groupMailboxData.TargetUsers.Count > WorkingSetPublisherConfiguration.MaxTargetUsersToCachePerModernGroup)
            {
                groupMailboxData.TimeStamp -= WorkingSetPublisherConfiguration.ModernGroupsDataExpiryTime;
            }
            this.groupsCache[session.MailboxGuid] = groupMailboxData;
        }
Example #2
0
        internal NspiPrincipal NspiPrincipalFromLegacyDN(string legacyDN)
        {
            ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(this.nspiPrincipal.OrganizationId);
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, this.nspiPrincipal.DirectorySearchRoot, CultureInfo.CurrentCulture.LCID, true, ConsistencyMode.IgnoreInvalid, null, sessionSettings, 584, "NspiPrincipalFromLegacyDN", "f:\\15.00.1497\\sources\\dev\\DoMT\\src\\Service\\RfriContext.cs");

            tenantOrRootOrgRecipientSession.ServerTimeout = Configuration.ADTimeout;
            try
            {
                ADUser aduser = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(legacyDN) as ADUser;
                if (aduser != null && !(bool)aduser[ADRecipientSchema.HiddenFromAddressListsValue])
                {
                    return(NspiPrincipal.FromADUser(aduser));
                }
            }
            catch (NonUniqueRecipientException)
            {
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "NonUniqueRecipientException thrown for {0}", legacyDN);
            }
            catch (ObjectNotFoundException)
            {
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "ObjectNotFoundException thrown: Couldn't find requested user  for {0}", legacyDN);
            }
            catch (MailboxInfoStaleException)
            {
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "MailboxInfoStaleException thrown for {0}", legacyDN);
            }
            catch (CannotGetSiteInfoException)
            {
                RfriContext.ReferralTracer.TraceDebug <string>((long)this.ContextHandle, "CannotGetSiteInfoException thrown for {0}", legacyDN);
            }
            return(null);
        }
        public IGenericADUser FindByLegacyExchangeDn(IRecipientSession recipientSession, string legacyExchangeDn)
        {
            ArgumentValidator.ThrowIfNull("recipientSession", recipientSession);
            IGenericADUser adUser = null;

            this.DoAdCallAndTranslateExceptions(delegate
            {
                adUser = this.TranslateADRecipient(recipientSession.FindByLegacyExchangeDN(legacyExchangeDn), false);
            }, "DirectoryAccessor::FindByLegacyExchangeDn");
            return(adUser);
        }
        // Token: 0x0600256D RID: 9581 RVA: 0x000D89FC File Offset: 0x000D6BFC
        internal override void RenderContents(TextWriter writer, UserContext userContext, RecipientWellType type, RecipientWellNode.RenderFlags flags, RenderRecipientWellNode wellNode)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            if (!this.HasRecipients(type))
            {
                return;
            }
            RecipientWellNode.RenderFlags renderFlags = flags & ~RecipientWellNode.RenderFlags.RenderCommas;
            bool   flag        = true;
            string smtpAddress = null;
            string alias       = null;
            int    num         = 0;
            MultiValuedProperty <string> addressList      = this.GetAddressList(type);
            IRecipientSession            recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext);

            foreach (string text in addressList)
            {
                ADObjectId  adObjectId  = null;
                ADRecipient adrecipient = recipientSession.FindByLegacyExchangeDN(text);
                bool        flag2       = (flags & RecipientWellNode.RenderFlags.ReadOnly) != RecipientWellNode.RenderFlags.None;
                if (adrecipient != null)
                {
                    adObjectId  = adrecipient.Id;
                    smtpAddress = adrecipient.PrimarySmtpAddress.ToString();
                    if (flag2)
                    {
                        alias = adrecipient.Alias;
                    }
                    if (adrecipient is IADDistributionList)
                    {
                        num |= 1;
                    }
                    if (DirectoryAssistance.IsADRecipientRoom(adrecipient))
                    {
                        num |= 2;
                    }
                }
                if (wellNode(writer, userContext, (adrecipient != null) ? adrecipient.DisplayName : text.ToString(), smtpAddress, (adrecipient != null) ? adrecipient.LegacyExchangeDN : text.ToString(), "EX", alias, (adrecipient != null) ? AddressOrigin.Directory : AddressOrigin.Unknown, num, null, EmailAddressIndex.None, adObjectId, renderFlags, null, null) && flag)
                {
                    flag = false;
                    if ((flags & RecipientWellNode.RenderFlags.RenderCommas) != RecipientWellNode.RenderFlags.None)
                    {
                        renderFlags |= RecipientWellNode.RenderFlags.RenderCommas;
                    }
                }
            }
        }
Example #5
0
        private static object GetObjectFromLegacyDN(string legacyDN, PropertyDefinition propDef)
        {
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(Command.CurrentOrganizationId), 84, "GetObjectFromLegacyDN", "f:\\15.00.1497\\sources\\dev\\AirSync\\src\\AirSync\\SchemaConverter\\XSO\\XsoManagerProperty.cs");
            ADRecipient       adrecipient = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(legacyDN);

            Command.CurrentCommand.Context.ProtocolLogger.SetValue(ProtocolLoggerData.DomainController, tenantOrRootOrgRecipientSession.LastUsedDc);
            if (adrecipient == null)
            {
                return(null);
            }
            return(adrecipient[propDef]);
        }
        protected virtual bool IsUserFlighted(IRecipientSession adSession, string userLegDn)
        {
            ADRecipient adrecipient = adSession.FindByLegacyExchangeDN(userLegDn);
            ADUser      aduser      = adrecipient as ADUser;

            if (adrecipient == null || aduser == null)
            {
                return(false);
            }
            VariantConfigurationSnapshot snapshot = VariantConfiguration.GetSnapshot(aduser.GetContext(null), null, null);

            return(snapshot.OwaClientServer.ModernGroupsWorkingSet.Enabled);
        }
        protected override void WriteResult(IConfigurable dataObject)
        {
            TaskLogger.LogEnter();
            UMAutoAttendant umautoAttendant = dataObject as UMAutoAttendant;

            if (umautoAttendant != null && !string.IsNullOrEmpty(umautoAttendant.DefaultMailboxLegacyDN))
            {
                IRecipientSession recipientSessionScopedToOrganization = Utility.GetRecipientSessionScopedToOrganization(umautoAttendant.OrganizationId, true);
                umautoAttendant.DefaultMailbox = (recipientSessionScopedToOrganization.FindByLegacyExchangeDN(umautoAttendant.DefaultMailboxLegacyDN) as ADUser);
            }
            base.WriteResult(dataObject);
            TaskLogger.LogExit();
        }
 // Token: 0x06000BCE RID: 3022 RVA: 0x0004DF24 File Offset: 0x0004C124
 internal static bool InRole(IRecipientSession rs, ADRecipient recipient, MultiValuedProperty <string> roleMembersLegDN, MultiValuedProperty <ADObjectId> roleMemberslegacy)
 {
     if (recipient == null)
     {
         return(false);
     }
     if (roleMemberslegacy == null && roleMembersLegDN == null)
     {
         return(false);
     }
     if (roleMembersLegDN != null && roleMembersLegDN.Count != 0)
     {
         foreach (string text in roleMembersLegDN)
         {
             if (string.Equals(text, recipient.LegacyExchangeDN, StringComparison.InvariantCultureIgnoreCase))
             {
                 return(true);
             }
             ADRecipient adrecipient = rs.FindByLegacyExchangeDN(text);
             if (adrecipient != null && adrecipient is ADGroup && recipient.IsMemberOf(adrecipient.Id, false))
             {
                 BookingPolicy.Tracer.TraceDebug((long)recipient.GetHashCode(), "{0}: Group match", new object[]
                 {
                     TraceContext.Get()
                 });
                 return(true);
             }
         }
     }
     if (roleMemberslegacy != null && roleMemberslegacy.Count != 0)
     {
         foreach (ADObjectId adobjectId in roleMemberslegacy)
         {
             if (ADObjectId.Equals(adobjectId, recipient.Id))
             {
                 return(true);
             }
             ADRecipient adrecipient2 = rs.Read(adobjectId);
             if (adrecipient2 != null && adrecipient2 is ADGroup && recipient.IsMemberOf(adrecipient2.Id, false))
             {
                 BookingPolicy.Tracer.TraceDebug((long)recipient.GetHashCode(), "{0}: Group match", new object[]
                 {
                     TraceContext.Get()
                 });
                 return(true);
             }
         }
     }
     return(false);
 }
Example #9
0
        private static ADUser GetAdUser(IRecipientSession recipientSession, string scope, bool throwIfNotFound)
        {
            LegacyDN legacyDN;
            ADUser   aduser;

            if (LegacyDN.TryParse(scope, out legacyDN))
            {
                aduser = (recipientSession.FindByLegacyExchangeDN(scope) as ADUser);
            }
            else
            {
                aduser = recipientSession.FindADUserByExternalDirectoryObjectId(scope);
            }
            if (aduser == null && throwIfNotFound)
            {
                throw new ComplianceTaskPermanentException("Recipient not found: " + scope, UnifiedPolicyErrorCode.FailedToOpenContainer);
            }
            return(aduser);
        }
Example #10
0
        private ADObjectId FindUserObjectId()
        {
            ADRecipient       adrecipient      = null;
            IRecipientSession recipientSession = AccessingUserInfo.GetRecipientSession(this.organizationId);

            ArgumentValidator.ThrowIfNull("recipientSession", recipientSession);
            if (this.LegacyExchangeDN != null)
            {
                adrecipient = recipientSession.FindByLegacyExchangeDN(this.LegacyExchangeDN);
            }
            else if (this.ExternalDirectoryObjectId != null)
            {
                adrecipient = recipientSession.FindADUserByExternalDirectoryObjectId(this.ExternalDirectoryObjectId);
            }
            if (adrecipient == null)
            {
                return(null);
            }
            return(adrecipient.Id);
        }
 internal MailboxSearchObject(MailboxDiscoverySearch discoverySearch, OrganizationId orgId)
 {
     if (discoverySearch == null)
     {
         throw new ArgumentNullException("discoverySearch");
     }
     this.discoverySearch = discoverySearch;
     if (orgId != null)
     {
         ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopes(ADSystemConfigurationSession.GetRootOrgContainerIdForLocalForest(), orgId, null, false);
         IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.PartiallyConsistent, sessionSettings, 791, ".ctor", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxSearchObject.cs");
         if (this.discoverySearch.Sources != null && this.discoverySearch.Sources.Count > 0)
         {
             if (VariantConfiguration.InvariantNoFlightingSnapshot.Global.MultiTenancy.Enabled)
             {
                 tenantOrRootOrgRecipientSession.SessionSettings.IncludeInactiveMailbox = true;
             }
             Result <ADRawEntry>[] array = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDNs(this.discoverySearch.Sources.ToArray(), null);
             if (array != null && array.Length > 0)
             {
                 this.sourceMailboxes = new MultiValuedProperty <ADObjectId>();
                 for (int i = 0; i < array.Length; i++)
                 {
                     if (array[i].Data != null)
                     {
                         this.sourceMailboxes.Add(array[i].Data.Id);
                     }
                 }
             }
         }
         if (!string.IsNullOrEmpty(this.discoverySearch.Target))
         {
             tenantOrRootOrgRecipientSession.SessionSettings.IncludeInactiveMailbox = false;
             ADRawEntry adrawEntry = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(this.discoverySearch.Target);
             if (adrawEntry != null)
             {
                 this.targetMailbox = adrawEntry.Id;
             }
         }
     }
 }
Example #12
0
        // Token: 0x0600015E RID: 350 RVA: 0x00006CCC File Offset: 0x00004ECC
        private ADSystemAttendantMailbox GetSystemAttendant()
        {
            string            text = LocalServer.GetServer().ExchangeLegacyDN + "/cn=Microsoft System Attendant";
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(ConsistencyMode.IgnoreInvalid, ADSessionSettings.FromRootOrgScopeSet(), 571, "GetSystemAttendant", "f:\\15.00.1497\\sources\\dev\\assistants\\src\\Assistants\\DatabaseInfo.cs");
            ADRecipient       adrecipient = null;

            try
            {
                adrecipient = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(text);
            }
            catch (DataValidationException arg)
            {
                ExTraceGlobals.DatabaseInfoTracer.TraceError <DataValidationException>((long)this.GetHashCode(), "{0}: Invalid system attendant mailbox: {1}", arg);
            }
            if (adrecipient == null || !(adrecipient is ADSystemAttendantMailbox))
            {
                ExTraceGlobals.DatabaseInfoTracer.TraceError <DatabaseInfo, string>((long)this.GetHashCode(), "{0}: Unable to find valid SA mailbox with legDN: {1}", this, text);
                return(null);
            }
            return((ADSystemAttendantMailbox)adrecipient);
        }
Example #13
0
        // Token: 0x06000A61 RID: 2657 RVA: 0x0004438C File Offset: 0x0004258C
        internal static ADRecipient GetADRecipient(Guid tenantGuid, string userLegacyDN)
        {
            ADSessionSettings sessionSettings = (tenantGuid == Guid.Empty) ? ADSessionSettings.FromRootOrgScopeSet() : ADSessionSettings.FromExternalDirectoryOrganizationId(tenantGuid);
            IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(true, ConsistencyMode.PartiallyConsistent, sessionSettings, 48, "GetADRecipient", "f:\\15.00.1497\\sources\\dev\\MailboxAssistants\\src\\assistants\\CalendarNotification\\Utils.cs");
            ADRecipient       result = null;

            try
            {
                result = tenantOrRootOrgRecipientSession.FindByLegacyExchangeDN(userLegacyDN);
            }
            catch (NonUniqueRecipientException)
            {
                Utils.Tracer.TraceError <string>((long)typeof(MailboxData).GetHashCode(), "User {0} AD object is not unique", userLegacyDN);
            }
            catch (ADTransientException)
            {
                Utils.Tracer.TraceError <string>((long)typeof(MailboxData).GetHashCode(), "Due to ADTransientException we can't get AD object for User {0} ", userLegacyDN);
            }
            catch (ADOperationException)
            {
                Utils.Tracer.TraceError <string>((long)typeof(MailboxData).GetHashCode(), "Due to ADOperationException we can't get AD object for User {0} ", userLegacyDN);
            }
            return(result);
        }
Example #14
0
        // Token: 0x06000B30 RID: 2864 RVA: 0x0004F208 File Offset: 0x0004D408
        public static void GetItemIMInfo(OwaStoreObjectId itemId, bool getNormalizedSubject, UserContext userContext, out string displayName, out string emailAddress, out string sipUri, out string subject)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException("itemId");
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            PropertyDefinition[] prefetchProperties = new PropertyDefinition[]
            {
                MessageItemSchema.SenderDisplayName,
                getNormalizedSubject ? ItemSchema.NormalizedSubject : ItemSchema.Subject,
                MessageItemSchema.SenderEmailAddress,
                MessageItemSchema.SenderAddressType
            };
            sipUri = string.Empty;
            using (Item item = Utilities.GetItem <Item>(userContext, itemId, prefetchProperties))
            {
                string text = string.Empty;
                object obj  = item.TryGetProperty(MessageItemSchema.SenderAddressType);
                if (!(obj is PropertyError))
                {
                    text = (string)obj;
                }
                emailAddress = string.Empty;
                obj          = item.TryGetProperty(MessageItemSchema.SenderEmailAddress);
                if (!(obj is PropertyError))
                {
                    emailAddress = (string)obj;
                }
                if (!string.IsNullOrEmpty(text) && !string.IsNullOrEmpty(emailAddress))
                {
                    if (string.CompareOrdinal(text, "EX") == 0)
                    {
                        try
                        {
                            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext);
                            ADRecipient       adrecipient      = recipientSession.FindByLegacyExchangeDN(emailAddress);
                            if (adrecipient != null)
                            {
                                sipUri = InstantMessageUtilities.GetSipUri(adrecipient);
                            }
                            goto IL_12E;
                        }
                        catch (NonUniqueRecipientException ex)
                        {
                            ExTraceGlobals.InstantMessagingTracer.TraceDebug <string>(0L, "IntantMessageUtilities.GetItemIMInfo: NonUniqueRecipientException was thrown by User: {0}", ex.Message);
                            goto IL_12E;
                        }
                    }
                    if (string.CompareOrdinal(text, "SMTP") == 0 && emailAddress != null)
                    {
                        sipUri = ContactUtilities.GetContactRecipientIMAddress(emailAddress, userContext, true);
                    }
                }
IL_12E:
                subject = string.Empty;
                obj     = item.TryGetProperty(getNormalizedSubject ? ItemSchema.NormalizedSubject : ItemSchema.Subject);
                if (!(obj is PropertyError))
                {
                    subject = (string)obj;
                }
                displayName = string.Empty;
                obj         = item.TryGetProperty(MessageItemSchema.SenderDisplayName);
                if (!(obj is PropertyError))
                {
                    displayName = (string)obj;
                }
            }
        }
Example #15
0
        private void LoadFrom(MapiAclTableAdapter mapiAclTableAdapter)
        {
            IRecipientSession      recipientSession = null;
            ExternalUserCollection disposable       = null;

            AclTableEntry[] all = mapiAclTableAdapter.GetAll();
            try
            {
                foreach (AclTableEntry aclTableEntry in all)
                {
                    long         memberId      = aclTableEntry.MemberId;
                    byte[]       memberEntryId = aclTableEntry.MemberEntryId;
                    string       memberName    = aclTableEntry.MemberName;
                    MemberRights memberRights  = aclTableEntry.MemberRights;
                    if (memberId == 0L)
                    {
                        this.defaultMemberPermission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Default), memberRights, memberId);
                    }
                    else if (memberId == -1L)
                    {
                        this.anonymousMemberPermission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(PermissionSecurityPrincipal.SpecialPrincipalType.Anonymous), memberRights, memberId);
                    }
                    else if (memberEntryId != null)
                    {
                        ADParticipantEntryId adparticipantEntryId = mapiAclTableAdapter.TryGetParticipantEntryId(memberEntryId);
                        if (adparticipantEntryId != null)
                        {
                            if (recipientSession == null)
                            {
                                recipientSession = mapiAclTableAdapter.Session.GetADRecipientSession(true, ConsistencyMode.IgnoreInvalid);
                            }
                            ADRecipient adrecipient = null;
                            try
                            {
                                adrecipient = recipientSession.FindByLegacyExchangeDN(adparticipantEntryId.LegacyDN);
                            }
                            catch (DataValidationException)
                            {
                                ExTraceGlobals.StorageTracer.TraceDebug <string, string>(0L, "PermissionTable::PermissionTable. Caught exception from ADSesssion.FindByLegacyExchangeDN when trying to find a recipient from the ACL Table. Recipient name = {0}, LegDN = {1}.", memberName, adparticipantEntryId.LegacyDN);
                                this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights);
                                goto IL_17E;
                            }
                            if (adrecipient != null)
                            {
                                Permission permission = this.permissionSet.CreatePermission(new PermissionSecurityPrincipal(adrecipient), memberRights, memberId);
                                this.AddPermissionEntry(permission.Principal, permission);
                            }
                            else
                            {
                                ExTraceGlobals.StorageTracer.TraceDebug <string, string>(0L, "PermissionTable::PermissionTable. Did not find the recipient from the ACL table in the AD. Recipient name = {0}, LegDN = {1}.", memberName, adparticipantEntryId.LegacyDN);
                                this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights);
                            }
                        }
                        else
                        {
                            this.AddNonADEntry(mapiAclTableAdapter, ref disposable, memberName, memberId, memberEntryId, memberRights);
                        }
                    }
                    else
                    {
                        ExTraceGlobals.StorageTracer.TraceDebug <string>(0L, "PermissionTable::PermissionTable. Found a member in the ACL table (other than anonymous and default) without a member entry id. Recipient Name = {0}.", memberName);
                        this.AddUnknownEntry(memberName, memberId, memberEntryId, memberRights);
                    }
                    IL_17E :;
                }
            }
            finally
            {
                Util.DisposeIfPresent(disposable);
            }
        }
Example #16
0
        protected void ResolveRequestedADRecipient()
        {
            string resolveMethod = "Unknown";

            try
            {
                if (this.Caller != null)
                {
                    if (!string.IsNullOrEmpty(this.RequestData.LegacyDN) && string.Equals(this.Caller.LegacyExchangeDN, this.RequestData.LegacyDN, StringComparison.OrdinalIgnoreCase))
                    {
                        this.RequestedRecipient = this.Caller;
                        resolveMethod           = "CallerByLegacyDN";
                        return;
                    }
                    if (!string.IsNullOrEmpty(this.RequestData.LegacyDN) && this.Caller.EmailAddresses != null)
                    {
                        string       x500 = "x500:" + this.RequestData.LegacyDN;
                        ProxyAddress a    = this.Caller.EmailAddresses.Find((ProxyAddress x) => string.Equals(x.ToString(), x500, StringComparison.OrdinalIgnoreCase));
                        if (a != null)
                        {
                            this.RequestedRecipient = this.Caller;
                            resolveMethod           = "CallerByX500";
                            return;
                        }
                    }
                    if (!string.IsNullOrEmpty(this.RequestData.EMailAddress) && SmtpAddress.IsValidSmtpAddress(this.RequestData.EMailAddress))
                    {
                        SmtpProxyAddress smtpProxy = new SmtpProxyAddress(this.RequestData.EMailAddress, true);
                        ProxyAddress     a2        = this.Caller.EmailAddresses.Find((ProxyAddress x) => x.Equals(smtpProxy));
                        if (a2 != null)
                        {
                            this.RequestedRecipient = this.Caller;
                            resolveMethod           = "CallerByProxy";
                            return;
                        }
                    }
                    if (AutodiscoverCommonUserSettings.HasLocalArchive(this.Caller) && AutodiscoverCommonUserSettings.IsEmailAddressTargetingArchive(this.Caller as ADUser, this.RequestData.EMailAddress))
                    {
                        this.RequestedRecipient = this.Caller;
                        resolveMethod           = "CallerByArchive";
                        return;
                    }
                }
                if (this.Caller == null)
                {
                    if (VariantConfiguration.InvariantNoFlightingSnapshot.Autodiscover.NoADLookupForUser.Enabled)
                    {
                        goto IL_285;
                    }
                }
                try
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .Current.TrackLatency(ServiceLatencyMetadata.RequestedUserADLatency, delegate()
                    {
                        IRecipientSession callerScopedRecipientSession = this.GetCallerScopedRecipientSession();
                        if (!string.IsNullOrEmpty(this.RequestData.LegacyDN))
                        {
                            this.RequestedRecipient = callerScopedRecipientSession.FindByLegacyExchangeDN(this.RequestData.LegacyDN);
                            if (this.RequestedRecipient != null)
                            {
                                resolveMethod = "FoundByLegacyDN";
                            }
                        }
                        if (this.RequestedRecipient == null && this.RequestData.EMailAddress != null && SmtpAddress.IsValidSmtpAddress(this.RequestData.EMailAddress))
                        {
                            Guid guid;
                            if (AutodiscoverCommonUserSettings.TryGetExchangeGuidFromEmailAddress(this.RequestData.EMailAddress, out guid))
                            {
                                this.RequestedRecipient = callerScopedRecipientSession.FindByExchangeGuidIncludingArchive(guid);
                                ADUser aduser           = this.RequestedRecipient as ADUser;
                                if (aduser != null && aduser.ArchiveGuid.Equals(guid) && RemoteMailbox.IsRemoteMailbox(aduser.RecipientTypeDetails) && aduser.ArchiveDatabase == null)
                                {
                                    this.RequestedRecipient = null;
                                }
                                if (this.RequestedRecipient != null)
                                {
                                    resolveMethod = "FoundByGUID";
                                }
                            }
                            if (this.RequestedRecipient == null)
                            {
                                SmtpProxyAddress proxyAddress = new SmtpProxyAddress(this.RequestData.EMailAddress, true);
                                this.RequestedRecipient       = callerScopedRecipientSession.FindByProxyAddress(proxyAddress);
                                if (this.RequestedRecipient != null)
                                {
                                    resolveMethod = "FoundBySMTP";
                                }
                            }
                        }
                    });
                }
                catch (LocalizedException ex)
                {
                    ExTraceGlobals.FrameworkTracer.TraceError <string, string>(0L, "[UpdateCacheCallback()] 'LocalizedException' Message=\"{0}\";StackTrace=\"{1}\"", ex.Message, ex.StackTrace);
                    Common.EventLog.LogEvent(AutodiscoverEventLogConstants.Tuple_ErrWebException, Common.PeriodicKey, new object[]
                    {
                        ex.Message,
                        ex.StackTrace
                    });
                    resolveMethod = "Exception";
                }
                IL_285 :;
            }
            finally
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .Current.AppendGenericInfo("ResolveMethod", resolveMethod);
            }
        }
Example #17
0
        private static void AddContacts(UserContext userContext, AnrManager.Options options, PropertyDefinition[] properties, object[][] results, List <RecipientAddress> addresses)
        {
            if (results != null && results.GetLength(0) > 0)
            {
                int i = 0;
                while (i < results.GetLength(0))
                {
                    object[]    results2    = results[i];
                    Participant participant = null;
                    string      displayName = null;
                    string      text        = Utilities.NormalizePhoneNumber(AnrManager.FindFromResultsMapping(ContactSchema.MobilePhone, properties, results2) as string);
                    VersionedId versionedId = AnrManager.FindFromResultsMapping(ItemSchema.Id, properties, results2) as VersionedId;
                    if (!options.ResolveAgainstAllContacts && !options.IsDefaultRoutingType("MOBILE"))
                    {
                        participant = (AnrManager.FindFromResultsMapping(ContactBaseSchema.AnrViewParticipant, properties, results2) as Participant);
                        displayName = participant.DisplayName;
                        goto IL_1AB;
                    }
                    Participant participant2 = AnrManager.FindFromResultsMapping(DistributionListSchema.AsParticipant, properties, results2) as Participant;
                    if (participant2 != null)
                    {
                        participant = participant2;
                        displayName = participant.DisplayName;
                        goto IL_1AB;
                    }
                    if (options.IsDefaultRoutingType("MOBILE"))
                    {
                        if (!string.IsNullOrEmpty(text))
                        {
                            displayName = (AnrManager.FindFromResultsMapping(StoreObjectSchema.DisplayName, properties, results2) as string);
                            participant = new Participant(displayName, text, "MOBILE", new StoreParticipantOrigin(versionedId), new KeyValuePair <PropertyDefinition, object> [0]);
                        }
                        else if (options.OnlyAllowDefaultRoutingType)
                        {
                            goto IL_339;
                        }
                    }
                    if (!(participant == null))
                    {
                        goto IL_1AB;
                    }
                    Participant participant3 = AnrManager.FindFromResultsMapping(ContactSchema.Email1, properties, results2) as Participant;
                    Participant participant4 = AnrManager.FindFromResultsMapping(ContactSchema.Email2, properties, results2) as Participant;
                    Participant participant5 = AnrManager.FindFromResultsMapping(ContactSchema.Email3, properties, results2) as Participant;
                    if (participant3 != null && !string.IsNullOrEmpty(participant3.EmailAddress))
                    {
                        participant = participant3;
                        displayName = participant.DisplayName;
                        goto IL_1AB;
                    }
                    if (participant4 != null && !string.IsNullOrEmpty(participant4.EmailAddress))
                    {
                        participant = participant4;
                        displayName = participant.DisplayName;
                        goto IL_1AB;
                    }
                    if (participant5 != null && !string.IsNullOrEmpty(participant5.EmailAddress))
                    {
                        participant = participant5;
                        displayName = participant.DisplayName;
                        goto IL_1AB;
                    }
                    goto IL_1AB;
IL_339:
                    i++;
                    continue;
IL_1AB:
                    RecipientAddress recipientAddress  = new RecipientAddress();
                    recipientAddress.MobilePhoneNumber = text;
                    recipientAddress.DisplayName       = displayName;
                    recipientAddress.AddressOrigin     = AddressOrigin.Store;
                    if (participant != null)
                    {
                        if (Utilities.IsMapiPDL(participant.RoutingType) && Utilities.IsFlagSet((int)options.RecipientBlockType, 2))
                        {
                            goto IL_339;
                        }
                        recipientAddress.RoutingType       = participant.RoutingType;
                        recipientAddress.EmailAddressIndex = ((StoreParticipantOrigin)participant.Origin).EmailAddressIndex;
                        if (!string.IsNullOrEmpty(participant.EmailAddress))
                        {
                            recipientAddress.RoutingAddress = participant.EmailAddress;
                            if (string.CompareOrdinal(recipientAddress.RoutingType, "EX") == 0)
                            {
                                string text2 = participant.TryGetProperty(ParticipantSchema.SmtpAddress) as string;
                                if (string.IsNullOrEmpty(text2))
                                {
                                    IRecipientSession recipientSession = Utilities.CreateADRecipientSession(Culture.GetUserCulture().LCID, true, ConsistencyMode.IgnoreInvalid, true, userContext);
                                    ADRecipient       adrecipient      = null;
                                    try
                                    {
                                        adrecipient = recipientSession.FindByLegacyExchangeDN(recipientAddress.RoutingAddress);
                                    }
                                    catch (NonUniqueRecipientException ex)
                                    {
                                        ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "AnrManager.GetNamesByAnrFromContacts: NonUniqueRecipientException was thrown by FindByLegacyExchangeDN: {0}", ex.Message);
                                    }
                                    if (adrecipient == null || adrecipient.HiddenFromAddressListsEnabled)
                                    {
                                        goto IL_339;
                                    }
                                    recipientAddress.SmtpAddress = adrecipient.PrimarySmtpAddress.ToString();
                                }
                                else
                                {
                                    recipientAddress.SmtpAddress = text2;
                                }
                            }
                            else if (string.CompareOrdinal(recipientAddress.RoutingType, "SMTP") == 0)
                            {
                                recipientAddress.SmtpAddress = recipientAddress.RoutingAddress;
                            }
                        }
                    }
                    if (Utilities.IsMapiPDL(recipientAddress.RoutingType))
                    {
                        recipientAddress.IsDistributionList = true;
                    }
                    if (versionedId != null)
                    {
                        recipientAddress.StoreObjectId = versionedId.ObjectId;
                    }
                    addresses.Add(recipientAddress);
                    goto IL_339;
                }
            }
        }
Example #18
0
        private GetGroupResponse GetDLData()
        {
            GetGroupResponse  getGroupResponse            = new GetGroupResponse();
            ADRecipient       adrecipient                 = null;
            IRecipientSession galscopedADRecipientSession = base.CallContext.ADRecipientSessionContext.GetGALScopedADRecipientSession(base.CallContext.EffectiveCaller.ClientSecurityContext);

            if (!string.IsNullOrEmpty(this.smtpAddress))
            {
                Directory.TryFindRecipient(this.smtpAddress, galscopedADRecipientSession, out adrecipient);
            }
            if (adrecipient == null)
            {
                if (!string.IsNullOrEmpty(this.adObjectId))
                {
                    Guid guid = new Guid(this.adObjectId);
                    adrecipient = galscopedADRecipientSession.FindByObjectGuid(guid);
                }
                else if (!string.IsNullOrEmpty(this.legacyExchangeDN))
                {
                    adrecipient = galscopedADRecipientSession.FindByLegacyExchangeDN(this.legacyExchangeDN);
                }
            }
            ADGroup adgroup = adrecipient as ADGroup;

            if (adgroup != null)
            {
                IADDistributionList iaddistributionList = adgroup;
                if (iaddistributionList != null)
                {
                    if (this.IsGeneralInfoInResultSet)
                    {
                        getGroupResponse.Description = adgroup.Description;
                        getGroupResponse.Notes       = adrecipient.Notes;
                        this.SetOwners(galscopedADRecipientSession, iaddistributionList, getGroupResponse);
                    }
                    if (this.IsMembersInResultSet)
                    {
                        getGroupResponse.MembersCount = ((iaddistributionList.Members != null) ? iaddistributionList.Members.Count : 0);
                        this.WriteDebugTrace("Total DL members count is " + getGroupResponse.MembersCount);
                        if (adrecipient.RecipientType != RecipientType.DynamicDistributionGroup)
                        {
                            if (getGroupResponse.MembersCount > 0)
                            {
                                this.SetMembers(galscopedADRecipientSession, iaddistributionList, getGroupResponse);
                            }
                        }
                        else
                        {
                            this.WriteDebugTrace("DDL - Members information is not loaded");
                        }
                    }
                }
                else
                {
                    this.WriteDebugTrace("No DL was found");
                }
            }
            else
            {
                this.WriteDebugTrace("The AD recipient is not a DL");
            }
            return(getGroupResponse);
        }