Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / binding / MessageDecoder.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/MessageDecoder.h
19  *
20  * Interface to SAML protocol binding message decoders.
21  */
22
23 #ifndef __saml_decoder_h__
24 #define __saml_decoder_h__
25
26 #include <saml/base.h>
27
28 #include <vector>
29 #include <xercesc/util/XMLUniDefs.hpp>
30
31 namespace xmltooling {
32     class XMLTOOL_API GenericRequest;
33     class XMLTOOL_API XMLObject;
34 };
35
36 namespace opensaml {
37
38     class SAML_API SAMLArtifact;
39     class SAML_API SecurityPolicy;
40     namespace saml1p {
41         class SAML_API Response;
42     };
43     namespace saml2p {
44         class SAML_API SAML2Artifact;
45         class SAML_API ArtifactResponse;
46     };
47     namespace saml2md {
48         class SAML_API MetadataProvider;
49         class SAML_API IDPSSODescriptor;
50         class SAML_API RoleDescriptor;
51         class SAML_API SSODescriptorType;
52     };
53
54     /**
55      * Interface to SAML protocol binding message decoders.
56      */
57     class SAML_API MessageDecoder
58     {
59         MAKE_NONCOPYABLE(MessageDecoder);
60     public:
61         virtual ~MessageDecoder();
62
63         /**
64          * Indicates whether a web browser or similar user agent delivered the message.
65          *
66          * @return true iff the message was delivered by a user agent
67          */
68         virtual bool isUserAgentPresent() const;
69
70         /**
71          * Interface to caller-supplied artifact resolution mechanism.
72          *
73          * Resolving artifacts requires internally performing a SOAP-based
74          * call to the artifact source, usually in a mutually authenticated fashion.
75          * The potential options vary widely, so the work is encapsulated by this
76          * interface, though of course other library facilities may be used.
77          *
78          * <p>A MessageDecoder implementation will invoke the supplied interface
79          * when it requires an artifact be resolved.
80          */
81         class SAML_API ArtifactResolver {
82             MAKE_NONCOPYABLE(ArtifactResolver);
83         protected:
84             ArtifactResolver();
85
86         public:
87             virtual ~ArtifactResolver();
88
89             /**
90              * Resolves one or more SAML 1.x artifacts into a response containing a set of
91              * resolved Assertions. The caller is responsible for the resulting Response.
92              * The supplied SecurityPolicy is used to access caller-supplied infrastructure
93              * and to pass back the result of authenticating the resolution process.
94              *
95              * @param artifacts         one or more SAML 1.x artifacts
96              * @param idpDescriptor     reference to IdP role of artifact issuer
97              * @param policy            reference to policy containing rules, MetadataProvider, TrustEngine, etc.
98              * @return the corresponding SAML Assertions wrapped in a Response.
99              */
100             virtual saml1p::Response* resolve(
101                 const std::vector<SAMLArtifact*>& artifacts,
102                 const saml2md::IDPSSODescriptor& idpDescriptor,
103                 SecurityPolicy& policy
104                 ) const=0;
105
106             /**
107              * Resolves a SAML 2.0 artifact into the corresponding SAML protocol message.
108              * The caller is responsible for the resulting ArtifactResponse message.
109              * The supplied SecurityPolicy is used to access caller-supplied infrastructure
110              * and to pass back the result of authenticating the resolution process.
111              *
112              * @param artifact          reference to a SAML 2.0 artifact
113              * @param ssoDescriptor     reference to SSO role of artifact issuer (may be SP or IdP)
114              * @param policy            reference to policy containing rules, MetadataProvider, TrustEngine, etc.
115              * @return the corresponding SAML protocol message or NULL
116              */
117             virtual saml2p::ArtifactResponse* resolve(
118                 const saml2p::SAML2Artifact& artifact,
119                 const saml2md::SSODescriptorType& ssoDescriptor,
120                 SecurityPolicy& policy
121                 ) const=0;
122
123             /**
124              * Returns true iff the metadata provided includes a supported artifact resolution service.
125              *
126              * @param ssoDescriptor reference to SSO role of artifact issuer (may be SP or IdP)
127              * @return true iff the artifact issuer offers endpoints supported by this resolver
128              */
129             virtual bool isSupported(const saml2md::SSODescriptorType& ssoDescriptor) const;
130         };
131
132         /**
133          * Provides an ArtifactResolver implementation for the MessageDecoder to use.
134          * The implementation's lifetime must be longer than the lifetime of this object.
135          * This method must be externally synchronized.
136          *
137          * @param artifactResolver   an ArtifactResolver implementation to use
138          */
139         void setArtifactResolver(const ArtifactResolver* artifactResolver);
140
141         /**
142          * Decodes a transport request into a SAML protocol message, and evaluates it
143          * against a supplied SecurityPolicy. If the transport request does not contain
144          * the information necessary to decode the request, NULL will be returned.
145          * Errors during the decoding process will be raised as exceptions.
146          *
147          * <p>Artifact-based bindings require an ArtifactResolver be set to
148          * turn an artifact into the corresponding message.
149          *
150          * @param relayState        will be set to RelayState/TARGET value accompanying message
151          * @param genericRequest    reference to interface for accessing transport request to decode
152          * @param policy            reference to policy containing rules, MetadataProvider, TrustEngine, etc.
153          * @return  the decoded message, or NULL if the decoder did not recognize the request content
154          */
155         virtual xmltooling::XMLObject* decode(
156             std::string& relayState,
157             const xmltooling::GenericRequest& genericRequest,
158             SecurityPolicy& policy
159             ) const=0;
160
161     protected:
162         MessageDecoder();
163
164         /** Pointer to an ArtifactResolver implementation. */
165         const ArtifactResolver* m_artifactResolver;
166
167         /**
168          * Extracts policy-relevant message details.
169          *
170          * @param message   the incoming message
171          * @param request   the protocol request
172          * @param protocol  the protocol family in use
173          * @param policy    SecurityPolicy to provide various components and track message data
174          */
175         virtual void extractMessageDetails (
176             const xmltooling::XMLObject& message,
177             const xmltooling::GenericRequest& request,
178             const XMLCh* protocol,
179             SecurityPolicy& policy
180             ) const=0;
181     };
182
183     /**
184      * Registers MessageDecoder plugins into the runtime.
185      */
186     void SAML_API registerMessageDecoders();
187 };
188
189 #endif /* __saml_decoder_h__ */