/** * Validates the provided input against the given white list and black list patterns. * Precedence was give to the white list patterns. Thus, if the input is both white listed and blacklisted it * will be considered as valid. * * @param input input * @param whiteListPatterns a String array of white list pattern keys * @param blackListPatterns a String array of black list pattern keys * @return isWhiteListed || isNotBlackListed */ public static boolean isValid(String input, String[] whiteListPatterns, String[] blackListPatterns) { if (ArrayUtils.isEmpty(whiteListPatterns) || ArrayUtils.isEmpty(blackListPatterns)) { throw new IllegalArgumentException("Should provide at least one white list pattern and black list pattern"); } return isValidOverWhiteListPatterns(input, whiteListPatterns) || isValidOverBlackListPatterns(input, blackListPatterns); }
/** * Validates the provided input against the given white list and black list patterns. * Precedence was give to the white list patterns. Thus, if the input is both white listed and blacklisted it * will be considered as valid. * * @param input input * @param whiteListPatterns a String array of white list pattern keys * @param blackListPatterns a String array of black list pattern keys * @return isWhiteListed || isNotBlackListed */ public static boolean isValid(String input, String[] whiteListPatterns, String[] blackListPatterns) { if (ArrayUtils.isEmpty(whiteListPatterns) || ArrayUtils.isEmpty(blackListPatterns)) { throw new IllegalArgumentException("Should provide at least one white list pattern and black list pattern"); } return isValidOverWhiteListPatterns(input, whiteListPatterns) || isValidOverBlackListPatterns(input, blackListPatterns); }
/** * Returns the input if valid over the given white list patterns else throws an IdentityValidationException * * @param input input * @param whiteListPatterns a String array of white list pattern keys * @return input if valid over the given white list patterns else throws an IdentityValidationException */ public static String getValidInputOverWhiteListPatterns(String input, String... whiteListPatterns) throws IdentityValidationException { if (StringUtils.isEmpty(input) || isValidOverWhiteListPatterns(input, whiteListPatterns)) { return input; } throw new IdentityValidationException( msgSection1 + String.format(msgSection2, getPatternString(whiteListPatterns))); }
/** * Returns the input if valid over the given white list patterns else throws an IdentityValidationException * * @param input input * @param whiteListPatterns a String array of white list pattern keys * @return input if valid over the given white list patterns else throws an IdentityValidationException * @throws IdentityValidationException if a white list pattern key provided does not correspond to a registered * regex. */ public static String getValidInputOverWhiteListPatterns(String input, String... whiteListPatterns) throws IdentityValidationException { if (StringUtils.isEmpty(input) || isValidOverWhiteListPatterns(input, whiteListPatterns)) { return input; } throw new IdentityValidationException( msgSection1 + String.format(msgSection2, getPatternString(whiteListPatterns))); }