Example #1
0
 private void CreateFeatureManagerFactoryFromMailbox(OWAMiniRecipient miniRecipient)
 {
     UserConfigurationManager.IAggregationContext aggregationContext = null;
     try
     {
         this.LockAndReconnectMailboxSession();
         aggregationContext = base.MailboxSession.UserConfigurationManager.AttachAggregator(AggregatedUserConfigurationSchema.Instance.OwaUserConfiguration);
         base.UnlockAndDisconnectMailboxSession();
         OwaFlightConfigData  owaFlightConfigData  = UserContext.ReadAggregatedFlightConfigData(aggregationContext, base.ExchangePrincipal.MailboxInfo.OrganizationId);
         RecipientTypeDetails recipientTypeDetails = base.ExchangePrincipal.RecipientTypeDetails;
         this.featuresManagerFactory = new FeaturesManagerFactory(miniRecipient, new ConfigurationContext(this), new ScopeFlightsSettingsProvider(), (VariantConfigurationSnapshot c) => new FeaturesStateOverride(c, recipientTypeDetails), owaFlightConfigData.RampId, owaFlightConfigData.IsFirstRelease);
     }
     finally
     {
         if (aggregationContext != null)
         {
             aggregationContext.Detach();
             this.bootAggregationContext = aggregationContext;
         }
         if (base.MailboxSessionLockedByCurrentThread())
         {
             base.UnlockAndDisconnectMailboxSession();
         }
     }
 }
        // Token: 0x06000695 RID: 1685 RVA: 0x00013B64 File Offset: 0x00011D64
        public void UpgradePartialIdentity()
        {
            OWAMiniRecipient owaminiRecipient = null;
            SmtpAddress      smtpAddress      = new SmtpAddress(this.proxyAddress.AddressString);

            ExTraceGlobals.CoreCallTracer.TraceDebug <string>(0L, "OwaMiniRecipientIdentity.UpgradePartialIdentity for smtp: {0}", this.proxyAddress.AddressString);
            IRecipientSession recipientSession = UserContextUtilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, smtpAddress.Domain, null);
            Exception         ex = null;

            try
            {
                owaminiRecipient = recipientSession.FindMiniRecipientByProxyAddress <OWAMiniRecipient>(this.proxyAddress, OWAMiniRecipientSchema.AdditionalProperties);
                if (owaminiRecipient == null)
                {
                    throw new OwaExplicitLogonException(string.Format("The address {0} is an object in AD database but it is not an user", this.proxyAddress), Strings.GetLocalizedString(-1332692688), ex);
                }
            }
            catch (NonUniqueRecipientException ex2)
            {
                ex = ex2;
            }
            if (owaminiRecipient == null || ex != null)
            {
                throw new OwaExplicitLogonException(string.Format("Couldn't find a match for {0}", this.proxyAddress.ToString()), string.Format(Strings.GetLocalizedString(-13616305), this.proxyAddress), ex);
            }
            base.OwaMiniRecipient = owaminiRecipient;
        }
        private ICollection <string> ExtractSmtpAddresses(OwaIdentity requestor)
        {
            if (requestor == null)
            {
                return(Array <string> .Empty);
            }
            OWAMiniRecipient owaminiRecipient = requestor.OwaMiniRecipient ?? requestor.GetOWAMiniRecipient();

            if (owaminiRecipient == null)
            {
                this.tracer.TraceDebug((long)this.GetHashCode(), "OwaPhotoRequestorWriter:  cannot extract SMTP addresses because recipient information has NOT been initialized or computed for requestor.");
                return(Array <string> .Empty);
            }
            HashSet <string> hashSet            = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
            SmtpAddress      primarySmtpAddress = requestor.PrimarySmtpAddress;

            hashSet.Add(requestor.PrimarySmtpAddress.ToString());
            if (owaminiRecipient.EmailAddresses != null && owaminiRecipient.EmailAddresses.Count > 0)
            {
                hashSet.UnionWith(from a in owaminiRecipient.EmailAddresses
                                  where OwaPhotoRequestorWriter.IsNonBlankSmtpAddress(a)
                                  select a.ValueString);
            }
            return(hashSet);
        }
        // Token: 0x06000FC6 RID: 4038 RVA: 0x00062878 File Offset: 0x00060A78
        public void UpgradePartialIdentity()
        {
            OWAMiniRecipient  owaminiRecipient = null;
            SmtpAddress       smtpAddress      = new SmtpAddress(this.proxyAddress.AddressString);
            IRecipientSession recipientSession = Utilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, smtpAddress.Domain);
            Exception         ex = null;

            try
            {
                owaminiRecipient = recipientSession.FindMiniRecipientByProxyAddress <OWAMiniRecipient>(this.proxyAddress, OWAMiniRecipientSchema.AdditionalProperties);
                if (owaminiRecipient == null)
                {
                    throw new OwaExplicitLogonException(string.Format("The address {0} is an object in AD database but it is not an user", this.proxyAddress), LocalizedStrings.GetNonEncoded(-1332692688), ex);
                }
            }
            catch (NonUniqueRecipientException ex2)
            {
                ex = ex2;
            }
            base.LastRecipientSessionDCServerName = recipientSession.LastUsedDc;
            if (owaminiRecipient == null || ex != null)
            {
                throw new OwaExplicitLogonException(string.Format("Couldn't find a match for {0}", this.proxyAddress.ToString()), string.Format(LocalizedStrings.GetNonEncoded(-13616305), this.proxyAddress), ex);
            }
            this.owaMiniRecipient = owaminiRecipient;
        }
Example #5
0
        private void CreateFeatureManagerFactoryFromAD(OWAMiniRecipient miniRecipient)
        {
            OwaFlightConfigData  owaFlightConfigData  = UserContext.ReadFlightConfigDataFromAD(base.ExchangePrincipal.MailboxInfo.OrganizationId);
            RecipientTypeDetails recipientTypeDetails = base.ExchangePrincipal.RecipientTypeDetails;

            this.featuresManagerFactory = new FeaturesManagerFactory(miniRecipient, new ConfigurationContext(this), new ScopeFlightsSettingsProvider(), (VariantConfigurationSnapshot c) => new FeaturesStateOverride(c, recipientTypeDetails), owaFlightConfigData.RampId, owaFlightConfigData.IsFirstRelease);
        }
 // Token: 0x06000FC4 RID: 4036 RVA: 0x000627D6 File Offset: 0x000609D6
 public static OwaMiniRecipientIdentity CreateFromOWAMiniRecipient(OWAMiniRecipient recipient)
 {
     if (recipient == null)
     {
         throw new ArgumentNullException("user", "AD User cannot be null");
     }
     return(new OwaMiniRecipientIdentity(recipient));
 }
 // Token: 0x06000690 RID: 1680 RVA: 0x00013A54 File Offset: 0x00011C54
 public static OwaMiniRecipientIdentity CreateFromOWAMiniRecipient(OWAMiniRecipient recipient)
 {
     if (recipient == null)
     {
         throw new ArgumentNullException("recipient");
     }
     ExTraceGlobals.CoreCallTracer.TraceDebug <SecurityIdentifier>(0L, "OwaMiniRecipientIdentity.CreateFromOWAMiniRecipient for recipient with Sid:{0}", recipient.Sid);
     return(new OwaMiniRecipientIdentity(recipient));
 }
Example #8
0
        internal ExchangePrincipal CreateExchangePrincipal()
        {
            ExchangePrincipal result = null;

            try
            {
                OwaDiagnostics.TracePfd(18057, "Creating new ExchangePrincipal", new object[0]);
                if (ExTraceGlobals.CoreTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    string text = null;
                    using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                    {
                        text = current.Name;
                    }
                    if (string.IsNullOrEmpty(text))
                    {
                        text = "<n/a>";
                    }
                    string arg = this.SafeGetRenderableName();
                    ExTraceGlobals.CoreTracer.TraceDebug <string, string>(0L, "Using accout {0} to bind to ExchangePrincipal object for user {1}", text, arg);
                }
                result = this.InternalCreateExchangePrincipal();
            }
            catch (ObjectNotFoundException ex)
            {
                bool flag = false;
                DataValidationException ex2 = ex.InnerException as DataValidationException;
                if (ex2 != null)
                {
                    PropertyValidationError propertyValidationError = ex2.Error as PropertyValidationError;
                    if (propertyValidationError != null && propertyValidationError.PropertyDefinition == MiniRecipientSchema.Languages)
                    {
                        OWAMiniRecipient owaminiRecipient = this.FixCorruptOWAMiniRecipientCultureEntry();
                        if (owaminiRecipient != null)
                        {
                            try
                            {
                                result = ExchangePrincipal.FromMiniRecipient(owaminiRecipient, RemotingOptions.AllowCrossSite);
                                flag   = true;
                            }
                            catch (ObjectNotFoundException)
                            {
                            }
                        }
                    }
                }
                if (!flag)
                {
                    throw ex;
                }
            }
            return(result);
        }
Example #9
0
        public OWAMiniRecipient CreateOWAMiniRecipientBySid()
        {
            IRecipientSession recipientSession = Utilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, this.DomainName);
            OWAMiniRecipient  owaminiRecipient = recipientSession.FindMiniRecipientBySid <OWAMiniRecipient>(this.UserSid, OWAMiniRecipientSchema.AdditionalProperties);

            this.LastRecipientSessionDCServerName = recipientSession.LastUsedDc;
            if (owaminiRecipient == null)
            {
                throw new OwaADObjectNotFoundException();
            }
            return(owaminiRecipient);
        }
Example #10
0
 private void CreateFeatureManagerFactory(OWAMiniRecipient miniRecipient)
 {
     if (this.featuresManagerFactory != null)
     {
         return;
     }
     if (!base.IsExplicitLogon)
     {
         this.CreateFeatureManagerFactoryFromMailbox(miniRecipient);
         return;
     }
     this.CreateFeatureManagerFactoryFromAD(miniRecipient);
 }
        private static OrganizationId GetOrganization(OwaIdentity requestor)
        {
            if (requestor.UserOrganizationId != null)
            {
                return(requestor.UserOrganizationId);
            }
            OWAMiniRecipient owaminiRecipient = requestor.OwaMiniRecipient ?? requestor.GetOWAMiniRecipient();

            if (owaminiRecipient != null)
            {
                return(owaminiRecipient.OrganizationId);
            }
            return(null);
        }
 private OwaClientSecurityContextIdentity(ClientSecurityContext clientSecurityContext, string logonName, string authenticationType, OrganizationId userOrganizationId)
 {
     if (clientSecurityContext == null)
     {
         throw new ArgumentNullException("clientSecurityContext");
     }
     if (string.IsNullOrEmpty(logonName))
     {
         throw new ArgumentNullException("logonName", "logonName cannot be null or empty.");
     }
     if (userOrganizationId == null && !OwaIdentity.IsLogonNameFullyQualified(logonName))
     {
         throw new ArgumentException("logonName", string.Format(CultureInfo.InvariantCulture, "'{0}' is not a valid logon name.", new object[]
         {
             logonName
         }));
     }
     if (string.IsNullOrEmpty(authenticationType))
     {
         throw new ArgumentNullException("authenticationType", "authenticationType cannot be null or empty.");
     }
     this.logonName          = logonName;
     this.authenticationType = authenticationType;
     base.UserOrganizationId = userOrganizationId;
     if (!SyncUtilities.IsDatacenterMode())
     {
         this.clientSecurityContext = clientSecurityContext;
         OWAMiniRecipient owaminiRecipient = base.GetOWAMiniRecipient();
         if (owaminiRecipient != null && owaminiRecipient.MasterAccountSid != null)
         {
             try
             {
                 this.clientSecurityContext = OwaClientSecurityContextIdentity.TokenMunger.MungeToken(clientSecurityContext, OrganizationId.ForestWideOrgId);
                 return;
             }
             catch (TokenMungingException ex)
             {
                 ExTraceGlobals.CoreCallTracer.TraceError(0L, "OwaClientSecurityContextIdentity.TokenMunger.MungeToken for LogonName='{0}', AuthenticationType='{1}', UserOrgId='{2}' failed with exception: {3}", new object[]
                 {
                     this.logonName,
                     this.authenticationType,
                     base.UserOrganizationId,
                     ex.Message
                 });
             }
         }
     }
     this.clientSecurityContext = clientSecurityContext.Clone();
 }
Example #13
0
        private string EnsureGroupIsInDirectoryCache(GroupMailbox group)
        {
            IRecipientSession tenantOrRootRecipientReadOnlySession = DirectorySessionFactory.Default.GetTenantOrRootRecipientReadOnlySession(base.ADSession, group.OriginatingServer, 350, "EnsureGroupIsInDirectoryCache", "f:\\15.00.1497\\sources\\dev\\Management\\src\\FederatedDirectory\\CreateUnifiedGroupTask.cs");
            ProxyAddress      proxyAddress     = new SmtpProxyAddress(group.PrimarySmtpAddress.ToString(), true);
            OWAMiniRecipient  owaminiRecipient = tenantOrRootRecipientReadOnlySession.FindMiniRecipientByProxyAddress <OWAMiniRecipient>(proxyAddress, OWAMiniRecipientSchema.AdditionalProperties);
            string            text             = (owaminiRecipient != null) ? (owaminiRecipient.IsCached ? "ReadFromCache" : "ReadFromDc") : "NotFound";

            UnifiedGroupsTask.Tracer.TraceDebug((long)this.GetHashCode(), "ActivityId={0}. CreateUnifiedGroupTask.EnsureGroupIsInDirectoryCache: ProxyAddress={1}, DomainController={2}, Result={3}", new object[]
            {
                base.ActivityId,
                proxyAddress,
                group.OriginatingServer,
                text
            });
            return(text);
        }
Example #14
0
        // Token: 0x06000B20 RID: 2848 RVA: 0x0004ED24 File Offset: 0x0004CF24
        private static Dictionary <string, string[]> GetProxyAddresses(string[] upns, UserContext userContext)
        {
            Dictionary <string, string[]> dictionary       = new Dictionary <string, string[]>();
            IRecipientSession             recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext);

            Result <OWAMiniRecipient>[] array = recipientSession.FindOWAMiniRecipientByUserPrincipalName(upns);
            for (int i = 0; i < array.Length; i++)
            {
                OWAMiniRecipient data = array[i].Data;
                string           text = data.UserPrincipalName.ToString();
                if (!string.IsNullOrEmpty(text) && !dictionary.ContainsKey(text))
                {
                    dictionary.Add(text, InstantMessageUtilities.GetProxyAddressesForRecipient(data));
                }
            }
            return(dictionary);
        }
        protected virtual void DoLoad(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, UserContextStatistics stats)
        {
            if (logonIdentity == null)
            {
                throw new ArgumentNullException("logonIdentity");
            }
            this.logonIdentity = logonIdentity;
            if (mailboxIdentity != null)
            {
                this.isExplicitLogon = true;
                this.mailboxIdentity = mailboxIdentity;
            }
            else
            {
                this.mailboxIdentity = logonIdentity;
            }
            if (this.IsExplicitLogon)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <string>(0L, "Created partial mailbox identity from SMTP address={0}", mailboxIdentity.SafeGetRenderableName());
                OwaMiniRecipientIdentity owaMiniRecipientIdentity = this.mailboxIdentity as OwaMiniRecipientIdentity;
                try
                {
                    owaMiniRecipientIdentity.UpgradePartialIdentity();
                }
                catch (DataValidationException ex)
                {
                    PropertyValidationError propertyValidationError = ex.Error as PropertyValidationError;
                    if (propertyValidationError == null || propertyValidationError.PropertyDefinition != MiniRecipientSchema.Languages)
                    {
                        throw;
                    }
                    OWAMiniRecipient owaminiRecipient = this.MailboxIdentity.FixCorruptOWAMiniRecipientCultureEntry();
                    if (owaminiRecipient != null)
                    {
                        this.mailboxIdentity = OwaMiniRecipientIdentity.CreateFromOWAMiniRecipient(owaminiRecipient);
                    }
                }
            }
            Stopwatch stopwatch = Stopwatch.StartNew();

            this.exchangePrincipal = this.mailboxIdentity.CreateExchangePrincipal();
            stats.ExchangePrincipalCreationTime = (int)stopwatch.ElapsedMilliseconds;
            this.LogTrace("UserContextBase.Load", "CreateExchangePrincipal finished");
            this.pendingRequestManager = new PendingRequestManager(this, ListenerChannelsManager.Instance);
        }
Example #16
0
        // Token: 0x06000B21 RID: 2849 RVA: 0x0004ED94 File Offset: 0x0004CF94
        private static string[] GetProxyAddressesForRecipient(OWAMiniRecipient owaMiniRecipient)
        {
            ProxyAddressCollection emailAddresses = owaMiniRecipient.EmailAddresses;

            string[] array;
            if (emailAddresses != null && emailAddresses.Count > 0)
            {
                array = new string[emailAddresses.Count];
                for (int i = 0; i < emailAddresses.Count; i++)
                {
                    array[i] = emailAddresses[i].AddressString;
                }
            }
            else
            {
                array = new string[0];
            }
            return(array);
        }
Example #17
0
        public OWAMiniRecipient CreateOWAMiniRecipientBySid()
        {
            IRecipientSession recipientSession = (this.UserOrganizationId == null) ? UserContextUtilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, this.DomainName, null) : UserContextUtilities.CreateScopedRecipientSession(true, ConsistencyMode.FullyConsistent, null, this.UserOrganizationId);
            bool flag    = false;
            bool enabled = VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).OwaServer.OwaClientAccessRulesEnabled.Enabled;

            if (enabled)
            {
                ClientAccessRuleCollection collection = ClientAccessRulesCache.Instance.GetCollection(this.UserOrganizationId ?? OrganizationId.ForestWideOrgId);
                flag = (collection.Count > 0);
            }
            OWAMiniRecipient owaminiRecipient = recipientSession.FindMiniRecipientBySid <OWAMiniRecipient>(this.UserSid, flag ? OWAMiniRecipientSchema.AdditionalPropertiesWithClientAccessRules : OWAMiniRecipientSchema.AdditionalProperties);

            if (owaminiRecipient == null)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier>(0L, "OwaIdentity.CreateOWAMiniRecipientBySid: got null OWAMiniRecipient for Sid: {0}", this.UserSid);
                throw new OwaADUserNotFoundException(this.SafeGetRenderableName());
            }
            return(owaminiRecipient);
        }
Example #18
0
        protected override void DoLoad(OwaIdentity logonIdentity, OwaIdentity mailboxIdentity, UserContextStatistics stats)
        {
            HttpContext          httpContext = HttpContext.Current;
            RequestDetailsLogger current     = RequestDetailsLoggerBase <RequestDetailsLogger> .GetCurrent(httpContext);

            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.UserContextLoadBegin);
            base.DoLoad(logonIdentity, mailboxIdentity, stats);
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.GetOWAMiniRecipientBegin);
            Stopwatch        stopwatch        = Stopwatch.StartNew();
            OWAMiniRecipient owaminiRecipient = base.LogonIdentity.GetOWAMiniRecipient();

            stats.MiniRecipientCreationTime = (int)stopwatch.ElapsedMilliseconds;
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.GetOWAMiniRecipientEnd);
            base.LogTrace("UserContext.Load", "GetOWAMiniRecipient finished");
            this.sipUri = ADPersonToContactConverter.GetSipUri(owaminiRecipient);
            stopwatch.Restart();
            this.IsBposUser             = CapabilityHelper.HasBposSKUCapability(owaminiRecipient.PersistedCapabilities);
            stats.SKUCapabilityTestTime = (int)stopwatch.ElapsedMilliseconds;
            base.LogTrace("UserContext.Load", "HasBposSKUCapability finished");
            if (Globals.IsFirstReleaseFlightingEnabled)
            {
                this.CreateFeatureManagerFactory(owaminiRecipient);
            }
            else
            {
                RecipientTypeDetails recipientTypeDetails = base.ExchangePrincipal.RecipientTypeDetails;
                this.featuresManagerFactory = new FeaturesManagerFactory(owaminiRecipient, new ConfigurationContext(this), new ScopeFlightsSettingsProvider(), (VariantConfigurationSnapshot c) => new FeaturesStateOverride(c, recipientTypeDetails), string.Empty, false);
            }
            this.BposSkuCapability = string.Empty;
            if (this.IsBposUser)
            {
                Capability?skucapability = CapabilityHelper.GetSKUCapability(owaminiRecipient.PersistedCapabilities);
                if (skucapability != null)
                {
                    this.BposSkuCapability = skucapability.ToString();
                }
            }
            this.LogEventCommonData = new LogEventCommonData(this);
            this.IsGroupUserContext = (base.IsExplicitLogon && base.ExchangePrincipal.RecipientTypeDetails == RecipientTypeDetails.GroupMailbox);
            RequestDetailsLogger.LogEvent(current, OwaServerLogger.LoggerData.UserContextLoadEnd);
        }
Example #19
0
        internal static ProxySettings[] GetProxySettings(string[] upns, IUserContext userContext)
        {
            List <ProxySettings> list             = new List <ProxySettings>();
            IRecipientSession    recipientSession = InstantMessageUtilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext.ExchangePrincipal, userContext.MailboxIdentity.GetOWAMiniRecipient().QueryBaseDN);

            Result <OWAMiniRecipient>[] array = recipientSession.FindOWAMiniRecipientByUserPrincipalName(upns);
            for (int i = 0; i < array.Length; i++)
            {
                OWAMiniRecipient data = array[i].Data;
                string           text = data.UserPrincipalName.ToString();
                if (string.IsNullOrEmpty(text))
                {
                    list.Add(new ProxySettings(text, null));
                }
                else
                {
                    list.Add(new ProxySettings(text, InstantMessageUtilities.GetProxyAddressesForRecipient(data)));
                }
            }
            return(list.ToArray());
        }
Example #20
0
        internal static string EnsureGroupIsInDirectoryCache(string perfTrackerPrefix, IRecipientSession readWriteSession, ADUser groupAdUser)
        {
            string result;

            using (new StopwatchPerformanceTracker(perfTrackerPrefix + ".EnsureGroupIsInDirectoryCache", GenericCmdletInfoDataLogger.Instance))
            {
                IRecipientSession tenantOrRootRecipientReadOnlySession = DirectorySessionFactory.Default.GetTenantOrRootRecipientReadOnlySession(readWriteSession, groupAdUser.OriginatingServer, 204, "EnsureGroupIsInDirectoryCache", "f:\\15.00.1497\\sources\\dev\\Management\\src\\Management\\RecipientTasks\\GroupMailbox\\GroupMailboxContext.cs");
                ProxyAddress      proxyAddress     = new SmtpProxyAddress(groupAdUser.PrimarySmtpAddress.ToString(), true);
                ADUser            aduser           = tenantOrRootRecipientReadOnlySession.FindByProxyAddress(proxyAddress) as ADUser;
                OWAMiniRecipient  owaminiRecipient = tenantOrRootRecipientReadOnlySession.FindMiniRecipientByProxyAddress <OWAMiniRecipient>(proxyAddress, OWAMiniRecipientSchema.AdditionalProperties);
                string            text             = string.Format("Querying AD for group. ProxyAddress={0}, DomainController={1}, FoundADUser={2}, FoundOwaMiniRecipient={3}", new object[]
                {
                    proxyAddress,
                    groupAdUser.OriginatingServer,
                    aduser != null,
                    owaminiRecipient != null
                });
                GroupMailboxContext.Tracer.TraceDebug <string>(0L, "{0}", text);
                result = text;
            }
            return(result);
        }
        private static bool ShouldBlockConnection(HttpContext httpContext, OwaIdentity logonIdentity)
        {
            if (!VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null).OwaServer.OwaClientAccessRulesEnabled.Enabled)
            {
                return(false);
            }
            RequestDetailsLogger logger = OwaApplication.GetRequestDetailsLogger;
            Action <ClientAccessRulesEvaluationContext> blockLoggerDelegate = delegate(ClientAccessRulesEvaluationContext context)
            {
                RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(logger, ClientAccessRulesConstants.ClientAccessRuleName, context.CurrentRule.Name);
            };
            Action <double> latencyLoggerDelegate = delegate(double latency)
            {
                if (latency > 50.0)
                {
                    RequestDetailsLoggerBase <RequestDetailsLogger> .SafeAppendGenericInfo(logger, ClientAccessRulesConstants.ClientAccessRulesLatency, latency);
                }
            };
            OWAMiniRecipient owaminiRecipient          = logonIdentity.GetOWAMiniRecipient();
            string           usernameFromIdInformation = ClientAccessRulesUtils.GetUsernameFromIdInformation(owaminiRecipient.WindowsLiveID, owaminiRecipient.MasterAccountSid, owaminiRecipient.Sid, owaminiRecipient.ObjectId);

            return(ClientAccessRulesUtils.ShouldBlockConnection(logonIdentity.UserOrganizationId, usernameFromIdInformation, ClientAccessProtocol.OutlookWebApp, ClientAccessRulesUtils.GetRemoteEndPointFromContext(httpContext), httpContext.Request.IsAuthenticatedByAdfs() ? ClientAccessAuthenticationMethod.AdfsAuthentication : ClientAccessAuthenticationMethod.BasicAuthentication, owaminiRecipient, blockLoggerDelegate, latencyLoggerDelegate));
        }
 // Token: 0x06000687 RID: 1671 RVA: 0x00013A00 File Offset: 0x00011C00
 private OwaMiniRecipientIdentity(OWAMiniRecipient owaMiniRecipient)
 {
     base.OwaMiniRecipient = owaMiniRecipient;
 }
Example #23
0
 // Token: 0x06000B25 RID: 2853 RVA: 0x0004EF35 File Offset: 0x0004D135
 internal static string GetSipUri(OWAMiniRecipient owaMiniRecipient)
 {
     return(InstantMessageUtilities.GetSipUri(owaMiniRecipient.EmailAddresses));
 }
 // Token: 0x06000FC2 RID: 4034 RVA: 0x000627B8 File Offset: 0x000609B8
 private OwaMiniRecipientIdentity(OWAMiniRecipient owaMiniRecipient)
 {
     this.owaMiniRecipient = owaMiniRecipient;
 }
Example #25
0
        // Token: 0x060003B5 RID: 949 RVA: 0x00015440 File Offset: 0x00013640
        internal static ADObject CreateAndInitializeRecipientObject <TRecipientObject>(ADPropertyBag propertyBag, ADRawEntry dummyObject, IRecipientSession recipientSession) where TRecipientObject : IConfigurable, new()
        {
            ArgumentValidator.ThrowIfNull("propertyBag", propertyBag);
            ArgumentValidator.ThrowIfNull("dummyObject", dummyObject);
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[ADObjectSchema.ObjectClass];
            ADObject adobject;

            if (dummyObject is OWAMiniRecipient)
            {
                adobject = new OWAMiniRecipient();
            }
            else if (dummyObject is ActiveSyncMiniRecipient)
            {
                adobject = new ActiveSyncMiniRecipient();
            }
            else if (dummyObject is StorageMiniRecipient)
            {
                adobject = new StorageMiniRecipient();
            }
            else if (dummyObject is TransportMiniRecipient)
            {
                adobject = new TransportMiniRecipient();
            }
            else if (dummyObject is LoadBalancingMiniRecipient)
            {
                adobject = new LoadBalancingMiniRecipient();
            }
            else if (dummyObject is MiniRecipientWithTokenGroups)
            {
                adobject = new MiniRecipientWithTokenGroups();
            }
            else if (dummyObject is FrontEndMiniRecipient)
            {
                adobject = new FrontEndMiniRecipient();
            }
            else if (dummyObject is MiniRecipient)
            {
                adobject = new MiniRecipient();
            }
            else if (dummyObject is RemovedMailbox)
            {
                adobject = new RemovedMailbox();
            }
            else if (dummyObject is DeletedRecipient)
            {
                adobject = new DeletedRecipient();
            }
            else if (multiValuedProperty.Contains(ADComputerRecipient.MostDerivedClass))
            {
                adobject = new ADComputerRecipient();
            }
            else if (multiValuedProperty.Contains(ADUser.MostDerivedClass))
            {
                adobject = new ADUser();
            }
            else if (multiValuedProperty.Contains(ADContact.MostDerivedClass))
            {
                adobject = new ADContact();
            }
            else if (multiValuedProperty.Contains(ADGroup.MostDerivedClass))
            {
                adobject = new ADGroup();
            }
            else if (multiValuedProperty.Contains(ADDynamicGroup.MostDerivedClass))
            {
                adobject = new ADDynamicGroup();
            }
            else if (multiValuedProperty.Contains(ADPublicFolder.MostDerivedClass))
            {
                adobject = new ADPublicFolder();
            }
            else if (multiValuedProperty.Contains(ADSystemAttendantMailbox.MostDerivedClass))
            {
                adobject = new ADSystemAttendantMailbox();
            }
            else if (multiValuedProperty.Contains(ADSystemMailbox.MostDerivedClass))
            {
                adobject = new ADSystemMailbox();
            }
            else if (multiValuedProperty.Contains(ADPublicDatabase.MostDerivedClass))
            {
                adobject = new ADPublicDatabase();
            }
            else
            {
                if (!multiValuedProperty.Contains(ADMicrosoftExchangeRecipient.MostDerivedClass))
                {
                    string objectClass = string.Empty;
                    foreach (string text in multiValuedProperty)
                    {
                        objectClass = text;
                    }
                    ObjectValidationError error = new ObjectValidationError(DirectoryStrings.UnsupportedObjectClass(objectClass), (ADObjectId)propertyBag[ADObjectSchema.Id], string.Empty);
                    ADProviderPerf.UpdateProcessCounter(Counter.ProcessRateCriticalValidationFailures, UpdateType.Update, 1U);
                    Globals.LogEvent(DirectoryEventLogConstants.Tuple_DSC_EVENT_VALIDATION_FAILED_FCO_MODE_RECIPIENT, ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToString(), new object[]
                    {
                        ((ADObjectId)propertyBag[ADObjectSchema.Id]).ToDNString()
                    });
                    throw new DataValidationException(error);
                }
                adobject = new ADMicrosoftExchangeRecipient();
            }
            adobject.m_Session   = recipientSession;
            adobject.propertyBag = propertyBag;
            adobject.Initialize();
            adobject.ResetChangeTracking(true);
            if (recipientSession != null)
            {
                adobject.SetIsReadOnly(recipientSession.ReadOnly);
            }
            ExTraceGlobals.ADReadDetailsTracer.TraceDebug <string, RecipientType>((long)((recipientSession != null) ? recipientSession.GetHashCode() : 0), "ADRecipientObjectSession::CreateObject - Got {0} as {1}", adobject.DistinguishedName, (RecipientType)adobject[ADRecipientSchema.RecipientType]);
            return(adobject);
        }
Example #26
0
        // Token: 0x0600211A RID: 8474 RVA: 0x0007953C File Offset: 0x0007773C
        internal SessionSettingsType(UserContext userContext, MailboxSession mailboxSession, UserAgent userAgent, CallContext callContext, UMSettingsData umSettings, OwaHelpUrlData helpUrlData)
        {
            if (userContext == null)
            {
                throw new ArgumentNullException("userContext");
            }
            if (userContext.ExchangePrincipal == null)
            {
                throw new OwaInvalidRequestException("userContext.ExchangePrincipal is null");
            }
            StorePerformanceCountersCapture countersCapture = StorePerformanceCountersCapture.Start(mailboxSession);

            this.userDisplayName      = userContext.ExchangePrincipal.MailboxInfo.DisplayName;
            this.userEmailAddress     = userContext.ExchangePrincipal.MailboxInfo.PrimarySmtpAddress.ToString();
            this.userLegacyExchangeDN = userContext.ExchangePrincipal.LegacyDn;
            this.hasArchive           = this.UserHasArchive(userContext.ExchangePrincipal);
            this.archiveDisplayName   = (this.hasArchive ? userContext.ExchangePrincipal.GetArchiveMailbox().ArchiveName : string.Empty);
            IEnumerable <string> source = from emailAddress in userContext.ExchangePrincipal.MailboxInfo.EmailAddresses
                                          select emailAddress.AddressString;

            if (source.Any <string>())
            {
                this.userProxyAddresses = source.ToArray <string>();
            }
            this.UpdateMailboxQuotaLimits(mailboxSession);
            this.isBposUser        = userContext.IsBposUser;
            this.userSipUri        = userContext.SipUri;
            this.userPrincipalName = userContext.UserPrincipalName;
            this.isGallatin        = SessionSettingsType.GetIsGallatin();
            if (userContext.ExchangePrincipal.MailboxInfo.OrganizationId != null)
            {
                this.TenantGuid = userContext.ExchangePrincipal.MailboxInfo.OrganizationId.GetTenantGuid().ToString();
            }
            if (userContext.LogEventCommonData != null)
            {
                this.TenantDomain = userContext.LogEventCommonData.TenantDomain;
            }
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.SessionSettingsMisc, countersCapture, true);
            int?maximumMessageSize = SessionSettingsType.GetMaximumMessageSize(mailboxSession);

            this.maxMessageSizeInKb = ((maximumMessageSize != null) ? maximumMessageSize.Value : 5120);
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.SessionSettingsMessageSize, countersCapture, true);
            this.isPublicLogon = UserContextUtilities.IsPublicRequest(callContext.HttpContext.Request);
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.SessionSettingsIsPublicLogon, countersCapture, true);
            ADUser aduser = null;

            if (userContext.IsExplicitLogon)
            {
                IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, true, ConsistencyMode.IgnoreInvalid, null, userContext.ExchangePrincipal.MailboxInfo.OrganizationId.ToADSessionSettings(), 303, ".ctor", "f:\\15.00.1497\\sources\\dev\\clients\\src\\Owa2\\Server\\Core\\types\\SessionSettingsType.cs");
                aduser = (DirectoryHelper.ReadADRecipient(userContext.ExchangePrincipal.MailboxInfo.MailboxGuid, userContext.ExchangePrincipal.MailboxInfo.IsArchive, tenantOrRootOrgRecipientSession) as ADUser);
                if (aduser != null && aduser.SharePointUrl != null)
                {
                    this.sharePointUrl   = aduser.SharePointUrl.ToString();
                    this.sharePointTitle = aduser.DisplayName;
                }
            }
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.TeamMailbox, countersCapture, true);
            if (userContext.LogonIdentity != null)
            {
                OWAMiniRecipient owaminiRecipient = userContext.LogonIdentity.GetOWAMiniRecipient();
                this.LogonEmailAddress = string.Empty;
                if (owaminiRecipient != null)
                {
                    SmtpAddress primarySmtpAddress = owaminiRecipient.PrimarySmtpAddress;
                    this.LogonEmailAddress = owaminiRecipient.PrimarySmtpAddress.ToString();
                }
                OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.GetOWAMiniRecipient, countersCapture, false);
            }
            this.MailboxGuid     = userContext.ExchangePrincipal.MailboxInfo.MailboxGuid.ToString();
            this.isExplicitLogon = userContext.IsExplicitLogon;
            this.isExplicitLogonOthersMailbox = false;
            this.canActAsOwner = true;
            countersCapture    = StorePerformanceCountersCapture.Start(mailboxSession);
            this.SetDefaultFolderMapping(mailboxSession);
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.SetDefaultFolderMapping, countersCapture, false);
            CultureInfo currentUICulture = Thread.CurrentThread.CurrentUICulture;

            this.userCulture = currentUICulture.Name;
            this.isUserCultureSpeechEnabled = Culture.IsCultureSpeechEnabled(currentUICulture);
            this.isUserCultureRightToLeft   = currentUICulture.TextInfo.IsRightToLeft;
            countersCapture                    = StorePerformanceCountersCapture.Start(mailboxSession);
            this.playOnPhoneDialString         = umSettings.PlayOnPhoneDialString;
            this.isRequireProtectedPlayOnPhone = umSettings.IsRequireProtectedPlayOnPhone;
            this.isUMEnabled                   = umSettings.IsUMEnabled;
            if (SyncUtilities.IsDatacenterMode())
            {
                SendAsSubscriptionsAndPeopleConnectResult allSendAsSubscriptionsAndPeopleConnect = SubscriptionManager.GetAllSendAsSubscriptionsAndPeopleConnect(mailboxSession);
                List <PimAggregationSubscription>         pimSendAsAggregationSubscriptionList   = allSendAsSubscriptionsAndPeopleConnect.PimSendAsAggregationSubscriptionList;
                this.PeopleConnectionsExist = allSendAsSubscriptionsAndPeopleConnect.PeopleConnectionsExist;
                List <AggregatedAccountInfo> list = null;
                if (aduser == null && userContext.ExchangePrincipal != null)
                {
                    IRecipientSession tenantOrRootOrgRecipientSession2 = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, true, ConsistencyMode.IgnoreInvalid, null, userContext.ExchangePrincipal.MailboxInfo.OrganizationId.ToADSessionSettings(), 375, ".ctor", "f:\\15.00.1497\\sources\\dev\\clients\\src\\Owa2\\Server\\Core\\types\\SessionSettingsType.cs");
                    aduser = (DirectoryHelper.ReadADRecipient(userContext.ExchangePrincipal.MailboxInfo.MailboxGuid, userContext.ExchangePrincipal.MailboxInfo.IsArchive, tenantOrRootOrgRecipientSession2) as ADUser);
                }
                if (aduser != null)
                {
                    AggregatedAccountHelper aggregatedAccountHelper = new AggregatedAccountHelper(mailboxSession, aduser);
                    list = aggregatedAccountHelper.GetListOfAccounts();
                }
                int capacity = pimSendAsAggregationSubscriptionList.Count + ((list != null) ? list.Count : 0);
                List <ConnectedAccountInfo> list2 = new List <ConnectedAccountInfo>(capacity);
                foreach (PimAggregationSubscription pimAggregationSubscription in pimSendAsAggregationSubscriptionList)
                {
                    list2.Add(new ConnectedAccountInfo
                    {
                        SubscriptionGuid = pimAggregationSubscription.SubscriptionGuid,
                        EmailAddress     = SessionSettingsType.DecodeIdnDomain(pimAggregationSubscription.UserEmailAddress),
                        DisplayName      = pimAggregationSubscription.UserDisplayName
                    });
                }
                if (list != null)
                {
                    foreach (AggregatedAccountInfo aggregatedAccountInfo in list)
                    {
                        bool   flag = false;
                        string aggregatedAccountEmail = SessionSettingsType.DecodeIdnDomain(aggregatedAccountInfo.SmtpAddress);
                        if (!string.IsNullOrWhiteSpace(aggregatedAccountEmail))
                        {
                            if (list2.Find((ConnectedAccountInfo account) => StringComparer.InvariantCultureIgnoreCase.Equals(account.EmailAddress, aggregatedAccountEmail)) != null)
                            {
                                break;
                            }
                            if (!flag)
                            {
                                list2.Add(new ConnectedAccountInfo
                                {
                                    SubscriptionGuid = aggregatedAccountInfo.RequestGuid,
                                    EmailAddress     = aggregatedAccountEmail,
                                    DisplayName      = aggregatedAccountEmail
                                });
                            }
                        }
                    }
                }
                this.connectedAccountInfos = list2.ToArray();
            }
            OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.IsDatacenterMode, countersCapture, true);
            this.helpUrl = helpUrlData.HelpUrl;
            this.isPublicComputerSession = UserContextUtilities.IsPublicComputerSession(callContext.HttpContext);
            string errorString = string.Empty;

            try
            {
                IMailboxInfo mailboxInfo = userContext.ExchangePrincipal.MailboxInfo;
                TenantPublicFolderConfiguration tenantPublicFolderConfiguration = null;
                if (TenantPublicFolderConfigurationCache.Instance.TryGetValue(mailboxInfo.OrganizationId, out tenantPublicFolderConfiguration))
                {
                    ADObjectId            defaultPublicFolderMailbox = userContext.ExchangePrincipal.DefaultPublicFolderMailbox;
                    PublicFolderRecipient publicFolderRecipient      = tenantPublicFolderConfiguration.GetPublicFolderRecipient(mailboxInfo.MailboxGuid, defaultPublicFolderMailbox);
                    if (publicFolderRecipient != null)
                    {
                        if (publicFolderRecipient.IsLocal)
                        {
                            this.DefaultPublicFolderMailbox = publicFolderRecipient.PrimarySmtpAddress.ToString();
                        }
                        else if (publicFolderRecipient.ObjectId == null)
                        {
                            errorString = "publicFolderRecipient not local and ObjectId null";
                        }
                        else
                        {
                            errorString = "publicFolderRecipient not local and ObjectId " + publicFolderRecipient.ObjectId.ObjectGuid;
                        }
                    }
                    else
                    {
                        errorString = "publicFolderRecipient null";
                    }
                }
            }
            catch (LocalizedException ex)
            {
                errorString = ex.ToString();
            }
            finally
            {
                OwaUserConfigurationLogUtilities.LogAndResetPerfCapture(OwaUserConfigurationLogType.DefaultPublicFolderMailbox, countersCapture, true, errorString);
            }
        }
        // Token: 0x06000211 RID: 529 RVA: 0x000082BC File Offset: 0x000064BC
        internal static string GetWacUrl(OwaIdentity identity, string endPointUrl, string documentUrl, bool isEdit)
        {
            string arg  = isEdit ? "2" : "4";
            string text = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
            string result;

            using (HttpClient httpClient = new HttpClient())
            {
                OWAMiniRecipient    owaminiRecipient    = identity.GetOWAMiniRecipient();
                ICredentials        oauthCredential     = OauthUtils.GetOauthCredential(owaminiRecipient);
                WebHeaderCollection oauthRequestHeaders = OneDriveProUtilities.GetOAuthRequestHeaders();
                HttpSessionConfig   sessionConfig       = new HttpSessionConfig
                {
                    Method          = "GET",
                    Credentials     = oauthCredential,
                    UserAgent       = OneDriveProUtilities.UserAgentString,
                    ContentType     = "application/json;odata=verbose",
                    PreAuthenticate = true,
                    Headers         = oauthRequestHeaders
                };
                DownloadResult downloadResult;
                try
                {
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                catch (WebException ex)
                {
                    if (!OneDriveProUtilities.IsDurableUrlFormat(documentUrl))
                    {
                        throw ex;
                    }
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Exception while trying to get wac token using durable url. : {0}", ex.StackTrace);
                    documentUrl = documentUrl.Substring(0, documentUrl.LastIndexOf("?", StringComparison.InvariantCulture));
                    text        = string.Format("{0}/_api/Microsoft.SharePoint.Yammer.WACAPI.GetWacToken(fileUrl=@p, wopiAction={2})?@p='{1}'", endPointUrl, documentUrl, arg);
                    ExTraceGlobals.AttachmentHandlingTracer.TraceWarning <string>(0L, "OneDriveProUtilities.GetWacUrl Fallback to canonical url format: {0}", text);
                    OwaServerTraceLogger.AppendToLog(new TraceLogEvent("SP.GWT", null, "GetWacToken", string.Format("Error getting WAC Token fallback to canonical format:{0}", text)));
                    downloadResult = OneDriveProUtilities.TryTwice(httpClient, sessionConfig, text);
                }
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(downloadResult.ResponseStream);
                string namespaceURI = "http://schemas.microsoft.com/ado/2007/08/dataservices";
                string text2        = null;
                string text3        = null;
                string text4        = null;
                foreach (object obj in xmlDocument.GetElementsByTagName("*", namespaceURI))
                {
                    XmlNode xmlNode = (XmlNode)obj;
                    if (xmlNode is XmlElement)
                    {
                        if (text2 != null && text3 != null && text4 != null)
                        {
                            break;
                        }
                        if (string.CompareOrdinal(xmlNode.LocalName, "AppUrl") == 0)
                        {
                            text2 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessToken") == 0)
                        {
                            text3 = xmlNode.InnerText;
                        }
                        else if (string.CompareOrdinal(xmlNode.LocalName, "AccessTokenTtl") == 0)
                        {
                            text4 = xmlNode.InnerText;
                        }
                    }
                }
                if (text2 == null || text3 == null || text4 == null)
                {
                    throw new OwaException("SharePoint's GetWacToken response is not usable.");
                }
                string text5 = isEdit ? "OwaEdit" : "OwaView";
                result = string.Format("{0}&access_token={1}&access_token_ttl={2}&sc={3}", new object[]
                {
                    text2,
                    text3,
                    text4,
                    text5
                });
            }
            return(result);
        }
 private static bool InPhotoFasterPhotoFlight(OWAMiniRecipient requestor)
 {
     return(requestor != null && VariantConfiguration.GetSnapshot(requestor.GetContext(null), null, null).OwaClientServer.FasterPhoto.Enabled);
 }
Example #29
0
        private ExchangePrincipal GetExchangePrincipalFromWindowsIdentity(WindowsIdentity windowsIdentity, string smtpAddress)
        {
            OwaIdentity       owaIdentity  = OwaWindowsIdentity.CreateFromWindowsIdentity(windowsIdentity);
            OwaIdentity       owaIdentity2 = null;
            bool              flag         = false;
            bool              flag2        = false;
            ExchangePrincipal result;

            try
            {
                ExchangePrincipal exchangePrincipal = null;
                if (smtpAddress != null)
                {
                    owaIdentity2 = OwaIdentity.CreateOwaIdentityFromSmtpAddress(owaIdentity, smtpAddress, out exchangePrincipal, out flag, out flag2);
                }
                else
                {
                    owaIdentity2 = owaIdentity;
                }
                if (flag && owaIdentity2.IsPartial)
                {
                    OwaMiniRecipientIdentity owaMiniRecipientIdentity = owaIdentity2 as OwaMiniRecipientIdentity;
                    try
                    {
                        owaMiniRecipientIdentity.UpgradePartialIdentity();
                    }
                    catch (DataValidationException ex)
                    {
                        PropertyValidationError propertyValidationError = ex.Error as PropertyValidationError;
                        if (propertyValidationError == null || propertyValidationError.PropertyDefinition != MiniRecipientSchema.Languages)
                        {
                            return(null);
                        }
                        OWAMiniRecipient owaminiRecipient = owaIdentity2.FixCorruptOWAMiniRecipientCultureEntry();
                        if (owaminiRecipient != null)
                        {
                            owaIdentity2.Dispose();
                            owaIdentity2 = OwaMiniRecipientIdentity.CreateFromOWAMiniRecipient(owaminiRecipient);
                        }
                    }
                }
                if (owaIdentity == owaIdentity2 && exchangePrincipal != null)
                {
                    result = exchangePrincipal;
                }
                else
                {
                    try
                    {
                        result = owaIdentity2.InternalCreateExchangePrincipal();
                    }
                    catch (UserHasNoMailboxException)
                    {
                        result = null;
                    }
                }
            }
            finally
            {
                if (owaIdentity != owaIdentity2 && owaIdentity2 != null)
                {
                    owaIdentity2.Dispose();
                    owaIdentity2 = null;
                }
                if (owaIdentity != null)
                {
                    owaIdentity.Dispose();
                    owaIdentity = null;
                }
            }
            return(result);
        }
Example #30
0
        internal ExchangePrincipal CreateExchangePrincipal()
        {
            ExchangePrincipal exchangePrincipal = null;

            try
            {
                if (ExTraceGlobals.CoreTracer.IsTraceEnabled(TraceType.DebugTrace))
                {
                    string text = null;
                    using (WindowsIdentity current = WindowsIdentity.GetCurrent())
                    {
                        text = current.Name;
                    }
                    if (string.IsNullOrEmpty(text))
                    {
                        text = "<n/a>";
                    }
                    string arg = this.SafeGetRenderableName();
                    ExTraceGlobals.CoreTracer.TraceDebug <string, string>(0L, "Using accout {0} to bind to ExchangePrincipal object for user {1}", text, arg);
                }
                exchangePrincipal = this.InternalCreateExchangePrincipal();
            }
            catch (AdUserNotFoundException innerException)
            {
                throw new OwaADUserNotFoundException(this.SafeGetRenderableName(), null, innerException);
            }
            catch (ObjectNotFoundException ex)
            {
                bool flag = false;
                DataValidationException ex2 = ex.InnerException as DataValidationException;
                if (ex2 != null)
                {
                    PropertyValidationError propertyValidationError = ex2.Error as PropertyValidationError;
                    if (propertyValidationError != null && propertyValidationError.PropertyDefinition == MiniRecipientSchema.Languages)
                    {
                        OWAMiniRecipient owaminiRecipient = this.FixCorruptOWAMiniRecipientCultureEntry();
                        if (owaminiRecipient != null)
                        {
                            try
                            {
                                exchangePrincipal = ExchangePrincipal.FromMiniRecipient(owaminiRecipient);
                                ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier>(0L, "OwaIdentity.CreateExchangePrincipal: Got ExchangePrincipal from MiniRecipient for Sid: {0}", this.UserSid);
                                flag = true;
                            }
                            catch (ObjectNotFoundException)
                            {
                            }
                        }
                    }
                }
                if (!flag)
                {
                    ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier, ObjectNotFoundException>(0L, "OwaIdentity.CreateExchangePrincipal: Fail to create ExchangePrincipal for Sid: {0}. Cannot recover from exception: {1}", this.UserSid, ex);
                    throw ex;
                }
            }
            if (exchangePrincipal == null)
            {
                ExTraceGlobals.CoreTracer.TraceDebug <SecurityIdentifier>(0L, "OwaIdentity.CreateExchangePrincipal: Got a null ExchangePrincipal for Sid: {0}", this.UserSid);
            }
            return(exchangePrincipal);
        }