Search in sources :

Example 1 with NoParameterCallbackUrlResolver

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

use of org.pac4j.core.http.callback.NoParameterCallbackUrlResolver in project druid by druid-io.

the class Pac4jAuthenticator method createPac4jConfig.

private Config createPac4jConfig(OIDCConfig oidcConfig) {
    OidcConfiguration oidcConf = new OidcConfiguration();
    oidcConf.setClientId(oidcConfig.getClientID());
    oidcConf.setSecret(oidcConfig.getClientSecret().getPassword());
    oidcConf.setDiscoveryURI(oidcConfig.getDiscoveryURI());
    oidcConf.setExpireSessionWithToken(true);
    oidcConf.setUseNonce(true);
    oidcConf.setReadTimeout(Ints.checkedCast(pac4jCommonConfig.getReadTimeout().getMillis()));
    oidcConf.setResourceRetriever(// ResourceRetriever is used to get Auth server configuration from "discoveryURI"
    new CustomSSLResourceRetriever(pac4jCommonConfig.getReadTimeout().getMillis(), sslSocketFactory));
    OidcClient oidcClient = new OidcClient(oidcConf);
    oidcClient.setUrlResolver(new DefaultUrlResolver(true));
    oidcClient.setCallbackUrlResolver(new NoParameterCallbackUrlResolver());
    // This is used by OidcClient in various places to make HTTPrequests.
    if (sslSocketFactory != null) {
        HTTPRequest.setDefaultSSLSocketFactory(sslSocketFactory);
    }
    return new Config(Pac4jCallbackResource.SELF_URL, oidcClient);
}
Also used : OidcConfiguration(org.pac4j.oidc.config.OidcConfiguration) OidcClient(org.pac4j.oidc.client.OidcClient) Config(org.pac4j.core.config.Config) DefaultUrlResolver(org.pac4j.core.http.url.DefaultUrlResolver) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)

Example 3 with NoParameterCallbackUrlResolver

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

the class ClientsTests method testAddClient.

@Test
public void testAddClient() {
    final var facebookClient = newFacebookClient();
    final var yahooClient = newYahooClient();
    final var clients = new Clients(CALLBACK_URL, facebookClient);
    clients.findAllClients();
    final List<Client> list = new ArrayList<>();
    list.add(facebookClient);
    list.add(yahooClient);
    clients.setClients(list);
    clients.setCallbackUrlResolver(new NoParameterCallbackUrlResolver());
    final var yclient = (IndirectClient) clients.findClient("YahooClient").get();
    assertTrue(yclient.getCallbackUrlResolver() instanceof NoParameterCallbackUrlResolver);
    final var fclient = (IndirectClient) clients.findClient("FacebookClient").get();
    assertTrue(fclient.getCallbackUrlResolver() instanceof NoParameterCallbackUrlResolver);
}
Also used : ArrayList(java.util.ArrayList) NoParameterCallbackUrlResolver(org.pac4j.core.http.callback.NoParameterCallbackUrlResolver) Test(org.junit.Test)

Aggregations

NoParameterCallbackUrlResolver (org.pac4j.core.http.callback.NoParameterCallbackUrlResolver)3 ArrayList (java.util.ArrayList)1 lombok.val (lombok.val)1 Test (org.junit.Test)1 Config (org.pac4j.core.config.Config)1 PathParameterCallbackUrlResolver (org.pac4j.core.http.callback.PathParameterCallbackUrlResolver)1 QueryParameterCallbackUrlResolver (org.pac4j.core.http.callback.QueryParameterCallbackUrlResolver)1 DefaultUrlResolver (org.pac4j.core.http.url.DefaultUrlResolver)1 OidcClient (org.pac4j.oidc.client.OidcClient)1 OidcConfiguration (org.pac4j.oidc.config.OidcConfiguration)1