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