2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 * Implements SOAP 1.1 messaging over a transport.
24 #include "exceptions.h"
26 #include "binding/SOAPClient.h"
27 #include "saml2/metadata/Metadata.h"
28 #include "saml2/metadata/MetadataProvider.h"
30 #include <xmltooling/security/X509TrustEngine.h>
31 #include <xmltooling/soap/SOAP.h>
32 #include <xmltooling/soap/HTTPSOAPTransport.h>
34 using namespace opensaml::saml2;
35 using namespace opensaml::saml2md;
36 using namespace opensaml;
37 using namespace xmltooling;
40 void SOAPClient::send(const soap11::Envelope* env, const KeyInfoSource& peer, const char* endpoint)
43 m_policy.setIssuer(NULL);
44 m_policy.setIssuerMetadata(NULL);
46 m_peer = dynamic_cast<const RoleDescriptor*>(&peer);
48 soap11::SOAPClient::send(env, peer, endpoint);
51 void SOAPClient::prepareTransport(const xmltooling::SOAPTransport& transport)
53 const HTTPSOAPTransport* http = dynamic_cast<const HTTPSOAPTransport*>(&transport);
55 http->setRequestHeader("SOAPAction", "http://www.oasis-open.org/committees/security");
56 http->setRequestHeader("Xerces-C", XERCES_FULLVERSIONDOT);
57 http->setRequestHeader("XML-Security-C", XSEC_VERSION);
58 http->setRequestHeader("OpenSAML-C", OPENSAML_FULLVERSIONDOT);
61 const X509TrustEngine* engine = dynamic_cast<const X509TrustEngine*>(m_policy.getTrustEngine());
63 const MetadataProvider* metadata = m_policy.getMetadataProvider();
64 if (!transport.setTrustEngine(engine, m_force, metadata ? metadata->getKeyResolver() : NULL))
65 throw BindingException("Unable to install X509TrustEngine into SOAPTransport.");
69 soap11::Envelope* SOAPClient::receive()
71 auto_ptr<soap11::Envelope> env(soap11::SOAPClient::receive());
73 if (m_peer && m_transport->isSecure()) {
74 // Set issuer based on peer identity.
75 EntityDescriptor* parent = dynamic_cast<EntityDescriptor*>(m_peer->getParent());
77 Issuer* issuer = IssuerBuilder::buildIssuer();
78 issuer->setName(parent->getEntityID());
79 m_policy.setIssuer(issuer);
80 m_policy.setIssuerMetadata(m_peer);
81 m_policy.setSecure(true);
84 m_policy.evaluate(*(env.get()));