List of usage examples for com.google.common.net InternetDomainName parent
public InternetDomainName parent()
From source file:google.registry.util.DomainNameUtils.java
/** * Returns the canonicalized TLD part of a valid fully-qualified domain name by stripping off the * leftmost part.//from ww w. ja va2s . c om * * <p>This function is compatible with multi-part TLDs and should not be called with subdomains. * * @throws IllegalArgumentException if there is no TLD */ public static String getTldFromDomainName(InternetDomainName domainName) { checkArgumentNotNull(domainName); checkArgument(domainName.hasParent(), "secondLevelDomainName does not have a TLD"); return domainName.parent().toString(); }
From source file:google.registry.model.registry.Registries.java
/** * Returns TLD which the domain name or hostname falls under, no matter how many levels of * sublabels there are./*from www . jav a2s . c o m*/ * * <p><b>Note:</b> This routine will only work on names under TLDs for which this registry is * authoritative. To extract TLDs from domains (not hosts) that other registries control, use * {@link google.registry.util.DomainNameUtils#getTldFromDomainName(String) * DomainNameUtils#getTldFromDomainName}. * * @param domainName domain name or host name (but not TLD) under an authoritative TLD * @return TLD or absent if {@code domainName} has no labels under an authoritative TLD */ public static Optional<InternetDomainName> findTldForName(InternetDomainName domainName) { ImmutableSet<String> tlds = getTlds(); while (domainName.hasParent()) { domainName = domainName.parent(); if (tlds.contains(domainName.toString())) { return Optional.of(domainName); } } return Optional.absent(); }
From source file:uk.bl.wa.extract.LinkExtractor.java
private static ImmutableList.Builder<String> parentLevels(InternetDomainName internetDomainName) { ImmutableList.Builder<String> levels; if (internetDomainName.hasParent()) { levels = parentLevels(internetDomainName.parent()); } else {/*from ww w . j a va 2s.co m*/ levels = ImmutableList.builder(); } levels.add(internetDomainName.toString()); return levels; }
From source file:google.registry.model.registry.label.ReservedList.java
/** * Returns true if the given label and TLD is reserved for an anchor tenant, and the given * auth code matches the one set on the reservation. *//*from ww w. j a va 2 s . c o m*/ public static boolean matchesAnchorTenantReservation(InternetDomainName domainName, String authCode) { ReservedListEntry entry = getReservedListEntry(domainName.parts().get(0), domainName.parent().toString()); return entry != null && entry.reservationType == RESERVED_FOR_ANCHOR_TENANT && Objects.equals(entry.getAuthCode(), authCode); }
From source file:google.registry.flows.domain.DomainPricingLogic.java
/** * Checks whether an LRP token String maps to a valid {@link LrpTokenEntity} for the domain name's * TLD, and return that entity (wrapped in an {@link Optional}) if one exists. * * <p>This method has no knowledge of whether or not an auth code (interpreted here as an LRP * token) has already been checked against the reserved list for QLP (anchor tenant), as auth * codes are used for both types of registrations. */// w ww . ja v a 2 s. co m public static Optional<LrpTokenEntity> getMatchingLrpToken(String lrpToken, InternetDomainName domainName) { // Note that until the actual per-TLD logic is built out, what's being done here is a basic // domain-name-to-assignee match. if (!lrpToken.isEmpty()) { LrpTokenEntity token = ofy().load().key(Key.create(LrpTokenEntity.class, lrpToken)).now(); if (token != null && token.getAssignee().equalsIgnoreCase(domainName.toString()) && token.getRedemptionHistoryEntry() == null && token.getValidTlds().contains(domainName.parent().toString())) { return Optional.of(token); } } return Optional.<LrpTokenEntity>absent(); }
From source file:google.registry.flows.host.HostFlowUtils.java
/** Checks that a host name is valid. */ static InternetDomainName validateHostName(String name) throws EppException { checkArgumentNotNull(name, "Must specify host name to validate"); if (name.length() > 253) { throw new HostNameTooLongException(); }// w w w . j a va 2 s .c o m String hostNameLowerCase = Ascii.toLowerCase(name); if (!name.equals(hostNameLowerCase)) { throw new HostNameNotLowerCaseException(hostNameLowerCase); } try { String hostNamePunyCoded = Idn.toASCII(name); if (!name.equals(hostNamePunyCoded)) { throw new HostNameNotPunyCodedException(hostNamePunyCoded); } InternetDomainName hostName = InternetDomainName.from(name); if (!name.equals(hostName.toString())) { throw new HostNameNotNormalizedException(hostName.toString()); } // Checks whether a hostname is deep enough. Technically a host can be just one under a // public suffix (e.g. example.com) but we require by policy that it has to be at least one // part beyond that (e.g. ns1.example.com). The public suffix list includes all current // ccTlds, so this check requires 4+ parts if it's a ccTld that doesn't delegate second // level domains, such as .co.uk. But the list does not include new tlds, so in that case // we just ensure 3+ parts. In the particular case where our own tld has a '.' in it, we know // that there need to be 4 parts as well. if (hostName.isUnderPublicSuffix()) { if (hostName.parent().isUnderPublicSuffix()) { return hostName; } } else { // We need to know how many parts the hostname has beyond the public suffix, but we don't // know what the public suffix is. If the host is in bailiwick and we are hosting a // multipart "tld" like .co.uk the publix suffix might be 2 parts. Otherwise it's an // unrecognized tld that's not on the public suffix list, so assume the tld alone is the // public suffix. Optional<InternetDomainName> tldParsed = findTldForName(hostName); int suffixSize = tldParsed.isPresent() ? tldParsed.get().parts().size() : 1; if (hostName.parts().size() >= suffixSize + 2) { return hostName; } } throw new HostNameTooShallowException(); } catch (IllegalArgumentException e) { throw new InvalidHostNameException(); } }
From source file:google.registry.flows.domain.ClaimsCheckFlow.java
@Override public EppResponse run() throws EppException { extensionManager.register(LaunchCheckExtension.class); extensionManager.validate();/*from w w w . j a v a 2 s .c o m*/ validateClientIsLoggedIn(clientId); List<String> targetIds = ((Check) resourceCommand).getTargetIds(); verifyTargetIdCount(targetIds, maxChecks); Set<String> seenTlds = new HashSet<>(); ImmutableList.Builder<LaunchCheck> launchChecksBuilder = new ImmutableList.Builder<>(); for (String targetId : ImmutableSet.copyOf(targetIds)) { InternetDomainName domainName = validateDomainName(targetId); validateDomainNameWithIdnTables(domainName); String tld = domainName.parent().toString(); // Only validate access to a TLD the first time it is encountered. if (seenTlds.add(tld)) { checkAllowedAccessToTld(clientId, tld); Registry registry = Registry.get(tld); if (!isSuperuser) { DateTime now = clock.nowUtc(); verifyNotInPredelegation(registry, now); if (registry.getTldState(now) == TldState.SUNRISE) { throw new ClaimsCheckNotAllowedInSunrise(); } verifyClaimsPeriodNotEnded(registry, now); } } String claimKey = ClaimsListShard.get().getClaimKey(domainName.parts().get(0)); launchChecksBuilder .add(LaunchCheck.create(LaunchCheckName.create(claimKey != null, targetId), claimKey)); } return responseBuilder .setOnlyExtension(LaunchCheckResponseExtension.create(CLAIMS, launchChecksBuilder.build())).build(); }
From source file:google.registry.flows.domain.DomainFlowUtils.java
/** Returns an enum that encodes how and when this name is reserved in the current tld. */ static ReservationType getReservationType(InternetDomainName domainName) { // The TLD should always be the parent of the requested domain name. return getReservation(domainName.parts().get(0), domainName.parent().toString()); }
From source file:google.registry.flows.domain.DomainFlowUtils.java
/** * Returns name of first matching IDN table for domain label. * * @throws InvalidIdnDomainLabelException if IDN table or language validation failed * @see #validateDomainName(String)// ww w . j a va2 s .c o m */ static String validateDomainNameWithIdnTables(InternetDomainName domainName) throws InvalidIdnDomainLabelException { Optional<String> idnTableName = findValidIdnTableForTld(domainName.parts().get(0), domainName.parent().toString()); if (!idnTableName.isPresent()) { throw new InvalidIdnDomainLabelException(); } return idnTableName.get(); }
From source file:org.archive.crawler.prefetch.HostQuotaEnforcer.java
@Override protected boolean shouldProcess(CrawlURI curi) { String uriHostname = serverCache.getHostFor(curi.getUURI()).getHostName(); if (getApplyToSubdomains() && InternetDomainName.isValid(host) && InternetDomainName.isValid(uriHostname)) { InternetDomainName h = InternetDomainName.from(host); InternetDomainName uriHostOrAncestor = InternetDomainName.from(uriHostname); while (true) { if (uriHostOrAncestor.equals(h)) { return true; }/*from w ww . j av a 2 s . co m*/ if (uriHostOrAncestor.hasParent()) { uriHostOrAncestor = uriHostOrAncestor.parent(); } else { break; } } return false; } else { return serverCache.getHostFor(curi.getUURI()) == serverCache.getHostFor(host); } }