Search in sources :

Example 1 with OAuth20Client

use of org.pac4j.oauth.client.OAuth20Client in project cas by apereo.

the class DelegatedClientWebflowManager method store.

/**
 * Store.
 *
 * @param webContext the web context
 * @param client     the client
 * @return the ticket
 */
public Ticket store(final WebContext webContext, final BaseClient client) {
    final Map<String, Serializable> properties = new LinkedHashMap<>();
    final Service service = determineService(webContext);
    properties.put(CasProtocolConstants.PARAMETER_SERVICE, service);
    properties.put(this.themeParamName, StringUtils.defaultString(webContext.getRequestParameter(this.themeParamName)));
    properties.put(this.localParamName, StringUtils.defaultString(webContext.getRequestParameter(this.localParamName)));
    properties.put(CasProtocolConstants.PARAMETER_METHOD, StringUtils.defaultString(webContext.getRequestParameter(CasProtocolConstants.PARAMETER_METHOD)));
    final TransientSessionTicketFactory transientFactory = (TransientSessionTicketFactory) this.ticketFactory.get(TransientSessionTicket.class);
    final TransientSessionTicket ticket = transientFactory.create(service, properties);
    LOGGER.debug("Storing delegated authentication request ticket [{}] for service [{}] with properties [{}]", ticket.getId(), ticket.getService(), ticket.getProperties());
    this.ticketRegistry.addTicket(ticket);
    webContext.setRequestAttribute(PARAMETER_CLIENT_ID, ticket.getId());
    if (client instanceof SAML2Client) {
        webContext.getSessionStore().set(webContext, SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, ticket.getId());
    }
    if (client instanceof OAuth20Client) {
        final OAuth20Client oauthClient = (OAuth20Client) client;
        oauthClient.getConfiguration().setWithState(true);
        oauthClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof OidcClient) {
        final OidcClient oidcClient = (OidcClient) client;
        oidcClient.getConfiguration().setCustomParams(CollectionUtils.wrap(PARAMETER_CLIENT_ID, ticket.getId()));
        oidcClient.getConfiguration().setWithState(true);
        oidcClient.getConfiguration().setStateData(ticket.getId());
    }
    if (client instanceof CasClient) {
        final CasClient casClient = (CasClient) client;
        casClient.getConfiguration().addCustomParam(DelegatedClientWebflowManager.PARAMETER_CLIENT_ID, ticket.getId());
    }
    return ticket;
}
Also used : TransientSessionTicket(org.apereo.cas.ticket.TransientSessionTicket) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) Serializable(java.io.Serializable) OidcClient(org.pac4j.oidc.client.OidcClient) WebApplicationService(org.apereo.cas.authentication.principal.WebApplicationService) Service(org.apereo.cas.authentication.principal.Service) SAML2Client(org.pac4j.saml.client.SAML2Client) TransientSessionTicketFactory(org.apereo.cas.ticket.TransientSessionTicketFactory) LinkedHashMap(java.util.LinkedHashMap) CasClient(org.pac4j.cas.client.CasClient)

Example 2 with OAuth20Client

use of org.pac4j.oauth.client.OAuth20Client in project pac4j by pac4j.

the class RunOAuth20Client method getClient.

@Override
protected IndirectClient getClient() {
    final OAuth20Configuration config = new OAuth20Configuration();
    config.setApi(GitHubApi.instance());
    config.setProfileDefinition(new GitHubProfileDefinition());
    config.setScope("user");
    config.setKey("62374f5573a89a8f9900");
    config.setSecret("01dd26d60447677ceb7399fb4c744f545bb86359");
    final OAuth20Client client = new OAuth20Client();
    client.setConfiguraton(config);
    client.setCallbackUrl(PAC4J_BASE_URL);
    return client;
}
Also used : OAuth20Client(org.pac4j.oauth.client.OAuth20Client) OAuth20Configuration(org.pac4j.oauth.config.OAuth20Configuration) GitHubProfileDefinition(org.pac4j.oauth.profile.github.GitHubProfileDefinition)

Example 3 with OAuth20Client

use of org.pac4j.oauth.client.OAuth20Client in project cas by apereo.

the class DefaultDelegatedClientAuthenticationWebflowManagerTests method verifyOAuth2StoreOperation.

@Test
public void verifyOAuth2StoreOperation() throws Exception {
    val config = new OAuth20Configuration();
    config.setKey(UUID.randomUUID().toString());
    config.setSecret(UUID.randomUUID().toString());
    val client = new OAuth20Client();
    client.setConfiguration(config);
    val ticket = delegatedClientAuthenticationWebflowManager.store(context, client);
    assertNotNull(ticketRegistry.getTicket(ticket.getId()));
    val service = delegatedClientAuthenticationWebflowManager.retrieve(requestContext, context, client);
    assertNotNull(service);
    assertNull(ticketRegistry.getTicket(ticket.getId()));
}
Also used : lombok.val(lombok.val) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) OAuth20Configuration(org.pac4j.oauth.config.OAuth20Configuration) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with OAuth20Client

use of org.pac4j.oauth.client.OAuth20Client in project cas by apereo.

the class DefaultDelegatedClientAuthenticationWebflowManager method store.

@Override
public TransientSessionTicket store(final JEEContext webContext, final Client client) throws Exception {
    val ticket = storeDelegatedClientAuthenticationRequest(webContext);
    rememberSelectedClientIfNecessary(webContext, client);
    if (client instanceof SAML2Client) {
        trackSessionIdForSAML2Client(webContext, ticket, (SAML2Client) client);
    }
    if (client instanceof OAuth20Client) {
        trackSessionIdForOAuth20Client(webContext, (OAuth20Client) client, ticket);
    }
    if (client instanceof OidcClient) {
        trackSessionIdForOidcClient(webContext, (OidcClient) client, ticket);
    }
    if (client instanceof CasClient) {
        trackSessionIdForCasClient(webContext, ticket, (CasClient) client);
    }
    if (client instanceof OAuth10Client) {
        trackSessionIdForOAuth10Client(webContext, ticket);
    }
    return ticket;
}
Also used : lombok.val(lombok.val) OAuth20Client(org.pac4j.oauth.client.OAuth20Client) OAuth10Client(org.pac4j.oauth.client.OAuth10Client) OidcClient(org.pac4j.oidc.client.OidcClient) SAML2Client(org.pac4j.saml.client.SAML2Client) CasClient(org.pac4j.cas.client.CasClient)

Aggregations

OAuth20Client (org.pac4j.oauth.client.OAuth20Client)4 lombok.val (lombok.val)2 CasClient (org.pac4j.cas.client.CasClient)2 OAuth20Configuration (org.pac4j.oauth.config.OAuth20Configuration)2 OidcClient (org.pac4j.oidc.client.OidcClient)2 SAML2Client (org.pac4j.saml.client.SAML2Client)2 Serializable (java.io.Serializable)1 LinkedHashMap (java.util.LinkedHashMap)1 Service (org.apereo.cas.authentication.principal.Service)1 WebApplicationService (org.apereo.cas.authentication.principal.WebApplicationService)1 TransientSessionTicket (org.apereo.cas.ticket.TransientSessionTicket)1 TransientSessionTicketFactory (org.apereo.cas.ticket.TransientSessionTicketFactory)1 Test (org.junit.jupiter.api.Test)1 OAuth10Client (org.pac4j.oauth.client.OAuth10Client)1 GitHubProfileDefinition (org.pac4j.oauth.profile.github.GitHubProfileDefinition)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1