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