com.quorum.tessera.server.jaxrs.OriginMatchUtil Maven / Gradle / Ivy
The newest version!
package com.quorum.tessera.server.jaxrs;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
public class OriginMatchUtil {
private final List tokens;
private final Predicate wildcardMatch = s -> s.equals("*");
public OriginMatchUtil(List tokens) {
this.tokens = tokens.stream()
.map(String::toLowerCase)
.map(s -> ("\\Q" + s + "\\E"))
.map(s -> s.replace("*", "\\E.*\\Q"))
.collect(Collectors.toList());
}
public boolean matches(String origin) {
if(Objects.isNull(origin) || Objects.equals("", origin)) {
return false;
}
Predicate subdomainMatch = s -> origin.toLowerCase().matches(s);
Predicate matchingCritera = wildcardMatch.or(subdomainMatch);
return tokens.stream().anyMatch(matchingCritera);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy