use of org.pac4j.core.client.BaseClient in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureCasClient.
private void configureCasClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getCas().stream().filter(cas -> StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
final CasConfiguration cfg = new CasConfiguration(cas.getLoginUrl(), cas.getProtocol());
final CasClient client = new CasClient(cfg);
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
use of org.pac4j.core.client.BaseClient 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.core.client.BaseClient in project cas by apereo.
the class Pac4jAuthenticationEventExecutionPlanConfiguration method configureOAuth20Client.
private void configureOAuth20Client(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
casProperties.getAuthn().getPac4j().getOauth2().stream().filter(oauth -> StringUtils.isNotBlank(oauth.getId()) && StringUtils.isNotBlank(oauth.getSecret())).forEach(oauth -> {
final GenericOAuth20Client client = new GenericOAuth20Client();
client.setKey(oauth.getId());
client.setSecret(oauth.getSecret());
client.setProfileAttrs(oauth.getProfileAttrs());
client.setProfileNodePath(oauth.getProfilePath());
client.setProfileUrl(oauth.getProfileUrl());
client.setProfileVerb(Verb.valueOf(oauth.getProfileVerb().toUpperCase()));
client.setTokenUrl(oauth.getTokenUrl());
client.setAuthUrl(oauth.getAuthUrl());
client.setCustomParams(oauth.getCustomParams());
client.setName(client.getClass().getSimpleName() + index.incrementAndGet());
properties.add(client);
});
}
use of org.pac4j.core.client.BaseClient in project cas by apereo.
the class CasConsentReviewConfiguration method casConsentPac4jConfig.
@Bean
@RefreshScope
public Config casConsentPac4jConfig() {
final CasConfiguration conf = new CasConfiguration(casProperties.getServer().getLoginUrl());
final CasClient client = new CasClient(conf);
client.setName(CAS_CONSENT_CLIENT);
client.setCallbackUrl(casProperties.getServer().getPrefix().concat("/consentReview/callback"));
client.setAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
final Clients clients = new Clients(client);
final Config config = new Config(clients);
config.setAuthorizer(new IsAuthenticatedAuthorizer());
config.setCallbackLogic(new DefaultCallbackLogic());
config.setLogoutLogic(new DefaultLogoutLogic());
// get role authorizer from admin pages for smooth integration
final Map<String, Authorizer> adminAuthorizers = casAdminPagesPac4jConfig.getAuthorizers();
final String auth = RequireAnyRoleAuthorizer.class.getSimpleName();
if (adminAuthorizers.containsKey(auth)) {
config.addAuthorizer(auth, adminAuthorizers.get(auth));
final BaseClient adminClient = casAdminPagesPac4jConfig.getClients().findClient(DirectCasClient.class);
client.addAuthorizationGenerators(adminClient.getAuthorizationGenerators());
}
return config;
}
use of org.pac4j.core.client.BaseClient in project cas by apereo.
the class DelegatedClientFactory method configureCasClient.
/**
* Configure cas client.
*
* @param properties the properties
*/
protected void configureCasClient(final Collection<BaseClient> properties) {
final AtomicInteger index = new AtomicInteger();
pac4jProperties.getCas().stream().filter(cas -> StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
final CasConfiguration cfg = new CasConfiguration(cas.getLoginUrl(), CasProtocol.valueOf(cas.getProtocol()));
final CasClient client = new CasClient(cfg);
final int count = index.intValue();
if (StringUtils.isBlank(cas.getClientName())) {
client.setName(client.getClass().getSimpleName() + count);
}
configureClient(client, cas);
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
Aggregations