use of org.pac4j.core.context.WebContext in project cas by apereo.
the class OidcAuthorizationRequestSupport method getOidcMaxAgeFromAuthorizationRequest.
/**
* Gets oidc max age from authorization request.
*
* @param context the context
* @return the oidc max age from authorization request
*/
public static Optional<Long> getOidcMaxAgeFromAuthorizationRequest(final WebContext context) {
final URIBuilder builderContext = new URIBuilder(context.getFullRequestURL());
final Optional<URIBuilder.BasicNameValuePair> parameter = builderContext.getQueryParams().stream().filter(p -> OidcConstants.MAX_AGE.equals(p.getName())).findFirst();
if (parameter.isPresent()) {
final long maxAge = NumberUtils.toLong(parameter.get().getValue(), -1);
return Optional.of(maxAge);
}
return Optional.empty();
}
use of org.pac4j.core.context.WebContext in project cas by apereo.
the class DelegatedClientAuthenticationAction method prepareForLoginPage.
/**
* Prepare the data for the login page.
*
* @param context The current webflow context
*/
protected void prepareForLoginPage(final RequestContext context) {
final Service service = WebUtils.getService(context);
final HttpServletRequest request = WebUtils.getHttpServletRequestFromExternalWebflowContext(context);
final HttpServletResponse response = WebUtils.getHttpServletResponseFromExternalWebflowContext(context);
final WebContext webContext = Pac4jUtils.getPac4jJ2EContext(request, response);
final Set<ProviderLoginPageConfiguration> urls = new LinkedHashSet<>();
this.clients.findAllClients().stream().filter(client -> client instanceof IndirectClient && isDelegatedClientAuthorizedForService(client, service)).map(IndirectClient.class::cast).forEach(client -> {
try {
final Optional<ProviderLoginPageConfiguration> provider = buildProviderConfiguration(client, webContext);
provider.ifPresent(urls::add);
} catch (final Exception e) {
LOGGER.error("Cannot process client [{}]", client, e);
}
});
if (!urls.isEmpty()) {
context.getFlowScope().put(PAC4J_URLS, urls);
} else if (response.getStatus() != HttpStatus.UNAUTHORIZED.value()) {
LOGGER.warn("No delegated authentication providers could be determined based on the provided configuration. " + "Either no clients are configured, or the current access strategy rules prohibit CAS from using authentication providers for this request.");
}
}
use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class PostSAML2ClientTests method testSetComparisonTypeWithPostBinding.
@Test
public void testSetComparisonTypeWithPostBinding() {
final SAML2Client client = getClient();
client.getConfiguration().setComparisonType(AuthnContextComparisonTypeEnumeration.EXACT.toString());
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final RedirectAction action = client.getRedirectAction(context);
assertTrue(getDecodedAuthnRequest(action.getContent()).contains("Comparison=\"exact\""));
}
use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class RedirectSAML2ClientTests method testForceAuthIsSetForRedirectBinding.
@Test
public void testForceAuthIsSetForRedirectBinding() {
final SAML2Client client = getClient();
client.getConfiguration().setForceAuth(true);
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
final RedirectAction action = client.getRedirectAction(context);
assertTrue(getInflatedAuthnRequest(action.getLocation()).contains("ForceAuthn=\"true\""));
}
use of org.pac4j.core.context.WebContext in project pac4j by pac4j.
the class RedirectSAML2ClientTests method testRelayState.
@Test
public void testRelayState() {
final SAML2Client client = getClient();
final WebContext context = new J2EContext(new MockHttpServletRequest(), new MockHttpServletResponse());
context.getSessionStore().set(context, SAML2Client.SAML_RELAY_STATE_ATTRIBUTE, "relayState");
final RedirectAction action = client.getRedirectAction(context);
assertTrue(action.getLocation().contains("RelayState=relayState"));
}
Aggregations