Ejemplo n.º 1
0
        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);
            IntraOrganizationConnector intraOrganizationConnector = organizationIdCacheValue.GetIntraOrganizationConnector(domain);

            if (intraOrganizationConnector == null)
            {
                AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string>((long)this.GetHashCode(), "{0}: IntraOrganizationConnector lookup for domain {1} found nothing", TraceContext.Get(), domain);
                throw new AutoDiscoverFailedException(Strings.descConfigurationInformationNotFound(domain), 58684U);
            }
            if (intraOrganizationConnector.DiscoveryEndpoint == null)
            {
                AutoDiscoverQuery.AutoDiscoverTracer.TraceError <object, string, ADObjectId>((long)this.GetHashCode(), "{0}: IntraOrganizationConnector lookup for domain {1} found {2}, but it doesn't have DiscoveryEndpoint set", TraceContext.Get(), domain, intraOrganizationConnector.Id);
                throw new AutoDiscoverFailedException(Strings.descMisconfiguredIntraOrganizationConnector(intraOrganizationConnector.Id.ToString()), 34108U);
            }
            AutoDiscoverQuery.AutoDiscoverTracer.TraceDebug <object, string, ADObjectId>((long)this.GetHashCode(), "{0}: IntraOrganizationConnector lookup for domain {1} found {2}", TraceContext.Get(), domain, intraOrganizationConnector.Id);
            QueryList queryListFromQueryItems = base.GetQueryListFromQueryItems(queryItems);

            return(new AutoDiscoverQueryExternalByOAuth(base.Application, base.ClientContext, base.RequestLogger, intraOrganizationConnector.DiscoveryEndpoint, base.Authenticator, queryItems, redirectionDepth, base.CreateAutoDiscoverRequest, queryListFromQueryItems));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 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);
 }