Search in sources :

Example 1 with OidcClient

use of org.pac4j.oidc.client.OidcClient in project cas by apereo.

the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureOidcClient.

private void configureOidcClient(final Collection<BaseClient> properties) {
    final AtomicInteger index = new AtomicInteger();
    casProperties.getAuthn().getPac4j().getOidc().stream().filter(oidc -> StringUtils.isNotBlank(oidc.getId()) && StringUtils.isNotBlank(oidc.getSecret())).forEach(oidc -> {
        final OidcConfiguration cfg = new OidcConfiguration();
        if (StringUtils.isNotBlank(oidc.getScope())) {
            cfg.setScope(oidc.getScope());
        }
        cfg.setUseNonce(oidc.isUseNonce());
        cfg.setSecret(oidc.getSecret());
        cfg.setClientId(oidc.getId());
        if (StringUtils.isNotBlank(oidc.getPreferredJwsAlgorithm())) {
            cfg.setPreferredJwsAlgorithm(JWSAlgorithm.parse(oidc.getPreferredJwsAlgorithm().toUpperCase()));
        }
        cfg.setMaxClockSkew(oidc.getMaxClockSkew());
        cfg.setDiscoveryURI(oidc.getDiscoveryUri());
        cfg.setCustomParams(oidc.getCustomParams());
        final OidcClient client;
        switch(oidc.getType().toUpperCase()) {
            case "GOOGLE":
                client = new GoogleOidcClient(cfg);
                break;
            case "AZURE":
                client = new AzureAdClient(cfg);
                break;
            case "GENERIC":
            default:
                client = new OidcClient(cfg);
                break;
        }
        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) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OidcClient(org.pac4j.oidc.client.OidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient)

Aggregations

Verb (com.github.scribejava.core.model.Verb)1 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AuthenticationEventExecutionPlan (org.apereo.cas.authentication.AuthenticationEventExecutionPlan)1 AuthenticationHandler (org.apereo.cas.authentication.AuthenticationHandler)1 AuthenticationMetaDataPopulator (org.apereo.cas.authentication.AuthenticationMetaDataPopulator)1 DefaultPrincipalFactory (org.apereo.cas.authentication.principal.DefaultPrincipalFactory)1 PrincipalFactory (org.apereo.cas.authentication.principal.PrincipalFactory)1 PrincipalResolver (org.apereo.cas.authentication.principal.PrincipalResolver)1 AuthenticationEventExecutionPlanConfigurer (org.apereo.cas.config.support.authentication.AuthenticationEventExecutionPlanConfigurer)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 Pac4jProperties (org.apereo.cas.configuration.model.support.pac4j.Pac4jProperties)1 ServicesManager (org.apereo.cas.services.ServicesManager)1 ClientAuthenticationMetaDataPopulator (org.apereo.cas.support.pac4j.authentication.ClientAuthenticationMetaDataPopulator)1 ClientAuthenticationHandler (org.apereo.cas.support.pac4j.authentication.handler.support.ClientAuthenticationHandler)1