diff --git a/backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigService.java b/backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigService.java index 5a2c16fb08..bbc1eed7e2 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/clientconfig/ClientConfigService.java @@ -3,6 +3,8 @@ import ch.puzzle.okr.dto.ClientConfigDto; import ch.puzzle.okr.multitenancy.TenantConfigProvider; import jakarta.persistence.EntityNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -12,6 +14,7 @@ @Service public class ClientConfigService { + private static final Logger logger = LoggerFactory.getLogger(ClientConfigService.class); private final ClientCustomizationProperties clientCustomizationProperties; private final TenantConfigProvider tenantConfigProvider; @@ -26,8 +29,11 @@ public ClientConfigService(final ClientCustomizationProperties clientCustomizati public ClientConfigDto getConfigBasedOnActiveEnv(String hostName) { String subdomain = hostName.split("\\.")[0]; + String domainPrefixByHyphen = hostName.split("-")[0]; + + Optional tenantConfig = getTenantConfig(hostName, subdomain, + domainPrefixByHyphen); - Optional tenantConfig = tenantConfigProvider.getTenantConfigById(subdomain); if (tenantConfig.isEmpty()) { throw new EntityNotFoundException( MessageFormat.format("Could not find tenant for subdomain:{0}", subdomain)); @@ -37,4 +43,17 @@ public ClientConfigDto getConfigBasedOnActiveEnv(String hostName) { clientCustomizationProperties.getFavicon(), clientCustomizationProperties.getLogo(), clientCustomizationProperties.getTitle(), clientCustomizationProperties.getCustomStyles()); } + + private Optional getTenantConfig(String hostname, String... tenantsFromUrl) { + for (String tenant : tenantsFromUrl) { + Optional tenantConfig = tenantConfigProvider.getTenantConfigById(tenant); + if (tenantConfig.isPresent()) { + logger.info("get config for " + tenant + ": OK"); + return tenantConfig; + } + logger.info("get config found for " + tenant + ": failed"); + } + logger.info("no config found for " + hostname + ": failed"); + return Optional.empty(); + } }