Moved key/cred resolution classes out of xmlsig namespace.
[shibboleth/cpp-xmltooling.git] / xmltooling / soap / SOAPTransport.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 xmltooling/soap/SOAPTransport.h
19  * 
20  * Encapsulates a transport layer protocol for sending/receiving messages.
21  */
22
23 #ifndef __xmltooling_soaptrans_h__
24 #define __xmltooling_soaptrans_h__
25
26 #include <xmltooling/base.h>
27 #include <iostream>
28
29 namespace xmlsignature {
30     class XMLTOOL_API CredentialResolver;
31     class XMLTOOL_API KeyResolver;
32 };
33
34 namespace xmltooling {
35     
36     class XMLTOOL_API X509TrustEngine;
37     
38     /**
39      * Encapsulates a transport layer protocol for sending/receiving messages.
40      * 
41      * Most of the methods are const, meaning they don't affect the transport
42      * layer until the data is sent.
43      */
44     class XMLTOOL_API SOAPTransport
45     {
46         MAKE_NONCOPYABLE(SOAPTransport);
47     protected:
48         SOAPTransport() {}
49     public:
50         virtual ~SOAPTransport() {}
51         
52         /**
53          * Indicates whether transport provides confidentiality.
54          * 
55          * @return  true iff transport layer provides confidentiality
56          */
57         virtual bool isConfidential() const=0;
58         
59         /**
60          * Sets the connection timeout.
61          * 
62          * @param timeout  time to wait for connection to server in seconds, or -1 for no timeout
63          * @return  true iff the transport supports connection timeouts
64          */
65         virtual bool setConnectTimeout(long timeout)=0;
66         
67         /**
68          * Sets the request timeout.
69          * 
70          * @param timeout  time to wait for a response in seconds, or -1 for no timeout
71          * @return  true iff the transport supports request/response timeouts
72          */
73         virtual bool setTimeout(long timeout)=0;
74         
75         /**
76          * Common types of transport authentication that may be supported.
77          */
78         enum transport_auth_t {
79             transport_auth_none = 0,
80             transport_auth_basic = 1,
81             transport_auth_digest = 2,
82             transport_auth_ntlm = 3,
83             transport_auth_gss = 4
84         };
85         
86         /**
87          * Sets a particular form of transport authentication and credentials.
88          * 
89          * @param authType  type of transport authentication to use
90          * @param username  username for transport authentication
91          * @param password  simple password/credential for transport authentication
92          * @return  true iff the transport supports the indicated form of authentication
93          */
94         virtual bool setAuth(transport_auth_t authType, const char* username=NULL, const char* password=NULL)=0;
95
96 #ifndef XMLTOOLING_NO_XMLSEC
97         /**
98          * Provides a CredentialResolver to the transport to supply transport credentials.
99          * The lifetime of the resolver must be longer than the lifetime of this object.
100          * 
101          * <p>The CredentialResolver <strong>MUST</strong> be locked by the caller. 
102          * 
103          * @param credResolver  a locked CredentialResolver instance, or NULL
104          * @return true iff the transport supports the use of a CredentialResolver
105          */
106         virtual bool setCredentialResolver(const CredentialResolver* credResolver)=0;
107
108         /**
109          * Provides a TrustEngine to the transport to authenticate the transport peer.
110          * The lifetime of the engine must be longer than the lifetime of this object.
111          * 
112          * @param trustEngine   a TrustEngine instance, or NULL
113          * @param mandatory     flag controls whether message is sent at all if the
114          *                      transport isn't authenticated using the TrustEngine
115          * @param keyResolver   optional externally supplied KeyResolver, or NULL
116          * @return true iff the transport supports the use of a TrustEngine
117          */
118         virtual bool setTrustEngine(
119             const X509TrustEngine* trustEngine,
120             bool mandatory=true,
121             const KeyResolver* keyResolver=NULL
122             )=0;
123 #endif
124
125         /**
126          * Sends a stream of data over the transport. The function may return without
127          * having received any data, depending on the nature of the transport.
128          * 
129          * @param in    input stream to send
130          */        
131         virtual void send(std::istream& in)=0;
132         
133         /**
134          * Returns reference to response stream.  The resulting stream must be
135          * checked directly to determine whether data is available.
136          * 
137          * @return  reference to a stream containing the response, if any
138          */
139         virtual std::istream& receive()=0;
140         
141         /**
142          * Returns result of authenticating transport peer.
143          * 
144          * @return true iff TrustEngine or other mechanism successfully authenticated the peer
145          */
146         virtual bool isSecure() const=0;
147
148         /**
149          * Returns the MIME type of the response, if any.
150          * 
151          * @return  MIME type of response, or an empty string
152          */
153         virtual std::string getContentType() const=0;
154     };
155
156     /**
157      * Registers SOAPTransport classes into the runtime.
158      */
159     void XMLTOOL_API registerSOAPTransports();
160     
161     /**
162      * Notifies transport infrastructure to initialize. 
163      */
164     void XMLTOOL_API initSOAPTransports();
165     
166     /**
167      * Notifies transport infrastructure to shutdown. 
168      */
169     void XMLTOOL_API termSOAPTransports();
170
171 };
172
173 #endif /* __xmltooling_soaptrans_h__ */