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;
}
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;
}
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()));
}
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;
}
Aggregations