Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / binding / SOAPClient.h
1 /*
2  *  Copyright 2001-2009 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/saml2/metadata/MetadataCredentialCriteria.h>
27
28 #include <xmltooling/soap/SOAPClient.h>
29
30 namespace opensaml {
31
32     class SAML_API SecurityPolicy;
33
34     /**
35      * Specialized SOAPClient for SAML SOAP bindings.
36      */
37     class SAML_API SOAPClient : public soap11::SOAPClient
38     {
39     public:
40         /**
41          * Creates a SOAP client instance with a particular SecurityPolicy.
42          * 
43          * @param policy        reference to SecurityPolicy to apply
44          */
45         SOAPClient(SecurityPolicy& policy);
46         
47         virtual ~SOAPClient() {}
48
49         /**
50          * Controls whether to force transport/peer authentication via an X509TrustEngine.
51          * 
52          * <p>Only makes sense if an X509TrustEngine is supplied by the SecurityPolicy. 
53          * 
54          * @param force  true iff the client should refuse to communicate without this protection
55          */
56         void forceTransportAuthentication(bool force=true) {
57             m_force = force;
58         }
59         
60         using soap11::SOAPClient::send;
61
62         /**
63          * SAML-specific method uses metadata to determine the peer name and prepare the
64          * transport layer with peer credential information. The SecurityPolicy is also reset,
65          * in case the policy is reused.
66          * 
67          * @param env       SOAP envelope to send
68          * @param from      identity of sending application
69          * @param to        peer to send message to, expressed in metadata criteria terms
70          * @param endpoint  URL of endpoint to recieve message
71          */
72         virtual void send(const soap11::Envelope& env, const char* from, saml2md::MetadataCredentialCriteria& to, const char* endpoint);
73         
74         /**
75          * Override applies SecurityPolicy to envelope before returning it.
76          * 
77          * @return response envelope after SecurityPolicy has been applied
78          */
79         soap11::Envelope* receive();
80         
81         void reset();
82
83         /**
84          * Returns the SecurityPolicy supplied to the client.
85          *
86          * @return  the associated SecurityPolicy
87          */
88         SecurityPolicy& getPolicy() const {
89             return m_policy;
90         }
91
92     protected:
93         /**
94          * Override prepares transport by assigning an X509TrustEngine to it, if one is
95          * attached to the policy.
96          * 
97          * @param transport reference to transport layer
98          */
99         void prepareTransport(xmltooling::SOAPTransport& transport);
100         
101         /** Reference to security policy to apply. */
102         SecurityPolicy& m_policy;
103         
104         /** Flag controlling whether transport/peer authn is mandatory. */
105         bool m_force;
106     
107         /** Metadata-based peer identity. */        
108         const saml2md::RoleDescriptor* m_peer;
109
110         /** Metadata-based CredentialCriteria for supplying credentials to TrustEngine. */
111         saml2md::MetadataCredentialCriteria* m_criteria;
112     };
113
114 };
115
116 #endif /* __saml_soap11client_h__ */