Search in sources :

Example 1 with AppleClient

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

Aggregations

SneakyThrows (lombok.SneakyThrows)1 lombok.val (lombok.val)1 PrivateKeyFactoryBean (org.apereo.cas.util.crypto.PrivateKeyFactoryBean)1 AppleClient (org.pac4j.oidc.client.AppleClient)1 AzureAdClient (org.pac4j.oidc.client.AzureAdClient)1 GoogleOidcClient (org.pac4j.oidc.client.GoogleOidcClient)1 KeycloakOidcClient (org.pac4j.oidc.client.KeycloakOidcClient)1 OidcClient (org.pac4j.oidc.client.OidcClient)1 AzureAdOidcConfiguration (org.pac4j.oidc.config.AzureAdOidcConfiguration)1