List of usage examples for com.google.common.net InetAddresses isInetAddress
public static boolean isInetAddress(String ipString)
From source file:org.everit.json.schema.internal.IPAddressValidator.java
/** * Creates an {@link InetAddress} instance if possible and returns it, or on failure it returns * {@code Optional.empty()}.//www. j a v a2 s .c o m * * @param subject the string to be validated. * @return the optional validation failure message */ protected Optional<InetAddress> asInetAddress(final String subject) { try { if (InetAddresses.isInetAddress(subject)) { return Optional.of(InetAddresses.forString(subject)); } else { return Optional.empty(); } } catch (NullPointerException e) { return Optional.empty(); } }
From source file:com.eucalyptus.cloudformation.template.url.S3Helper.java
public static BucketAndKey getBucketAndKeyFromUrl(URL url, String[] validServicePaths, String[] validHostBucketSuffixes, String[] validDomains) throws ValidationErrorException { if (url.getHost() == null || url.getPath() == null) { throw new ValidationErrorException("Invalid S3 " + url); }/*from www. j a va 2 s. c o m*/ // We may not get every form of possible URLs right at this point, but we will allow 3 types // 1) http://<ip address>/<service_path>/bucket/key (No address checks will be done) // 2) Valid external domain, including something with ".objectstorage" or ".walrus". In this case bucket name is first, and key is path // 3) Valid external domain, must start with objectstorage or walrus. In this case bucket name is part of the path // 4) Valid external domain, with no objectstorage or walrus. In this case there must be a service path, and /bucket/key will be assumed to be there. if (InetAddresses.isInetAddress(url.getHost())) { // must end in valid service path... for (String validServicePath : validServicePaths) { if (url.getPath().startsWith(validServicePath)) { return getBucketAndKeyFromPath(url.getPath().substring(validServicePath.length()), url); } } throw new ValidationErrorException( "Invalid S3 url" + url + ", contains IP address but no OSG service path"); } for (String validDomain : validDomains) { // DNS case insensitive String hostLower = url.getHost().toLowerCase(); String validDomainLower = validDomain.toLowerCase(); if (hostLower.endsWith(validDomainLower)) { // check bucket style... for (String validHostBucketSuffix : validHostBucketSuffixes) { String validHostNameBucketNameSuffixLower = validHostBucketSuffix.toLowerCase(); if (hostLower.contains("." + validHostNameBucketNameSuffixLower)) { String bucket = hostLower.substring(0, hostLower.indexOf("." + validHostNameBucketNameSuffixLower)); return getBucketAndKeyFromPath(bucket + "/" + url.getPath(), url); } } // check beginnings for (String validHostBucketSuffix : validHostBucketSuffixes) { String validHostNameBucketNameSuffixLower = validHostBucketSuffix.toLowerCase(); if (hostLower.startsWith(validHostNameBucketNameSuffixLower + ".")) { return getBucketAndKeyFromPath(url.getPath(), url); } } // check service path for (String validServicePath : validServicePaths) { if (url.getPath().startsWith(validServicePath)) { return getBucketAndKeyFromPath(url.getPath().substring(validServicePath.length()), url); } } } } throw new ValidationErrorException("Invalid S3 url " + url + ", does not match any known S3 domains"); }
From source file:com.spotify.helios.agent.AddExtraHostContainerDecorator.java
/** * Validates that the argument has form "host:ip-address". Does not validate the form of the * hostname argument, but checks that the second half is valid via {@link * InetAddresses#isInetAddress}./*from w ww. jav a 2 s.co m*/ */ public static boolean isValidArg(String arg) { final String[] args = arg.split(":"); if (args.length != 2) { return false; } final String ip = args[1]; return InetAddresses.isInetAddress(ip); }
From source file:org.eel.kitchen.jsonschema.keyword.common.format.IPV6Validator.java
@Override public ValidationReport validate(final ValidationContext context, final JsonNode instance) throws JsonValidationFailureException { final ValidationReport report = context.createReport(); final String ipaddr = instance.getTextValue(); if (!InetAddresses.isInetAddress(ipaddr)) { report.fail("string is not a valid IPv6 address"); return report; }// ww w. j a v a 2 s .co m if (InetAddresses.forString(ipaddr).getAddress().length != IPV6_LENGTH) report.fail("string is not a valid IPv6 address"); return report; }
From source file:org.eel.kitchen.jsonschema.keyword.common.format.IPV4Validator.java
@Override public ValidationReport validate(final ValidationContext context, final JsonNode instance) throws JsonValidationFailureException { final ValidationReport report = context.createReport(); final String ipaddr = instance.getTextValue(); if (!InetAddresses.isInetAddress(ipaddr)) { report.fail("string is not a valid IPv4 address"); return report; }/*from w ww . j a v a 2s.com*/ if (InetAddresses.forString(ipaddr).getAddress().length != IPV4_LENGTH) report.fail("string is not a valid IPv4 address"); return report; }
From source file:org.eel.kitchen.jsonschema.format.IPV6FormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV6_LENGTH) return;// w ww . j a va 2s .co m final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv6 address").addInfo("value", value); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.format.IPV6FormatSpecifier.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV6_LENGTH) return;/*from w ww . jav a 2s. c o m*/ final ValidationMessage.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv6 address") .addInfo("value", value); report.addMessage(msg.build()); }
From source file:com.github.fge.jsonschema.format.helpers.IPv4FormatAttribute.java
@Override public void validate(final ProcessingReport report, final MessageBundle bundle, final FullData data) throws ProcessingException { final String ipaddr = data.getInstance().getNode().textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;//w ww . j a v a 2s . co m report.error(newMsg(data, bundle, "err.format.invalidIPv4Address").putArgument("value", ipaddr)); }
From source file:org.eel.kitchen.jsonschema.format.IPV4FormatAttribute.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;/* w w w .j av a 2 s. c o m*/ final Message.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv4 address").addInfo("value", value); report.addMessage(msg.build()); }
From source file:org.eel.kitchen.jsonschema.format.IPV4FormatSpecifier.java
@Override public void checkValue(final String fmt, final ValidationContext ctx, final ValidationReport report, final JsonNode value) { final String ipaddr = value.textValue(); if (InetAddresses.isInetAddress(ipaddr) && InetAddresses.forString(ipaddr).getAddress().length == IPV4_LENGTH) return;/* w ww . ja v a2s . c om*/ final ValidationMessage.Builder msg = newMsg(fmt).setMessage("string is not a valid IPv4 address") .addInfo("value", value); report.addMessage(msg.build()); }