public DeveloperWrapper(DeveloperModel developer, X509Certificate2 standardSamlCertificate) { Developer = developer; _tenantInfoMappings = new Dictionary <string, ITenantInfo>(); _tenantInfoMappingsByUuid = new Dictionary <long, ITenantInfo>(); TenantInfos = new List <ITenantInfo>(); developer.Tenants.ForEach(tenant => { string subdomainPattern = tenant.SubdomainPattern; X509Certificate2 developerCertificate = null; if (!string.IsNullOrEmpty(developer.Certificate)) { if (string.IsNullOrEmpty(developer.CertificatePassword)) { throw new Exception("Developer in tenant database has certificate set, but no certificate password is present"); } developerCertificate = new X509Certificate2(GetCertificateBytesFromPEM(developer.Certificate), developer.CertificatePassword); } if (string.IsNullOrEmpty(tenant.Name)) { throw new Exception("The tenant name is empty"); } if (string.IsNullOrEmpty(tenant.FrontendApiUrl)) { throw new Exception("The tenant frontend API URL is empty"); } if (string.IsNullOrEmpty(tenant.BackendApiUrl)) { throw new Exception("The tenant backend API url is empty"); } if (string.IsNullOrEmpty(tenant.WebUrl)) { throw new Exception("The tenant web url is empty"); } bool?requiresTermsAndConditions = tenant.RequiresTermsAndConditions; if (requiresTermsAndConditions == null) { requiresTermsAndConditions = developer.RequiresTermsAndConditions; } string logoSvgUrl = tenant.LogoSvgUrl; if (string.IsNullOrEmpty(logoSvgUrl)) { logoSvgUrl = developer.LogoSvgUrl; } string logoPngUrl = tenant.LogoPngUrl; if (string.IsNullOrEmpty(logoPngUrl)) { logoPngUrl = developer.LogoPngUrl; } string iconIcoUrl = tenant.IconIcoUrl; if (string.IsNullOrEmpty(iconIcoUrl)) { iconIcoUrl = developer.IconIcoUrl; } string storageImplementation = tenant.StorageImplementation; if (string.IsNullOrEmpty(storageImplementation)) { storageImplementation = developer.StorageImplementation; } // storage is optional string storageConnectionString = null; if (!string.IsNullOrEmpty(storageImplementation)) { if (!storageImplementation.Equals(StorageConstants.StorageImplementationAzure) && !storageImplementation.Equals(StorageConstants.StorageImplementationGoogleCloud)) { throw new Exception("The tenant storage implementation specification is invalid"); } storageConnectionString = tenant.StorageConnectionString; if (string.IsNullOrEmpty(storageConnectionString)) { storageConnectionString = developer.StorageConnectionString; } } int?primaryColor = tenant.PrimaryColor; if (primaryColor == null) { primaryColor = developer.PrimaryColor; } int?secondaryColor = tenant.SecondaryColor; if (secondaryColor == null) { secondaryColor = developer.SecondaryColor; } int?textOnPrimaryColor = tenant.TextOnPrimaryColor; if (textOnPrimaryColor == null) { textOnPrimaryColor = developer.TextOnPrimaryColor; } int?textOnSecondaryColor = tenant.TextOnSecondaryColor; if (textOnSecondaryColor == null) { textOnSecondaryColor = developer.TextOnSecondaryColor; } string supportEmail = tenant.SupportEmail; if (string.IsNullOrEmpty(supportEmail)) { supportEmail = developer.SupportEmail; } string noreplyEmail = tenant.NoreplyEmail; if (string.IsNullOrEmpty(noreplyEmail)) { noreplyEmail = developer.NoreplyEmail; } string customInvitationEmailTextPrefix = tenant.CustomInvitationEmailTextPrefix; if (string.IsNullOrEmpty(customInvitationEmailTextPrefix)) { customInvitationEmailTextPrefix = null; } string customInvitationEmailTextSuffix = tenant.CustomInvitationEmailTextSuffix; if (string.IsNullOrEmpty(customInvitationEmailTextSuffix)) { customInvitationEmailTextSuffix = null; } string productName = tenant.ProductName; if (string.IsNullOrEmpty(productName)) { productName = developer.ProductName; } string defaultCulture = tenant.DefaultCulture; if (string.IsNullOrEmpty(defaultCulture)) { defaultCulture = "en"; } string defaultCurrency = tenant.DefaultCurrency; if (string.IsNullOrEmpty(defaultCurrency)) { defaultCurrency = "eur"; } bool usersAreExternallyManaged = false; string externalAuthorizationMethod = tenant.ExternalAuthenticationMethod; // external authorization is optional string oidcClientId = null; string oidcClientSecret = null; string oidcEndpointUrl = null; string samlEntityId = null; string samlMetadataLocation = null; string samlProviderUrl = null; X509Certificate2 samlCertificate = null; bool samlAllowWeakSigningAlgorithm = false; string externalDirectoryType = null; string externalDirectoryHost = null; int?externalDirectoryPort = null; bool?externalDirectoryUsesSsl = null; X509Certificate2 externalDirectorySslCertificate = null; string externalDirectoryAccountDistinguishedName = null; string externalDirectoryPassword = null; string externalDirectoryLoginAttribute = null; string externalDirectoryBaseContexts = null; string externalDirectoryUserFilter = null; string externalDirectoryGroupFilter = null; int?externalDirectorySyncIntervalSeconds = null; string externalDirectoryAdministratorGroupUuid = null; if (!string.IsNullOrEmpty(externalAuthorizationMethod)) { if (!externalAuthorizationMethod.Equals(TenantConstants.ExternalAuthenticationMethodOidc) && !externalAuthorizationMethod.Equals(TenantConstants.ExternalAuthenticationMethodSaml)) { throw new Exception("The tenant external authentication method specification is invalid"); } if (externalAuthorizationMethod.Equals(TenantConstants.ExternalAuthenticationMethodOidc)) { oidcClientId = tenant.OidcClientId; if (string.IsNullOrEmpty(oidcClientId)) { throw new Exception("The tenant OIDC client ID is missing"); } oidcClientSecret = tenant.OidcClientSecret; if (string.IsNullOrEmpty(oidcClientSecret)) { throw new Exception("The tenant OIDC client secret is missing"); } oidcEndpointUrl = tenant.OidcEndpointUrl; if (string.IsNullOrEmpty(oidcEndpointUrl)) { throw new Exception("The tenant OIDC endpoint URL is missing"); } } else if (externalAuthorizationMethod.Equals(TenantConstants.ExternalAuthenticationMethodSaml)) { samlEntityId = tenant.SamlEntityId; if (string.IsNullOrEmpty(samlEntityId)) { throw new Exception("The tenant SAML entity ID is missing"); } samlMetadataLocation = tenant.SamlMetadataLocation; if (string.IsNullOrEmpty(samlMetadataLocation)) { throw new Exception("The tenant SAML metadata location is missing"); } samlProviderUrl = tenant.SamlProviderUrl; if (string.IsNullOrEmpty(samlProviderUrl)) { throw new Exception("The tenant SAML provider URL is missing"); } if (!string.IsNullOrEmpty(tenant.SamlCertificate)) { samlCertificate = new X509Certificate2(GetCertificateBytesFromPEM(tenant.SamlCertificate)); } else { samlCertificate = standardSamlCertificate; } samlAllowWeakSigningAlgorithm = tenant.SamlAllowWeakSigningAlgorithm ?? false; } externalDirectoryType = tenant.ExternalDirectoryType; if (string.IsNullOrEmpty(externalDirectoryType)) { throw new Exception("The tenant external directory type is missing"); } if (/* !string.Equals(externalDirectoryType, DirectoryConstants.DirectoryTypeAD) && * !string.Equals(externalDirectoryType, DirectoryConstants.DirectoryTypeADLDS) && * !string.Equals(externalDirectoryType, DirectoryConstants.DirectoryTypeLDAP) && */ !string.Equals(externalDirectoryType, DirectoryConstants.DirectoryTypeDynamic)) { throw new Exception("The tenant external directory type specification is invalid"); } // TODO: LDAP etc. is not yet implemented if (!string.Equals(externalDirectoryType, DirectoryConstants.DirectoryTypeDynamic)) { // dynamic directory types will create users on-demand when logging in externalDirectoryHost = tenant.ExternalDirectoryHost; if (string.IsNullOrEmpty(externalDirectoryHost)) { throw new Exception("The tenant external directory host is missing"); } externalDirectoryUsesSsl = tenant.ExternalDirectoryUsesSsl ?? false; externalDirectoryPort = tenant.ExternalDirectoryPort; if (externalDirectoryPort != null && (externalDirectoryPort <= 0 || externalDirectoryPort >= ushort.MaxValue)) { throw new Exception("The tenant external directory port is invalid"); } if (!string.IsNullOrEmpty(tenant.ExternalDirectorySslCertificate)) { externalDirectorySslCertificate = new X509Certificate2(GetCertificateBytesFromPEM(tenant.ExternalDirectorySslCertificate)); } if ((bool)externalDirectoryUsesSsl && externalDirectorySslCertificate == null) { throw new Exception("The tenant external directory SSL certificate is missing"); } externalDirectoryAccountDistinguishedName = tenant.ExternalDirectoryAccountDistinguishedName; if (string.IsNullOrEmpty(externalDirectoryAccountDistinguishedName)) { throw new Exception("The tenant external directory account distinguished name is missing"); } externalDirectoryPassword = tenant.ExternalDirectoryPassword; if (string.IsNullOrEmpty(externalDirectoryPassword)) { throw new Exception("The tenant external directory password is missing"); } externalDirectoryLoginAttribute = tenant.ExternalDirectoryLoginAttribute; externalDirectoryBaseContexts = tenant.ExternalDirectoryBaseContexts; if (string.IsNullOrEmpty(externalDirectoryBaseContexts)) { throw new Exception("The tenant external directory base contexts are missing"); } externalDirectoryUserFilter = tenant.ExternalDirectoryUserFilter; externalDirectoryGroupFilter = tenant.ExternalDirectoryGroupFilter; externalDirectorySyncIntervalSeconds = tenant.ExternalDirectorySyncIntervalSeconds; if (externalDirectorySyncIntervalSeconds != null && externalDirectorySyncIntervalSeconds < 1) { throw new Exception("The tenant external directory sync interval is invalid"); } externalDirectoryAdministratorGroupUuid = tenant.ExternalDirectoryAdministratorGroupUuid; if (string.IsNullOrEmpty(externalDirectoryAdministratorGroupUuid)) { throw new Exception("The tenant external directory administrator group UUID is missing"); } } usersAreExternallyManaged = true; } var tenantInfo = new TenantInfoImpl() { DeveloperUuid = developer.Uuid, DeveloperAuthority = developer.Authority, DeveloperAudience = developer.Audience, DeveloperCertificate = developerCertificate, DeveloperAuthCookieDomain = developer.AuthCookieDomain, DeveloperName = developer.Name, DeveloperPrivacyPolicyUrl = developer.PrivacyPolicyUrl, DeveloperPrivacyPolicyVersion = developer.PrivacyPolicyVersion, DeveloperTermsAndConditionsUrl = developer.TermsAndConditionsUrl, DeveloperTermsAndConditionsVersion = developer.TermsAndConditionsVersion, TenantUuid = tenant.Uuid, Name = tenant.Name, RequiresTermsAndConditions = requiresTermsAndConditions ?? true, LogoSvgUrl = logoSvgUrl, LogoPngUrl = logoPngUrl, IconIcoUrl = iconIcoUrl, StorageImplementation = storageImplementation, StorageConnectionString = storageConnectionString, PrimaryColor = (int)primaryColor, SecondaryColor = (int)secondaryColor, TextOnPrimaryColor = (int)textOnPrimaryColor, TextOnSecondaryColor = (int)textOnSecondaryColor, PrimaryColorHex = ConvertToHexColor(primaryColor), SecondaryColorHex = ConvertToHexColor(secondaryColor), TextOnPrimaryColorHex = ConvertToHexColor(textOnPrimaryColor), TextOnSecondaryColorHex = ConvertToHexColor(textOnSecondaryColor), SupportEmail = supportEmail, NoreplyEmail = noreplyEmail, CustomInvitationEmailTextPrefix = customInvitationEmailTextPrefix, CustomInvitationEmailTextSuffix = customInvitationEmailTextSuffix, ProductName = productName, BackendApiUrl = tenant.BackendApiUrl, FrontendApiUrl = tenant.FrontendApiUrl, WebUrl = tenant.WebUrl, DefaultCulture = defaultCulture, DefaultCurrency = defaultCurrency, UsersAreExternallyManaged = usersAreExternallyManaged, ExternalAuthenticationMethod = externalAuthorizationMethod, OidcClientId = oidcClientId, OidcClientSecret = oidcClientSecret, OidcEndpointUrl = oidcEndpointUrl, SamlEntityId = samlEntityId, SamlMetadataLocation = samlMetadataLocation, SamlProviderUrl = samlProviderUrl, SamlCertificate = samlCertificate, SamlAllowWeakSigningAlgorithm = samlAllowWeakSigningAlgorithm, ExternalDirectoryType = externalDirectoryType, ExternalDirectoryHost = externalDirectoryHost, ExternalDirectoryPort = externalDirectoryPort, ExternalDirectoryUsesSsl = externalDirectoryUsesSsl, ExternalDirectorySslCertificate = externalDirectorySslCertificate, ExternalDirectoryAccountDistinguishedName = externalDirectoryAccountDistinguishedName, ExternalDirectoryPassword = externalDirectoryPassword, ExternalDirectoryLoginAttribute = externalDirectoryLoginAttribute, ExternalDirectoryBaseContexts = externalDirectoryBaseContexts, ExternalDirectoryUserFilter = externalDirectoryUserFilter, ExternalDirectoryGroupFilter = externalDirectoryGroupFilter, ExternalDirectorySyncIntervalSeconds = externalDirectorySyncIntervalSeconds, ExternalDirectoryAdministratorGroupUuid = externalDirectoryAdministratorGroupUuid }; string[] subdomainPatternParts = subdomainPattern.Split(';'); subdomainPatternParts.ToList().ForEach(subdomainPatternPart => { _tenantInfoMappings.Add(subdomainPatternPart, tenantInfo); }); _tenantInfoMappingsByUuid.Add(tenantInfo.TenantUuid, tenantInfo); TenantInfos.Add(tenantInfo); }); }
public DeveloperWrapper(DeveloperModel developer) { Developer = developer; _tenantInfoMappings = new Dictionary <string, ITenantInfo>(); _tenantInfoMappingsByUuid = new Dictionary <long, ITenantInfo>(); TenantInfos = new List <ITenantInfo>(); developer.Tenants.ForEach(tenant => { string subdomainPattern = tenant.SubdomainPattern; if (developer.Certificate != null && developer.Certificate.Length > 0 && string.IsNullOrEmpty(developer.CertificatePassword)) { throw new Exception("Developer in tenant database has certificate set, but no certificate password is present"); } if (string.IsNullOrEmpty(tenant.Name)) { throw new Exception("The tenant name is empty"); } if (string.IsNullOrEmpty(tenant.FrontendApiUrl)) { throw new Exception("The tenant frontend API URL is empty"); } if (string.IsNullOrEmpty(tenant.BackendApiUrl)) { throw new Exception("The tenant backend API url is empty"); } if (string.IsNullOrEmpty(tenant.WebUrl)) { throw new Exception("The tenant web url is empty"); } string logoSvgUrl = tenant.LogoSvgUrl; if (string.IsNullOrEmpty(logoSvgUrl)) { logoSvgUrl = developer.LogoSvgUrl; } string logoPngUrl = tenant.LogoPngUrl; if (string.IsNullOrEmpty(logoPngUrl)) { logoPngUrl = developer.LogoPngUrl; } string iconIcoUrl = tenant.IconIcoUrl; if (string.IsNullOrEmpty(iconIcoUrl)) { iconIcoUrl = developer.IconIcoUrl; } string storageImplementation = tenant.StorageImplementation; if (string.IsNullOrEmpty(storageImplementation)) { storageImplementation = developer.StorageImplementation; } // storage is optional string storageConnectionString = null; if (!string.IsNullOrEmpty(storageImplementation)) { if (!storageImplementation.Equals(StorageConstants.StorageImplementationAzure) && !storageImplementation.Equals(StorageConstants.StorageImplementationGoogleCloud)) { throw new Exception("The tenant storage implementation specification is invalid"); } storageConnectionString = tenant.StorageConnectionString; if (string.IsNullOrEmpty(storageConnectionString)) { storageConnectionString = developer.StorageConnectionString; } } int?primaryColor = tenant.PrimaryColor; if (primaryColor == null) { primaryColor = developer.PrimaryColor; } int?secondaryColor = tenant.SecondaryColor; if (secondaryColor == null) { secondaryColor = developer.SecondaryColor; } int?textOnPrimaryColor = tenant.TextOnPrimaryColor; if (textOnPrimaryColor == null) { textOnPrimaryColor = developer.TextOnPrimaryColor; } int?textOnSecondaryColor = tenant.TextOnSecondaryColor; if (textOnSecondaryColor == null) { textOnSecondaryColor = developer.TextOnSecondaryColor; } string supportEmail = tenant.SupportEmail; if (string.IsNullOrEmpty(supportEmail)) { supportEmail = developer.SupportEmail; } string noreplyEmail = tenant.NoreplyEmail; if (string.IsNullOrEmpty(noreplyEmail)) { noreplyEmail = developer.NoreplyEmail; } string productName = tenant.ProductName; if (string.IsNullOrEmpty(productName)) { productName = developer.ProductName; } string defaultCulture = tenant.DefaultCulture; if (string.IsNullOrEmpty(defaultCulture)) { defaultCulture = "en"; } var tenantInfo = new TenantInfoImpl() { DeveloperUuid = developer.Uuid, DeveloperAuthority = developer.Authority, DeveloperAudience = developer.Audience, DeveloperCertificate = developer.Certificate, DeveloperCertificatePassword = developer.CertificatePassword, DeveloperAuthCookieDomain = developer.AuthCookieDomain, DeveloperName = developer.Name, DeveloperPrivacyPolicyUrl = developer.PrivacyPolicyUrl, DeveloperPrivacyPolicyVersion = developer.PrivacyPolicyVersion, DeveloperTermsAndConditionsUrl = developer.TermsAndConditionsUrl, DeveloperTermsAndConditionsVersion = developer.TermsAndConditionsVersion, TenantUuid = tenant.Uuid, Name = tenant.Name, LogoSvgUrl = logoSvgUrl, LogoPngUrl = logoPngUrl, IconIcoUrl = iconIcoUrl, StorageImplementation = storageImplementation, StorageConnectionString = storageConnectionString, PrimaryColor = (int)primaryColor, SecondaryColor = (int)secondaryColor, TextOnPrimaryColor = (int)textOnPrimaryColor, TextOnSecondaryColor = (int)textOnSecondaryColor, PrimaryColorHex = ConvertToHexColor(primaryColor), SecondaryColorHex = ConvertToHexColor(secondaryColor), TextOnPrimaryColorHex = ConvertToHexColor(textOnPrimaryColor), TextOnSecondaryColorHex = ConvertToHexColor(textOnSecondaryColor), SupportEmail = supportEmail, NoreplyEmail = noreplyEmail, ProductName = productName, BackendApiUrl = tenant.BackendApiUrl, FrontendApiUrl = tenant.FrontendApiUrl, WebUrl = tenant.WebUrl, DefaultCulture = defaultCulture }; string[] subdomainPatternParts = subdomainPattern.Split(';'); subdomainPatternParts.ToList().ForEach(subdomainPatternPart => { _tenantInfoMappings.Add(subdomainPatternPart, tenantInfo); }); _tenantInfoMappingsByUuid.Add(tenantInfo.TenantUuid, tenantInfo); TenantInfos.Add(tenantInfo); }); }