use of org.apache.commons.lang3.StringUtils.appendIfMissing in project cas by apereo.
the class CasCoreViewsConfiguration method chainingTemplateViewResolver.
@Bean
public AbstractTemplateResolver chainingTemplateViewResolver() {
final ChainingTemplateViewResolver chain = new ChainingTemplateViewResolver();
casProperties.getView().getTemplatePrefixes().forEach(Unchecked.consumer(prefix -> {
final String prefixPath = ResourceUtils.getFile(prefix).getCanonicalPath();
final String viewPath = StringUtils.appendIfMissing(prefixPath, "/");
final ThemeFileTemplateResolver theme = new ThemeFileTemplateResolver(casProperties);
configureTemplateViewResolver(theme);
theme.setPrefix(viewPath + "themes/%s/");
chain.addResolver(theme);
final FileTemplateResolver file = new FileTemplateResolver();
configureTemplateViewResolver(file);
file.setPrefix(viewPath);
chain.addResolver(file);
}));
return chain;
}
use of org.apache.commons.lang3.StringUtils.appendIfMissing in project cas by apereo.
the class ConfigurationMetadataPropertyCreator method collectJavadocsEnumFields.
/**
* Collect javadocs enum fields.
*
* @param prop the prop
* @param em the em
* @return the string builder
*/
public static StringBuilder collectJavadocsEnumFields(final ConfigurationMetadataProperty prop, final EnumDeclaration em) {
val builder = new StringBuilder(StringUtils.defaultString(prop.getDescription()));
builder.append("\nAvailable values are as follows:\n");
builder.append("<ul>");
em.getEntries().stream().filter(entry -> entry.getJavadoc().isPresent()).forEach(entry -> {
var text = entry.getJavadoc().get().getDescription().toText();
text = StringUtils.appendIfMissing(text, ".");
val member = String.format("<li>{@code %s}: %s</li>", entry.getNameAsString(), text);
builder.append(member);
});
builder.append("</ul>");
return builder;
}
use of org.apache.commons.lang3.StringUtils.appendIfMissing in project cas by apereo.
the class DefaultDelegatedClientFactory method configureCasClient.
/**
* Configure cas client.
*
* @param properties the properties
*/
protected void configureCasClient(final Collection<IndirectClient> properties) {
val pac4jProperties = casProperties.getAuthn().getPac4j();
val index = new AtomicInteger();
pac4jProperties.getCas().stream().filter(cas -> cas.isEnabled() && StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
val cfg = new CasConfiguration(cas.getLoginUrl(), CasProtocol.valueOf(cas.getProtocol()));
val prefix = PATTERN_LOGIN_URL.matcher(cas.getLoginUrl()).replaceFirst("/");
cfg.setPrefixUrl(StringUtils.appendIfMissing(prefix, "/"));
cfg.setHostnameVerifier(casSSLContext.getHostnameVerifier());
cfg.setSslSocketFactory(casSSLContext.getSslContext().getSocketFactory());
val client = new CasClient(cfg);
if (StringUtils.isBlank(cas.getClientName())) {
val count = index.intValue();
client.setName(client.getClass().getSimpleName() + count);
}
configureClient(client, cas);
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
use of org.apache.commons.lang3.StringUtils.appendIfMissing in project cas by apereo.
the class OidcRequestSupport method isValidIssuerForEndpoint.
/**
* Is valid issuer for endpoint.
*
* @param webContext the web context
* @param endpoint the endpoint
* @return true /false
*/
public boolean isValidIssuerForEndpoint(final WebContext webContext, final String endpoint) {
val requestUrl = webContext.getRequestURL();
val issuerFromRequestUrl = StringUtils.removeEnd(StringUtils.remove(requestUrl, '/' + endpoint), "/");
val definedIssuer = oidcIssuerService.determineIssuer(Optional.empty());
val definedIssuerWithSlash = StringUtils.appendIfMissing(definedIssuer, "/");
val result = definedIssuer.equalsIgnoreCase(issuerFromRequestUrl) || issuerFromRequestUrl.startsWith(definedIssuerWithSlash);
FunctionUtils.doIf(!result, o -> LOGGER.trace("Configured issuer [{}] defined does not match the request issuer [{}]", o, issuerFromRequestUrl)).accept(definedIssuer);
return result;
}
Aggregations