Search in sources :

Example 1 with StringUtils.appendIfMissing

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;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) AbstractConfigurableTemplateResolver(org.thymeleaf.templateresolver.AbstractConfigurableTemplateResolver) Unchecked(org.jooq.lambda.Unchecked) AbstractTemplateResolver(org.thymeleaf.templateresolver.AbstractTemplateResolver) ThymeleafProperties(org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ResourceUtils(org.springframework.util.ResourceUtils) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) ThemeFileTemplateResolver(org.apereo.cas.web.view.ThemeFileTemplateResolver) Bean(org.springframework.context.annotation.Bean) FileTemplateResolver(org.thymeleaf.templateresolver.FileTemplateResolver) ChainingTemplateViewResolver(org.apereo.cas.web.view.ChainingTemplateViewResolver) ChainingTemplateViewResolver(org.apereo.cas.web.view.ChainingTemplateViewResolver) ThemeFileTemplateResolver(org.apereo.cas.web.view.ThemeFileTemplateResolver) FileTemplateResolver(org.thymeleaf.templateresolver.FileTemplateResolver) ThemeFileTemplateResolver(org.apereo.cas.web.view.ThemeFileTemplateResolver) Bean(org.springframework.context.annotation.Bean)

Example 2 with StringUtils.appendIfMissing

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;
}
Also used : lombok.val(lombok.val) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) Set(java.util.Set) EnumDeclaration(com.github.javaparser.ast.body.EnumDeclaration) StringUtils(org.apache.commons.lang3.StringUtils) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) Slf4j(lombok.extern.slf4j.Slf4j) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) Map(java.util.Map) HashCodeBuilder(org.apache.commons.lang3.builder.HashCodeBuilder) StreamSupport(java.util.stream.StreamSupport) FieldAccessExpr(com.github.javaparser.ast.expr.FieldAccessExpr) RelaxedPropertyNames(org.apereo.cas.configuration.support.RelaxedPropertyNames) EqualsBuilder(org.apache.commons.lang3.builder.EqualsBuilder)

Example 3 with StringUtils.appendIfMissing

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);
    });
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) Pac4jBaseClientProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jBaseClientProperties) RandomUtils(org.apereo.cas.util.RandomUtils) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) SneakyThrows(lombok.SneakyThrows) Google2Client(org.pac4j.oauth.client.Google2Client) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SAML2Client(org.pac4j.saml.client.SAML2Client) HttpSessionStoreFactory(org.pac4j.saml.store.HttpSessionStoreFactory) Beans(org.apereo.cas.configuration.support.Beans) StringUtils(org.apache.commons.lang3.StringUtils) PrivateKeyFactoryBean(org.apereo.cas.util.crypto.PrivateKeyFactoryBean) YahooClient(org.pac4j.oauth.client.YahooClient) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) ClassUtils(org.apache.commons.lang3.ClassUtils) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) LinkedIn2Client(org.pac4j.oauth.client.LinkedIn2Client) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HiOrgServerClient(org.pac4j.oauth.client.HiOrgServerClient) IndirectClient(org.pac4j.core.client.IndirectClient) Pac4jOidcClientProperties(org.apereo.cas.configuration.model.support.pac4j.oidc.Pac4jOidcClientProperties) Synchronized(lombok.Synchronized) ResourceUtils(org.apereo.cas.util.ResourceUtils) Unchecked(org.jooq.lambda.Unchecked) Verb(com.github.scribejava.core.model.Verb) Collection(java.util.Collection) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) BasePac4jOidcClientProperties(org.apereo.cas.configuration.model.support.pac4j.oidc.BasePac4jOidcClientProperties) EmptyStoreFactory(org.pac4j.saml.store.EmptyStoreFactory) Slf4j(lombok.extern.slf4j.Slf4j) ClientCustomPropertyConstants(org.apereo.cas.authentication.principal.ClientCustomPropertyConstants) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) XMLSecSAML2MetadataSigner(org.pac4j.saml.metadata.XMLSecSAML2MetadataSigner) DisposableBean(org.springframework.beans.factory.DisposableBean) CasSSLContext(org.apereo.cas.authentication.CasSSLContext) CasWebflowConfigurer(org.apereo.cas.web.flow.CasWebflowConfigurer) CasProtocol(org.pac4j.cas.config.CasProtocol) FoursquareClient(org.pac4j.oauth.client.FoursquareClient) GitHubClient(org.pac4j.oauth.client.GitHubClient) SAML2Configuration(org.pac4j.saml.config.SAML2Configuration) Pattern(java.util.regex.Pattern) PathParameterCallbackUrlResolver(org.pac4j.core.http.callback.PathParameterCallbackUrlResolver) WindowsLiveClient(org.pac4j.oauth.client.WindowsLiveClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) Getter(lombok.Getter) BitbucketClient(org.pac4j.oauth.client.BitbucketClient) WordPressClient(org.pac4j.oauth.client.WordPressClient) SAML2ServiceProviderRequestedAttribute(org.pac4j.saml.metadata.SAML2ServiceProviderRequestedAttribute) OidcClient(org.pac4j.oidc.client.OidcClient) CollectionUtils(org.apereo.cas.util.CollectionUtils) PayPalClient(org.pac4j.oauth.client.PayPalClient) ECPrivateKey(java.security.interfaces.ECPrivateKey) LinkedHashSet(java.util.LinkedHashSet) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver) Period(java.time.Period) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) FacebookClient(org.pac4j.oauth.client.FacebookClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) lombok.val(lombok.val) ApplicationContext(org.springframework.context.ApplicationContext) AppleOidcConfiguration(org.pac4j.oidc.config.AppleOidcConfiguration) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) AppleClient(org.pac4j.oidc.client.AppleClient) TwitterClient(org.pac4j.oauth.client.TwitterClient) SAMLMessageStoreFactory(org.pac4j.saml.store.SAMLMessageStoreFactory) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) DropBoxClient(org.pac4j.oauth.client.DropBoxClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient)

Example 4 with StringUtils.appendIfMissing

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;
}
Also used : lombok.val(lombok.val) Arrays(java.util.Arrays) SneakyThrows(lombok.SneakyThrows) ZonedDateTime(java.time.ZonedDateTime) RequiredArgsConstructor(lombok.RequiredArgsConstructor) TicketRegistrySupport(org.apereo.cas.ticket.registry.TicketRegistrySupport) StringUtils(org.apache.commons.lang3.StringUtils) WebContext(org.pac4j.core.context.WebContext) FunctionUtils(org.apereo.cas.util.function.FunctionUtils) CasCookieBuilder(org.apereo.cas.web.cookie.CasCookieBuilder) Authentication(org.apereo.cas.authentication.Authentication) CollectionUtils(org.apereo.cas.util.CollectionUtils) ZoneOffset(java.time.ZoneOffset) JEEContext(org.pac4j.core.context.JEEContext) CasProtocolConstants(org.apereo.cas.CasProtocolConstants) OAuth20Constants(org.apereo.cas.support.oauth.OAuth20Constants) URIBuilder(org.apache.http.client.utils.URIBuilder) OidcConstants(org.apereo.cas.oidc.OidcConstants) NonNull(lombok.NonNull) lombok.val(lombok.val) Set(java.util.Set) BasicUserProfile(org.pac4j.core.profile.BasicUserProfile) SessionStore(org.pac4j.core.context.session.SessionStore) ProfileManager(org.pac4j.core.profile.ProfileManager) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) OidcIssuerService(org.apereo.cas.oidc.issuer.OidcIssuerService) NumberUtils(org.apache.commons.lang3.math.NumberUtils) Optional(java.util.Optional) UserProfile(org.pac4j.core.profile.UserProfile)

Aggregations

Slf4j (lombok.extern.slf4j.Slf4j)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Set (java.util.Set)3 RequiredArgsConstructor (lombok.RequiredArgsConstructor)3 lombok.val (lombok.val)3 SneakyThrows (lombok.SneakyThrows)2 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)2 CollectionUtils (org.apereo.cas.util.CollectionUtils)2 FunctionUtils (org.apereo.cas.util.function.FunctionUtils)2 EnumDeclaration (com.github.javaparser.ast.body.EnumDeclaration)1 FieldDeclaration (com.github.javaparser.ast.body.FieldDeclaration)1 BooleanLiteralExpr (com.github.javaparser.ast.expr.BooleanLiteralExpr)1 FieldAccessExpr (com.github.javaparser.ast.expr.FieldAccessExpr)1 LiteralStringValueExpr (com.github.javaparser.ast.expr.LiteralStringValueExpr)1 Verb (com.github.scribejava.core.model.Verb)1 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 ECPrivateKey (java.security.interfaces.ECPrivateKey)1 Period (java.time.Period)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1