Search in sources :

Example 1 with SaxSoapParserImpl

use of ee.ria.xroad.common.message.SaxSoapParserImpl in project X-Road by nordic-institute.

the class ProxyMessageDecoder method handleSignature.

private void handleSignature(BodyDescriptor bd, InputStream is) throws CodedException {
    try {
        LOG.trace("Looking for signature, got '{}'", bd.getMimeType());
        switch(bd.getMimeType() == null ? "" : bd.getMimeType().toLowerCase()) {
            case SIGNATURE_BDOC:
                // We got signature, just as expected.
                signature = new SignatureData(IOUtils.toString(is, UTF_8), signature.getHashChainResult(), signature.getHashChain());
                callback.signature(signature);
                break;
            case TEXT_XML:
                LOG.debug("Got fault instead of signature");
                // It seems that signing failed and the other
                // party sent SOAP fault instead of signature.
                // Parse the fault message.
                Soap soap = new SaxSoapParserImpl().parse(bd.getMimeType(), is);
                if (soap instanceof SoapFault) {
                    callback.fault((SoapFault) soap);
                    // The nextPart will be set to NONE
                    return;
                }
            // $FALL-THROUGH$ If not fault message, fall through to invalid message case.
            default:
                // the parsing is not interrupted.
                throw new CodedException(X_INVALID_CONTENT_TYPE, "Received invalid content type instead of signature: %s", bd.getMimeType());
        }
    } catch (Exception e) {
        throw translateException(e);
    }
}
Also used : SignatureData(ee.ria.xroad.common.signature.SignatureData) SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap) MimeException(org.apache.james.mime4j.MimeException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException)

Example 2 with SaxSoapParserImpl

use of ee.ria.xroad.common.message.SaxSoapParserImpl in project X-Road by nordic-institute.

the class ProxyMessageDecoder method handleSoap.

private void handleSoap(BodyDescriptor bd, InputStream is, String partContentType, Map<String, String> soapPartHeaders) {
    try {
        LOG.trace("Looking for SOAP, got: {}, {}", bd.getMimeType(), bd.getCharset());
        switch(bd.getMimeType().toLowerCase()) {
            case TEXT_XML:
            case XOP_XML:
                break;
            default:
                throw new CodedException(X_INVALID_CONTENT_TYPE, "Invalid content type for SOAP message: %s", bd.getMimeType());
        }
        Soap soap = new SaxSoapParserImpl().parse(partContentType, is);
        if (soap instanceof SoapFault) {
            callback.fault((SoapFault) soap);
        } else {
            callback.soap((SoapMessageImpl) soap, soapPartHeaders);
            verifier.addMessagePart(getHashAlgoId(), (SoapMessageImpl) soap);
        }
    } catch (Exception ex) {
        throw translateException(ex);
    }
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap) MimeException(org.apache.james.mime4j.MimeException) ErrorCodes.translateException(ee.ria.xroad.common.ErrorCodes.translateException) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException)

Example 3 with SaxSoapParserImpl

use of ee.ria.xroad.common.message.SaxSoapParserImpl in project X-Road by nordic-institute.

the class AsicContainerVerifier method getSigner.

private static ClientId getSigner(String messageXml) {
    final byte[] messageBytes = messageXml.getBytes(UTF_8);
    try {
        Soap soap = new SaxSoapParserImpl().parse(MimeTypes.TEXT_XML_UTF8, new ByteArrayInputStream(messageBytes));
        if (!(soap instanceof SoapMessageImpl)) {
            throw new RuntimeException("Unexpected SOAP: " + soap.getClass());
        }
        SoapMessageImpl msg = (SoapMessageImpl) soap;
        return msg.isRequest() ? msg.getClient() : msg.getService().getClientId();
    } catch (CodedException ce) {
        if (X_INVALID_SOAP.equals(ce.getFaultCode())) {
            try {
                final RestMessage restMessage = RestMessage.of(messageBytes);
                return restMessage.getSender();
            } catch (Exception e) {
                throw new RuntimeException("Invalid message", e);
            }
        }
    }
    return null;
}
Also used : CodedException(ee.ria.xroad.common.CodedException) ByteArrayInputStream(java.io.ByteArrayInputStream) RestMessage(ee.ria.xroad.common.message.RestMessage) SoapMessageImpl(ee.ria.xroad.common.message.SoapMessageImpl) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap) ResourceResolverException(org.apache.xml.security.utils.resolver.ResourceResolverException) IOException(java.io.IOException) CodedException(ee.ria.xroad.common.CodedException)

Example 4 with SaxSoapParserImpl

use of ee.ria.xroad.common.message.SaxSoapParserImpl in project X-Road by nordic-institute.

the class ProxyMessageDecoder method parseFault.

private void parseFault(InputStream is) throws Exception {
    Soap soap = new SaxSoapParserImpl().parse(MimeTypes.TEXT_XML_UTF8, is);
    if (!(soap instanceof SoapFault)) {
        throw new CodedException(X_INVALID_MESSAGE, "Expected fault message, but got reqular SOAP message");
    }
    callback.fault((SoapFault) soap);
}
Also used : SoapFault(ee.ria.xroad.common.message.SoapFault) CodedException(ee.ria.xroad.common.CodedException) SaxSoapParserImpl(ee.ria.xroad.common.message.SaxSoapParserImpl) Soap(ee.ria.xroad.common.message.Soap)

Aggregations

CodedException (ee.ria.xroad.common.CodedException)4 SaxSoapParserImpl (ee.ria.xroad.common.message.SaxSoapParserImpl)4 Soap (ee.ria.xroad.common.message.Soap)4 SoapFault (ee.ria.xroad.common.message.SoapFault)3 IOException (java.io.IOException)3 ErrorCodes.translateException (ee.ria.xroad.common.ErrorCodes.translateException)2 MimeException (org.apache.james.mime4j.MimeException)2 RestMessage (ee.ria.xroad.common.message.RestMessage)1 SoapMessageImpl (ee.ria.xroad.common.message.SoapMessageImpl)1 SignatureData (ee.ria.xroad.common.signature.SignatureData)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ResourceResolverException (org.apache.xml.security.utils.resolver.ResourceResolverException)1