use of com.google.common.net.InternetDomainName in project gravitee-api-management by gravitee-io.
the class VirtualHostServiceImpl method isValidDomainOrSubDomain.
private boolean isValidDomainOrSubDomain(String domain, List<String> domainRestrictions) {
boolean isSubDomain = false;
if (domainRestrictions.isEmpty()) {
return true;
}
for (String domainRestriction : domainRestrictions) {
InternetDomainName domainIDN = InternetDomainName.from(domain);
InternetDomainName parentIDN = InternetDomainName.from(domainRestriction);
if (domainIDN.equals(parentIDN)) {
return true;
}
while (!isSubDomain && domainIDN.hasParent()) {
isSubDomain = parentIDN.equals(domainIDN);
domainIDN = domainIDN.parent();
}
if (isSubDomain) {
break;
}
}
return isSubDomain;
}
use of com.google.common.net.InternetDomainName in project heritrix3 by internetarchive.
the class BdbCookieStore method cookieStoreFor.
/**
* Returns a {@link LimitedCookieStoreFacade} whose
* {@link LimitedCookieStoreFacade#getCookies()} method returns only cookies
* from {@code host} and its parent domains, if applicable.
*/
public CookieStore cookieStoreFor(String host) {
CompositeCollection cookieCollection = new CompositeCollection();
if (InternetDomainName.isValid(host)) {
InternetDomainName domain = InternetDomainName.from(host);
while (domain != null) {
Collection<Cookie> subset = hostSubset(domain.toString());
cookieCollection.addComposited(subset);
if (domain.hasParent()) {
domain = domain.parent();
} else {
domain = null;
}
}
} else {
Collection<Cookie> subset = hostSubset(host.toString());
cookieCollection.addComposited(subset);
}
@SuppressWarnings("unchecked") List<Cookie> cookieList = new RestrictedCollectionWrappedList<Cookie>(cookieCollection);
LimitedCookieStoreFacade store = new LimitedCookieStoreFacade(cookieList);
return store;
}
use of com.google.common.net.InternetDomainName in project furms by unity-idm.
the class SSHKeyFromOptionValidator method isValidHostname.
private static void isValidHostname(String input) {
if (CharMatcher.anyOf("*").matchesAnyOf(input)) {
String[] split = input.split("\\*");
String last = split[split.length - 1];
if (last.isEmpty()) {
throw new InvalidSSHKeyFromOptionException("* wildcard can be used only with domain name", input, ErrorType.WILDCARD_WITH_TLD);
} else {
InternetDomainName idm;
try {
idm = InternetDomainName.from(CharMatcher.is('.').trimLeadingFrom(last));
} catch (Exception e) {
throw new InvalidSSHKeyFromOptionException("* wildcard can be used only with domain name", input, ErrorType.WILDCARD_WITH_TLD);
}
if (idm.isRegistrySuffix()) {
throw new InvalidSSHKeyFromOptionException("* wildcard can not be used with top level domain name", input, ErrorType.WILDCARD_WITH_TLD);
}
}
}
}
use of com.google.common.net.InternetDomainName in project gravitee-management-rest-api by gravitee-io.
the class VirtualHostServiceImpl method isValidDomainOrSubDomain.
private boolean isValidDomainOrSubDomain(String domain, List<String> domainRestrictions) {
boolean isSubDomain = false;
if (domainRestrictions.isEmpty()) {
return true;
}
for (String domainRestriction : domainRestrictions) {
InternetDomainName domainIDN = InternetDomainName.from(domain);
InternetDomainName parentIDN = InternetDomainName.from(domainRestriction);
if (domainIDN.equals(parentIDN)) {
return true;
}
while (!isSubDomain && domainIDN.hasParent()) {
isSubDomain = parentIDN.equals(domainIDN);
domainIDN = domainIDN.parent();
}
if (isSubDomain) {
break;
}
}
return isSubDomain;
}
use of com.google.common.net.InternetDomainName in project nomulus by google.
the class EppToolCommand method validateAndGroupDomainNamesByTld.
/**
* Helper function for grouping sets of domain names into respective TLDs. Useful for batched
* EPP calls when invoking commands (i.e. domain check) with sets of domains across multiple TLDs.
*/
protected static Multimap<String, String> validateAndGroupDomainNamesByTld(List<String> names) {
ImmutableMultimap.Builder<String, String> builder = new ImmutableMultimap.Builder<>();
for (String name : names) {
String canonicalDomain = canonicalizeHostname(name);
InternetDomainName tld = findTldForNameOrThrow(InternetDomainName.from(canonicalDomain));
builder.put(tld.toString(), canonicalDomain);
}
return builder.build();
}
Aggregations