List of usage examples for org.apache.commons.validator.routines UrlValidator ALLOW_ALL_SCHEMES
long ALLOW_ALL_SCHEMES
To view the source code for org.apache.commons.validator.routines UrlValidator ALLOW_ALL_SCHEMES.
Click Source Link
From source file:com.liferay.ide.project.core.workspace.BundleUrlValidationService.java
@Override protected Status compute() { Status retval = Status.createOkStatus(); BaseLiferayWorkspaceOp op = _op();/* w ww . j a v a 2 s .co m*/ String bundleUrl = op.getBundleUrl().content(); UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_LOCAL_URLS | UrlValidator.ALLOW_ALL_SCHEMES); if ((bundleUrl != null) && !urlValidator.isValid(bundleUrl)) { retval = Status.createWarningStatus("The bundle URL may not be a vaild URL."); } return retval; }
From source file:elh.eus.absa.MicroTextNormalizer.java
/** * Normalize input String (urls -> URL) * //from w w w .ja v a 2 s. c o m * @param input : input string to normalize * @returns String */ private static String normalizeURL(String input) { //URL normalization UrlValidator defaultValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES); if (defaultValidator.isValid(input)) { return "URLURLURL"; // valid } else { return input; } }
From source file:org.apache.cxf.fediz.service.idp.beans.PassiveRequestorValidator.java
public boolean isValid(RequestContext context, String endpointAddress, String realm) throws Exception { if (endpointAddress == null) { return true; }/*w w w . j av a 2s . co m*/ Idp idpConfig = (Idp) WebUtils.getAttributeFromFlowScope(context, "idpConfig"); Application serviceConfig = idpConfig.findApplication(realm); if (serviceConfig == null) { LOG.warn("No service config found for " + realm); return true; } // The endpointAddress address must match the passive endpoint requestor constraint // (if it is specified) // Also, it must be a valid URL + start with https // Validate it first using commons-validator UrlValidator urlValidator = new UrlValidator( UrlValidator.ALLOW_LOCAL_URLS + UrlValidator.ALLOW_ALL_SCHEMES); if (!urlValidator.isValid(endpointAddress)) { LOG.warn("The given endpointAddress parameter {} is not a valid URL", endpointAddress); return false; } if (serviceConfig.getCompiledPassiveRequestorEndpointConstraint() == null) { LOG.warn("No passive requestor endpoint constraint is configured for the application. " + "This could lead to a malicious redirection attack"); return true; } Matcher matcher = serviceConfig.getCompiledPassiveRequestorEndpointConstraint().matcher(endpointAddress); if (!matcher.matches()) { LOG.error("The endpointAddress value of {} does not match any of the passive requestor values", endpointAddress); return false; } return true; }
From source file:org.apache.cxf.fediz.service.oidc.clients.ClientRegistrationService.java
private boolean isValidURI(String uri, boolean requireHttps) { UrlValidator urlValidator = null;/*from w ww. j av a 2 s . c o m*/ if (requireHttps) { String[] schemes = { "https" }; urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); } else { urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS + UrlValidator.ALLOW_ALL_SCHEMES); } if (!urlValidator.isValid(uri)) { return false; } // Do additional checks on the URI try { URI parsedURI = new URI(uri); // The URI can't have a fragment according to the OAuth 2.0 spec (+ audience spec) if (parsedURI.getFragment() != null) { return false; } } catch (URISyntaxException ex) { return false; } return true; }
From source file:org.apache.maven.report.projectinfo.LicenseReport.java
/** * @param project not null// w w w .ja v a 2 s. co m * @param url not null * @return a valid URL object from the url string * @throws IOException if any */ protected static URL getLicenseURL(MavenProject project, String url) throws IOException { URL licenseUrl; UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_ALL_SCHEMES); // UrlValidator does not accept file URLs because the file // URLs do not contain a valid authority (no hostname). // As a workaround accept license URLs that start with the // file scheme. if (urlValidator.isValid(url) || StringUtils.defaultString(url).startsWith("file://")) { try { licenseUrl = new URL(url); } catch (MalformedURLException e) { throw new MalformedURLException( "The license url '" + url + "' seems to be invalid: " + e.getMessage()); } } else { File licenseFile = new File(project.getBasedir(), url); if (!licenseFile.exists()) { // Workaround to allow absolute path names while // staying compatible with the way it was... licenseFile = new File(url); } if (!licenseFile.exists()) { throw new IOException("Maven can't find the file '" + licenseFile + "' on the system."); } try { licenseUrl = licenseFile.toURI().toURL(); } catch (MalformedURLException e) { throw new MalformedURLException( "The license url '" + url + "' seems to be invalid: " + e.getMessage()); } } return licenseUrl; }
From source file:org.codehaus.griffon.runtime.validation.constraints.UrlConstraint.java
@Override @SuppressWarnings("SuspiciousToArrayCall") public void setParameter(@Nonnull Object constraintParameter) { RegexValidator domainValidator = null; if (constraintParameter instanceof Boolean) { url = (Boolean) constraintParameter; } else if (constraintParameter instanceof String) { url = true;/*from w w w . ja va 2s.com*/ domainValidator = new RegexValidator((String) constraintParameter); } else if (constraintParameter instanceof List<?>) { url = true; List<?> regexpList = (List<?>) constraintParameter; domainValidator = new RegexValidator(regexpList.toArray(new String[regexpList.size()])); } else { throw new IllegalArgumentException("Parameter for constraint [" + VALIDATION_DSL_NAME + "] of property [" + constraintPropertyName + "] of class [" + constraintOwningClass + "] must be a boolean, string, or list value"); } validator = new UrlValidator(domainValidator, UrlValidator.ALLOW_ALL_SCHEMES + UrlValidator.ALLOW_2_SLASHES); super.setParameter(constraintParameter); }
From source file:org.mule.modules.validation.ValidationModule.java
/** * If the specified <code>url</code> is not a valid one throw an exception. * <p/>/*from w ww . ja va2s . co m*/ * {@sample.xml ../../../doc/mule-module-validation.xml.sample validation:validate-url} * * @param url URL to validate * @param allowTwoSlashes Allow two slashes in the path component of the URL. * @param allowAllSchemes Allows all validly formatted schemes to pass validation instead of supplying a set of valid schemes. * @param allowLocalURLs Allow local URLs, such as http://localhost/ or http://machine/ . * @param noFragments Enabling this options disallows any URL fragments. * @param customExceptionClassName Class name of the exception to throw * @throws Exception if not valid */ @Processor public void validateUrl(String url, @Optional @Default("false") boolean allowTwoSlashes, @Optional @Default("false") boolean allowAllSchemes, @Optional @Default("false") boolean allowLocalURLs, @Optional @Default("false") boolean noFragments, @Optional @Default("org.mule.modules.validation.InvalidException") String customExceptionClassName) throws Exception { long options = 0; if (allowAllSchemes) { options |= UrlValidator.ALLOW_ALL_SCHEMES; } if (allowTwoSlashes) { options |= UrlValidator.ALLOW_2_SLASHES; } if (allowLocalURLs) { options |= UrlValidator.ALLOW_LOCAL_URLS; } if (noFragments) { options |= UrlValidator.NO_FRAGMENTS; } UrlValidator validator = new UrlValidator(options); if (!validator.isValid(url)) { throw buildException(customExceptionClassName); } }