Java Code Examples for com.google.common.net.InternetDomainName#isValid()

The following examples show how to use com.google.common.net.InternetDomainName#isValid() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameServer.java    From The-5zig-Mod with GNU General Public License v3.0 5 votes vote down vote up
public void checkFriendServer(Friend friend) {
	getOnlineFriends().remove(friend.getUsername());
	String friendServer = friend.getServer();
	if (friendServer == null || friendServer.equals("Hidden")) {
		return;
	}
	String friendHost = friendServer.split(":")[0];
	if (StringUtils.equals(friendHost, getHost())) {
		getOnlineFriends().add(friend.getUsername());
	} else {
		boolean selfValid = InternetDomainName.isValid(getHost());
		boolean friendValid = InternetDomainName.isValid(friendHost);
		if (selfValid && friendValid) {
			InternetDomainName mainDomain = InternetDomainName.from(getHost());
			InternetDomainName friendDomain = InternetDomainName.from(friendHost);
			boolean mainPublic = mainDomain.isUnderPublicSuffix();
			boolean friendPublic = friendDomain.isUnderPublicSuffix();
			if (mainPublic && friendPublic) {
				String mainServerDomain = mainDomain.topPrivateDomain().toString();
				String friendMainServerDomain = friendDomain.topPrivateDomain().toString();
				if (mainServerDomain.equals(friendMainServerDomain)) {
					getOnlineFriends().add(friend.getUsername());
				}
			}
		}
	}
}
 
Example 2
Source File: GameServer.java    From The-5zig-Mod with MIT License 5 votes vote down vote up
public void checkFriendServer(Friend friend) {
	getOnlineFriends().remove(friend.getUsername());
	String friendServer = friend.getServer();
	if (friendServer == null || friendServer.equals("Hidden")) {
		return;
	}
	String friendHost = friendServer.split(":")[0];
	if (StringUtils.equals(friendHost, getHost())) {
		getOnlineFriends().add(friend.getUsername());
	} else {
		boolean selfValid = InternetDomainName.isValid(getHost());
		boolean friendValid = InternetDomainName.isValid(friendHost);
		if (selfValid && friendValid) {
			InternetDomainName mainDomain = InternetDomainName.from(getHost());
			InternetDomainName friendDomain = InternetDomainName.from(friendHost);
			boolean mainPublic = mainDomain.isUnderPublicSuffix();
			boolean friendPublic = friendDomain.isUnderPublicSuffix();
			if (mainPublic && friendPublic) {
				String mainServerDomain = mainDomain.topPrivateDomain().toString();
				String friendMainServerDomain = friendDomain.topPrivateDomain().toString();
				if (mainServerDomain.equals(friendMainServerDomain)) {
					getOnlineFriends().add(friend.getUsername());
				}
			}
		}
	}
}
 
Example 3
Source File: BucketNameValidator.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static IStatus allComponentsLengthAreValid(String value) {
  String[] components = value.split("\\.");
  for (String component : components) {
    if (component.length() == 0 || component.length() > 63) {
      return ValidationStatus.error(Messages.getString("bucket.name.invalid", value));
    }
  }
  // if contains dots then must be a valid domain name
  if (components.length > 1 && !InternetDomainName.isValid(value)) {
    return ValidationStatus.error(Messages.getString("bucket.name.invalid", value));
  }
  return ValidationStatus.ok();
}
 
Example 4
Source File: ServiceNameRule.java    From api-compiler with Apache License 2.0 5 votes vote down vote up
@Override
public void run(Model model) {
  String serviceName = model.getServiceConfig().getName();
  if (!Strings.isNullOrEmpty(serviceName)
      && (!InternetDomainName.isValid(serviceName)
          // InternetDomainName.isValid does a lenient validation and allows underscores (which we
          // do not want to permit as DNS names). Therefore explicitly checking for underscores.
          || INVALID_CHARACTER_PATTERN.matcher(serviceName).find())) {
    warning(
        MessageLocationContext.create(model.getServiceConfig(), Service.NAME_FIELD_NUMBER),
        "Invalid DNS name '%s'.",
        serviceName);
  }

}
 
Example 5
Source File: RegistrarFormFields.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private static @Nullable String parseHostname(@Nullable String input) {
  if (input == null) {
    return null;
  }
  if (!InternetDomainName.isValid(input)) {
    throw new FormFieldException("Not a valid hostname.");
  }
  return canonicalizeDomainName(input);
}
 
Example 6
Source File: MdIdDomainName.java    From onos with Apache License 2.0 5 votes vote down vote up
public static MdId asMdId(String mdName) {
    if (mdName == null || !InternetDomainName.isValid(mdName)) {
        throw new IllegalArgumentException("MD Name must follow internet domain name pattern "
                + " Rejecting: " + mdName);
    }
    return asMdId(InternetDomainName.from(mdName));
}