private bool TaskConfigure(ITaskContext taskContext) { IOrganizationConfig organizationConfig = taskContext.TenantSession.GetOrganizationConfig(); if (organizationConfig.IsDehydrated) { try { taskContext.TenantSession.EnableOrganizationCustomization(); } catch { } } if (this.RequiresFederationTrust()) { if (this.updateOnPremisesFedOrgId) { IFederatedOrganizationIdentifier federatedOrganizationIdentifier = base.OnPremisesSession.GetFederatedOrganizationIdentifier(); string text = (federatedOrganizationIdentifier != null && federatedOrganizationIdentifier.DelegationTrustLink != null) ? federatedOrganizationIdentifier.DelegationTrustLink.ToString() : Configuration.FederatedTrustIdentity; taskContext.OnPremisesSession.SetFederationTrustRefreshMetadata(text); SmtpDomain autoDiscoverHybridDomain = this.AutoDiscoverHybridDomain; string defaultDomain = (autoDiscoverHybridDomain != null && autoDiscoverHybridDomain.Domain != null) ? autoDiscoverHybridDomain.Domain : null; taskContext.OnPremisesSession.SetFederatedOrganizationIdentifier(this.accountNamespace, text, defaultDomain); } List <Uri> acceptedTokenIssuerUris = taskContext.Parameters.Get <List <Uri> >("_onPremAcceptedTokenIssuerUris"); if (!OrganizationRelationshipTask.VerifyAcceptedTokenIssuerUri(base.OnPremisesSession, acceptedTokenIssuerUris)) { throw new LocalizedException(HybridStrings.ErrorOnPremUsingConsumerLiveID); } acceptedTokenIssuerUris = taskContext.Parameters.Get <List <Uri> >("_tenantAcceptedTokenIssuerUris"); if (!OrganizationRelationshipTask.VerifyAcceptedTokenIssuerUri(base.TenantSession, acceptedTokenIssuerUris)) { throw new LocalizedException(HybridStrings.ErrorTenantUsingConsumerLiveID); } if (this.updateTenantFedOrgId) { base.TenantSession.SetFederatedOrganizationIdentifier(this.TenantCoexistenceDomain); } foreach (string domainName in this.addOnPremisesFedDomains) { taskContext.OnPremisesSession.AddFederatedDomain(domainName); } } OrganizationRelationship value = OrganizationRelationshipTask.ProvisionOrganizationRelationship(base.OnPremisesSession, taskContext.Parameters.Get <OrganizationRelationship>("_onPremOrgRel"), this.OnpremisesFederationInfo, new SmtpDomain[] { new SmtpDomain(this.TenantCoexistenceDomain) }, TaskCommon.GetOnPremOrgRelationshipName(this.OnPremOrgConfig)); taskContext.Parameters.Set <OrganizationRelationship>("_onPremOrgRel", value); value = OrganizationRelationshipTask.ProvisionOrganizationRelationship(base.TenantSession, taskContext.Parameters.Get <OrganizationRelationship>("_tenantOrgRel"), this.TenantFederationInfo, this.HybridDomains, TaskCommon.GetTenantOrgRelationshipName(this.OnPremOrgConfig)); taskContext.Parameters.Set <OrganizationRelationship>("_tenantOrgRel", value); return(true); }
private static bool VerifyAcceptedTokenIssuerUri(ICommonSession session, List <Uri> acceptedTokenIssuerUris) { IFederatedOrganizationIdentifier federatedOrganizationIdentifier = session.GetFederatedOrganizationIdentifier(); if (federatedOrganizationIdentifier == null) { throw new LocalizedException(HybridStrings.ErrorFederationIDNotProvisioned); } IFederationTrust fedTrust = session.GetFederationTrust(federatedOrganizationIdentifier.DelegationTrustLink); if (fedTrust == null) { throw new LocalizedException(Strings.ErrorFederationTrustNotFound(federatedOrganizationIdentifier.DelegationTrustLink.Name)); } return(acceptedTokenIssuerUris.Any((Uri u) => u.Equals(fedTrust.TokenIssuerUri))); }
private bool CheckTaskPrerequisites(ITaskContext taskContext) { this.Reset(); if (this.RequiresFederationTrust()) { string value = Configuration.SignupDomainSuffix(taskContext.HybridConfigurationObject.ServiceInstance); foreach (AutoDiscoverSmtpDomain autoDiscoverSmtpDomain in this.HybridDomains) { if (!autoDiscoverSmtpDomain.Domain.EndsWith(value, StringComparison.InvariantCultureIgnoreCase) && autoDiscoverSmtpDomain.Domain.Length <= 32) { this.accountNamespace = autoDiscoverSmtpDomain.Domain; break; } } if (string.IsNullOrEmpty(this.accountNamespace)) { base.Logger.LogInformation(HybridStrings.HybridInfoTaskLogTemplate(base.Name, HybridStrings.ErrorAccountNamespace)); base.AddLocalizedStringError(HybridStrings.ErrorAccountNamespace); return(false); } int num = base.OnPremisesSession.GetFederationTrust().Count <IFederationTrust>(); if (num == 0) { base.Logger.LogInformation(HybridStrings.HybridInfoTaskLogTemplate(base.Name, Strings.ErrorFederationTrustNotFound(""))); base.AddLocalizedStringError(HybridStrings.ErrorNoFederationTrustFound); return(false); } if (num > 1) { base.Logger.LogInformation(HybridStrings.HybridInfoTaskLogTemplate(base.Name, HybridStrings.ErrorMultipleFederationTrusts)); base.AddLocalizedStringError(HybridStrings.ErrorMultipleFederationTrusts); return(false); } IFederatedOrganizationIdentifier federatedOrganizationIdentifier = base.OnPremisesSession.GetFederatedOrganizationIdentifier(); if (federatedOrganizationIdentifier == null) { this.updateOnPremisesFedOrgId = true; } else if (federatedOrganizationIdentifier.AccountNamespace == null || string.IsNullOrEmpty(federatedOrganizationIdentifier.AccountNamespace.Domain)) { this.updateOnPremisesFedOrgId = true; } else { if (!federatedOrganizationIdentifier.Enabled) { base.Logger.LogInformation(HybridStrings.HybridInfoTaskLogTemplate(base.Name, HybridStrings.ErrorFederatedIdentifierDisabled)); base.AddLocalizedStringError(HybridStrings.ErrorFederatedIdentifierDisabled); return(false); } this.accountNamespace = federatedOrganizationIdentifier.AccountNamespace.Domain.Replace(FederatedOrganizationId.HybridConfigurationWellKnownSubDomain + ".", string.Empty); if (!string.Equals(TaskCommon.ToStringOrNull(federatedOrganizationIdentifier.DelegationTrustLink), Configuration.FederatedTrustIdentity)) { this.updateOnPremisesFedOrgId = true; } else { this.updateOnPremisesFedOrgId = false; using (IEnumerator <string> enumerator2 = (from d in this.HybridDomains select d.Domain).GetEnumerator()) { while (enumerator2.MoveNext()) { string hybridDomain = enumerator2.Current; if (!federatedOrganizationIdentifier.Domains.Any((FederatedDomain d) => string.Equals(d.Domain.Domain, hybridDomain, StringComparison.InvariantCultureIgnoreCase))) { this.addOnPremisesFedDomains.Add(hybridDomain); } } } } if (!TaskCommon.AreEqual(federatedOrganizationIdentifier.DefaultDomain, this.AutoDiscoverHybridDomain)) { this.updateOnPremisesFedOrgId = true; } } if (this.updateOnPremisesFedOrgId) { foreach (string text in from d in this.HybridDomains select d.Domain) { if (!text.Equals(this.accountNamespace, StringComparison.InvariantCultureIgnoreCase)) { this.addOnPremisesFedDomains.Add(text); } } } IFederatedOrganizationIdentifier federatedOrganizationIdentifier2 = base.TenantSession.GetFederatedOrganizationIdentifier(); string text2 = (federatedOrganizationIdentifier2 != null && federatedOrganizationIdentifier2.DefaultDomain != null) ? federatedOrganizationIdentifier2.DefaultDomain.ToString() : null; if (text2 == null || !text2.Equals(this.TenantCoexistenceDomain, StringComparison.InvariantCultureIgnoreCase)) { this.updateTenantFedOrgId = true; } } return(true); }
private string GetDefaultOwaUri(IEnumerable <IAcceptedDomain> acceptedDomains, IFederatedOrganizationIdentifier fedOrgId) { string str = Configuration.TargetOwaPrefix(base.TaskContext.HybridConfigurationObject.ServiceInstance); foreach (IAcceptedDomain acceptedDomain in acceptedDomains) { if (fedOrgId != null) { using (MultiValuedProperty <FederatedDomain> .Enumerator enumerator2 = fedOrgId.Domains.GetEnumerator()) { while (enumerator2.MoveNext()) { FederatedDomain federatedDomain = enumerator2.Current; if (federatedDomain.Domain.Domain.Equals(acceptedDomain.DomainNameDomain, StringComparison.InvariantCultureIgnoreCase)) { return(str + acceptedDomain.DomainNameDomain); } } continue; } } foreach (SmtpDomain smtpDomain in this.HybridDomains) { if (smtpDomain.Domain.Equals(acceptedDomain.DomainNameDomain, StringComparison.InvariantCultureIgnoreCase)) { return(str + acceptedDomain.DomainNameDomain); } } } throw new LocalizedException(HybridStrings.ErrorNoFederatedDomainsOnTenant); }