Search in sources :

Example 11 with BaseClient

use of org.pac4j.core.client.BaseClient in project cas by apereo.

the class DelegatedClientFactory method configureSamlClient.

/**
 * Configure saml client.
 *
 * @param properties the properties
 */
protected void configureSamlClient(final Collection<BaseClient> properties) {
    final AtomicInteger index = new AtomicInteger();
    pac4jProperties.getSaml().stream().filter(saml -> StringUtils.isNotBlank(saml.getKeystorePath()) && StringUtils.isNotBlank(saml.getIdentityProviderMetadataPath()) && StringUtils.isNotBlank(saml.getServiceProviderEntityId()) && StringUtils.isNotBlank(saml.getServiceProviderMetadataPath())).forEach(saml -> {
        final SAML2ClientConfiguration cfg = new SAML2ClientConfiguration(saml.getKeystorePath(), saml.getKeystorePassword(), saml.getPrivateKeyPassword(), saml.getIdentityProviderMetadataPath());
        cfg.setMaximumAuthenticationLifetime(saml.getMaximumAuthenticationLifetime());
        cfg.setServiceProviderEntityId(saml.getServiceProviderEntityId());
        cfg.setServiceProviderMetadataPath(saml.getServiceProviderMetadataPath());
        cfg.setDestinationBindingType(saml.getDestinationBinding());
        cfg.setForceAuth(saml.isForceAuth());
        cfg.setPassive(saml.isPassive());
        cfg.setWantsAssertionsSigned(saml.isWantsAssertionsSigned());
        cfg.setAttributeConsumingServiceIndex(saml.getAttributeConsumingServiceIndex());
        if (saml.getAssertionConsumerServiceIndex() >= 0) {
            cfg.setAssertionConsumerServiceIndex(saml.getAssertionConsumerServiceIndex());
        }
        if (StringUtils.isNotBlank(saml.getAuthnContextClassRef())) {
            cfg.setComparisonType(saml.getAuthnContextComparisonType().toUpperCase());
            cfg.setAuthnContextClassRef(saml.getAuthnContextClassRef());
        }
        if (StringUtils.isNotBlank(saml.getKeystoreAlias())) {
            cfg.setKeystoreAlias(saml.getKeystoreAlias());
        }
        if (StringUtils.isNotBlank(saml.getNameIdPolicyFormat())) {
            cfg.setNameIdPolicyFormat(saml.getNameIdPolicyFormat());
        }
        final SAML2Client client = new SAML2Client(cfg);
        final int count = index.intValue();
        if (StringUtils.isBlank(saml.getClientName())) {
            client.setName(client.getClass().getSimpleName() + count);
        }
        configureClient(client, saml);
        index.incrementAndGet();
        LOGGER.debug("Created delegated client [{}]", client);
        properties.add(client);
    });
}
Also used : Pac4jBaseClientProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jBaseClientProperties) WindowsLiveClient(org.pac4j.oauth.client.WindowsLiveClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) BitbucketClient(org.pac4j.oauth.client.BitbucketClient) SneakyThrows(lombok.SneakyThrows) Google2Client(org.pac4j.oauth.client.Google2Client) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) RequiredArgsConstructor(lombok.RequiredArgsConstructor) SAML2Client(org.pac4j.saml.client.SAML2Client) WordPressClient(org.pac4j.oauth.client.WordPressClient) StringUtils(org.apache.commons.lang3.StringUtils) YahooClient(org.pac4j.oauth.client.YahooClient) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) LinkedIn2Client(org.pac4j.oauth.client.LinkedIn2Client) OidcClient(org.pac4j.oidc.client.OidcClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PayPalClient(org.pac4j.oauth.client.PayPalClient) LinkedHashSet(java.util.LinkedHashSet) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) FacebookClient(org.pac4j.oauth.client.FacebookClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) Verb(com.github.scribejava.core.model.Verb) Collection(java.util.Collection) Pac4jDelegatedAuthenticationProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jDelegatedAuthenticationProperties) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) Slf4j(lombok.extern.slf4j.Slf4j) BaseClient(org.pac4j.core.client.BaseClient) TwitterClient(org.pac4j.oauth.client.TwitterClient) Pac4jOidcProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jOidcProperties) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) CasProtocol(org.pac4j.cas.config.CasProtocol) FoursquareClient(org.pac4j.oauth.client.FoursquareClient) GitHubClient(org.pac4j.oauth.client.GitHubClient) OrcidClient(org.pac4j.oauth.client.OrcidClient) DropBoxClient(org.pac4j.oauth.client.DropBoxClient) SAML2ClientConfiguration(org.pac4j.saml.client.SAML2ClientConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SAML2Client(org.pac4j.saml.client.SAML2Client) SAML2ClientConfiguration(org.pac4j.saml.client.SAML2ClientConfiguration)

Example 12 with BaseClient

use of org.pac4j.core.client.BaseClient in project cas by apereo.

the class DelegatedClientAuthenticationAction method restoreAuthenticationRequestInContext.

private Service restoreAuthenticationRequestInContext(final RequestContext requestContext, final J2EContext webContext, final String clientName) {
    delegatedSessionCookieManager.restore(webContext);
    final BaseClient<Credentials, CommonProfile> client = (BaseClient<Credentials, CommonProfile>) this.clients.findClient(clientName);
    final Service service = delegatedClientWebflowManager.retrieve(requestContext, webContext, client);
    return service;
}
Also used : CommonProfile(org.pac4j.core.profile.CommonProfile) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) RegisteredService(org.apereo.cas.services.RegisteredService) Service(org.apereo.cas.authentication.principal.Service) BaseClient(org.pac4j.core.client.BaseClient) Credentials(org.pac4j.core.credentials.Credentials)

Example 13 with BaseClient

use of org.pac4j.core.client.BaseClient in project pac4j by pac4j.

the class DefaultCallbackLogic method renewSession.

protected void renewSession(final C context, final Config config) {
    final SessionStore<C> sessionStore = context.getSessionStore();
    if (sessionStore != null) {
        final String oldSessionId = sessionStore.getOrCreateSessionId(context);
        final boolean renewed = sessionStore.renewSession(context);
        if (renewed) {
            final String newSessionId = sessionStore.getOrCreateSessionId(context);
            logger.debug("Renewing session: {} -> {}", oldSessionId, newSessionId);
            final Clients clients = config.getClients();
            if (clients != null) {
                final List<Client> clientList = clients.getClients();
                for (final Client client : clientList) {
                    final BaseClient baseClient = (BaseClient) client;
                    baseClient.notifySessionRenewal(oldSessionId, context);
                }
            }
        } else {
            logger.error("Unable to renew the session. The session store may not support this feature");
        }
    } else {
        logger.error("No session store available for this web context");
    }
}
Also used : Clients(org.pac4j.core.client.Clients) BaseClient(org.pac4j.core.client.BaseClient) Client(org.pac4j.core.client.Client) BaseClient(org.pac4j.core.client.BaseClient)

Aggregations

BaseClient (org.pac4j.core.client.BaseClient)13 CasClient (org.pac4j.cas.client.CasClient)9 CasConfiguration (org.pac4j.cas.config.CasConfiguration)9 Verb (com.github.scribejava.core.model.Verb)8 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)8 Collection (java.util.Collection)8 LinkedHashSet (java.util.LinkedHashSet)8 Set (java.util.Set)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 StringUtils (org.apache.commons.lang3.StringUtils)8 BitbucketClient (org.pac4j.oauth.client.BitbucketClient)8 DropBoxClient (org.pac4j.oauth.client.DropBoxClient)8 FacebookClient (org.pac4j.oauth.client.FacebookClient)8 FoursquareClient (org.pac4j.oauth.client.FoursquareClient)8 GenericOAuth20Client (org.pac4j.oauth.client.GenericOAuth20Client)8 GitHubClient (org.pac4j.oauth.client.GitHubClient)8 Google2Client (org.pac4j.oauth.client.Google2Client)8 LinkedIn2Client (org.pac4j.oauth.client.LinkedIn2Client)8 PayPalClient (org.pac4j.oauth.client.PayPalClient)8 TwitterClient (org.pac4j.oauth.client.TwitterClient)8