List of usage examples for com.google.common.net InternetDomainName parts
ImmutableList parts
To view the source code for com.google.common.net InternetDomainName parts.
Click Source Link
From source file:google.registry.dns.writer.dnsupdate.DnsUpdateWriter.java
@Override public void publishHost(String hostName) { // Get the superordinate domain name of the host. InternetDomainName host = InternetDomainName.from(hostName); ImmutableList<String> hostParts = host.parts(); Optional<InternetDomainName> tld = Registries.findTldForName(host); // host not managed by our registry, no need to update DNS. if (!tld.isPresent()) { return;// w ww . java 2s . c o m } ImmutableList<String> tldParts = tld.get().parts(); ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1, hostParts.size()); String domain = Joiner.on(".").join(domainParts); // Refresh the superordinate domain, always delete the host first to ensure idempotency, // and only publish the host if it is a glue record. publishDomain(domain, hostName); }
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)/*from ww w. java2 s .com*/ */ 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:google.registry.flows.domain.DomainFlowUtils.java
/** * Check that if there's a claims notice it's on the claims list, and that if there's not one it's * not on the claims list and is a sunrise application. *//*from www . j av a 2 s . c om*/ static void verifyClaimsNoticeIfAndOnlyIfNeeded(InternetDomainName domainName, boolean hasSignedMarks, boolean hasClaimsNotice) throws EppException { boolean isInClaimsList = ClaimsListShard.get().getClaimKey(domainName.parts().get(0)) != null; if (hasClaimsNotice && !isInClaimsList) { throw new UnexpectedClaimsNoticeException(domainName.toString()); } if (!hasClaimsNotice && isInClaimsList && !hasSignedMarks) { throw new MissingClaimsNoticeException(domainName.toString()); } }
From source file:google.registry.flows.domain.DomainFlowUtils.java
/** * Returns parsed version of {@code name} if domain name label follows our naming rules and is * under one of the given allowed TLDs./* ww w .ja v a 2 s . c o m*/ * * <p><b>Note:</b> This method does not perform language validation with IDN tables. * * @see #validateDomainNameWithIdnTables(InternetDomainName) */ static InternetDomainName validateDomainName(String name) throws EppException { if (!ALLOWED_CHARS.matchesAllOf(name)) { throw new BadDomainNameCharacterException(); } List<String> parts = Splitter.on('.').splitToList(name); if (parts.size() <= 1) { throw new BadDomainNamePartsCountException(); } if (any(parts, equalTo(""))) { throw new EmptyDomainNamePartException(); } validateFirstLabel(parts.get(0)); InternetDomainName domainName = InternetDomainName.from(name); Optional<InternetDomainName> tldParsed = findTldForName(domainName); if (!tldParsed.isPresent()) { throw new TldDoesNotExistException(domainName.parent().toString()); } if (domainName.parts().size() != tldParsed.get().parts().size() + 1) { throw new BadDomainNamePartsCountException(); } return domainName; }
From source file:google.registry.flows.domain.DomainCreateFlow.java
@Override public final EppResponse run() throws EppException { extensionManager.register(FeeCreateCommandExtension.class, SecDnsCreateExtension.class, MetadataExtension.class, LaunchCreateExtension.class); customLogic.beforeValidation();//from w w w. j a v a 2s .c o m extensionManager.validate(); validateClientIsLoggedIn(clientId); DateTime now = ofy().getTransactionTime(); Create command = cloneAndLinkReferences((Create) resourceCommand, now); Period period = command.getPeriod(); verifyUnitIsYears(period); int years = period.getValue(); failfastForCreate(targetId, now); verifyResourceDoesNotExist(DomainResource.class, targetId, now); // Validate that this is actually a legal domain name on a TLD that the registrar has access to. InternetDomainName domainName = validateDomainName(command.getFullyQualifiedDomainName()); String domainLabel = domainName.parts().get(0); Registry registry = Registry.get(domainName.parent().toString()); validateCreateCommandContactsAndNameservers(command, registry.getTldStr()); TldState tldState = registry.getTldState(now); boolean isAnchorTenant = isAnchorTenant(domainName); LaunchCreateExtension launchCreate = eppInput.getSingleExtension(LaunchCreateExtension.class); boolean hasSignedMarks = launchCreate != null && !launchCreate.getSignedMarks().isEmpty(); boolean hasClaimsNotice = launchCreate != null && launchCreate.getNotice() != null; if (launchCreate != null) { verifyNoCodeMarks(launchCreate); validateLaunchCreateNotice(launchCreate.getNotice(), domainLabel, isSuperuser, now); } boolean isSunriseCreate = hasSignedMarks && SUNRISE_STATES.contains(tldState); // Superusers can create reserved domains, force creations on domains that require a claims // notice without specifying a claims key, ignore the registry phase, and override blocks on // registering premium domains. if (!isSuperuser) { checkAllowedAccessToTld(clientId, registry.getTldStr()); if (launchCreate != null) { verifyLaunchPhaseMatchesRegistryPhase(registry, launchCreate, now); } if (!isAnchorTenant) { verifyNotReserved(domainName, isSunriseCreate); } if (hasClaimsNotice) { verifyClaimsPeriodNotEnded(registry, now); } if (now.isBefore(registry.getClaimsPeriodEnd())) { verifyClaimsNoticeIfAndOnlyIfNeeded(domainName, hasSignedMarks, hasClaimsNotice); } verifyPremiumNameIsNotBlocked(targetId, now, clientId); verifyNoOpenApplications(now); verifyIsGaOrIsSpecialCase(tldState, isAnchorTenant); } String signedMarkId = hasSignedMarks // If a signed mark was provided, then it must match the desired domain label. Get the mark // at this point so that we can verify it before the "after validation" extension point. ? tmchUtils.verifySignedMarks(launchCreate.getSignedMarks(), domainLabel, now).getId() : null; customLogic.afterValidation( DomainCreateFlowCustomLogic.AfterValidationParameters.newBuilder().setDomainName(domainName) .setYears(years).setSignedMarkId(Optional.fromNullable(signedMarkId)).build()); FeeCreateCommandExtension feeCreate = eppInput.getSingleExtension(FeeCreateCommandExtension.class); FeesAndCredits feesAndCredits = pricingLogic.getCreatePrice(registry, targetId, now, years); validateFeeChallenge(targetId, registry.getTldStr(), now, feeCreate, feesAndCredits); SecDnsCreateExtension secDnsCreate = validateSecDnsExtension( eppInput.getSingleExtension(SecDnsCreateExtension.class)); String repoId = createDomainRepoId(ObjectifyService.allocateId(), registry.getTldStr()); DateTime registrationExpirationTime = leapSafeAddYears(now, years); HistoryEntry historyEntry = buildHistory(repoId, period, now); // Bill for the create. BillingEvent.OneTime createBillingEvent = createOneTimeBillingEvent(registry, isAnchorTenant, years, feesAndCredits, historyEntry, now); // Create a new autorenew billing event and poll message starting at the expiration time. BillingEvent.Recurring autorenewBillingEvent = createAutorenewBillingEvent(historyEntry, registrationExpirationTime); PollMessage.Autorenew autorenewPollMessage = createAutorenewPollMessage(historyEntry, registrationExpirationTime); ImmutableSet.Builder<ImmutableObject> entitiesToSave = new ImmutableSet.Builder<>(); entitiesToSave.add(historyEntry, createBillingEvent, autorenewBillingEvent, autorenewPollMessage); // Bill for EAP cost, if any. if (!feesAndCredits.getEapCost().isZero()) { entitiesToSave.add(createEapBillingEvent(feesAndCredits, createBillingEvent)); } DomainResource newDomain = new DomainResource.Builder().setCreationClientId(clientId) .setCurrentSponsorClientId(clientId).setRepoId(repoId) .setIdnTableName(validateDomainNameWithIdnTables(domainName)) .setRegistrationExpirationTime(registrationExpirationTime) .setAutorenewBillingEvent(Key.create(autorenewBillingEvent)) .setAutorenewPollMessage(Key.create(autorenewPollMessage)) .setLaunchNotice(hasClaimsNotice ? launchCreate.getNotice() : null).setSmdId(signedMarkId) .setDsData(secDnsCreate == null ? null : secDnsCreate.getDsData()) .setRegistrant(command.getRegistrant()).setAuthInfo(command.getAuthInfo()) .setFullyQualifiedDomainName(targetId).setNameservers(command.getNameservers()) .setContacts(command.getContacts()) .addGracePeriod(GracePeriod.forBillingEvent(GracePeriodStatus.ADD, createBillingEvent)).build(); entitiesToSave.add(newDomain, ForeignKeyIndex.create(newDomain, newDomain.getDeletionTime()), EppResourceIndex.create(Key.create(newDomain))); // Anchor tenant registrations override LRP, and landrush applications can skip it. // If a token is passed in outside of an LRP phase, it is simply ignored (i.e. never redeemed). if (isLrpCreate(registry, isAnchorTenant, now)) { entitiesToSave.add(prepareMarkedLrpTokenEntity(authInfo.getPw().getValue(), domainName, historyEntry)); } enqueueTasks(isSunriseCreate, hasClaimsNotice, newDomain); EntityChanges entityChanges = customLogic.beforeSave(DomainCreateFlowCustomLogic.BeforeSaveParameters .newBuilder().setNewDomain(newDomain).setHistoryEntry(historyEntry) .setEntityChanges(EntityChanges.newBuilder().setSaves(entitiesToSave.build()).build()) .setYears(years).build()); persistEntityChanges(entityChanges); BeforeResponseReturnData responseData = customLogic.beforeResponse(BeforeResponseParameters.newBuilder() .setResData(DomainCreateData.create(targetId, now, registrationExpirationTime)) .setResponseExtensions(createResponseExtensions(feeCreate, feesAndCredits)).build()); return responseBuilder.setResData(responseData.resData()).setExtensions(responseData.responseExtensions()) .build(); }
From source file:google.registry.dns.writer.clouddns.CloudDnsWriter.java
/** * Publish A/AAAA records to Cloud DNS./*ww w .ja v a 2s . c o m*/ * * <p>Cloud DNS has no API for glue -- A/AAAA records are automatically matched to their * corresponding NS records to serve glue. */ @Override public void publishHost(String hostName) { // Get the superordinate domain name of the host. InternetDomainName host = InternetDomainName.from(hostName); Optional<InternetDomainName> tld = Registries.findTldForName(host); // Host not managed by our registry, no need to update DNS. if (!tld.isPresent()) { logger.severefmt("publishHost called for invalid host %s", hostName); return; } // Extract the superordinate domain name. The TLD and host may have several dots so this // must calculate a sublist. ImmutableList<String> hostParts = host.parts(); ImmutableList<String> tldParts = tld.get().parts(); ImmutableList<String> domainParts = hostParts.subList(hostParts.size() - tldParts.size() - 1, hostParts.size()); String domain = Joiner.on(".").join(domainParts); // Refresh the superordinate domain, since we shouldn't be publishing glue records if we are not // authoritative for the superordinate domain. publishDomain(domain); }
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 av a 2s. c om*/ 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();// ww w .j av a 2 s .c om 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.DomainApplicationCreateFlow.java
private void validateLaunchCreateExtension(LaunchCreateExtension launchCreate, Registry registry, InternetDomainName domainName, DateTime now) throws EppException { verifyNoCodeMarks(launchCreate);//w ww . j a v a 2s. c o m boolean hasClaimsNotice = launchCreate.getNotice() != null; if (hasClaimsNotice) { verifyClaimsPeriodNotEnded(registry, now); } boolean isSunriseApplication = !launchCreate.getSignedMarks().isEmpty(); if (!isSuperuser) { // Superusers can ignore the phase. verifyRegistryStateAllowsLaunchFlows(registry, now); verifyLaunchPhaseMatchesRegistryPhase(registry, launchCreate, now); } if (now.isBefore(registry.getClaimsPeriodEnd())) { verifyClaimsNoticeIfAndOnlyIfNeeded(domainName, isSunriseApplication, hasClaimsNotice); } TldState tldState = registry.getTldState(now); if (launchCreate.getSignedMarks().isEmpty()) { // During sunrise, a signed mark is required since only trademark holders are allowed to // create an application. However, we found no marks (ie, this was a landrush application). if (tldState == TldState.SUNRISE) { throw new LandrushApplicationDisallowedDuringSunriseException(); } } else { if (hasClaimsNotice) { // Can't use a claims notice id with a signed mark. throw new NoticeCannotBeUsedWithSignedMarkException(); } if (tldState == TldState.LANDRUSH) { throw new SunriseApplicationDisallowedDuringLandrushException(); } } String domainLabel = domainName.parts().get(0); validateLaunchCreateNotice(launchCreate.getNotice(), domainLabel, isSuperuser, now); // If a signed mark was provided, then it must match the desired domain label. if (!launchCreate.getSignedMarks().isEmpty()) { tmchUtils.verifySignedMarks(launchCreate.getSignedMarks(), domainLabel, now); } }