Search in sources :

Example 1 with QueryParameterCallbackUrlResolver

use of org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver in project pac4j by pac4j.

the class ClientsTests method testValuesSet.

@Test
public void testValuesSet() {
    MockIndirectClient facebookClient = newFacebookClient();
    final Clients clients = new Clients(facebookClient);
    final AjaxRequestResolver ajaxRequestResolver = new DefaultAjaxRequestResolver();
    final UrlResolver urlResolver = new DefaultUrlResolver();
    final CallbackUrlResolver callbackUrlResolver = new QueryParameterCallbackUrlResolver();
    final AuthorizationGenerator authorizationGenerator = (context, profile) -> profile;
    clients.setCallbackUrl(CALLBACK_URL);
    clients.setAjaxRequestResolver(ajaxRequestResolver);
    clients.setUrlResolver(urlResolver);
    clients.setCallbackUrlResolver(callbackUrlResolver);
    clients.addAuthorizationGenerator(authorizationGenerator);
    clients.init();
    assertEquals(CALLBACK_URL, facebookClient.getCallbackUrl());
    assertEquals(urlResolver, facebookClient.getUrlResolver());
    assertEquals(callbackUrlResolver, facebookClient.getCallbackUrlResolver());
    assertEquals(ajaxRequestResolver, facebookClient.getAjaxRequestResolver());
    assertEquals(authorizationGenerator, facebookClient.getAuthorizationGenerators().get(0));
}
Also used : TestsConstants(org.pac4j.core.util.TestsConstants) CommonProfile(org.pac4j.core.profile.CommonProfile) TestsHelper(org.pac4j.core.util.TestsHelper) Test(org.junit.Test) AjaxRequestResolver(org.pac4j.core.http.ajax.AjaxRequestResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) ArrayList(java.util.ArrayList) RedirectAction(org.pac4j.core.redirect.RedirectAction) List(java.util.List) UrlResolver(org.pac4j.core.http.url.UrlResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Credentials(org.pac4j.core.credentials.Credentials) Assert(org.junit.Assert) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) UrlResolver(org.pac4j.core.http.url.UrlResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) AjaxRequestResolver(org.pac4j.core.http.ajax.AjaxRequestResolver) DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) AuthorizationGenerator(org.pac4j.core.authorization.generator.AuthorizationGenerator) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) CallbackUrlResolver(org.pac4j.core.http.callback.CallbackUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) Test(org.junit.Test)

Example 2 with QueryParameterCallbackUrlResolver

use of org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver in project cas by apereo.

the class DefaultDelegatedClientFactory method configureClient.

/**
 * Sets client name.
 *
 * @param client the client
 * @param props  the props
 */
protected void configureClient(final IndirectClient client, final Pac4jBaseClientProperties props) {
    val cname = props.getClientName();
    if (StringUtils.isNotBlank(cname)) {
        client.setName(cname);
    } else {
        val className = client.getClass().getSimpleName();
        val genName = className.concat(RandomUtils.randomNumeric(2));
        client.setName(genName);
        LOGGER.warn("Client name for [{}] is set to a generated value of [{}]. " + "Consider defining an explicit name for the delegated provider", className, genName);
    }
    val customProperties = client.getCustomProperties();
    customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_AUTO_REDIRECT_TYPE, props.getAutoRedirectType());
    if (StringUtils.isNotBlank(props.getPrincipalAttributeId())) {
        customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_PRINCIPAL_ATTRIBUTE_ID, props.getPrincipalAttributeId());
    }
    if (StringUtils.isNotBlank(props.getCssClass())) {
        customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_CSS_CLASS, props.getCssClass());
    }
    if (StringUtils.isNotBlank(props.getDisplayName())) {
        customProperties.put(ClientCustomPropertyConstants.CLIENT_CUSTOM_PROPERTY_AUTO_DISPLAY_NAME, props.getDisplayName());
    }
    val callbackUrl = StringUtils.defaultString(props.getCallbackUrl(), casProperties.getServer().getLoginUrl());
    client.setCallbackUrl(callbackUrl);
    switch(props.getCallbackUrlType()) {
        case PATH_PARAMETER:
            client.setCallbackUrlResolver(new PathParameterCallbackUrlResolver());
            break;
        case NONE:
            client.setCallbackUrlResolver(new NoParameterCallbackUrlResolver());
            break;
        case QUERY_PARAMETER:
        default:
            client.setCallbackUrlResolver(new QueryParameterCallbackUrlResolver());
    }
    this.customizers.forEach(customizer -> customizer.customize(client));
    if (!casProperties.getAuthn().getPac4j().getCore().isLazyInit()) {
        client.init();
    }
}
Also used : lombok.val(lombok.val) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver) PathParameterCallbackUrlResolver(org.pac4j.core.http.callback.PathParameterCallbackUrlResolver) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)

Example 3 with QueryParameterCallbackUrlResolver

use of org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver in project ddf by codice.

the class OidcHandler method getCredentialsFromRequest.

private OidcCredentials getCredentialsFromRequest(OidcClient<OidcConfiguration> oidcClient, JEEContext jeeContext) {
    // Check that the request contains a code, an access token or an id token
    Map<String, String[]> requestParams = jeeContext.getRequestParameters();
    if (!requestParams.containsKey("code") && !requestParams.containsKey("access_token") && !requestParams.containsKey("id_token")) {
        return new OidcCredentials();
    }
    oidcClient.setCallbackUrlResolver(new QueryParameterCallbackUrlResolver());
    OidcExtractor oidcExtractor = new OidcExtractor(oidcClient.getConfiguration(), oidcClient);
    return oidcExtractor.extract(jeeContext).orElse(null);
}
Also used : OidcCredentials(org.pac4j.oidc.credentials.OidcCredentials) OidcExtractor(org.pac4j.oidc.credentials.extractor.OidcExtractor) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)

Example 4 with QueryParameterCallbackUrlResolver

use of org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver 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 5 with QueryParameterCallbackUrlResolver

use of org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver in project pac4j by pac4j.

the class IndirectClient method internalInit.

@Override
protected final void internalInit() {
    // check configuration
    CommonHelper.assertNotBlank("callbackUrl", this.callbackUrl, "set it up either on this IndirectClient or on the global Config");
    if (this.urlResolver == null) {
        this.urlResolver = new DefaultUrlResolver();
    }
    if (this.callbackUrlResolver == null) {
        this.callbackUrlResolver = new QueryParameterCallbackUrlResolver();
    }
    if (this.ajaxRequestResolver == null) {
        ajaxRequestResolver = new DefaultAjaxRequestResolver();
    }
    clientInit();
    // ensures components have been properly initialized
    CommonHelper.assertNotNull("redirectActionBuilder", this.redirectActionBuilder);
    CommonHelper.assertNotNull("credentialsExtractor", getCredentialsExtractor());
    CommonHelper.assertNotNull("authenticator", getAuthenticator());
    CommonHelper.assertNotNull("profileCreator", getProfileCreator());
    CommonHelper.assertNotNull("logoutActionBuilder", this.logoutActionBuilder);
}
Also used : DefaultAjaxRequestResolver(org.pac4j.core.http.ajax.DefaultAjaxRequestResolver) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) QueryParameterCallbackUrlResolver(org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)

Aggregations

QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)5 DefaultAjaxRequestResolver (org.pac4j.core.http.ajax.DefaultAjaxRequestResolver)2 DefaultUrlResolver (org.pac4j.core.http.url.DefaultUrlResolver)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 lombok.val (lombok.val)1 Assert (org.junit.Assert)1 Test (org.junit.Test)1 CasAuthenticator (org.pac4j.cas.credentials.authenticator.CasAuthenticator)1 TicketAndLogoutRequestExtractor (org.pac4j.cas.credentials.extractor.TicketAndLogoutRequestExtractor)1 CasRedirectActionBuilder (org.pac4j.cas.redirect.CasRedirectActionBuilder)1 AuthorizationGenerator (org.pac4j.core.authorization.generator.AuthorizationGenerator)1 Credentials (org.pac4j.core.credentials.Credentials)1 AjaxRequestResolver (org.pac4j.core.http.ajax.AjaxRequestResolver)1 CallbackUrlResolver (org.pac4j.core.http.callback.CallbackUrlResolver)1 NoParameterCallbackUrlResolver (org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)1 PathParameterCallbackUrlResolver (org.pac4j.core.http.callback.PathParameterCallbackUrlResolver)1 UrlResolver (org.pac4j.core.http.url.UrlResolver)1 CommonProfile (org.pac4j.core.profile.CommonProfile)1 RedirectAction (org.pac4j.core.redirect.RedirectAction)1