Search in sources :

Example 1 with InternetDomainName

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;
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 2 with InternetDomainName

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;
}
Also used : Cookie(org.apache.http.cookie.Cookie) InternetDomainName(com.google.common.net.InternetDomainName) CompositeCollection(org.apache.commons.collections.collection.CompositeCollection)

Example 3 with InternetDomainName

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);
            }
        }
    }
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 4 with InternetDomainName

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;
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName)

Example 5 with InternetDomainName

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();
}
Also used : InternetDomainName(com.google.common.net.InternetDomainName) ImmutableMultimap(com.google.common.collect.ImmutableMultimap)

Aggregations

InternetDomainName (com.google.common.net.InternetDomainName)23 DateTime (org.joda.time.DateTime)5 Registry (google.registry.model.tld.Registry)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 AllocationToken (google.registry.model.domain.token.AllocationToken)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 DomainCommand (google.registry.model.domain.DomainCommand)2 Check (google.registry.model.domain.DomainCommand.Check)2 AllocationTokenExtension (google.registry.model.domain.token.AllocationTokenExtension)2 TldState (google.registry.model.tld.Registry.TldState)2 MalformedURLException (java.net.MalformedURLException)2 HashSet (java.util.HashSet)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Maps (com.google.common.collect.Maps)1