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));
}
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);
}
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()));
}
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;
}
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());
}
Aggregations