Search in sources :

Example 1 with Envelope

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

the class SamlProfileSamlSoap11FaultResponseBuilder method build.

@Override
public Envelope build(final AuthnRequest authnRequest, final HttpServletRequest request, final HttpServletResponse response, final org.jasig.cas.client.validation.Assertion casAssertion, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) throws SamlException {
    final Header header = newSoapObject(Header.class);
    final Body body = newSoapObject(Body.class);
    final Fault fault = newSoapObject(Fault.class);
    final FaultCode faultCode = newSoapObject(FaultCode.class);
    faultCode.setValue(FaultCode.SERVER);
    fault.setCode(faultCode);
    final FaultActor faultActor = newSoapObject(FaultActor.class);
    faultActor.setValue(SamlIdPUtils.getIssuerFromSamlRequest(authnRequest));
    fault.setActor(faultActor);
    final FaultString faultString = newSoapObject(FaultString.class);
    faultString.setValue(request.getAttribute(SamlIdPConstants.REQUEST_ATTRIBUTE_ERROR).toString());
    fault.setMessage(faultString);
    body.getUnknownXMLObjects().add(fault);
    final Envelope envelope = newSoapObject(Envelope.class);
    envelope.setHeader(header);
    envelope.setBody(body);
    encodeFinalResponse(request, response, service, adaptor, envelope);
    return envelope;
}
Also used : FaultCode(org.opensaml.soap.soap11.FaultCode) FaultActor(org.opensaml.soap.soap11.FaultActor) Header(org.opensaml.soap.soap11.Header) Fault(org.opensaml.soap.soap11.Fault) FaultString(org.opensaml.soap.soap11.FaultString) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 2 with Envelope

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

the class CasHttpSoap11Encoder method buildAndStoreSOAPMessage.

@Override
protected void buildAndStoreSOAPMessage(final XMLObject payload) {
    final XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
    final SOAPObjectBuilder<Envelope> envBuilder = (SOAPObjectBuilder<Envelope>) builderFactory.getBuilder(Envelope.DEFAULT_ELEMENT_NAME);
    final Envelope envelope = envBuilder.buildObject(SOAPConstants.SOAP11_NS, Envelope.DEFAULT_ELEMENT_LOCAL_NAME, OPENSAML_11_SOAP_NS_PREFIX);
    final SOAPObjectBuilder<Body> bodyBuilder = (SOAPObjectBuilder<Body>) builderFactory.getBuilder(Body.DEFAULT_ELEMENT_NAME);
    final Body 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 : SOAPObjectBuilder(org.opensaml.soap.common.SOAPObjectBuilder) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 3 with Envelope

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

the class ECPProfileHandlerController method handleEcpRequest.

/**
     * Handle ecp request.
     *
     * @param response    the response
     * @param request     the request
     * @param soapContext the soap context
     * @param credential  the credential
     */
protected void handleEcpRequest(final HttpServletResponse response, final HttpServletRequest request, final MessageContext soapContext, final Credential credential) {
    final Envelope envelope = soapContext.getSubcontext(SOAP11Context.class).getEnvelope();
    SamlUtils.logSamlObject(configBean, envelope);
    final AuthnRequest authnRequest = (AuthnRequest) soapContext.getMessage();
    final Pair<AuthnRequest, MessageContext> authenticationContext = Pair.of(authnRequest, soapContext);
    try {
        final Pair<SamlRegisteredService, SamlRegisteredServiceServiceProviderMetadataFacade> serviceRequest = verifySamlAuthenticationRequest(authenticationContext, request);
        final Authentication authentication = authenticateEcpRequest(credential, authenticationContext);
        buildSamlResponse(response, request, authenticationContext, buildEcpCasAssertion(authentication, serviceRequest.getKey()));
    } catch (final AuthenticationException e) {
        LOGGER.error(e.getMessage(), e);
        final String error = e.getHandlerErrors().values().stream().map(Class::getSimpleName).collect(Collectors.joining(","));
        buildEcpFaultResponse(response, request, Pair.of(authnRequest, error));
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        buildEcpFaultResponse(response, request, Pair.of(authnRequest, e.getMessage()));
    }
}
Also used : AuthenticationException(org.apereo.cas.authentication.AuthenticationException) SamlRegisteredServiceServiceProviderMetadataFacade(org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade) Envelope(org.opensaml.soap.soap11.Envelope) AuthenticationException(org.apereo.cas.authentication.AuthenticationException) SOAP11Context(org.opensaml.soap.messaging.context.SOAP11Context) AuthnRequest(org.opensaml.saml.saml2.core.AuthnRequest) Authentication(org.apereo.cas.authentication.Authentication) SamlRegisteredService(org.apereo.cas.support.saml.services.SamlRegisteredService) MessageContext(org.opensaml.messaging.context.MessageContext)

Example 4 with Envelope

use of org.opensaml.soap.soap11.Envelope in project ddf by codice.

the class SamlProtocol method createSoapMessage.

public static Envelope createSoapMessage(SignableSAMLObject signableSAMLObject) {
    Body body = soapBodyBuilder.buildObject();
    body.getUnknownXMLObjects().add(signableSAMLObject);
    Envelope envelope = soapEnvelopeBuilder.buildObject();
    envelope.setBody(body);
    Header header = soapHeaderBuilder.buildObject();
    envelope.setHeader(header);
    return envelope;
}
Also used : Header(org.opensaml.soap.soap11.Header) Envelope(org.opensaml.soap.soap11.Envelope) Body(org.opensaml.soap.soap11.Body)

Example 5 with Envelope

use of org.opensaml.soap.soap11.Envelope in project ddf by codice.

the class AttributeQueryClient method createSoapMessage.

/**
     * Creates a SOAP message of the AttributeQuery request.
     *
     * @param attributeQuery is added to the SOAP message
     * @return soapElement is the Element of the SOAP message
     */
private Element createSoapMessage(AttributeQuery attributeQuery) throws AttributeQueryException {
    LOGGER.debug("Creating SOAP message from the SAML AttributeQuery.");
    Envelope envelope = SamlProtocol.createSoapMessage(attributeQuery);
    LOGGER.debug("SOAP message from the SAML AttributeQuery created.");
    try {
        return new EnvelopeMarshaller().marshall(envelope);
    } catch (MarshallingException e) {
        throw new AttributeQueryException("Cannot marshall SOAP object to an Element.", e);
    }
}
Also used : EnvelopeMarshaller(org.opensaml.soap.soap11.impl.EnvelopeMarshaller) MarshallingException(org.opensaml.core.xml.io.MarshallingException) Envelope(org.opensaml.soap.soap11.Envelope)

Aggregations

Envelope (org.opensaml.soap.soap11.Envelope)6 Body (org.opensaml.soap.soap11.Body)4 Header (org.opensaml.soap.soap11.Header)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Authentication (org.apereo.cas.authentication.Authentication)1 AuthenticationException (org.apereo.cas.authentication.AuthenticationException)1 SamlRegisteredService (org.apereo.cas.support.saml.services.SamlRegisteredService)1 SamlRegisteredServiceServiceProviderMetadataFacade (org.apereo.cas.support.saml.services.idp.metadata.SamlRegisteredServiceServiceProviderMetadataFacade)1 XMLObjectBuilderFactory (org.opensaml.core.xml.XMLObjectBuilderFactory)1 MarshallingException (org.opensaml.core.xml.io.MarshallingException)1 MessageContext (org.opensaml.messaging.context.MessageContext)1 AuthnRequest (org.opensaml.saml.saml2.core.AuthnRequest)1 Response (org.opensaml.saml.saml2.ecp.Response)1 SOAPObjectBuilder (org.opensaml.soap.common.SOAPObjectBuilder)1 SOAP11Context (org.opensaml.soap.messaging.context.SOAP11Context)1 Fault (org.opensaml.soap.soap11.Fault)1 FaultActor (org.opensaml.soap.soap11.FaultActor)1 FaultCode (org.opensaml.soap.soap11.FaultCode)1 FaultString (org.opensaml.soap.soap11.FaultString)1 EnvelopeMarshaller (org.opensaml.soap.soap11.impl.EnvelopeMarshaller)1