Java Code Examples for org.apache.commons.validator.routines.UrlValidator#isValid()
The following examples show how to use
org.apache.commons.validator.routines.UrlValidator#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: SPARQLRepositoryWrapper.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Override public void validateConfig(Map<String, Object> props) { super.validateConfig(props); SPARQLRepositoryConfig config = Configurable.createConfigurable(SPARQLRepositoryConfig.class, props); String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(config.endpointUrl())) { throw new RepositoryConfigException( new IllegalArgumentException("Repository endpointUrl is not a valid URL: " + config.endpointUrl()) ); } if (config.updateEndpointUrl() != null && !urlValidator.isValid(config.updateEndpointUrl())) { throw new RepositoryConfigException( new IllegalArgumentException("Repository updateEndpointUrl is not a valid URL: " + config.updateEndpointUrl()) ); } }
Example 2
Source File: CommonsURLValidator.java From cxf-fediz with Apache License 2.0 | 6 votes |
public boolean isValid(RequestContext context, String endpointAddress) throws Exception { if (endpointAddress == null) { return true; } // The endpointAddress address must be a valid URL + start with http(s) // Validate it first using commons-validator UrlValidator urlValidator = new UrlValidator(new String[] {"http", "https"}, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(endpointAddress)) { LOG.warn("The given endpointAddress parameter {} is not a valid URL", endpointAddress); return false; } return true; }
Example 3
Source File: CreateUserFormValidator.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * * @param userSubscriptionCommand * @param errors * @return */ private boolean checkSiteUrl(CreateUserCommand userSubscriptionCommand, Errors errors) { if (!checkSiteUrl) { return true; } if (userSubscriptionCommand.getSiteUrl() == null || userSubscriptionCommand.getSiteUrl().trim().isEmpty()) { errors.rejectValue(SITE_URL_KEY, MISSING_URL_KEY); return false; } else { String url = userSubscriptionCommand.getSiteUrl().trim(); String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator (schemes, UrlValidator.ALLOW_2_SLASHES); if (!urlValidator.isValid(url)) { errors.rejectValue(SITE_URL_KEY, INVALID_URL_KEY); return false; } } return true; }
Example 4
Source File: CreateContractFormValidator.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * * @param userSubscriptionCommand * @param errors * @return */ private boolean checkContractUrl(CreateContractCommand createContractCommand, Errors errors) { String url = createContractCommand.getContractUrl().trim(); if (StringUtils.isBlank(url)) { // forbid contract without URL and with website audit enabled Map<String, Boolean> functionalityMap = createContractCommand.getFunctionalityMap(); for (Entry<String, Boolean> it : functionalityMap.entrySet()) { if (it.getKey().equals("DOMAIN") && it.getValue() != null) { errors.rejectValue(CONTRACT_URL_KEY, MISSING_URL_KEY); return false; } } return true; } String[] schemes = {"http","https"}; long validatorOptions = UrlValidator.ALLOW_2_SLASHES + UrlValidator.ALLOW_LOCAL_URLS; UrlValidator urlValidator = new UrlValidator (schemes, new RegexValidator(".*"), validatorOptions); if (!urlValidator.isValid(url)) { errors.rejectValue(CONTRACT_URL_KEY, INVALID_URL_KEY); return false; } return true; }
Example 5
Source File: SignUpFormValidator.java From Asqatasun with GNU Affero General Public License v3.0 | 6 votes |
/** * * @param userSubscriptionCommand * @param errors * @return */ private boolean checkSiteUrl(CreateUserCommand userSubscriptionCommand, Errors errors) { if (!checkSiteUrl) { return true; } if (userSubscriptionCommand.getSiteUrl() == null || userSubscriptionCommand.getSiteUrl().trim().isEmpty()) { errors.rejectValue(SITE_URL_KEY, MISSING_URL_KEY); return false; } else { String url = userSubscriptionCommand.getSiteUrl().trim(); String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator (schemes, UrlValidator.ALLOW_2_SLASHES); if (!urlValidator.isValid(url)) { errors.rejectValue(SITE_URL_KEY, INVALID_URL_KEY); return false; } } return true; }
Example 6
Source File: NSDUtils.java From NFVO with Apache License 2.0 | 6 votes |
private void checkIntegrityVNFPackage( VirtualNetworkFunctionDescriptor virtualNetworkFunctionDescriptor) { if (virtualNetworkFunctionDescriptor.getVnfPackageLocation() != null) { UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid( virtualNetworkFunctionDescriptor.getVnfPackageLocation())) { // this is a script link VNFPackage vnfPackage = new VNFPackage(); vnfPackage.setScriptsLink(virtualNetworkFunctionDescriptor.getVnfPackageLocation()); vnfPackage.setName(virtualNetworkFunctionDescriptor.getName()); vnfPackage.setProjectId(virtualNetworkFunctionDescriptor.getProjectId()); if (vnfPackage.getId() == null) vnfPackage = vnfPackageRepository.save(vnfPackage); virtualNetworkFunctionDescriptor.setVnfPackageLocation(vnfPackage.getId()); } } else { log.warn("vnfPackageLocation is null. Are you sure?"); } }
Example 7
Source File: CSARParser.java From NFVO with Apache License 2.0 | 6 votes |
public VirtualNetworkFunctionDescriptor onboardVNFD(byte[] bytes, String projectId) throws NotFoundException, PluginException, VimException, IOException, IncompatibleVNFPackage, org.openbaton.tosca.exceptions.NotFoundException, BadRequestException, AlreadyExistingException, BadFormatException, InterruptedException, EntityUnreachableException, ExecutionException { InputStream input = new ByteArrayInputStream(bytes); readFiles(input); VNFDTemplate vnfdt = Utils.bytesToVNFDTemplate(this.template); VirtualNetworkFunctionDescriptor vnfd = toscaParser.parseVNFDTemplate(vnfdt); String scriptsLink = null; UrlValidator urlValidator = new UrlValidator(); if (urlValidator.isValid(vnfd.getVnfPackageLocation())) { scriptsLink = vnfd.getVnfPackageLocation(); } saveVNFD(vnfd, projectId, scripts, scriptsLink); input.close(); this.template.close(); this.metadata.close(); return vnfd; }
Example 8
Source File: JWTPolicyBean.java From apiman-plugins with Apache License 2.0 | 5 votes |
/** * Signing Key * <p> * To validate JWT. Must be Base-64 encoded. * * @param signingKeyString * The signingKeyString * @throws Exception key parsing exceptions */ @JsonProperty("signingKeyString") public void setSigningKeyString(String signingKeyString) throws Exception { if (signingKey == null) { String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator(schemes); // If it is a jwk(s) url we don't set the signingKey if (!urlValidator.isValid(signingKeyString)){ signingKey = PemUtils.decodePublicKey(signingKeyString); } } this.signingKeyString = signingKeyString; }
Example 9
Source File: SimpleURLValidator.java From secure-data-service with Apache License 2.0 | 5 votes |
@Override public boolean validate(URI url) { String[] schemes = {"http", "https"}; UrlValidator validator = new UrlValidator(schemes); return validator.isValid(url.toString()); }
Example 10
Source File: HTTPRepositoryWrapper.java From mobi with GNU Affero General Public License v3.0 | 5 votes |
@Override public void validateConfig(Map<String, Object> props) { super.validateConfig(props); HTTPRepositoryConfig config = Configurable.createConfigurable(HTTPRepositoryConfig.class, props); String[] schemes = {"http","https"}; UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(config.serverUrl())) { throw new RepositoryConfigException( new IllegalArgumentException("Repository serverUrl is not a valid URL: " + config.serverUrl()) ); } }
Example 11
Source File: FormattedTextImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean validateURL(String urlToValidate) { if (StringUtils.isBlank(urlToValidate)) return false; if ( ABOUT_BLANK.equals(urlToValidate) ) return true; // Check if the url is "Escapable" - run through the URL-URI-URL gauntlet String escapedURL = sanitizeHrefURL(urlToValidate); if ( escapedURL == null ) return false; // For a protocol-relative URL, we validate with protocol attached // RFC 1808 Section 4 if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = PROTOCOL_PREFIX + urlToValidate; } // For a site-relative URL, we validate with host name and protocol attached // SAK-13787 SAK-23752 if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = HOST_PREFIX + urlToValidate; } // Validate the url UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); return urlValidator.isValid(urlToValidate); }
Example 12
Source File: R2MVerifyHelper.java From r2m-plugin-android with Apache License 2.0 | 5 votes |
public static boolean isValidUrl(String url) { String templateURL = url; templateURL = templateURL.replaceAll(R2MConstants.START_TEMPLATE_VARIABLE_REGEX, ""); templateURL = templateURL.replaceAll(R2MConstants.END_TEMPLATE_VARIABLE_REGEX, ""); UrlValidator urlValidator = new UrlValidator(SUPPORTED_PROTOCOL_SCHEMES, URL_VALIDATION_OPTIONS); return urlValidator.isValid(templateURL); }
Example 13
Source File: SaltApiNodeStepPlugin.java From salt-step with BSD 3-Clause "New" or "Revised" License | 5 votes |
protected void validate(String user, String password, INodeEntry entry) throws SaltStepValidationException { checkNotEmpty(SALT_API_END_POINT_OPTION_NAME, saltEndpoint, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); checkNotEmpty(SALT_API_FUNCTION_OPTION_NAME, function, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); checkNotEmpty(SALT_API_EAUTH_OPTION_NAME, eAuth, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); checkNotEmpty(SALT_USER_OPTION_NAME, user, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); checkNotEmpty(SALT_PASSWORD_OPTION_NAME, password, SaltApiNodeStepFailureReason.ARGUMENTS_MISSING, entry); UrlValidator urlValidator = new UrlValidator(endPointSchemes, UrlValidator.ALLOW_LOCAL_URLS); if (!urlValidator.isValid(saltEndpoint)) { throw new SaltStepValidationException(SALT_API_END_POINT_OPTION_NAME, String.format( "%s is not a valid endpoint.", saltEndpoint), SaltApiNodeStepFailureReason.ARGUMENTS_INVALID, entry.getNodename()); } }
Example 14
Source File: PortletIFrame.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean validateURL(String urlToValidate) { // return FormattedText.validateURL(urlToValidate); // KNL-1105 if (StringUtils.isBlank(urlToValidate)) return false; if ( ABOUT_BLANK.equals(urlToValidate) ) return true; // Check if the url is "Escapable" - run through the URL-URI-URL gauntlet String escapedURL = sanitizeHrefURL(urlToValidate); if ( escapedURL == null ) return false; // For a protocol-relative URL, we validate with protocol attached // RFC 1808 Section 4 if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = PROTOCOL_PREFIX + urlToValidate; } // For a site-relative URL, we validate with host name and protocol attached // SAK-13787 SAK-23752 if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = HOST_PREFIX + urlToValidate; } // Validate the url UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); return urlValidator.isValid(urlToValidate); }
Example 15
Source File: FormattedTextImpl.java From sakai with Educational Community License v2.0 | 5 votes |
public boolean validateURL(String urlToValidate) { if (StringUtils.isBlank(urlToValidate)) return false; if ( ABOUT_BLANK.equals(urlToValidate) ) return true; // Check if the url is "Escapable" - run through the URL-URI-URL gauntlet String escapedURL = sanitizeHrefURL(urlToValidate); if ( escapedURL == null ) return false; // For a protocol-relative URL, we validate with protocol attached // RFC 1808 Section 4 if ((urlToValidate.startsWith("//")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = PROTOCOL_PREFIX + urlToValidate; } // For a site-relative URL, we validate with host name and protocol attached // SAK-13787 SAK-23752 if ((urlToValidate.startsWith("/")) && (urlToValidate.indexOf("://") == -1)) { urlToValidate = HOST_PREFIX + urlToValidate; } // Validate the url UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); return urlValidator.isValid(urlToValidate); }
Example 16
Source File: HIPAAMatcherAttributeValue.java From arx with Apache License 2.0 | 4 votes |
@Override public boolean matches(String value) { UrlValidator validator = UrlValidator.getInstance(); return validator.isValid(value); }
Example 17
Source File: PropertiesEncryption.java From data-prep with Apache License 2.0 | 4 votes |
private static boolean isUrl(String field) { UrlValidator urlValidator = new UrlValidator(ALLOW_LOCAL_URLS + ALLOW_ALL_SCHEMES + ALLOW_2_SLASHES); return urlValidator.isValid(field); }
Example 18
Source File: StratosApplication.java From attic-stratos with Apache License 2.0 | 4 votes |
/** * @return {@code true} if required properties are loaded */ private boolean loadRequiredProperties() { if (logger.isDebugEnabled()) { logger.debug("Loading properties..."); } // Load properties String stratosURL = null; String username = null; String password = null; stratosURL = System.getenv(CliConstants.STRATOS_URL_ENV_PROPERTY); username = System.getenv(CliConstants.STRATOS_USERNAME_ENV_PROPERTY); password = System.getenv(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY); if (StringUtils.isBlank(stratosURL)) { if (logger.isDebugEnabled()) { logger.debug("Required configuration not found."); } // Stratos Controller details are not set. System.out.format("Could not find required \"%s\" variable in your environment.%n", CliConstants.STRATOS_URL_ENV_PROPERTY); return false; } if (logger.isDebugEnabled()) { logger.debug("Required configuration found. Validating {}", stratosURL); } int slashCount = StringUtils.countMatches(stratosURL, "/"); int colonCount = StringUtils.countMatches(stratosURL, ":"); UrlValidator urlValidator = new UrlValidator(new String[]{"https"}, UrlValidator.ALLOW_LOCAL_URLS); // port must be provided, so colonCount must be 2 // context path must not be provided, so slashCount must not be >3 if (!urlValidator.isValid(stratosURL) || colonCount != 2 || slashCount > 3) { if (logger.isDebugEnabled()) { logger.debug("Stratos Controller URL {} is not valid", stratosURL); } System.out.format( "The \"%s\" variable in your environment is not a valid URL. You have provided \"%s\".%n" + "Please provide the Stratos Controller URL as follows%nhttps://<host>:<port>%n", CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL); return false; } if (logger.isDebugEnabled()) { logger.debug("Stratos Controller URL {} is valid.", stratosURL); logger.debug("Adding the values to context."); } context.put(CliConstants.STRATOS_URL_ENV_PROPERTY, stratosURL); context.put(CliConstants.STRATOS_USERNAME_ENV_PROPERTY, username); context.put(CliConstants.STRATOS_PASSWORD_ENV_PROPERTY, password); return true; }
Example 19
Source File: SSOSessionCheckFilter.java From testgrid with Apache License 2.0 | 4 votes |
/** * Check each request's path and do check for SESSION if the path has to be secured. * Otherwise allowed */ @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { //Skip checking for session if disabled in property file. String isSsoEnabled = ConfigurationContext.getProperty(ConfigurationProperties.ENABLE_SSO); String ssoLoginUrl = ConfigurationContext.getProperty(ConfigurationProperties.SSO_LOGIN_URL); UrlValidator urlValidator = new UrlValidator(UrlValidator.ALLOW_LOCAL_URLS); if (isSsoEnabled != null) { if (Boolean.valueOf(isSsoEnabled)) { if (ssoLoginUrl == null || !urlValidator.isValid(ssoLoginUrl)) { throw new ServletException( StringUtil.concatStrings("SSO login url is not set in the ", TestGridConstants .TESTGRID_CONFIG_FILE, " or invalid url is set")); } String path = ((HttpServletRequest) servletRequest).getRequestURI(); if (isSecuredAPI(path)) { Boolean isSessionValid = ((HttpServletRequest) servletRequest).isRequestedSessionIdValid(); // Adding a token based Authentication to call backend api without SSO for testing. if (!StringUtil.isStringNullOrEmpty( ((HttpServletRequest) servletRequest).getHeader("Authorization"))) { if (((HttpServletRequest) servletRequest).getHeader("Authorization").equals (ConfigurationContext.getProperty(ConfigurationProperties.API_TOKEN))) { isSessionValid = true; } } if (!isSessionValid) { HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; //If the request is for a backend API, Status Code 401 is sent. if (path.startsWith(Constants.BACKEND_API_URI)) { httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { httpResponse.sendRedirect(ssoLoginUrl + Constants.QUERY_PARAM_APPEND + Constants.RELAY_STATE_PARAM + Constants.QUERY_PARAM_EQUAL + ((HttpServletRequest) servletRequest).getRequestURI()); } return; } } } filterChain.doFilter(servletRequest, servletResponse); } else { String errorMsg = StringUtil.concatStrings(ConfigurationProperties.ENABLE_SSO.toString(), " is not set in ", TestGridConstants.TESTGRID_CONFIG_FILE); logger.error(errorMsg); throw new ServletException(errorMsg); } }
Example 20
Source File: URIValidator.java From gerbil with GNU Affero General Public License v3.0 | 2 votes |
/** * Tests a given string if it is a valid url. * * @param url * @return true if the string represents a valid url, false otherwise */ public static boolean isValidURL(String url) { UrlValidator validator = UrlValidator.getInstance(); return validator.isValid(url); }