433e44adc47dfab8bfdacf7cc7ba3d54ed8e5314
[shibboleth/cpp-opensaml.git] / saml / binding / SOAPClient.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 /**
18  * @file saml/binding/SOAPClient.h
19  * 
20  * Specialized SOAPClient for SAML SOAP bindings.
21  */
22
23 #ifndef __saml_soap11client_h__
24 #define __saml_soap11client_h__
25
26 #include <saml/binding/SecurityPolicy.h>
27 #include <xmltooling/soap/SOAPClient.h>
28
29 namespace opensaml {
30
31     /**
32      * Specialized SOAPClient for SAML SOAP bindings.
33      */
34     class SAML_API SOAPClient : public soap11::SOAPClient
35     {
36     public:
37         /**
38          * Creates a SOAP client instance with a particular SecurityPolicy.
39          * 
40          * @param policy        reference to SecurityPolicy to apply
41          * @param validating    controls schema validation
42          */
43         SOAPClient(SecurityPolicy& policy)
44             : soap11::SOAPClient(policy.getValidating()), m_policy(policy), m_force(true), m_peer(NULL) {}
45         
46         virtual ~SOAPClient() {}
47
48         /**
49          * Controls whether to force transport/peer authentication via an X509TrustEngine.
50          * 
51          * <p>Only makes sense if an X509TrustEngine is supplied by the SecurityPolicy. 
52          * 
53          * @param force  true iff the client should refuse to communicate without this protection
54          */
55         void forceTransportAuthentication(bool force=true) {
56             m_force = force;
57         }
58         
59         /**
60          * Override prepares the SecurityPolicy by clearing Issuer identity, in case the policy
61          * is reused.
62          * 
63          * @param env       SOAP envelope to send
64          * @param peer      peer to send message to, expressed in TrustEngine terms
65          * @param endpoint  URL of endpoint to recieve message
66          */
67         void send(const soap11::Envelope& env, const xmltooling::KeyInfoSource& peer, const char* endpoint);
68         
69         /**
70          * Override applies SecurityPolicy to envelope before returning it.
71          * 
72          * @return response envelope after SecurityPolicy has been applied
73          */
74         soap11::Envelope* receive();
75         
76         void reset();
77
78         /**
79          * Returns the SecurityPolicy supplied to the client.
80          *
81          * @return  the associated SecurityPolicy
82          */
83         SecurityPolicy& getPolicy() const {
84             return m_policy;
85         }
86
87     protected:
88         /**
89          * Override prepares transport by assigning an X509TrustEngine to it, if one is
90          * attached to the policy.
91          * 
92          * @param transport reference to transport layer
93          */
94         void prepareTransport(xmltooling::SOAPTransport& transport);
95         
96         /** Reference to security policy to apply. */
97         SecurityPolicy& m_policy;
98         
99         /** Flag controlling whether transport/peer authn is mandatory. */
100         bool m_force;
101     
102         /** Metadata-based peer identity. */        
103         const saml2md::RoleDescriptor* m_peer;
104     };
105
106 };
107
108 #endif /* __saml_soap11client_h__ */