private static TokenTarget FromOrganizationRelationship(string domain, OrganizationId organizationId) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId); TargetUriResolver.Tracer.TraceDebug <string, OrganizationId>(0L, "Searching for OrganizationRelationship that matches domain {0} in organization {1}", domain, organizationId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship == null) { TargetUriResolver.Tracer.TraceError <string, OrganizationId>(0L, "Found no OrganizationRelationship that matches domain {0} in organization {1}", domain, organizationId); return(null); } if (organizationRelationship.TargetApplicationUri == null) { TargetUriResolver.Tracer.TraceError <string, OrganizationId, ADObjectId>(0L, "Found OrganizationRelationship that matches domain {0} in organization {1}, but it has not TargetApplicationUri. OrganizationRelationship is {2}", domain, organizationId, organizationRelationship.Id); return(null); } TokenTarget tokenTarget = organizationRelationship.GetTokenTarget(); TargetUriResolver.Tracer.TraceDebug(0L, "Found OrganizationRelationship that matches domain {0} in organization {1}. Target is '{2}'. OrganizationRelationship is {3}", new object[] { domain, organizationId, tokenTarget, organizationRelationship.Id }); return(tokenTarget); }
private bool HasOrganizationRelationship(OrganizationId organizationId) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(this.callerExternalIdentity.EmailAddress.Domain); return(organizationRelationship != null && organizationRelationship.Enabled && organizationRelationship.DomainNames.Contains(new SmtpDomain(this.callerExternalIdentity.EmailAddress.Domain))); }
// Token: 0x060003AC RID: 940 RVA: 0x00016E68 File Offset: 0x00015068 private ICollection <OrganizationRelationshipSettings> GetOrganizationRelationships(OrganizationIdCacheValue organizationIdCacheValue, List <SmtpAddress> addressList) { Dictionary <string, OrganizationRelationshipSettings> dictionary = new Dictionary <string, OrganizationRelationshipSettings>(); foreach (SmtpAddress smtpAddress in addressList) { OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(smtpAddress.Domain); if (organizationRelationship == null) { ExTraceGlobals.FrameworkTracer.TraceDebug <string>(0L, "GetOrganizationRelationshipSettingsRequestMessage.GetOrganizationRelationships() domain: {0} does not match any organization relationship.", smtpAddress.Domain); } else if (!organizationRelationship.Enabled) { ExTraceGlobals.FrameworkTracer.TraceDebug <string, OrganizationId>(0L, "GetOrganizationRelationshipSettingsRequestMessage.GetOrganizationRelationships() organization relationship for domain: {0} with id {1} is disabled.", smtpAddress.Domain, organizationIdCacheValue.OrganizationId); } else if (!dictionary.ContainsKey(organizationRelationship.DistinguishedName)) { dictionary.Add(organizationRelationship.DistinguishedName, new OrganizationRelationshipSettings(organizationRelationship)); } } if (dictionary.Count == 0) { return(null); } return(dictionary.Values); }
protected ADObjectId ResolveMailboxDatabase(ADRawEntry activeDirectoryRawEntry) { if (activeDirectoryRawEntry == null) { throw new ArgumentNullException("activeDirectoryRawEntry"); } SmtpProxyAddress smtpProxyAddress = (SmtpProxyAddress)activeDirectoryRawEntry[ADRecipientSchema.ExternalEmailAddress]; if (smtpProxyAddress != null) { OrganizationId key = (OrganizationId)activeDirectoryRawEntry[ADObjectSchema.OrganizationId]; OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(key); if (!((SmtpAddress)smtpProxyAddress).IsValidAddress) { ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: ExternalEmailAddress configured is invalid."); } else { OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(((SmtpAddress)smtpProxyAddress).Domain); if (organizationRelationship != null && organizationRelationship.TargetOwaURL != null) { string absoluteUri = organizationRelationship.TargetOwaURL.AbsoluteUri; ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: Stop processing and redirect to {0}.", absoluteUri); base.Logger.AppendGenericInfo("ExternalRedir", absoluteUri); throw new ServerSideTransferException(absoluteUri, LegacyRedirectTypeOptions.Manual); } ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: Unable to find OrganizationRelationShip or its TargetOwaUrl is not configured."); base.Logger.AppendGenericInfo("ExternalRedir", "Org-Relationship or targetOwaUrl not found."); } } return(null); }
private static bool IsOrganizationHasOrganizationRelationshipWithDomain(OrganizationId organizationId, string domain) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); return(organizationRelationship != null); }
public OrganizationRelationship GetOrganizationRelationship(OrganizationId organizationId, string domain) { OrganizationRelationship relationship = null; this.DoAdCallAndTranslateExceptions(delegate { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId); relationship = organizationIdCacheValue.GetOrganizationRelationship(domain); }, "DirectoryAccessor:GetOrganizationRelationship"); return(relationship); }
private OrganizationRelationship TryGetOrganizationRelationship(OrganizationId orgId, string targetDomain) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(orgId); if (organizationIdCacheValue == null) { TraceWrapper.SearchLibraryTracer.TraceError(this.GetHashCode(), "Null cache value returned from OrganizationIdCacheValue", new object[0]); TrackingFatalException.RaiseED(ErrorCode.InvalidADData, "Organization Relationships could not be read for organization {0}", new object[] { orgId }); } return(organizationIdCacheValue.GetOrganizationRelationship(targetDomain)); }
// Token: 0x06000302 RID: 770 RVA: 0x000100E8 File Offset: 0x0000E2E8 private string GetRedirectAddressForUserHasNoMailbox(ActiveSyncMiniRecipient activesyncMiniRecipient) { string easEndpoint = null; if (!VariantConfiguration.InvariantNoFlightingSnapshot.ActiveSync.RedirectForOnBoarding.Enabled) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "The hybrid on boarding redirect feature is only for OnPrem servers."); return(null); } if (this.context.CommandType != CommandType.Options && this.context.AirSyncVersion < GlobalSettings.MinRedirectProtocolVersion) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "The protocol version is less than 14.0 that doesn't support 451 redirect protocol call."); return(null); } AirSyncDiagnostics.FaultInjectionPoint(3414568253U, delegate { if (activesyncMiniRecipient != null && activesyncMiniRecipient.ExternalEmailAddress != null) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Try to figure out eas endpoint for user: {0}.", activesyncMiniRecipient.ExternalEmailAddress.AddressString); this.context.ProtocolLogger.SetValue(ProtocolLoggerData.RedirectTo, "TryToFigureOutEasEndpoint"); SmtpProxyAddress smtpProxyAddress = activesyncMiniRecipient.ExternalEmailAddress as SmtpProxyAddress; if (smtpProxyAddress != null && !string.IsNullOrEmpty(smtpProxyAddress.AddressString)) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(activesyncMiniRecipient.OrganizationId); string domain = ((SmtpAddress)smtpProxyAddress).Domain; OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship != null) { Uri targetOwaURL = organizationRelationship.TargetOwaURL; easEndpoint = this.TransferTargetOwaUrlToEasEndpoint(targetOwaURL); AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Redirect to EASEndpoint : {0}.", easEndpoint); this.context.ProtocolLogger.AppendValue(ProtocolLoggerData.RedirectTo, easEndpoint); return; } AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "OrganizationRelationShip is null for the domain {0}", domain); return; } else { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "External email address is null"); } } }, delegate { Uri targetOwaUri = new Uri("http://outlook.com/owa"); easEndpoint = this.TransferTargetOwaUrlToEasEndpoint(targetOwaUri); }); return(easEndpoint); }
internal static OrganizationRelationship GetOrganizationRelationship(OrganizationId organizationId, string requesterDomain) { OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get((organizationId == null) ? OrganizationId.ForestWideOrgId : organizationId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(requesterDomain); if (organizationRelationship == null) { FreeBusyPermission.SecurityTracer.TraceDebug <object, string>(0L, "{0}: No organization relationship found for domain {1}", TraceContext.Get(), requesterDomain); return(null); } if (!organizationRelationship.Enabled) { FreeBusyPermission.SecurityTracer.TraceDebug <object, string>(0L, "{0}: Organization relationship for domain {1} is disabled.", TraceContext.Get(), requesterDomain); return(null); } return(organizationRelationship); }
// Token: 0x06001232 RID: 4658 RVA: 0x0004D0F0 File Offset: 0x0004B2F0 private bool PhotoSharingEnabled(PhotoPrincipal requestor, PhotoPrincipal target) { OrganizationIdCacheValue organizationIdCacheValue = this.organizationConfigCache.Get((target.OrganizationId == null) ? OrganizationId.ForestWideOrgId : target.OrganizationId); if (organizationIdCacheValue == null) { this.tracer.TraceError((long)this.GetHashCode(), "Photo authorization: target organization's configuration not available in cache."); return(false); } foreach (string domain in requestor.GetEmailAddressDomains()) { OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship != null && organizationRelationship.Enabled && organizationRelationship.PhotosEnabled) { return(true); } } return(false); }
// Token: 0x060005CB RID: 1483 RVA: 0x000202C4 File Offset: 0x0001E4C4 protected ADObjectId ResolveMailboxDatabase(ADRawEntry activeDirectoryRawEntry) { if (activeDirectoryRawEntry == null) { throw new ArgumentNullException("activeDirectoryRawEntry"); } SmtpProxyAddress smtpProxyAddress = (SmtpProxyAddress)activeDirectoryRawEntry[ADRecipientSchema.ExternalEmailAddress]; if (smtpProxyAddress != null) { OrganizationId organizationId = (OrganizationId)activeDirectoryRawEntry[ADObjectSchema.OrganizationId]; OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(organizationId); SmtpAddress smtpAddress = (SmtpAddress)smtpProxyAddress; if (!smtpAddress.IsValidAddress) { if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1)) { ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: ExternalEmailAddress configured is invalid."); } } else { OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(((SmtpAddress)smtpProxyAddress).Domain); if (organizationRelationship != null && organizationRelationship.TargetOwaURL != null) { string absoluteUri = organizationRelationship.TargetOwaURL.AbsoluteUri; if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1)) { ExTraceGlobals.VerboseTracer.TraceDebug <string>((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: Stop processing and redirect to {0}.", absoluteUri); } base.Logger.AppendGenericInfo("ExternalRedir", absoluteUri); throw new HttpException(302, this.GetCrossPremiseRedirectUrl(smtpAddress.Domain, organizationId.ToExternalDirectoryOrganizationId(), smtpProxyAddress.SmtpAddress)); } if (ExTraceGlobals.VerboseTracer.IsTraceEnabled(1)) { ExTraceGlobals.VerboseTracer.TraceDebug((long)this.GetHashCode(), "[OwaProxyRequestHandler::ResolveMailboxDatabase]: Unable to find OrganizationRelationShip or its TargetOwaUrl is not configured."); } base.Logger.AppendGenericInfo("ExternalRedir", "Org-Relationship or targetOwaUrl not found."); } } return(null); }
protected override AutoDiscoverQuery CreateAutoDiscoverQuery(string domain, AutoDiscoverQueryItem[] queryItems, int redirectionDepth) { AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Search for OrganizationRelationship for domain {1}", TraceContext.Get(), domain); OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(base.ClientContext.OrganizationId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship == null) { AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: OrganizationRelationship lookup for domain {1} found nothing", TraceContext.Get(), domain); throw new AutoDiscoverFailedException(Strings.descConfigurationInformationNotFound(domain), 54588U); } if (organizationRelationship.TargetAutodiscoverEpr == null) { AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string, ADObjectId>((long)this.GetHashCode(), "{0}: OrganizationRelationship lookup for domain {1} found {2}, but it doesn't have TargetAutodiscoverEpr set", TraceContext.Get(), domain, organizationRelationship.Id); throw new AutoDiscoverFailedException(Strings.descMisconfiguredOrganizationRelationship(organizationRelationship.Id.ToString()), 42300U); } AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug <object, string, ADObjectId>((long)this.GetHashCode(), "{0}: OrganizationRelationship lookup for domain {1} found {2}", TraceContext.Get(), domain, organizationRelationship.Id); QueryList queryListFromQueryItems = base.GetQueryListFromQueryItems(queryItems); return(new AutoDiscoverQueryExternal(base.Application, base.ClientContext, base.RequestLogger, organizationRelationship.TargetAutodiscoverEpr, base.Authenticator, queryItems, redirectionDepth, base.CreateAutoDiscoverRequest, queryListFromQueryItems)); }
// Token: 0x06000220 RID: 544 RVA: 0x0000CBEC File Offset: 0x0000ADEC private static OrganizationRelationship GetOrganizationRelationship(ADRecipient user, string overrideOwaUrlString = null) { if (overrideOwaUrlString != null) { ExTraceGlobals.FrameworkTracer.TraceDebug(0L, "[MobileRedirectOptimization] Creating mock OrganizationRelationship for testing."); return(new OrganizationRelationship { TargetOwaURL = new Uri(overrideOwaUrlString), Enabled = true }); } ExTraceGlobals.FrameworkTracer.TraceDebug <string>(0L, "[MobileRedirectOptimization] Attempting to retrieve OrganizationRelationship for user {0}.", MobileRedirectOptimization.SafeGetEmailAddressStringFromADUser(user)); OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(user.OrganizationId); if (organizationIdCacheValue != null) { string text = MobileRedirectOptimization.SafeGetEmailDomainFromADUser(user); if (text != null) { return(organizationIdCacheValue.GetOrganizationRelationship(text)); } } return(null); }
private void Discover(ExchangePrincipal principal, ADUser executingUser, out string ewsEndpoint, out DelegationTokenRequest ewsTokenRequest) { SmtpAddress value = principal.MailboxInfo.RemoteIdentity.Value; ADSessionSettings sessionSettings = ADSessionSettings.FromOrganizationIdWithoutRbacScopesServiceOnly(OrganizationId.ForestWideOrgId); IRecipientSession tenantOrRootOrgRecipientSession = DirectorySessionFactory.Default.GetTenantOrRootOrgRecipientSession(null, true, ConsistencyMode.FullyConsistent, null, sessionSettings, ConfigScopes.TenantSubTree, 168, "Discover", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxSearchEwsClient.cs"); ADUser aduser = null; TransportConfigContainer transportConfigContainer = DirectorySessionFactory.Default.GetTenantOrTopologyConfigurationSession(true, ConsistencyMode.IgnoreInvalid, sessionSettings, 171, "Discover", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxSearchEwsClient.cs").FindSingletonConfigurationObject <TransportConfigContainer>(); if (transportConfigContainer != null && transportConfigContainer.OrganizationFederatedMailbox != SmtpAddress.NullReversePath) { SmtpAddress organizationFederatedMailbox = transportConfigContainer.OrganizationFederatedMailbox; ProxyAddress proxyAddress = null; try { proxyAddress = ProxyAddress.Parse(organizationFederatedMailbox.ToString()); } catch (ArgumentException ex) { ExTraceGlobals.SessionTracer.TraceError <string>((long)this.GetHashCode(), "Proxy address of organization federated mailbox is invalid: {0}", ex.ToString()); } if (proxyAddress != null && !(proxyAddress is InvalidProxyAddress)) { aduser = (tenantOrRootOrgRecipientSession.FindByProxyAddress(proxyAddress) as ADUser); } } OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(OrganizationId.ForestWideOrgId); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(value.Domain); if (aduser == null || organizationRelationship == null) { throw new OrganizationNotFederatedException(); } DelegationTokenRequest request = new DelegationTokenRequest { FederatedIdentity = aduser.GetFederatedIdentity(), EmailAddress = aduser.GetFederatedSmtpAddress().ToString(), Target = organizationRelationship.GetTokenTarget(), Offer = Offer.Autodiscover }; FedOrgCredentials credentials = new FedOrgCredentials(request, this.GetSecurityTokenService(aduser.OrganizationId)); Uri uri = null; using (AutoDiscoverUserSettingsClient autoDiscoverUserSettingsClient = AutoDiscoverUserSettingsClient.CreateInstance(DirectorySessionFactory.Default.CreateTopologyConfigurationSession(ConsistencyMode.IgnoreInvalid, sessionSettings, 215, "Discover", "f:\\15.00.1497\\sources\\dev\\data\\src\\storage\\Search\\MailboxSearch\\MailboxSearchEwsClient.cs"), credentials, value, organizationRelationship.TargetAutodiscoverEpr, MailboxSearchEwsClient.AutoDiscoverRequestedSettings)) { UserSettings userSettings = autoDiscoverUserSettingsClient.Discover(); StringSetting stringSetting = userSettings.GetSetting("ExternalEwsUrl") as StringSetting; if (stringSetting == null || !Uri.TryCreate(stringSetting.Value, UriKind.Absolute, out uri)) { throw new AutoDAccessException(ServerStrings.AutoDRequestFailed); } } ewsEndpoint = EwsWsSecurityUrl.Fix(uri.ToString()); string text = null; if (executingUser.EmailAddresses != null && executingUser.EmailAddresses.Count > 0) { List <string> federatedEmailAddresses = executingUser.GetFederatedEmailAddresses(); if (federatedEmailAddresses != null && federatedEmailAddresses.Count > 0) { text = federatedEmailAddresses[0]; } } if (string.IsNullOrEmpty(text)) { ewsTokenRequest = new DelegationTokenRequest { FederatedIdentity = aduser.GetFederatedIdentity(), EmailAddress = aduser.GetFederatedSmtpAddress().ToString(), Target = organizationRelationship.GetTokenTarget(), Offer = Offer.MailboxSearch }; return; } ewsTokenRequest = new DelegationTokenRequest { FederatedIdentity = executingUser.GetFederatedIdentity(), EmailAddress = text.ToString(), Target = organizationRelationship.GetTokenTarget(), Offer = Offer.MailboxSearch }; }
public SharingInformation Read(EmailAddress emailAddress, Application application) { if (this.requester == null) { SharingReader.RequestRoutingTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: Unable to get the requestor from the client context - address {1}", TraceContext.Get(), emailAddress.Address); return(new SharingInformation(new InvalidClientSecurityContextException())); } if (this.supportsPersonalSharing) { SharingSubscriptionData userSubscription = this.SubscriptionLoader.GetUserSubscription(emailAddress); if (!this.SubscriptionLoader.IsValid) { SharingReader.RequestRoutingTracer.TraceError <object, EmailAddress, Exception>((long)this.GetHashCode(), "{0}: SubscriptionLoader cannot open mailbox {1}. Exception: {2}", TraceContext.Get(), emailAddress, this.SubscriptionLoader.HandledException); } if (userSubscription != null) { SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Found a personal relationship for {1}", TraceContext.Get(), emailAddress.Address); if (SmtpAddress.IsValidSmtpAddress(userSubscription.SubscriberIdentity) && SmtpAddress.IsValidSmtpAddress(userSubscription.SharingKey)) { Uri sharingUrl = userSubscription.SharingUrl; return(new SharingInformation(new SmtpAddress(userSubscription.SubscriberIdentity), new SmtpAddress(userSubscription.SharingKey), new TokenTarget(userSubscription.SharerIdentityFederationUri), new WebServiceUri(sharingUrl.OriginalString, sharingUrl.Scheme, UriSource.Directory, Globals.E14SP2Version), null)); } SharingReader.RequestRoutingTracer.TraceError <object, EmailAddress>((long)this.GetHashCode(), "{0}: The subscriber information in the mailbox is invalid for address {1}. Personal subscription can't be used.", TraceContext.Get(), emailAddress); } } string domain = emailAddress.Domain; OrganizationId key = (this.requester.OrganizationId == null) ? OrganizationId.ForestWideOrgId : this.requester.OrganizationId; OrganizationIdCacheValue organizationIdCacheValue = OrganizationIdCache.Singleton.Get(key); SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Looking for an Intra-Organization connector with domain {1}.", TraceContext.Get(), domain); IntraOrganizationConnector intraOrganizationConnector = organizationIdCacheValue.GetIntraOrganizationConnector(domain); WebServiceUri targetSharingEpr; if (intraOrganizationConnector != null && intraOrganizationConnector.Enabled) { Uri discoveryEndpoint = intraOrganizationConnector.DiscoveryEndpoint; int autodiscoverVersionBucket = application.GetAutodiscoverVersionBucket(AutodiscoverType.External); targetSharingEpr = RemoteServiceUriCache.Get(emailAddress, autodiscoverVersionBucket); return(new SharingInformation(this.requester.PrimarySmtpAddress, targetSharingEpr, discoveryEndpoint)); } SharingReader.RequestRoutingTracer.TraceDebug <object, string>((long)this.GetHashCode(), "{0}: Looking for an Organization Relationship with domain {1}.", TraceContext.Get(), domain); OrganizationRelationship organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(domain); if (organizationRelationship == null) { SharingReader.RequestRoutingTracer.TraceError <object, string, EmailAddress>((long)this.GetHashCode(), "{0}: Unable to find a organization Relationship with domain {1} for emailAddress {2}.", TraceContext.Get(), emailAddress.Domain, emailAddress); return(null); } if (!organizationRelationship.Enabled) { SharingReader.RequestRoutingTracer.TraceError <object, OrganizationRelationship, string>((long)this.GetHashCode(), "{0}: Organization Relationship {1} is not enabled for access to domain {2}. Ignoring this relationship.", TraceContext.Get(), organizationRelationship, emailAddress.Domain); return(null); } if (!application.EnabledInRelationship(organizationRelationship)) { SharingReader.RequestRoutingTracer.TraceError((long)this.GetHashCode(), "{0}: Organization Relationship {1} is not enabled for application {2} to domain {3}. Ignoring this relationship.", new object[] { TraceContext.Get(), organizationRelationship, application.GetType(), emailAddress.Domain }); return(null); } if (!organizationRelationship.IsValidForRequestDispatcher()) { SharingReader.RequestRoutingTracer.TraceError((long)this.GetHashCode(), "{0}: Organization Relationship is invalid for dispatching requests, TargetApplicationUri:{1}, TargetSharingEpr:{2}, AutoDiscoverEpr:{3}.", new object[] { TraceContext.Get(), organizationRelationship.TargetApplicationUri, organizationRelationship.TargetSharingEpr, organizationRelationship.TargetAutodiscoverEpr }); return(new SharingInformation(new InvalidOrganizationRelationshipForRequestDispatcherException(organizationRelationship.ToString()))); } if (DateTime.UtcNow > this.readDeadline) { return(new SharingInformation(new TimeoutExpiredException("OrganizationRelationship lookup"))); } Uri targetSharingEpr2 = organizationRelationship.TargetSharingEpr; if (targetSharingEpr2 == null) { int autodiscoverVersionBucket2 = application.GetAutodiscoverVersionBucket(AutodiscoverType.External); targetSharingEpr = RemoteServiceUriCache.Get(emailAddress, autodiscoverVersionBucket2); } else { targetSharingEpr = new WebServiceUri(targetSharingEpr2.OriginalString, targetSharingEpr2.Scheme, UriSource.Directory, Globals.E14SP2Version); } return(new SharingInformation(this.requester.PrimarySmtpAddress, SmtpAddress.Empty, organizationRelationship.GetTokenTarget(), targetSharingEpr, organizationRelationship.TargetAutodiscoverEpr)); }
public static bool TryGetDiscoveryEndPoint(OrganizationId orgId, string crossPremiseDomain, Func <OrganizationId, OrganizationIdCacheValue> getOrgIdCacheValue, Func <OrganizationIdCacheValue, string, IntraOrganizationConnector> getIntraOrganizationConnector, Func <OrganizationIdCacheValue, string, OrganizationRelationship> getOrganizationRelationShip, out Uri discoveryEndPoint, out EndPointDiscoveryInfo info) { discoveryEndPoint = null; info = new EndPointDiscoveryInfo(); if (orgId == null) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.Error, "orgId is null"); return(false); } if (string.IsNullOrEmpty(crossPremiseDomain)) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.Error, "crossPremiseDomain is invalid"); return(false); } try { OrganizationIdCacheValue organizationIdCacheValue = null; if (getOrgIdCacheValue == null) { organizationIdCacheValue = OrganizationIdCache.Singleton.Get(orgId); } else { organizationIdCacheValue = getOrgIdCacheValue(orgId); } IntraOrganizationConnector intraOrganizationConnector = null; try { if (getIntraOrganizationConnector == null) { if (organizationIdCacheValue == null) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.Error, string.Format("OrganizationIdCacheValue == null. OrgID=[{0}], domain=[{1}]. getOrgIdCacheValue is{2} null.", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, (getOrgIdCacheValue == null) ? string.Empty : " not")); return(false); } intraOrganizationConnector = organizationIdCacheValue.GetIntraOrganizationConnector(crossPremiseDomain); } else { intraOrganizationConnector = getIntraOrganizationConnector(organizationIdCacheValue, crossPremiseDomain); } } catch (Exception ex) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.IocException, ex.ToString()); } if (intraOrganizationConnector == null) { string message = string.Format("IntraOrganizationConnector lookup for org [{0}], domain [{1}] found nothing. getIntraOrganizationConnector is{2} null.", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, (getIntraOrganizationConnector == null) ? string.Empty : " not"); info.AddInfo((info.Status == EndPointDiscoveryInfo.DiscoveryStatus.Success) ? EndPointDiscoveryInfo.DiscoveryStatus.IocNotFound : info.Status, message); } else { if (!(intraOrganizationConnector.DiscoveryEndpoint == null)) { ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug(0L, "IntraOrganizationConnector lookup for org [{0}], domain [{1}] found [{2}]. End point=[{3}].", new object[] { orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, intraOrganizationConnector.Id, intraOrganizationConnector.DiscoveryEndpoint }); discoveryEndPoint = intraOrganizationConnector.DiscoveryEndpoint; return(true); } info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.IocNoUri, string.Format("IntraOrganizationConnector lookup for org [{0}], domain [{1}] found [{2}], but it doesn't have DiscoveryEndpoint set. getIntraOrganizationConnector is{3} null.", new object[] { orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, intraOrganizationConnector.Id, (getIntraOrganizationConnector == null) ? string.Empty : " not" })); } OrganizationRelationship organizationRelationship; if (getOrganizationRelationShip == null) { if (organizationIdCacheValue == null) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.Error, string.Format("OrganizationIdCacheValue is null. OrgID=[{0}], domain=[{1}]. getOrgIdCacheValue is{2} null.", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, (getOrgIdCacheValue == null) ? string.Empty : " not")); return(false); } organizationRelationship = organizationIdCacheValue.GetOrganizationRelationship(crossPremiseDomain); } else { organizationRelationship = getOrganizationRelationShip(organizationIdCacheValue, crossPremiseDomain); } if (organizationRelationship == null) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.OrNotFound, string.Format("Unable to find the org relationship for OrgID=[{0}], domain=[{1}]. getOrganizationRelationShip is{2} null.", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, (getOrganizationRelationShip == null) ? string.Empty : " not")); return(false); } if (organizationRelationship.TargetAutodiscoverEpr == null) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.OrNoUri, string.Format("The TargetAutodiscoverEpr in org relationship is null for OrgID=[{0}], domain=[{1}]. getOrganizationRelationShip is{2} null.", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, (getOrganizationRelationShip == null) ? string.Empty : " not")); return(false); } ExTraceGlobals.ServiceDiscoveryTracer.TraceDebug <string, string, Uri>(0L, "OrganizationRelationship lookup for org [{0}], domain [{1}] found end point: [{2}]", orgId.ToExternalDirectoryOrganizationId(), crossPremiseDomain, organizationRelationship.TargetAutodiscoverEpr); discoveryEndPoint = organizationRelationship.TargetAutodiscoverEpr; } catch (Exception ex2) { info.AddInfo(EndPointDiscoveryInfo.DiscoveryStatus.Error, ex2.ToString()); return(false); } return(true); }