Search in sources :

Example 6 with Header

use of org.opensaml.soap.soap11.Header in project cas by apereo.

the class SamlIdPSaml1ArtifactResolutionProfileHandlerControllerTests method verifyFault.

@Test
@Order(2)
public void verifyFault() throws Exception {
    val response = new MockHttpServletResponse();
    val request = new MockHttpServletRequest();
    request.setMethod("POST");
    request.setContentType(MediaType.TEXT_XML_VALUE);
    var builder = (SOAPObjectBuilder) openSamlConfigBean.getBuilderFactory().getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    var envelope = (Envelope) builder.buildObject();
    builder = (SOAPObjectBuilder) openSamlConfigBean.getBuilderFactory().getBuilder(Header.DEFAULT_ELEMENT_NAME);
    val header = (Header) builder.buildObject();
    envelope.setHeader(header);
    builder = (SOAPObjectBuilder) openSamlConfigBean.getBuilderFactory().getBuilder(Body.DEFAULT_ELEMENT_NAME);
    val body = (Body) builder.buildObject();
    val artifactResolve = getArtifactResolve();
    body.getUnknownXMLObjects().add(artifactResolve);
    envelope.setBody(body);
    val xml = SamlUtils.transformSamlObject(openSamlConfigBean, envelope).toString();
    request.setContent(xml.getBytes(StandardCharsets.UTF_8));
    controller.handlePostRequest(response, request);
    assertEquals(HttpStatus.SC_OK, response.getStatus());
    assertNotNull(request.getAttribute(FaultString.class.getSimpleName()));
}
Also used : lombok.val(lombok.val) SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder) Header(org.opensaml.soap.soap11.Header) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test)

Example 7 with Header

use of org.opensaml.soap.soap11.Header in project cas by apereo.

the class SamlProfileSamlSoap11FaultResponseBuilder method build.

@Override
public Envelope build(final SamlProfileBuilderContext context) throws Exception {
    val body = SamlUtils.newSoapObject(Body.class);
    val fault = SamlUtils.newSoapObject(Fault.class);
    val faultCode = SamlUtils.newSoapObject(FaultCode.class);
    faultCode.setValue(FaultCode.SERVER);
    fault.setCode(faultCode);
    val faultActor = SamlUtils.newSoapObject(FaultActor.class);
    faultActor.setURI(SamlIdPUtils.getIssuerFromSamlObject(context.getSamlRequest()));
    fault.setActor(faultActor);
    val faultString = SamlUtils.newSoapObject(FaultString.class);
    val error = context.getHttpRequest().getAttribute(SamlIdPConstants.REQUEST_ATTRIBUTE_ERROR);
    if (error != null) {
        faultString.setValue(error.toString());
    } else {
        faultString.setValue("SOAP failure");
    }
    fault.setMessage(faultString);
    body.getUnknownXMLObjects().add(fault);
    val envelope = SamlUtils.newSoapObject(Envelope.class);
    val header = SamlUtils.newSoapObject(Header.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    val ctx = context.getMessageContext().getSubcontext(SOAP11Context.class, true);
    Objects.requireNonNull(ctx).setHTTPResponseStatus(HttpStatus.SC_OK);
    encodeFinalResponse(context, envelope);
    context.getHttpRequest().setAttribute(FaultString.class.getSimpleName(), error);
    return envelope;
}
Also used : lombok.val(lombok.val) FaultString(org.opensaml.soap.soap11.FaultString)

Example 8 with Header

use of org.opensaml.soap.soap11.Header in project cas by apereo.

the class SamlProfileSamlSoap11ResponseBuilder method buildResponse.

@Override
protected Envelope buildResponse(final Assertion assertion, final org.jasig.cas.client.validation.Assertion casAssertion, final AuthnRequest authnRequest, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletRequest request, final HttpServletResponse response) throws SamlException {
    final Response ecpResponse = newEcpResponse(adaptor.getAssertionConsumerService().getLocation());
    final Header header = newSoapObject(Header.class);
    header.getUnknownXMLObjects().add(ecpResponse);
    final Body body = newSoapObject(Body.class);
    final org.opensaml.saml.saml2.core.Response saml2Response = (org.opensaml.saml.saml2.core.Response) saml2ResponseBuilder.build(authnRequest, request, response, casAssertion, service, adaptor);
    body.getUnknownXMLObjects().add(saml2Response);
    final Envelope envelope = newSoapObject(Envelope.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    return envelope;
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.opensaml.saml.saml2.ecp.Response) Header(org.opensaml.soap.soap11.Header) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 9 with Header

use of org.opensaml.soap.soap11.Header in project cas by apereo.

the class SamlProfileArtifactResponseBuilder method buildResponse.

@Override
protected Envelope buildResponse(final Assertion assertion, final Object casAssertion, final RequestAbstractType authnRequest, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final HttpServletRequest request, final HttpServletResponse response, final String binding) throws SamlException {
    final org.jasig.cas.client.validation.Assertion castedAssertion = org.jasig.cas.client.validation.Assertion.class.cast(casAssertion);
    final SamlArtifactTicket ticket = (SamlArtifactTicket) castedAssertion.getAttributes().get("artifact");
    final ArtifactResponse artifactResponse = new ArtifactResponseBuilder().buildObject();
    artifactResponse.setIssueInstant(DateTime.now());
    artifactResponse.setIssuer(newIssuer(ticket.getIssuer()));
    artifactResponse.setInResponseTo(ticket.getRelyingPartyId());
    artifactResponse.setID(ticket.getId());
    artifactResponse.setStatus(newStatus(StatusCode.SUCCESS, "Success"));
    final SAMLObject samlResponse = SamlUtils.transformSamlObject(configBean, ticket.getObject(), SAMLObject.class);
    artifactResponse.setMessage(samlResponse);
    final Header header = newSoapObject(Header.class);
    final Body body = newSoapObject(Body.class);
    body.getUnknownXMLObjects().add(artifactResponse);
    final Envelope envelope = newSoapObject(Envelope.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    SamlUtils.logSamlObject(this.configBean, envelope);
    return envelope;
}
Also used : Header(org.opensaml.soap.soap11.Header) SAMLObject(org.opensaml.saml.common.SAMLObject) ArtifactResponse(org.opensaml.saml.saml2.core.ArtifactResponse) ArtifactResponseBuilder(org.opensaml.saml.saml2.core.impl.ArtifactResponseBuilder) SamlArtifactTicket(org.apereo.cas.ticket.artifact.SamlArtifactTicket) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 10 with Header

use of org.opensaml.soap.soap11.Header in project cas by apereo.

the class SamlProfileAttributeQueryResponseBuilder method build.

@Override
public Envelope build(final RequestAbstractType authnRequest, final HttpServletRequest request, final HttpServletResponse response, final Object casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor, final String binding) throws SamlException {
    final AttributeQuery query = (AttributeQuery) authnRequest;
    final Header header = newSoapObject(Header.class);
    final Body body = newSoapObject(Body.class);
    final Response saml2Response = buildSaml2Response(casAssertion, query, service, adaptor, request, SAMLConstants.SAML2_POST_BINDING_URI);
    body.getUnknownXMLObjects().add(saml2Response);
    final Envelope envelope = newSoapObject(Envelope.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    SamlUtils.logSamlObject(this.configBean, envelope);
    return encodeFinalResponse(request, response, service, adaptor, envelope, binding, authnRequest, casAssertion);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.opensaml.saml.saml2.core.Response) Header(org.opensaml.soap.soap11.Header) AttributeQuery(org.opensaml.saml.saml2.core.AttributeQuery) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Aggregations

Body (org.opensaml.soap.soap11.Body)11 Envelope (org.opensaml.soap.soap11.Envelope)11 Header (org.opensaml.soap.soap11.Header)11 lombok.val (lombok.val)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 SOAPObjectBuilder (org.opensaml.soap.common.SOAPObjectBuilder)3 FaultString (org.opensaml.soap.soap11.FaultString)3 Header (okhttp3.internal.http2.Header)2 Order (org.junit.jupiter.api.Order)2 Test (org.junit.jupiter.api.Test)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 Response (org.opensaml.saml.saml2.ecp.Response)2 Fault (org.opensaml.soap.soap11.Fault)2 FaultActor (org.opensaml.soap.soap11.FaultActor)2 FaultCode (org.opensaml.soap.soap11.FaultCode)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1