Search in sources :

Example 1 with KeycloakOidcClient

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

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

the class RunKeycloakOidcClient method getClient.

@Override
protected IndirectClient getClient() {
    final KeycloakOidcConfiguration configuration = new KeycloakOidcConfiguration();
    configuration.setClientId(CLIENT_ID);
    configuration.setSecret(SECRET_VALUE);
    configuration.setBaseUri(AUTH_URL);
    configuration.setRealm(REALM_VALUE);
    KeycloakOidcClient client = new KeycloakOidcClient(configuration);
    client.setCallbackUrl(CALLBACK_VALUE);
    return client;
}
Also used : KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration)

Example 3 with KeycloakOidcClient

use of org.pac4j.oidc.client.KeycloakOidcClient in project ddf by codice.

the class OidcHandlerConfigurationImplTest method testCreateOidcClientKeycloak.

@Test
public void testCreateOidcClientKeycloak() {
    OidcConfiguration oidcConfiguration = mock(KeycloakOidcConfiguration.class);
    OidcClient oidcClient = handlerConfiguration.createOidcClient("Keycloak", oidcConfiguration, DEFAULT_CALLBACK_URL);
    assertTrue(oidcClient instanceof KeycloakOidcClient);
}
Also used : OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) Test(org.junit.Test)

Example 4 with KeycloakOidcClient

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

the class DefaultDelegatedClientFactory method getOidcClientFrom.

@SneakyThrows
private OidcClient getOidcClientFrom(final Pac4jOidcClientProperties oidc) {
    if (oidc.getAzure().isEnabled() && StringUtils.isNotBlank(oidc.getAzure().getId())) {
        LOGGER.debug("Building OpenID Connect client for Azure AD...");
        val azure = getOidcConfigurationForClient(oidc.getAzure(), AzureAdOidcConfiguration.class);
        azure.setTenant(oidc.getAzure().getTenant());
        val cfg = new AzureAdOidcConfiguration(azure);
        val azureClient = new AzureAdClient(cfg);
        configureClient(azureClient, oidc.getAzure());
        return azureClient;
    }
    if (oidc.getGoogle().isEnabled() && StringUtils.isNotBlank(oidc.getGoogle().getId())) {
        LOGGER.debug("Building OpenID Connect client for Google...");
        val cfg = getOidcConfigurationForClient(oidc.getGoogle(), OidcConfiguration.class);
        val googleClient = new GoogleOidcClient(cfg);
        configureClient(googleClient, oidc.getGoogle());
        return googleClient;
    }
    if (oidc.getKeycloak().isEnabled() && StringUtils.isNotBlank(oidc.getKeycloak().getId())) {
        LOGGER.debug("Building OpenID Connect client for KeyCloak...");
        val cfg = getOidcConfigurationForClient(oidc.getKeycloak(), KeycloakOidcConfiguration.class);
        cfg.setRealm(oidc.getKeycloak().getRealm());
        cfg.setBaseUri(oidc.getKeycloak().getBaseUri());
        val kc = new KeycloakOidcClient(cfg);
        configureClient(kc, oidc.getKeycloak());
        return kc;
    }
    if (oidc.getApple().isEnabled() && StringUtils.isNotBlank(oidc.getApple().getPrivateKey())) {
        LOGGER.debug("Building OpenID Connect client for Apple...");
        val cfg = getOidcConfigurationForClient(oidc.getApple(), AppleOidcConfiguration.class);
        val factory = new PrivateKeyFactoryBean();
        factory.setAlgorithm("EC");
        factory.setSingleton(false);
        factory.setLocation(ResourceUtils.getResourceFrom(oidc.getApple().getPrivateKey()));
        cfg.setPrivateKey((ECPrivateKey) factory.getObject());
        cfg.setPrivateKeyID(oidc.getApple().getPrivateKeyId());
        cfg.setTeamID(oidc.getApple().getTeamId());
        cfg.setTimeout(Beans.newDuration(oidc.getApple().getTimeout()));
        val kc = new AppleClient(cfg);
        configureClient(kc, oidc.getApple());
        return kc;
    }
    if (oidc.getGeneric().isEnabled()) {
        LOGGER.debug("Building generic OpenID Connect client...");
        val generic = getOidcConfigurationForClient(oidc.getGeneric(), OidcConfiguration.class);
        val oc = new OidcClient(generic);
        configureClient(oc, oidc.getGeneric());
        return oc;
    }
    return null;
}
Also used : lombok.val(lombok.val) AzureAdOidcConfiguration(org.pac4j.oidc.config.AzureAdOidcConfiguration) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) PrivateKeyFactoryBean(org.apereo.cas.util.crypto.PrivateKeyFactoryBean) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) AppleClient(org.pac4j.oidc.client.AppleClient) SneakyThrows(lombok.SneakyThrows)

Example 5 with KeycloakOidcClient

use of org.pac4j.oidc.client.KeycloakOidcClient in project ddf by codice.

the class OidcHandlerConfigurationImpl method createOidcClient.

@VisibleForTesting
OidcClient createOidcClient(String idpType, OidcConfiguration oidcConfiguration, String callBackUri) {
    OidcClient oidcClient;
    if ("Keycloak".equals(idpType)) {
        oidcClient = new KeycloakOidcClient((KeycloakOidcConfiguration) oidcConfiguration);
    } else if ("Azure".equals(idpType)) {
        oidcClient = new AzureAdClient((AzureAdOidcConfiguration) oidcConfiguration);
    } else if ("Google".equals(idpType)) {
        oidcClient = new GoogleOidcClient(oidcConfiguration);
    } else {
        oidcClient = new OidcClient<>(oidcConfiguration);
    }
    oidcClient.setName(oidcConfiguration.getClientId());
    if (isBlank(callBackUri)) {
        oidcClient.setCallbackUrl(DEFAULT_CALLBACK_URL);
    } else {
        // Strip additional query parameters from the callBackUri
        String uri = callBackUri.split("&")[0];
        oidcClient.setCallbackUrl(uri);
    }
    return oidcClient;
}
Also used : KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) KeycloakOidcClient(org.pac4j.oidc.client.KeycloakOidcClient) OidcClient(org.pac4j.oidc.client.OidcClient) AzureAdClient(org.pac4j.oidc.client.AzureAdClient) KeycloakOidcConfiguration(org.pac4j.oidc.config.KeycloakOidcConfiguration) GoogleOidcClient(org.pac4j.oidc.client.GoogleOidcClient) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

KeycloakOidcClient (org.pac4j.oidc.client.KeycloakOidcClient)5 GoogleOidcClient (org.pac4j.oidc.client.GoogleOidcClient)4 OidcClient (org.pac4j.oidc.client.OidcClient)4 KeycloakOidcConfiguration (org.pac4j.oidc.config.KeycloakOidcConfiguration)4 AzureAdClient (org.pac4j.oidc.client.AzureAdClient)3 AzureAdOidcConfiguration (org.pac4j.oidc.config.AzureAdOidcConfiguration)3 SneakyThrows (lombok.SneakyThrows)2 OidcConfiguration (org.pac4j.oidc.config.OidcConfiguration)2 Verb (com.github.scribejava.core.model.Verb)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 Collection (java.util.Collection)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1 lombok.val (lombok.val)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Pac4jBaseClientProperties (org.apereo.cas.configuration.model.support.pac4j.Pac4jBaseClientProperties)1