Search in sources :

Example 1 with GenericOAuth20Client

use of org.pac4j.oauth.client.GenericOAuth20Client in project cas by apereo.

the class DelegatedClientFactory method configureOAuth20Client.

/**
 * Configure o auth 20 client.
 *
 * @param properties the properties
 */
protected void configureOAuth20Client(final Collection<BaseClient> properties) {
    final AtomicInteger index = new AtomicInteger();
    pac4jProperties.getOauth2().stream().filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret())).forEach(oauth -> {
        final GenericOAuth20Client client = new GenericOAuth20Client();
        client.setKey(oauth.getId());
        client.setSecret(oauth.getSecret());
        client.setProfileAttrs(oauth.getProfileAttrs());
        client.setProfileNodePath(oauth.getProfilePath());
        client.setProfileUrl(oauth.getProfileUrl());
        client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
        client.setTokenUrl(oauth.getTokenUrl());
        client.setAuthUrl(oauth.getAuthUrl());
        client.setCustomParams(oauth.getCustomParams());
        final int count = index.intValue();
        if (StringUtils.isBlank(oauth.getClientName())) {
            client.setName(client.getClass().getSimpleName() + count);
        }
        configureClient(client, oauth);
        index.incrementAndGet();
        LOGGER.debug("Created 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) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with GenericOAuth20Client

use of org.pac4j.oauth.client.GenericOAuth20Client in project cas by apereo.

the class DefaultDelegatedClientFactory method configureOAuth20Client.

/**
 * Configure OAuth client.
 *
 * @param properties the properties
 */
protected void configureOAuth20Client(final Collection<IndirectClient> properties) {
    val pac4jProperties = casProperties.getAuthn().getPac4j();
    val index = new AtomicInteger();
    pac4jProperties.getOauth2().stream().filter(oauth -> oauth.isEnabled() && StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret())).forEach(oauth -> {
        val client = new GenericOAuth20Client();
        client.setProfileId(StringUtils.defaultIfBlank(oauth.getPrincipalAttributeId(), pac4jProperties.getCore().getPrincipalAttributeId()));
        client.setKey(oauth.getId());
        client.setSecret(oauth.getSecret());
        client.setProfileAttrs(oauth.getProfileAttrs());
        client.setProfileNodePath(oauth.getProfilePath());
        client.setProfileUrl(oauth.getProfileUrl());
        client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
        client.setTokenUrl(oauth.getTokenUrl());
        client.setAuthUrl(oauth.getAuthUrl());
        client.setScope(oauth.getScope());
        client.setCustomParams(oauth.getCustomParams());
        client.getConfiguration().setResponseType(oauth.getResponseType());
        if (StringUtils.isBlank(oauth.getClientName())) {
            val count = index.intValue();
            client.setName(client.getClass().getSimpleName() + count);
        }
        configureClient(client, oauth);
        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) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 3 with GenericOAuth20Client

use of org.pac4j.oauth.client.GenericOAuth20Client in project cas by apereo.

the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureOAuth20Client.

private void configureOAuth20Client(final Collection<BaseClient> properties) {
    final AtomicInteger index = new AtomicInteger();
    casProperties.getAuthn().getPac4j().getOauth2().stream().filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret())).forEach(oauth -> {
        final GenericOAuth20Client client = new GenericOAuth20Client();
        client.setKey(oauth.getId());
        client.setSecret(oauth.getSecret());
        client.setProfileAttrs(oauth.getProfileAttrs());
        client.setProfileNodePath(oauth.getProfilePath());
        client.setProfileUrl(oauth.getProfileUrl());
        client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
        client.setTokenUrl(oauth.getTokenUrl());
        client.setAuthUrl(oauth.getAuthUrl());
        client.setCustomParams(oauth.getCustomParams());
        client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
        properties.add(client);
    });
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CasConfiguration(org.pac4j.cas.config.CasConfiguration) CasClient(org.pac4j.cas.client.CasClient) Google2Client(org.pac4j.oauth.client.Google2Client) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) SAML2Client(org.pac4j.saml.client.SAML2Client) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) AuthenticationEventExecutionPlan(org.apereo.cas.authentication.AuthenticationEventExecutionPlan) YahooClient(org.pac4j.oauth.client.YahooClient) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) AuthenticationHandler(org.apereo.cas.authentication.AuthenticationHandler) PrincipalFactory(org.apereo.cas.authentication.principal.PrincipalFactory) Clients(org.pac4j.core.client.Clients) LinkedIn2Client(org.pac4j.oauth.client.LinkedIn2Client) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ClientAuthenticationHandler(org.apereo.cas.support.pac4j.authentication.handler.support.ClientAuthenticationHandler) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ClientAuthenticationMetaDataPopulator(org.apereo.cas.support.pac4j.authentication.ClientAuthenticationMetaDataPopulator) Verb(com.github.scribejava.core.model.Verb) Collection(java.util.Collection) PrincipalResolver(org.apereo.cas.authentication.principal.PrincipalResolver) Set(java.util.Set) JWSAlgorithm(com.nimbusds.jose.JWSAlgorithm) SAML2ClientLogoutAction(org.apereo.cas.support.pac4j.web.flow.SAML2ClientLogoutAction) Action(org.springframework.webflow.execution.Action) AuthenticationEventExecutionPlanConfigurer(org.apereo.cas.config.support.authentication.AuthenticationEventExecutionPlanConfigurer) Configuration(org.springframework.context.annotation.Configuration) BaseClient(org.pac4j.core.client.BaseClient) FoursquareClient(org.pac4j.oauth.client.FoursquareClient) GitHubClient(org.pac4j.oauth.client.GitHubClient) SAML2ClientConfiguration(org.pac4j.saml.client.SAML2ClientConfiguration) AuthenticationMetaDataPopulator(org.apereo.cas.authentication.AuthenticationMetaDataPopulator) WindowsLiveClient(org.pac4j.oauth.client.WindowsLiveClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) BitbucketClient(org.pac4j.oauth.client.BitbucketClient) WordPressClient(org.pac4j.oauth.client.WordPressClient) ArrayList(java.util.ArrayList) OidcClient(org.pac4j.oidc.client.OidcClient) Qualifier(org.springframework.beans.factory.annotation.Qualifier) PayPalClient(org.pac4j.oauth.client.PayPalClient) SAMLConstants(org.opensaml.saml.common.xml.SAMLConstants) LinkedHashSet(java.util.LinkedHashSet) ServicesManager(org.apereo.cas.services.ServicesManager) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) Logger(org.slf4j.Logger) FacebookClient(org.pac4j.oauth.client.FacebookClient) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) Pac4jProperties(org.apereo.cas.configuration.model.support.pac4j.Pac4jProperties) TwitterClient(org.pac4j.oauth.client.TwitterClient) Bean(org.springframework.context.annotation.Bean) DefaultPrincipalFactory(org.apereo.cas.authentication.principal.DefaultPrincipalFactory) DropBoxClient(org.pac4j.oauth.client.DropBoxClient) GenericOAuth20Client(org.pac4j.oauth.client.GenericOAuth20Client) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

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