X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Futil%2FIPValidator.java;h=f6242657185eb75bef4788c83eb2e5634ceb9786;hb=4b5a7d721d994a49057e9bfb403c7bff1b376660;hp=3e02c009cd68d224a4911395e9f979502060246c;hpb=824dc7b5fc0e1ccdf7f460479aff344727f0f01e;p=aaf%2Fauthz.git diff --git a/misc/env/src/main/java/org/onap/aaf/misc/env/util/IPValidator.java b/misc/env/src/main/java/org/onap/aaf/misc/env/util/IPValidator.java index 3e02c009..f6242657 100644 --- a/misc/env/src/main/java/org/onap/aaf/misc/env/util/IPValidator.java +++ b/misc/env/src/main/java/org/onap/aaf/misc/env/util/IPValidator.java @@ -24,34 +24,34 @@ package org.onap.aaf.misc.env.util; import java.util.regex.Pattern; public class IPValidator { - private static final Pattern ipv4_p = Pattern.compile( - "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$" - ); + private static final Pattern ipv4_p = Pattern.compile( + "^((\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])\\.){3}\\2$" + ); - private static final Pattern ipv6_p = Pattern.compile( - "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$" - ); - - private static final Pattern doubleColon = Pattern.compile( - ".*::.*::.*" - ); + private static final Pattern ipv6_p = Pattern.compile( + "^(([0-9a-fA-F]{0,4})([:|.])){2,7}([0-9a-fA-F]{0,4})$" + ); + + private static final Pattern doubleColon = Pattern.compile( + ".*::.*::.*" + ); - private static final Pattern tooManyColon = Pattern.compile( - "(.*:){1,7}" - ); + private static final Pattern tooManyColon = Pattern.compile( + "(.*:){1,7}" + ); - - public static boolean ipv4(String str) { - return ipv4_p.matcher(str).matches(); - } - - public static boolean ipv6(String str) { - return ipv6_p.matcher(str).matches() && - !doubleColon.matcher(str).matches() && - !tooManyColon.matcher(str).matches(); - } - - public static boolean ip (String str) { - return ipv4_p.matcher(str).matches() || ipv6(str); - } + + public static boolean ipv4(String str) { + return ipv4_p.matcher(str).matches(); + } + + public static boolean ipv6(String str) { + return ipv6_p.matcher(str).matches() && + !doubleColon.matcher(str).matches() && + !tooManyColon.matcher(str).matches(); + } + + public static boolean ip (String str) { + return ipv4_p.matcher(str).matches() || ipv6(str); + } }