use of io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceImpl method validateDomainRestrictions.
private void validateDomainRestrictions(Collection<VirtualHost> virtualHosts) {
final EnvironmentEntity currentEnv = environmentService.findById(GraviteeContext.getCurrentEnvironment());
final List<String> domainRestrictions = currentEnv.getDomainRestrictions();
if (domainRestrictions != null && !domainRestrictions.isEmpty()) {
for (VirtualHost vHost : virtualHosts) {
String host = vHost.getHost();
if (!StringUtils.isEmpty(host)) {
String hostWithoutPort = host.split(":")[0];
if (!isValidDomainOrSubDomain(hostWithoutPort, domainRestrictions)) {
throw new InvalidVirtualHostException(hostWithoutPort, domainRestrictions);
}
} else {
vHost.setHost(domainRestrictions.get(0));
}
}
}
}
Aggregations