Search in sources :

Example 1 with CasAuthenticator

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<>());
}
Also used : ParameterExtractor(org.pac4j.core.credentials.extractor.ParameterExtractor) CasAuthenticator(org.pac4j.cas.credentials.authenticator.CasAuthenticator)

Example 2 with CasAuthenticator

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;
    }
}
Also used : CasAuthenticator(org.pac4j.cas.credentials.authenticator.CasAuthenticator) CredentialsException(org.pac4j.core.exception.CredentialsException) TokenCredentials(org.pac4j.core.credentials.TokenCredentials)

Example 3 with CasAuthenticator

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<>());
}
Also used : CasAuthenticator(org.pac4j.cas.credentials.authenticator.CasAuthenticator) TicketAndLogoutRequestExtractor(org.pac4j.cas.credentials.extractor.TicketAndLogoutRequestExtractor) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) CasRedirectActionBuilder(org.pac4j.cas.redirect.CasRedirectActionBuilder)

Example 4 with CasAuthenticator

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<>());
}
Also used : ParameterExtractor(org.pac4j.core.credentials.extractor.ParameterExtractor) CasAuthenticator(org.pac4j.cas.credentials.authenticator.CasAuthenticator) CasProtocol(org.pac4j.cas.config.CasProtocol)

Aggregations

CasAuthenticator (org.pac4j.cas.credentials.authenticator.CasAuthenticator)4 ParameterExtractor (org.pac4j.core.credentials.extractor.ParameterExtractor)2 CasProtocol (org.pac4j.cas.config.CasProtocol)1 TicketAndLogoutRequestExtractor (org.pac4j.cas.credentials.extractor.TicketAndLogoutRequestExtractor)1 CasRedirectActionBuilder (org.pac4j.cas.redirect.CasRedirectActionBuilder)1 TokenCredentials (org.pac4j.core.credentials.TokenCredentials)1 CredentialsException (org.pac4j.core.exception.CredentialsException)1 QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)1