use of org.pac4j.cas.credentials.authenticator.CasAuthenticator in project pac4j by pac4j.
the class DirectCasClient method clientInit.
@Override
protected void clientInit() {
CommonHelper.assertNotNull("urlResolver", this.urlResolver);
CommonHelper.assertNotNull("callbackUrlResolver", this.callbackUrlResolver);
CommonHelper.assertNotNull("configuration", this.configuration);
CommonHelper.assertTrue(!configuration.isGateway(), "the DirectCasClient can not support gateway to avoid infinite loops");
defaultCredentialsExtractor(new ParameterExtractor(CasConfiguration.TICKET_PARAMETER, true, false));
// only a fake one for the initialization as we will build a new one with the current url for each request
super.defaultAuthenticator(new CasAuthenticator(configuration, getName(), urlResolver, callbackUrlResolver, "fake"));
addAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
}
use of org.pac4j.cas.credentials.authenticator.CasAuthenticator in project pac4j by pac4j.
the class DirectCasClient method retrieveCredentials.
@Override
protected TokenCredentials retrieveCredentials(final WebContext context) {
init();
try {
String callbackUrl = callbackUrlResolver.compute(urlResolver, context.getFullRequestURL(), getName(), context);
final String loginUrl = configuration.computeFinalLoginUrl(context);
final TokenCredentials credentials = getCredentialsExtractor().extract(context);
if (credentials == null) {
// redirect to the login page
final String redirectionUrl = CommonUtils.constructRedirectUrl(loginUrl, CasConfiguration.SERVICE_PARAMETER, callbackUrl, configuration.isRenew(), false);
logger.debug("redirectionUrl: {}", redirectionUrl);
throw HttpAction.redirect(context, redirectionUrl);
}
// clean url from ticket parameter
callbackUrl = CommonHelper.substringBefore(callbackUrl, "?" + CasConfiguration.TICKET_PARAMETER + "=");
callbackUrl = CommonHelper.substringBefore(callbackUrl, "&" + CasConfiguration.TICKET_PARAMETER + "=");
final CasAuthenticator casAuthenticator = new CasAuthenticator(configuration, getName(), urlResolver, callbackUrlResolver, callbackUrl);
casAuthenticator.init();
casAuthenticator.validate(credentials, context);
return credentials;
} catch (CredentialsException e) {
logger.error("Failed to retrieve or validate CAS credentials", e);
return null;
}
}
use of org.pac4j.cas.credentials.authenticator.CasAuthenticator in project pac4j by pac4j.
the class CasClient method clientInit.
@Override
protected void clientInit() {
CommonHelper.assertNotNull("configuration", configuration);
configuration.setUrlResolver(this.getUrlResolver());
setCallbackUrlResolver(new QueryParameterCallbackUrlResolver(configuration.getCustomParams()));
defaultRedirectActionBuilder(new CasRedirectActionBuilder(configuration, this));
defaultCredentialsExtractor(new TicketAndLogoutRequestExtractor(configuration));
defaultAuthenticator(new CasAuthenticator(configuration, getName(), getUrlResolver(), getCallbackUrlResolver(), callbackUrl));
defaultLogoutActionBuilder(new CasLogoutActionBuilder<>(configuration.getPrefixUrl() + "logout", configuration.getPostLogoutUrlParameter()));
addAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
}
use of org.pac4j.cas.credentials.authenticator.CasAuthenticator in project pac4j by pac4j.
the class DirectCasProxyClient method clientInit.
@Override
protected void clientInit() {
CommonHelper.assertNotNull("urlResolver", this.urlResolver);
CommonHelper.assertNotNull("callbackUrlResolver", this.callbackUrlResolver);
CommonHelper.assertNotBlank("serviceUrl", this.serviceUrl);
CommonHelper.assertNotNull("configuration", this.configuration);
// must be a CAS proxy protocol
final CasProtocol protocol = configuration.getProtocol();
CommonHelper.assertTrue(protocol == CasProtocol.CAS20_PROXY || protocol == CasProtocol.CAS30_PROXY, "The DirectCasProxyClient must be configured with a CAS proxy protocol (CAS20_PROXY or CAS30_PROXY)");
defaultCredentialsExtractor(new ParameterExtractor(CasConfiguration.TICKET_PARAMETER, true, false));
defaultAuthenticator(new CasAuthenticator(configuration, getName(), urlResolver, callbackUrlResolver, this.serviceUrl));
addAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
}
Aggregations