use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class RefreshableDelegatedClientsTests method verifyOperation.
@Test
public void verifyOperation() {
val delegatedFactory = mock(DelegatedClientFactory.class);
when(delegatedFactory.build()).thenReturn(List.of());
val refreshableClients = new RefreshableDelegatedClients("http://localhost:8080/cas", delegatedFactory);
assertTrue(refreshableClients.findAllClients().isEmpty());
val client = new CasClient();
when(delegatedFactory.build()).thenReturn(List.of(client));
assertFalse(refreshableClients.findAllClients().isEmpty());
assertTrue(refreshableClients.findClient(client.getName()).isPresent());
}
use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class ChainingDelegatedClientUserProfileProvisionerTests method verifyOperation.
@Test
public void verifyOperation() {
val commonProfile = new CommonProfile();
commonProfile.setClientName("CasClient");
commonProfile.setId("testuser");
val client = new CasClient(new CasConfiguration("http://cas.example.org"));
val chain = new ChainingDelegatedClientUserProfileProvisioner(List.of(mock(DelegatedClientUserProfileProvisioner.class)));
assertDoesNotThrow(new Executable() {
@Override
public void execute() {
chain.execute(CoreAuthenticationTestUtils.getPrincipal(), commonProfile, client, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
}
});
}
use of org.pac4j.cas.client.CasClient 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.cas.client.CasClient 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.cas.client.CasClient 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