use of org.apache.commons.lang3.StringUtils.substringBetween in project cas by apereo.
the class AbstractOAuth20Tests method internalVerifyClientOK.
protected Pair<String, String> internalVerifyClientOK(final RegisteredService service, final boolean refreshToken, final boolean json) throws Exception {
final Principal principal = createPrincipal();
final OAuthCode code = addCode(principal, service);
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(HttpMethod.GET.name(), CONTEXT + OAuth20Constants.ACCESS_TOKEN_URL);
mockRequest.setParameter(OAuth20Constants.REDIRECT_URI, REDIRECT_URI);
mockRequest.setParameter(OAuth20Constants.GRANT_TYPE, OAuth20GrantTypes.AUTHORIZATION_CODE.name().toLowerCase());
final String auth = CLIENT_ID + ':' + CLIENT_SECRET;
final String value = EncodingUtils.encodeBase64(auth.getBytes(StandardCharsets.UTF_8));
mockRequest.addHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BASIC_HEADER_PREFIX + value);
mockRequest.setParameter(OAuth20Constants.CLIENT_ID, CLIENT_ID);
mockRequest.setParameter(OAuth20Constants.CLIENT_SECRET, CLIENT_SECRET);
mockRequest.setParameter(OAuth20Constants.CODE, code.getId());
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
requiresAuthenticationInterceptor.preHandle(mockRequest, mockResponse, null);
oAuth20AccessTokenController.handleRequest(mockRequest, mockResponse);
assertNull(this.ticketRegistry.getTicket(code.getId()));
assertEquals(HttpStatus.SC_OK, mockResponse.getStatus());
final String body = mockResponse.getContentAsString();
final String accessTokenId;
String refreshTokenId = null;
if (json) {
assertEquals(MediaType.APPLICATION_JSON_VALUE, mockResponse.getContentType());
assertTrue(body.contains('"' + OAuth20Constants.ACCESS_TOKEN + "\":\"AT-"));
final Map results = MAPPER.readValue(body, Map.class);
if (refreshToken) {
assertTrue(body.contains('"' + OAuth20Constants.REFRESH_TOKEN + "\":\"RT-"));
refreshTokenId = results.get(OAuth20Constants.REFRESH_TOKEN).toString();
}
assertTrue(body.contains('"' + OAuth20Constants.EXPIRES_IN + "\":"));
accessTokenId = results.get(OAuth20Constants.ACCESS_TOKEN).toString();
} else {
assertEquals(MediaType.TEXT_PLAIN_VALUE, mockResponse.getContentType());
assertTrue(body.contains(OAuth20Constants.ACCESS_TOKEN + "=AT-"));
if (refreshToken) {
assertTrue(body.contains(OAuth20Constants.REFRESH_TOKEN + "=RT-"));
refreshTokenId = Arrays.stream(body.split("&")).filter(f -> f.startsWith(OAuth20Constants.REFRESH_TOKEN)).map(f -> StringUtils.remove(f, OAuth20Constants.REFRESH_TOKEN + "=")).findFirst().get();
}
assertTrue(body.contains(OAuth20Constants.EXPIRES_IN + '='));
accessTokenId = StringUtils.substringBetween(body, OAuth20Constants.ACCESS_TOKEN + '=', "&");
}
final AccessToken accessToken = this.ticketRegistry.getTicket(accessTokenId, AccessToken.class);
assertEquals(principal, accessToken.getAuthentication().getPrincipal());
final int timeLeft = getTimeLeft(body, refreshToken, json);
assertTrue(timeLeft >= TIMEOUT - 10 - DELTA);
return Pair.of(accessTokenId, refreshTokenId);
}
use of org.apache.commons.lang3.StringUtils.substringBetween in project ddf by codice.
the class DocumentationTest method testBrokenAnchorsPresent.
@Test
public void testBrokenAnchorsPresent() throws IOException, URISyntaxException {
List<Path> docs = Files.list(getPath()).filter(f -> f.toString().endsWith(HTML_DIRECTORY)).collect(Collectors.toList());
Set<String> links = new HashSet<>();
Set<String> anchors = new HashSet<>();
for (Path path : docs) {
Document doc = Jsoup.parse(path.toFile(), "UTF-8", EMPTY_STRING);
String thisDoc = StringUtils.substringAfterLast(path.toString(), File.separator);
Elements elements = doc.body().getAllElements();
for (Element element : elements) {
if (!element.toString().contains(":") && StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE) != null) {
links.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), HREF_ANCHOR, CLOSE));
}
anchors.add(thisDoc + "#" + StringUtils.substringBetween(element.toString(), ID, CLOSE));
}
}
links.removeAll(anchors);
assertThat("Anchors missing section reference: " + links.toString(), links.isEmpty());
}
use of org.apache.commons.lang3.StringUtils.substringBetween in project syncope by apache.
the class CamelRouteLogic method metrics.
@PreAuthorize("isAuthenticated()")
public CamelMetrics metrics() {
CamelMetrics metrics = new CamelMetrics();
MetricsRegistryService registryService = context.getCamelContext().hasService(MetricsRegistryService.class);
if (registryService == null) {
LOG.warn("Camel metrics not available");
} else {
MetricRegistry registry = registryService.getMetricsRegistry();
registry.getTimers().entrySet().stream().map(entry -> {
CamelMetrics.MeanRate meanRate = new CamelMetrics.MeanRate();
meanRate.setRouteId(StringUtils.substringBetween(entry.getKey(), ".", "."));
meanRate.setValue(entry.getValue().getMeanRate());
return meanRate;
}).forEachOrdered(meanRate -> {
metrics.getResponseMeanRates().add(meanRate);
});
Collections.sort(metrics.getResponseMeanRates(), (o1, o2) -> Collections.reverseOrder(Comparator.<Double>naturalOrder()).compare(o1.getValue(), o2.getValue()));
}
return metrics;
}
use of org.apache.commons.lang3.StringUtils.substringBetween in project cas by apereo.
the class ConfigurationMetadataGenerator method processNestedEnumProperties.
private void processNestedEnumProperties(final Set<ConfigurationMetadataProperty> properties, final Set<ConfigurationMetadataProperty> groups) {
val propertiesToProcess = properties.stream().filter(e -> {
val matcher = NESTED_CLASS_PATTERN.matcher(e.getType());
return matcher.matches();
}).collect(Collectors.toSet());
for (val prop : propertiesToProcess) {
val matcher = NESTED_CLASS_PATTERN.matcher(prop.getType());
if (!matcher.matches()) {
throw new RuntimeException("Unable to find a match for " + prop.getType());
}
val parent = matcher.group(1);
val innerType = matcher.group(2);
var typePath = ConfigurationMetadataClassSourceLocator.buildTypeSourcePath(this.sourcePath, parent);
try {
TypeDeclaration<?> primaryType = null;
if (typePath.contains("$")) {
val innerClass = StringUtils.substringBetween(typePath, "$", ".");
typePath = StringUtils.remove(typePath, '$' + innerClass);
val cu = StaticJavaParser.parse(new File(typePath));
for (val type : cu.getTypes()) {
for (val member : type.getMembers()) {
if (member.isClassOrInterfaceDeclaration()) {
val name = member.asClassOrInterfaceDeclaration().getNameAsString();
if (name.equals(innerClass)) {
primaryType = member.asClassOrInterfaceDeclaration();
break;
}
}
}
}
} else {
val cu = StaticJavaParser.parse(new File(typePath));
primaryType = cu.getPrimaryType().get();
}
Objects.requireNonNull(primaryType).getMembers().stream().peek(member -> {
if (member.isFieldDeclaration()) {
var fieldDecl = member.asFieldDeclaration();
var variable = fieldDecl.getVariable(0);
if (variable.getInitializer().isPresent()) {
var beginIndex = prop.getName().lastIndexOf('.');
var propShortName = beginIndex != -1 ? prop.getName().substring(beginIndex + 1) : prop.getName();
var names = RelaxedPropertyNames.forCamelCase(variable.getNameAsString()).getValues();
if (names.contains(propShortName)) {
variable.getInitializer().ifPresent(exp -> {
var value = (Object) null;
if (exp instanceof LiteralStringValueExpr) {
value = ((LiteralStringValueExpr) exp).getValue();
} else if (exp instanceof BooleanLiteralExpr) {
value = ((BooleanLiteralExpr) exp).getValue();
} else if (exp instanceof FieldAccessExpr) {
value = ((FieldAccessExpr) exp).getNameAsString();
}
prop.setDefaultValue(value);
});
}
}
}
}).filter(member -> {
if (member.isEnumDeclaration()) {
val enumMem = member.asEnumDeclaration();
return enumMem.getNameAsString().equals(innerType);
}
if (member.isClassOrInterfaceDeclaration()) {
val typeName = member.asClassOrInterfaceDeclaration();
return typeName.getNameAsString().equals(innerType);
}
return false;
}).forEach(member -> {
if (member.isEnumDeclaration()) {
val enumMem = member.asEnumDeclaration();
val builder = ConfigurationMetadataPropertyCreator.collectJavadocsEnumFields(prop, enumMem);
prop.setDescription(builder.toString());
}
if (member.isClassOrInterfaceDeclaration()) {
val typeName = member.asClassOrInterfaceDeclaration();
typeName.getFields().stream().filter(field -> !field.isStatic()).forEach(field -> {
val resultProps = new HashSet<ConfigurationMetadataProperty>();
val resultGroups = new HashSet<ConfigurationMetadataProperty>();
val creator = new ConfigurationMetadataPropertyCreator(false, resultProps, resultGroups, parent);
creator.createConfigurationProperty(field, prop.getName());
groups.addAll(resultGroups);
properties.addAll(resultProps);
});
}
});
} catch (final Exception ex) {
throw new RuntimeException(ex);
}
}
}
use of org.apache.commons.lang3.StringUtils.substringBetween in project fmv by f-agu.
the class SoftTestCase method test1.
@Test
@Ignore
public void test1() throws Exception {
SoftFoundFactory ffSoftFoundFactory = ExecSoftFoundFactory.forProvider(new TestSoftProvider("ffprout")).withParameters("-version").parseFactory((file, softPolicy) -> new Parser() {
private Integer build;
@Override
public void readLine(String line) {
if (line.startsWith("ff")) {
build = Integer.parseInt(StringUtils.substringBetween(line, "N-", "-"));
}
}
@Override
public SoftFound closeAndParse(String cmdLineStr, int exitValue) throws IOException {
if (build == null) {
return SoftFound.foundBadSoft(file);
}
// return SoftFound.found(file, new TestSoftInfo(build));
return SoftFound.foundBadVersion(new TestSoftInfo(49), "85");
}
}).build();
// SoftFoundFactory identifyFoundFactory = ExecSoftFoundFactory.withParameters("-version").parseFactory(file ->
// new Parser() {
//
// @Override
// public void readLine(String line) {}
//
// @Override
// public SoftFound closeAndParse(String cmdLineStr, int exitValue) throws IOException {
// return SoftFound.foundBadVersion(new TestSoftInfo(49), "85");
// }
// }).build();
Soft soft = Soft.with(new TestSoftProvider("ffprout")).search(ffSoftFoundFactory);
// Soft ffprobeSoft = Soft.with("ffprobe").search(ffSoftFoundFactory);
// Soft identifySoft = Soft.withName("identify").search(identifyFoundFactory);
SoftLogger softFormatter = new SoftLogger(Arrays.asList(soft));
// SoftLogger softFormatter = new SoftLogger(Arrays.asList(ffprobeSoft, identifySoft, ffmpegSoft));
softFormatter.logDetails(System.out::println);
// System.out.println(soft.getFounds());
// System.out.println(soft.getFile());
soft.withParameters("").execute();
}
Aggregations