use of org.opensaml.saml.saml2.ecp.RelayState in project cas by apereo.
the class SamlProfileSamlSoap11ResponseBuilder method encode.
@Override
@SneakyThrows
protected Envelope encode(final SamlRegisteredService service, final Envelope envelope, final HttpServletResponse httpResponse, final HttpServletRequest httpRequest, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String relayState, final String binding, final RequestAbstractType authnRequest, final Object assertion) throws SamlException {
final MessageContext result = new MessageContext();
final SOAP11Context ctx = result.getSubcontext(SOAP11Context.class, true);
ctx.setEnvelope(envelope);
final HTTPSOAP11Encoder encoder = new HTTPSOAP11Encoder();
encoder.setHttpServletResponse(httpResponse);
encoder.setMessageContext(result);
encoder.initialize();
encoder.encode();
return envelope;
}
use of org.opensaml.saml.saml2.ecp.RelayState in project verify-hub by alphagov.
the class SamlMessageSenderHandlerTest method setUpAuthnResponseFromHub.
private Response setUpAuthnResponseFromHub(SessionId sessionId, String expectedSamlMessageId) throws MarshallingException, SignatureException {
AuthnResponseFromHubContainerDto hubContainerDto = new AuthnResponseFromHubContainerDto(samlRequest, postEndPoint, relayState, expectedSamlMessageId);
when(sessionProxy.getAuthnResponseFromHub(sessionId)).thenReturn(hubContainerDto);
Response openSamlResponse = aResponse().withId(expectedSamlMessageId).build();
when(responseTransformer.apply(anyString())).thenReturn(openSamlResponse);
return openSamlResponse;
}
use of org.opensaml.saml.saml2.ecp.RelayState in project verify-hub by alphagov.
the class SamlMessageSenderHandlerTest method generateErrorResponseFromHub_shouldAddExternalCommunicationEvent.
@Test
public void generateErrorResponseFromHub_shouldAddExternalCommunicationEvent() throws MarshallingException, SignatureException {
SessionId sessionId = SessionId.createNewSessionId();
String responseId = UUID.randomUUID().toString();
when(sessionProxy.getErrorResponseFromHub(sessionId)).thenReturn(new AuthnResponseFromHubContainerDto(samlRequest, postEndPoint, relayState, responseId));
Response samlResponse = setUpErrorResponseFromHub(sessionId, responseId);
when(responseTransformer.apply(samlRequest)).thenReturn(samlResponse);
SamlMessage samlMessage = samlMessageSenderHandler.generateErrorResponseFromHub(sessionId, principalIpAddressAsSeenByHub);
assertThat(samlMessage.getSamlMessage()).isEqualTo(samlRequest);
assertThat(samlMessage.getPostEndpoint()).isEqualTo(postEndPoint.toString());
assertThat(samlMessage.getRegistration().isPresent()).isFalse();
assertThat(samlMessage.getSamlMessageType()).isEqualTo(SamlMessageType.SAML_RESPONSE);
assertThat(samlMessage.getRelayState().isPresent()).isTrue();
assertThat(samlMessage.getRelayState()).isEqualTo(relayState);
verify(externalCommunicationEventLogger).logResponseFromHub(responseId, sessionId, postEndPoint, principalIpAddressAsSeenByHub);
}
use of org.opensaml.saml.saml2.ecp.RelayState in project cxf by apache.
the class AbstractServiceProviderFilter method createSamlRequestInfo.
protected SamlRequestInfo createSamlRequestInfo(Message m) throws Exception {
Document doc = DOMUtils.createDocument();
doc.appendChild(doc.createElement("root"));
// Create the AuthnRequest
AuthnRequest authnRequest = authnRequestBuilder.createAuthnRequest(m, getIssuerId(m), getAbsoluteAssertionServiceAddress(m));
if (isSignRequest()) {
authnRequest.setDestination(getIdpServiceAddress());
signAuthnRequest(authnRequest);
}
Element authnRequestElement = OpenSAMLUtil.toDom(authnRequest, doc);
String authnRequestEncoded = encodeAuthnRequest(authnRequestElement);
SamlRequestInfo info = new SamlRequestInfo();
info.setSamlRequest(authnRequestEncoded);
String webAppContext = getWebAppContext(m);
String originalRequestURI = new UriInfoImpl(m).getRequestUri().toString();
RequestState requestState = new RequestState(originalRequestURI, getIdpServiceAddress(), authnRequest.getID(), getIssuerId(m), webAppContext, getWebAppDomain(), System.currentTimeMillis());
String relayState = URLEncoder.encode(UUID.randomUUID().toString(), StandardCharsets.UTF_8.name());
getStateProvider().setRequestState(relayState, requestState);
info.setRelayState(relayState);
info.setWebAppContext(webAppContext);
info.setWebAppDomain(getWebAppDomain());
return info;
}
Aggregations