Search in sources :

Example 1 with InvalidVirtualHostException

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));
            }
        }
    }
}
Also used : EnvironmentEntity(io.gravitee.rest.api.model.EnvironmentEntity) InvalidVirtualHostException(io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException) VirtualHost(io.gravitee.definition.model.VirtualHost)

Aggregations

VirtualHost (io.gravitee.definition.model.VirtualHost)1 EnvironmentEntity (io.gravitee.rest.api.model.EnvironmentEntity)1 InvalidVirtualHostException (io.gravitee.rest.api.service.exceptions.InvalidVirtualHostException)1