use of org.pac4j.jee.context.JEEContext in project cas by apereo.
the class SamlIdPMultifactorAuthenticationTrigger method isActivated.
@Override
public Optional<MultifactorAuthenticationProvider> isActivated(final Authentication authentication, final RegisteredService registeredService, final HttpServletRequest request, final HttpServletResponse response, final Service service) {
val context = new JEEContext(request, response);
val result = SamlIdPUtils.retrieveSamlRequest(context, distributedSessionStore, openSamlConfigBean, AuthnRequest.class);
val mappings = getAuthenticationContextMappings();
return result.map(pair -> (AuthnRequest) pair.getLeft()).flatMap(authnRequest -> authnRequest.getRequestedAuthnContext().getAuthnContextClassRefs().stream().filter(Objects::nonNull).filter(ref -> StringUtils.isNotBlank(ref.getURI())).filter(ref -> {
val clazz = ref.getURI();
return mappings.containsKey(clazz);
}).findFirst().map(mapped -> mappings.get(mapped.getURI()))).flatMap(id -> {
val providerMap = MultifactorAuthenticationUtils.getAvailableMultifactorAuthenticationProviders(applicationContext);
return MultifactorAuthenticationUtils.resolveProvider(providerMap, id);
});
}
use of org.pac4j.jee.context.JEEContext in project cas by apereo.
the class SamlProfileSaml2ResponseBuilderTests method verifySamlResponseWithAttributeQuery.
@Test
public void verifySamlResponseWithAttributeQuery() throws Exception {
val request = buildHttpRequest();
val response = new MockHttpServletResponse();
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
val webContext = new JEEContext(request, response);
samlIdPDistributedSessionStore.set(webContext, WebUtils.PARAMETER_TICKET_GRANTING_TICKET_ID, tgt.getId());
val service = getSamlRegisteredServiceForTestShib(true, true);
service.setIssuerEntityId("https://issuer.example.org");
service.getAttributeValueTypes().put("permissions", XSObject.class.getSimpleName());
val adaptor = SamlRegisteredServiceServiceProviderMetadataFacade.get(samlRegisteredServiceCachingMetadataResolver, service, service.getServiceId()).get();
val authnRequest = getAuthnRequestFor(service);
val assertion = getAssertion();
RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request, response));
val samlResponse = buildResponse(request, response, service, adaptor, authnRequest, assertion, SAMLConstants.SAML2_ARTIFACT_BINDING_URI);
assertNotNull(samlResponse);
}
use of org.pac4j.jee.context.JEEContext in project cas by apereo.
the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequestWithUnknownCookie.
@Test
@Order(7)
public void verifyPostRequestWithUnknownCookie() throws Exception {
val response = new MockHttpServletResponse();
val tgt = new MockTicketGrantingTicket("casuser");
ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
val request = new MockHttpServletRequest();
request.setCookies(response.getCookies());
request.setMethod("POST");
val authnRequest = getAuthnRequest();
val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
samlIdPDistributedSessionStore.set(new JEEContext(request, response), SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "relay-state");
val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
assertEquals(HttpStatus.FOUND, mv.getStatus());
}
use of org.pac4j.jee.context.JEEContext in project cas by apereo.
the class SSOSamlIdPPostProfileHandlerControllerTests method verifyPostRequestWithSso.
@Test
@Order(5)
public void verifyPostRequestWithSso() throws Exception {
val response = new MockHttpServletResponse();
val tgt = new MockTicketGrantingTicket("casuser");
ticketRegistry.addTicket(tgt);
ticketGrantingTicketCookieGenerator.addCookie(response, tgt.getId());
val request = new MockHttpServletRequest();
request.setCookies(response.getCookies());
request.setMethod("POST");
val authnRequest = getAuthnRequest();
val xml = SamlUtils.transformSamlObject(openSamlConfigBean, authnRequest).toString();
request.addParameter(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
samlIdPDistributedSessionStore.set(new JEEContext(request, response), SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, "relay-state");
val mv = controller.handleSaml2ProfileSsoPostRequest(response, request);
assertNull(mv);
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertNotNull(response.getContentAsString());
}
use of org.pac4j.jee.context.JEEContext in project cas by apereo.
the class SSOSamlIdPProfileCallbackHandlerControllerWithBrowserStorageTests method verifyResumeFromStorage.
@Test
public void verifyResumeFromStorage() throws Exception {
val request = new MockHttpServletRequest();
val response = new MockHttpServletResponse();
val authn = getAuthnRequest();
authn.setProtocolBinding(SAMLConstants.SAML2_POST_BINDING_URI);
val xml = SamlUtils.transformSamlObject(openSamlConfigBean, getAuthnRequest()).toString();
request.getSession().setAttribute(SamlProtocolConstants.PARAMETER_SAML_REQUEST, EncodingUtils.encodeBase64(xml));
request.getSession().setAttribute(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE, UUID.randomUUID().toString());
val context = new MessageContext();
context.setMessage(getAuthnRequest());
request.getSession().setAttribute(MessageContext.class.getName(), SamlIdPAuthenticationContext.from(context).encode());
request.addParameter(CasProtocolConstants.PARAMETER_TICKET, "ST-1234567890");
val payload = samlIdPDistributedSessionStore.getTrackableSession(new JEEContext(request, response)).map(BrowserSessionStorage.class::cast).map(BrowserSessionStorage::getPayload).orElseThrow();
request.addParameter(BrowserSessionStorage.KEY_SESSION_STORAGE, payload);
val mv = controller.handleCallbackProfileRequestPost(response, request);
assertNull(mv);
assertEquals(HttpStatus.SC_OK, response.getStatus());
}
Aggregations