Java Code Examples for org.apache.commons.lang3.StringUtils.remove()

The following are Jave code examples for showing how to use remove() of the org.apache.commons.lang3.StringUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: cas-5.1.0   File: TemplatedMetadataAndCertificatesGenerationService.java   View Source Code Vote up 6 votes
/**
 * Build metadata generator parameters by passing the encryption,
 * signing and back-channel certs to the parameter generator.
 *
 * @throws Exception Thrown if cert files are missing, or metadata file inaccessible.
 */
protected void buildMetadataGeneratorParameters() throws Exception {
    final SamlIdPProperties idp = casProperties.getAuthn().getSamlIdp();
    final Resource template = this.resourceLoader.getResource("classpath:/template-idp-metadata.xml");

    String signingKey = FileUtils.readFileToString(idp.getMetadata().getSigningCertFile().getFile(), StandardCharsets.UTF_8);
    signingKey = StringUtils.remove(signingKey, BEGIN_CERTIFICATE);
    signingKey = StringUtils.remove(signingKey, END_CERTIFICATE).trim();

    String encryptionKey = FileUtils.readFileToString(idp.getMetadata().getEncryptionCertFile().getFile(), StandardCharsets.UTF_8);
    encryptionKey = StringUtils.remove(encryptionKey, BEGIN_CERTIFICATE);
    encryptionKey = StringUtils.remove(encryptionKey, END_CERTIFICATE).trim();

    try (StringWriter writer = new StringWriter()) {
        IOUtils.copy(template.getInputStream(), writer, StandardCharsets.UTF_8);
        final String metadata = writer.toString()
                .replace("${entityId}", idp.getEntityId())
                .replace("${scope}", idp.getScope())
                .replace("${idpEndpointUrl}", getIdPEndpointUrl())
                .replace("${encryptionKey}", encryptionKey)
                .replace("${signingKey}", signingKey);
        FileUtils.write(idp.getMetadata().getMetadataFile(), metadata, StandardCharsets.UTF_8);
    }
}
 
Example 2
Project: zkAdmin   File: RegexpUtils.java   View Source Code Vote up 6 votes
/**
 * 得到匹配结果分组。
 * @param
 * @param str     字符串
 * @param strict  使用严格方式,即只有字符完全匹配上正则表达式时才返回结果
 * @return        如果没有匹配上,返回一个null。
 */
public static String[] getMatcherResult(String str,String regexp,boolean strict){
    if(!strict){
        String tmp=StringUtils.remove(str, "\\(");
        tmp=StringUtils.remove(str, "\\)");
        if(tmp.indexOf('(')>-1 && tmp.indexOf(')')>-1){
            //用户给出的正则中已经有了分组信息
        }else{
            regexp="("+regexp+")";//补充一个默认分组
        }
    }
    Matcher m=getMatcher(str,regexp,strict);
    if(!m.matches())return null;
    int n=m.groupCount();
    if(n==0)return new String[]{m.group()};
    String[] result=new String[n];
    for(int i=1;i<=n;i++){
        result[i-1]=m.group(i);
    }
    return result;
}
 
Example 3
Project: Fetax-AI   File: XSSFilter.java   View Source Code Vote up 6 votes
private String rmXSSDangerousCharacters(String[] xss, String script) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				String regex = remove + ".*" + remove;

				Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, st);
					log.warn(st + "已移除");
				}
			}

			return script;
		}
 
Example 4
Project: awe-awesomesky   File: XSSFilter.java   View Source Code Vote up 6 votes
private String rmXSSDangerousCharacters(String[] xss, String script) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				String regex = remove + ".*" + remove;

				Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, st);
					log.warn(st + "已移除");
				}
			}

			return script;
		}
 
Example 5
Project: springboot-shiro-cas-mybatis   File: JsonServiceRegistryDao.java   View Source Code Vote up 5 votes
/**
 * Creates a JSON file for a registered service.
 * The file is named as {@code [SERVICE-NAME]-[SERVICE-ID]-.{@value #FILE_EXTENSION}}
 *
 * @param service Registered service.
 * @return JSON file in service registry directory.
 * @throws IllegalArgumentException if file name is invalid
 */
protected File makeFile(final RegisteredService service) {
    final String fileName = StringUtils.remove(service.getName() + '-' + service.getId() + '.' + FILE_EXTENSION, " ");
    try {
        final File svcFile = new File(serviceRegistryDirectory.toFile(), fileName);
        LOGGER.debug("Using [{}] as the service definition file", svcFile.getCanonicalPath());
        return svcFile;
    } catch (final IOException e) {
        LOGGER.warn("Service file name {} is invalid; Examine for illegal characters in the name.", fileName);
        throw new IllegalArgumentException(e);
    }
}
 
Example 6
Project: springboot-shiro-cas-mybatis   File: JsonServiceRegistryDao.java   View Source Code Vote up 5 votes
/**
 * Creates a JSON file for a registered service.
 * The file is named as <code>[SERVICE-NAME]-[SERVICE-ID]-.{@value #FILE_EXTENSION}</code>
 *
 * @param service Registered service.
 * @return JSON file in service registry directory.
 * @throws IllegalArgumentException if file name is invalid
 */
protected File makeFile(final RegisteredService service) {
    final String fileName = StringUtils.remove(service.getName() + '-' + service.getId() + '.' + FILE_EXTENSION, " ");
    try {
        final File svcFile = new File(serviceRegistryDirectory.toFile(), fileName);
        LOGGER.debug("Using [{}] as the service definition file", svcFile.getCanonicalPath());
        return svcFile;
    } catch (final IOException e) {
        LOGGER.warn("Service file name {} is invalid; Examine for illegal characters in the name.", fileName);
        throw new IllegalArgumentException(e);
    }
}
 
Example 7
Project: cas-5.1.0   File: OAuth20CallbackAuthorizeEndpointController.java   View Source Code Vote up 5 votes
/**
 * Handle request.
 *
 * @param request  the request
 * @param response the response
 * @return the model and view
 * @throws Exception the exception
 */
@GetMapping(path = OAuth20Constants.BASE_OAUTH20_URL + '/' + OAuth20Constants.CALLBACK_AUTHORIZE_URL)
public ModelAndView handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    this.callbackController.callback(request, response);
    final String url = StringUtils.remove(response.getHeader("Location"), "redirect:");
    final J2EContext ctx = WebUtils.getPac4jJ2EContext(request, response);
    final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
    return oAuth20CallbackAuthorizeViewResolver.resolve(ctx, manager, url);
}
 
Example 8
Project: cas-5.1.0   File: CompressionUtils.java   View Source Code Vote up 5 votes
/**
 * Use ZipOutputStream to zip text to byte array, then convert
 * byte array to base64 string, so it can be transferred via http request.
 *
 * @param srcTxt the src txt
 * @return the string in UTF-8 format and base64'ed, or null.
 */
public static String compress(final String srcTxt) {
    try {
        final ByteArrayOutputStream rstBao = new ByteArrayOutputStream();
        final GZIPOutputStream zos = new GZIPOutputStream(rstBao);
        zos.write(srcTxt.getBytes());
        IOUtils.closeQuietly(zos);
        final byte[] bytes = rstBao.toByteArray();
        final String base64 = StringUtils.remove(Base64.encodeBase64String(bytes), '\0');
        return new String(StandardCharsets.UTF_8.encode(base64).array(), StandardCharsets.UTF_8);
    } catch (final IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return null;
}
 
Example 9
Project: cas-5.1.0   File: AbstractResourceBasedServiceRegistryDao.java   View Source Code Vote up 5 votes
/**
 * Creates a file for a registered service.
 * The file is named as {@code [SERVICE-NAME]-[SERVICE-ID]-.{@value #getExtension()}}
 *
 * @param service Registered service.
 * @return file in service registry directory.
 * @throws IllegalArgumentException if file name is invalid
 */
protected File makeFile(final RegisteredService service) {
    final String fileName = StringUtils.remove(service.getName() + '-' + service.getId() + '.' + getExtension(), " ");
    try {
        final File svcFile = new File(this.serviceRegistryDirectory.toFile(), fileName);
        LOGGER.debug("Using [{}] as the service definition file", svcFile.getCanonicalPath());
        return svcFile;
    } catch (final IOException e) {
        LOGGER.warn("Service file name [{}] is invalid; Examine for illegal characters in the name.", fileName);
        throw new IllegalArgumentException(e);
    }
}
 
Example 10
Project: cas-server-4.2.1   File: JsonServiceRegistryDao.java   View Source Code Vote up 5 votes
/**
 * Creates a JSON file for a registered service.
 * The file is named as {@code [SERVICE-NAME]-[SERVICE-ID]-.{@value #FILE_EXTENSION}}
 *
 * @param service Registered service.
 * @return JSON file in service registry directory.
 * @throws IllegalArgumentException if file name is invalid
 */
protected File makeFile(final RegisteredService service) {
    final String fileName = StringUtils.remove(service.getName() + '-' + service.getId() + '.' + FILE_EXTENSION, " ");
    try {
        final File svcFile = new File(serviceRegistryDirectory.toFile(), fileName);
        LOGGER.debug("Using [{}] as the service definition file", svcFile.getCanonicalPath());
        return svcFile;
    } catch (final IOException e) {
        LOGGER.warn("Service file name {} is invalid; Examine for illegal characters in the name.", fileName);
        throw new IllegalArgumentException(e);
    }
}
 
Example 11
Project: saluki   File: ConsulRegistryRepository.java   View Source Code Vote up 5 votes
/**
 * ==============help method=============
 */
private Triple<String, String, String> getmachineInfo(String providerAndConsumerKv, String groupService) {
    String thralUrl = consulClient.getKVValue(providerAndConsumerKv).getValue().getDecodedValue();
    GrpcURL url = GrpcURL.valueOf(thralUrl);
    String flagAndIp = StringUtils.remove(providerAndConsumerKv, groupService + "/");
    String[] serverInfos = StringUtils.split(flagAndIp, "/");
    String machineFlag = serverInfos[1];
    return new ImmutableTriple<String, String, String>(machineFlag, url.getAddress(),
                                                       url.getParameter(Constants.HTTP_PORT_KEY));
}
 
Example 12
Project: Fetax-AI   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSDangerousCharacters(String script, String[] xss) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				if (StringUtils.indexOf(script, remove) < 0) {
					continue;
				}

				if (remove.length() == 1) {
					script = StringUtils.remove(script, remove.charAt(0));
					log.warn('[' + remove + "]已移除");
					continue;
				}

				Pattern p = Pattern.compile(remove, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, remove);
					log.warn('[' + st + "]已移除");
				}

			}

			return script;
		}
 
Example 13
Project: Fetax-AI   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSBetween(String script, final String open, final String close) {// 移除存在XSS攻击威胁的字符串

			String[] xss = StringUtils.substringsBetween(script, open, close);

			if (null != xss && xss.length > 0) {

				for (String xs : xss) {
					script = StringUtils.remove(script, open + xs + close);
					log.warn(open + xs + close + "已移除");
				}
			}

			return script;
		}
 
Example 14
Project: redirector   File: LocalHttpService.java   View Source Code Vote up 5 votes
private Function<String, String> removeRootPath(final String absolutePath) {
    return new Function<String, String>() {
        @Override
        public String apply(String fileName) {
            String tmp = StringUtils.remove(fileName, removeLastSeparator(absolutePath));
            return removeLeaderSeparator(tmp);
        }
    };
}
 
Example 15
Project: awe-awesomesky   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSDangerousCharacters(String script, String[] xss) {// 移除存在XSS攻击威胁的字符串

			if (null == xss || xss.length == 0) {
				return script;
			}

			for (String remove : xss) {

				if (StringUtils.isBlank(remove)) {
					continue;
				}

				if (StringUtils.indexOf(script, remove) < 0) {
					continue;
				}

				if (remove.length() == 1) {
					script = StringUtils.remove(script, remove.charAt(0));
					log.warn('[' + remove + "]已移除");
					continue;
				}

				Pattern p = Pattern.compile(remove, Pattern.CASE_INSENSITIVE);
				Matcher m = p.matcher(script);

				while (m.find()) {
					String st = m.group();
					script = StringUtils.remove(script, remove);
					log.warn('[' + st + "]已移除");
				}

			}

			return script;
		}
 
Example 16
Project: awe-awesomesky   File: XSSFilter.java   View Source Code Vote up 5 votes
private String rmXSSBetween(String script, final String open, final String close) {// 移除存在XSS攻击威胁的字符串

			String[] xss = StringUtils.substringsBetween(script, open, close);

			if (null != xss && xss.length > 0) {

				for (String xs : xss) {
					script = StringUtils.remove(script, open + xs + close);
					log.warn(open + xs + close + "已移除");
				}
			}

			return script;
		}
 
Example 17
Project: sunbird-lms-mw   File: BaseMetricsActor.java   View Source Code Vote up 4 votes
protected String formatKeyString(String key) {
  return StringUtils.remove(key, "-");
}
 
Example 18
Project: saluki   File: ConsulRegistryRepository.java   View Source Code Vote up 4 votes
private String generateServicekey(String group, String service, String version) {
    return StringUtils.remove(group, Constants.CONSUL_SERVICE_PRE) + ":" + service + ":" + version;
}
 
Example 19
Project: Quora-Marketing   File: QuoraCrawler.java   View Source Code Vote up 4 votes
private void crawlQuoraPage(String url, boolean crawlRelated) {
	// log("crawling for Quora url : " + url);
	uniqueQuoraLinks.add(url);
	Document doc = getDocument(url);
	if (doc == null) {
		// log("document is null for quora url: " + url);
		return;
	}

	Elements statsElements = doc.select("div.QuestionStats");
	for (Element statsElement : statsElements) {
		System.out.print(count++ + "\t" + url);
		Elements statsElementValues = statsElement.getElementsByTag("strong");
		int i = 1;
		for (Element statsElementValue : statsElementValues) {
			if (i > 2) {
				break;
			}
			System.out.print("\t" + statsElementValue.getElementsByTag("strong").text());
			i++;
		}
	}

	Elements activityElements = doc.getElementsByClass("QuestionLastActivityTime");
	if (activityElements.size() > 0) {
		for (Element activityElement : activityElements) {
			String lastAsked = StringUtils.remove(activityElement.text(), "Last asked: ");
			if (!lastAsked.contains("201")) {
				lastAsked = lastAsked + ", 2016";
			}
			System.out.println("\t" + lastAsked);
		}
	} else {
		System.out.println();
	}

	if (crawlRelated) {
		// log("crawlRelated is true for : " + url);
		Elements relatedQuestions = doc.getElementsByClass("question_related");
		List<Element> relatedQuestionList = new ArrayList<>();
		for (Element relatedQuestion : relatedQuestions) {
			Elements relatedQuestionHrefs = relatedQuestion.select("a[href]");
			for (Element element : relatedQuestionHrefs) {
				relatedQuestionList.add(element);
			}
		}

		relatedQuestionList = Utils.getSublist(relatedQuestionList, QuoraConstants.numReLatedQuestion);
		for (Element relatedQuestionHref : relatedQuestionList) {
			String relatedUrl = relatedQuestionHref.absUrl("href");
			if (!uniqueQuoraLinks.contains(relatedUrl)) {
				crawlQuoraPage(relatedUrl, false);
			}
		}

	}
}
 
Example 20
Project: vscrawler   File: Remove.java   View Source Code Vote up 4 votes
@Override
protected String handle(String input, String second) {
    return StringUtils.remove(input, second);
}