Skip to content

Commit

Permalink
MGR-138 Removed implicit include of host in aliases.
Browse files Browse the repository at this point in the history
  • Loading branch information
dheuvels committed Jul 11, 2022
1 parent 9834346 commit 2ab8d6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
17 changes: 4 additions & 13 deletions src/main/java/org/appng/application/manager/form/SiteForm.java
Expand Up @@ -15,13 +15,11 @@
*/
package org.appng.application.manager.form;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import javax.validation.Valid;

import org.appng.api.Environment;
Expand Down Expand Up @@ -71,30 +69,23 @@ public void setTemplate(String template) {
this.template = template;
}

private List<String> _getHostAliases() {
return site.getHostNames().stream().filter(hn -> !site.getHost().equals(hn)).sorted()
.collect(Collectors.toList());
}

public String getHostAliases() {
return String.join(System.lineSeparator(), _getHostAliases());
return String.join(System.lineSeparator(), site.getHostAliases());
}

public void setHostAliases(String hostAliases) {
Set<String> hostnames = new HashSet<String>();
hostnames.add(site.getHost());

Pattern splitPattern = Pattern.compile("^[ \t]*(.+?)[ \t]*$", Pattern.MULTILINE);
Matcher splitMatcher = splitPattern.matcher(hostAliases);
while(splitMatcher.find()) {
hostnames.add(splitMatcher.group(1));
}
site.setHostNames(hostnames);
site.setHostAliases(hostnames);
}

public void validate(Site site, Application application, Environment environment, Options options, Request request,
FieldProcessor fp) {
for (String name : _getHostAliases()) {
for (String name : this.site.getHostAliases()) {
if (! Pattern.matches(ValidationPatterns.HOST_PATTERN, name))
fp.addErrorMessage(fp.getField("hostAliases"),
request.getMessage(MessageConstants.SITE_HOSTALIAS_INVALID, name));
Expand Down
Expand Up @@ -1086,16 +1086,18 @@ private void checkSite(Request request, Site site, FieldProcessor fp, Site curre
if (fp.hasField("site.name") && !siteRepository.isUnique(site.getId(), "name", site.getName())) {
fp.addErrorMessage(fp.getField("site.name"), request.getMessage(MessageConstants.SITE_NAME_EXISTS));
}
List<SiteImpl> hostNameOverlapSites = siteRepository.findSitesForHostNames(site.getHostNames());
for (SiteImpl ovlSite : hostNameOverlapSites) {
if (site.getId() == ovlSite.getId()) continue;
Set<String>hostnames = new HashSet<String>(site.getHostAliases());
hostnames.add(site.getHost());
List<SiteImpl> hostOverlapSites = siteRepository.findSitesForHostNames(hostnames);
for (SiteImpl ovlpSite : hostOverlapSites) {
if (site.getId() == ovlpSite.getId()) continue;
else {
if (ovlSite.getHostNames().contains(site.getHost()))
if (ovlpSite.getHost().equals(site.getHost()) || ovlpSite.getHostAliases().contains(site.getHost()))
fp.addErrorMessage(fp.getField("site.host"), request.getMessage(MessageConstants.SITE_HOST_EXISTS,
ovlSite.getName()));
ovlpSite.getName()));
else
fp.addErrorMessage(fp.getField("hostAliases"), request.getMessage(MessageConstants.SITE_HOSTALIAS_EXISTS,
ovlSite.getName()));
fp.addErrorMessage(fp.getField("hostAliases"),
request.getMessage(MessageConstants.SITE_HOSTALIAS_EXISTS, ovlpSite.getName()));
}
}
if (!siteRepository.isUnique(site.getId(), "domain", site.getDomain())) {
Expand Down

0 comments on commit 2ab8d6e

Please sign in to comment.