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