Search in sources :

Example 1 with SOAPObjectBuilder

use of org.opensaml.soap.common.SOAPObjectBuilder in project cas by apereo.

the class AbstractSamlObjectBuilder method newSoapObject.

/**
 * New soap object t.
 *
 * @param <T>        the type parameter
 * @param objectType the object type
 * @return the t
 */
@SneakyThrows
public <T extends SOAPObject> T newSoapObject(final Class<T> objectType) {
    final QName qName = getSamlObjectQName(objectType);
    final SOAPObjectBuilder<T> builder = (SOAPObjectBuilder<T>) XMLObjectProviderRegistrySupport.getBuilderFactory().getBuilder(qName);
    if (builder == null) {
        throw new IllegalStateException("No SAML object builder is registered for class " + objectType.getName());
    }
    return objectType.cast(builder.buildObject(qName));
}
Also used : SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder) QName(javax.xml.namespace.QName) SneakyThrows(lombok.SneakyThrows)

Example 2 with SOAPObjectBuilder

use of org.opensaml.soap.common.SOAPObjectBuilder in project cas by apereo.

the class CasHttpSoap11Encoder method buildAndStoreSOAPMessage.

@Override
protected void buildAndStoreSOAPMessage(final XMLObject payload) {
    val builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
    val envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    val envelope = envBuilder.buildObject(SOAPConstants.SOAP11_NS, Envelope.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX);
    val bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
    val body = bodyBuilder.buildObject(SOAPConstants.SOAP11_NS, Body.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX);
    if (!body.getUnknownXMLObjects().isEmpty()) {
        LOGGER.warn("Existing SOAP Envelope Body already contained children");
    }
    body.getUnknownXMLObjects().add(payload);
    envelope.setBody(body);
    this.storeSOAPEnvelope(envelope);
}
Also used : lombok.val(lombok.val) SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder)

Example 3 with SOAPObjectBuilder

use of org.opensaml.soap.common.SOAPObjectBuilder 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 4 with SOAPObjectBuilder

use of org.opensaml.soap.common.SOAPObjectBuilder in project cas by apereo.

the class ECPSamlIdPProfileHandlerControllerTests method getEnvelope.

private Envelope getEnvelope(final String entityId) {
    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();
    body.getUnknownXMLObjects().add(getAuthnRequest(entityId));
    envelope.setBody(body);
    return envelope;
}
Also used : lombok.val(lombok.val) SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder) Header(org.opensaml.soap.soap11.Header) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 5 with SOAPObjectBuilder

use of org.opensaml.soap.common.SOAPObjectBuilder in project cas by apereo.

the class SamlIdPSaml1ArtifactResolutionProfileHandlerControllerTests method verifyOK.

@Test
@Order(1)
public void verifyOK() 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));
    val ticket = samlArtifactTicketFactory.create("https://cassp.example.org", CoreAuthenticationTestUtils.getAuthentication(), new MockTicketGrantingTicket("casuser"), "https://cas.example.org", "https://cassp.example.org", artifactResolve);
    ticketRegistry.addTicket(ticket);
    controller.handlePostRequest(response, request);
    assertEquals(HttpStatus.SC_OK, response.getStatus());
}
Also used : lombok.val(lombok.val) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) 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)

Aggregations

SOAPObjectBuilder (org.opensaml.soap.common.SOAPObjectBuilder)6 lombok.val (lombok.val)5 Body (org.opensaml.soap.soap11.Body)3 Envelope (org.opensaml.soap.soap11.Envelope)3 Header (org.opensaml.soap.soap11.Header)3 Order (org.junit.jupiter.api.Order)2 Test (org.junit.jupiter.api.Test)2 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)2 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 QName (javax.xml.namespace.QName)1 SneakyThrows (lombok.SneakyThrows)1 MockTicketGrantingTicket (org.apereo.cas.mock.MockTicketGrantingTicket)1