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);
});
}
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;
}
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);
}
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;
}
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;
}
Aggregations