Search in sources :

Example 1 with AzureAdClient

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

the class DelegatedClientFactory method configureOidcClient.

/**
 * Configure oidc client.
 *
 * @param properties the properties
 */
protected void configureOidcClient(final Collection<BaseClient> properties) {
    final AtomicInteger index = new AtomicInteger();
    pac4jProperties.getOidc().stream().filter(oidc -> StringUtils.isNotBlank(oidc.getId()) && StringUtils.isNotBlank(oidc.getSecret())).forEach(oidc -> {
        final OidcClient client;
        switch(oidc.getType().toUpperCase()) {
            case "GOOGLE":
                final OidcConfiguration cfg = getOidcConfigurationForClient(oidc, OidcConfiguration.class);
                client = new GoogleOidcClient(cfg);
                break;
            case "AZURE":
                final AzureAdOidcConfiguration azure = getOidcConfigurationForClient(oidc, AzureAdOidcConfiguration.class);
                client = new AzureAdClient(new AzureAdOidcConfiguration(azure));
                break;
            case "KEYCLOAK":
                final KeycloakOidcConfiguration keycfg = getOidcConfigurationForClient(oidc, KeycloakOidcConfiguration.class);
                client = new KeycloakOidcClient(keycfg);
                break;
            case "GENERIC":
            default:
                final OidcConfiguration gencfg = getOidcConfigurationForClient(oidc, OidcConfiguration.class);
                client = new OidcClient(gencfg);
                break;
        }
        final int count = index.intValue();
        if (StringUtils.isBlank(oidc.getClientName())) {
            client.setName(client.getClass().getSimpleName() + count);
        }
        configureClient(client, oidc);
        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) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OidcClient(org.pac4j.oidc.client.OidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient)

Example 2 with AzureAdClient

use of org.pac4j.oidc.client.AzureAdClient 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)

Example 3 with AzureAdClient

use of org.pac4j.oidc.client.AzureAdClient in project pac4j by pac4j.

the class RunAzureAdClient method getClient.

@Override
protected IndirectClient getClient() {
    final AzureAdOidcConfiguration configuration = new AzureAdOidcConfiguration();
    configuration.setClientId("788339d7-1c44-4732-97c9-134cb201f01f");
    configuration.setSecret("we/31zi+JYa7zOugO4TbSw0hzn+hv2wmENO9AS3T84s=");
    configuration.setTenant("38c46e5a-21f0-46e5-940d-3ca06fd1a330");
    final AzureAdClient client = new AzureAdClient(configuration);
    client.setCallbackUrl(PAC4J_URL);
    // client.setCallbackUrl(CommonHelper.addParameter(PAC4J_URL, Clients.DEFAULT_CLIENT_NAME_PARAMETER, client.getName()));
    return client;
}
Also used : AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) AzureAdClient(org.pac4j.oidc.client.AzureAdClient)

Example 4 with AzureAdClient

use of org.pac4j.oidc.client.AzureAdClient in project pac4j by pac4j.

the class OidcClientBuilder method tryCreateOidcClient.

public void tryCreateOidcClient(final List<Client> clients) {
    for (int i = 0; i <= MAX_NUM_CLIENTS; i++) {
        final String id = getProperty(OIDC_ID, i);
        final String secret = getProperty(OIDC_SECRET, i);
        if (isNotBlank(id) && isNotBlank(secret)) {
            final OidcConfiguration configuration = new OidcConfiguration();
            configuration.setClientId(id);
            configuration.setSecret(secret);
            final String scope = getProperty(OIDC_SCOPE, i);
            if (isNotBlank(scope)) {
                configuration.setScope(scope);
            }
            final String discoveryUri = getProperty(OIDC_DISCOVERY_URI, i);
            if (isNotBlank(discoveryUri)) {
                configuration.setDiscoveryURI(discoveryUri);
            }
            final String useNonce = getProperty(OIDC_USE_NONCE, i);
            if (isNotBlank(useNonce)) {
                configuration.setUseNonce(Boolean.parseBoolean(useNonce));
            }
            final String jwsAlgo = getProperty(OIDC_PREFERRED_JWS_ALGORITHM, i);
            if (isNotBlank(jwsAlgo)) {
                configuration.setPreferredJwsAlgorithm(JWSAlgorithm.parse(jwsAlgo));
            }
            final String maxClockSkew = getProperty(OIDC_MAX_CLOCK_SKEW, i);
            if (isNotBlank(maxClockSkew)) {
                configuration.setMaxClockSkew(Integer.parseInt(maxClockSkew));
            }
            final String clientAuthenticationMethod = getProperty(OIDC_CLIENT_AUTHENTICATION_METHOD, i);
            if (isNotBlank(clientAuthenticationMethod)) {
                configuration.setClientAuthenticationMethod(ClientAuthenticationMethod.parse(clientAuthenticationMethod));
            }
            for (int j = 1; j <= MAX_NUM_CUSTOM_PROPERTIES; j++) {
                if (containsProperty(OIDC_CUSTOM_PARAM_KEY + j, i)) {
                    configuration.addCustomParam(getProperty(OIDC_CUSTOM_PARAM_KEY + j, i), getProperty(OIDC_CUSTOM_PARAM_VALUE + j, i));
                }
            }
            final String type = getProperty(OIDC_TYPE, i);
            final OidcClient oidcClient;
            if (OIDC_AZURE_TYPE.equalsIgnoreCase(type)) {
                oidcClient = new AzureAdClient(new AzureAdOidcConfiguration(configuration));
            } else if (OIDC_GOOGLE_TYPE.equalsIgnoreCase(type)) {
                oidcClient = new GoogleOidcClient(configuration);
            } else {
                oidcClient = new OidcClient(configuration);
            }
            oidcClient.setName(concat(oidcClient.getName(), i));
            clients.add(oidcClient);
        }
    }
}
Also used : AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient)

Aggregations

AzureAdClient (org.pac4j.oidc.client.AzureAdClient)4 GoogleOidcClient (org.pac4j.oidc.client.GoogleOidcClient)3 OidcClient (org.pac4j.oidc.client.OidcClient)3 AzureAdOidcConfiguration (org.pac4j.oidc.config.AzureAdOidcConfiguration)3 OidcConfiguration (org.pac4j.oidc.config.OidcConfiguration)3 Verb (com.github.scribejava.core.model.Verb)2 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)2 Collection (java.util.Collection)2 LinkedHashSet (java.util.LinkedHashSet)2 Set (java.util.Set)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 StringUtils (org.apache.commons.lang3.StringUtils)2 CasClient (org.pac4j.cas.client.CasClient)2 CasConfiguration (org.pac4j.cas.config.CasConfiguration)2 BaseClient (org.pac4j.core.client.BaseClient)2 BitbucketClient (org.pac4j.oauth.client.BitbucketClient)2 DropBoxClient (org.pac4j.oauth.client.DropBoxClient)2 FacebookClient (org.pac4j.oauth.client.FacebookClient)2 FoursquareClient (org.pac4j.oauth.client.FoursquareClient)2 GenericOAuth20Client (org.pac4j.oauth.client.GenericOAuth20Client)2