use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class CasOAuthConfiguration method oauthSecConfig.
@Bean
public Config oauthSecConfig() {
final CasConfiguration cfg = new CasConfiguration(casProperties.getServer().getLoginUrl());
final CasClient oauthCasClient = new CasClient(cfg);
oauthCasClient.setRedirectActionBuilder(webContext -> oauthCasClientRedirectActionBuilder().build(oauthCasClient, webContext));
oauthCasClient.setName(Authenticators.CAS_OAUTH_CLIENT);
oauthCasClient.setUrlResolver(casCallbackUrlResolver());
final Authenticator authenticator = oAuthClientAuthenticator();
final DirectBasicAuthClient basicAuthClient = new DirectBasicAuthClient(authenticator);
basicAuthClient.setName(Authenticators.CAS_OAUTH_CLIENT_BASIC_AUTHN);
final DirectFormClient directFormClient = new DirectFormClient(authenticator);
directFormClient.setName(Authenticators.CAS_OAUTH_CLIENT_DIRECT_FORM);
directFormClient.setUsernameParameter(CLIENT_ID);
directFormClient.setPasswordParameter(CLIENT_SECRET);
final DirectFormClient userFormClient = new DirectFormClient(oAuthUserAuthenticator());
userFormClient.setName(Authenticators.CAS_OAUTH_CLIENT_USER_FORM);
final Config config = new Config(OAuth20Utils.casOAuthCallbackUrl(casProperties.getServer().getPrefix()), oauthCasClient, basicAuthClient, directFormClient, userFormClient);
config.setSessionStore(new J2ESessionStore());
return config;
}
use of org.pac4j.cas.client.CasClient in project pac4j by pac4j.
the class CasClientBuilder method tryCreateCasClient.
public void tryCreateCasClient(final List<Client> clients) {
for (int i = 0; i <= MAX_NUM_CLIENTS; i++) {
final String loginUrl = getProperty(CAS_LOGIN_URL, i);
final String protocol = getProperty(CAS_PROTOCOL, i);
if (isNotBlank(loginUrl)) {
CasConfiguration configuration = new CasConfiguration();
final CasClient casClient = new CasClient(configuration);
configuration.setLoginUrl(loginUrl);
if (isNotBlank(protocol)) {
configuration.setProtocol(CasProtocol.valueOf(protocol));
}
casClient.setName(concat(casClient.getName(), i));
clients.add(casClient);
}
}
}
use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class OAuth20DefaultCasClientRedirectActionBuilderTests method verifyOperation.
@Test
public void verifyOperation() {
val client = new CasClient(new CasConfiguration("https://example.org/cas/login"));
client.setCallbackUrl("https://example.org/cas/callback");
client.init();
val context = new JEEContext(new MockHttpServletRequest(), new MockHttpServletResponse());
val input = oauthCasClientRedirectActionBuilder.build(client, context);
assertFalse(input.isEmpty());
}
use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class RestfulDelegatedClientUserProfileProvisionerTests method verifyAllowedOperation.
@Test
public void verifyAllowedOperation() {
val commonProfile = new CommonProfile();
commonProfile.setClientName("CasClient");
commonProfile.setId("testuser");
val client = new CasClient(new CasConfiguration("http://cas.example.org"));
try (val webServer = new MockWebServer(9192, new ByteArrayResource(StringUtils.EMPTY.getBytes(StandardCharsets.UTF_8), "Output"), HttpStatus.OK)) {
webServer.start();
val props = new RestEndpointProperties();
props.setUrl("http://localhost:9192");
val service = new RestfulDelegatedClientUserProfileProvisioner(props);
service.execute(CoreAuthenticationTestUtils.getPrincipal(), commonProfile, client, CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword());
}
}
use of org.pac4j.cas.client.CasClient in project cas by apereo.
the class DefaultDelegatedClientFactory method configureCasClient.
/**
* Configure cas client.
*
* @param properties the properties
*/
protected void configureCasClient(final Collection<IndirectClient> properties) {
val pac4jProperties = casProperties.getAuthn().getPac4j();
val index = new AtomicInteger();
pac4jProperties.getCas().stream().filter(cas -> cas.isEnabled() && StringUtils.isNotBlank(cas.getLoginUrl())).forEach(cas -> {
val cfg = new CasConfiguration(cas.getLoginUrl(), CasProtocol.valueOf(cas.getProtocol()));
val prefix = PATTERN_LOGIN_URL.matcher(cas.getLoginUrl()).replaceFirst("/");
cfg.setPrefixUrl(StringUtils.appendIfMissing(prefix, "/"));
cfg.setHostnameVerifier(casSSLContext.getHostnameVerifier());
cfg.setSslSocketFactory(casSSLContext.getSslContext().getSocketFactory());
val client = new CasClient(cfg);
if (StringUtils.isBlank(cas.getClientName())) {
val count = index.intValue();
client.setName(client.getClass().getSimpleName() + count);
}
configureClient(client, cas);
index.incrementAndGet();
LOGGER.debug("Created client [{}]", client);
properties.add(client);
});
}
Aggregations