095a52301256d1847c929a22e1d84b2ee40d0bae
[shibboleth/cpp-opensaml.git] / saml / binding / MessageEncoder.h
1 /*
2  *  Copyright 2001-2010 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/MessageEncoder.h
19  * 
20  * Interface to SAML protocol binding message encoders. 
21  */
22
23 #ifndef __saml_encoder_h__
24 #define __saml_encoder_h__
25
26 #include <saml/base.h>
27
28 namespace xmltooling {
29     class XMLTOOL_API Credential;
30     class XMLTOOL_API GenericResponse;
31     class XMLTOOL_API XMLObject;
32 };
33
34 namespace opensaml {
35
36     class SAML_API SAMLArtifact;
37     namespace saml2p {
38         class SAML_API SAML2Artifact;
39     };
40     namespace saml2md {
41         class SAML_API EntityDescriptor;
42     };
43
44     /**
45      * Interface to SAML protocol binding message encoders.
46      */
47     class SAML_API MessageEncoder
48     {
49         MAKE_NONCOPYABLE(MessageEncoder);
50     public:
51         virtual ~MessageEncoder();
52
53         /**
54          * Indicates whether the encoding format requires that messages be as compact as possible.
55          *
56          * @return  true iff the encoding has size constraints
57          */
58         virtual bool isCompact() const;
59
60         /**
61          * Indicates whether a web browser or similar user agent will receive the message.
62          *
63          * @return true iff the message will be handled by a user agent
64          */
65         virtual bool isUserAgentPresent() const;
66
67         /**
68          * Returns identifier for the protocol family associated with the encoder.
69          *
70          * @return  a protocol family identifier, or nullptr
71          */
72         virtual const XMLCh* getProtocolFamily() const;
73
74         /**
75          * Interface to caller-supplied artifact generation mechanism.
76          * 
77          * Generating an artifact for storage and retrieval requires knowledge of
78          * the sender's SourceID (or sometimes SourceLocation), and the relying party's
79          * preferred artifact type. This information can be supplied using whatever
80          * configuration or defaults are appropriate for the SAML application.
81          * A MessageEncoder implementation will invoke the supplied generator interface
82          * when it requires an artifact be created.
83          */
84         class SAML_API ArtifactGenerator {
85             MAKE_NONCOPYABLE(ArtifactGenerator);
86         protected:
87             ArtifactGenerator();
88         public:
89             virtual ~ArtifactGenerator();
90             
91             /**
92              * Generate a SAML 1.x artifact suitable for consumption by the relying party.
93              * 
94              * @param relyingParty  the party that will recieve the artifact
95              * @return a SAML 1.x artifact with a random assertion handle
96              */
97             virtual SAMLArtifact* generateSAML1Artifact(const saml2md::EntityDescriptor* relyingParty) const=0;
98
99             /**
100              * Generate a SAML 2.0 artifact suitable for consumption by the relying party.
101              * 
102              * @param relyingParty  the party that will recieve the artifact
103              * @return a SAML 2.0 artifact with a random message handle
104              */
105             virtual saml2p::SAML2Artifact* generateSAML2Artifact(const saml2md::EntityDescriptor* relyingParty) const=0;
106         };
107
108         /**
109          * Encodes an XML object/message into a binding- and transport-specific response.
110          * The XML content cannot have a parent object, and any existing references to
111          * the content will be invalidated if the encode method returns successfully.
112          * 
113          * If a CredentialResolver is supplied, the message is also signed in a
114          * binding-specific manner. The CredentialResolver <strong>MUST</strong>
115          * be locked by the caller. 
116          * 
117          * <p>Artifact-based bindings require an ArtifactGenerator be set to
118          * produce an artifact suitable for the intended recipient.
119          * 
120          * @param genericResponse   reference to interface for sending transport response      
121          * @param xmlObject         XML message to encode
122          * @param destination       destination URL for message
123          * @param recipient         optional message recipient
124          * @param relayState        optional RelayState value to accompany message
125          * @param artifactGenerator optional interface for generation of artifacts
126          * @param credential        optional Credential to supply signing key
127          * @param signatureAlg      optional signature algorithm identifier
128          * @param digestAlg         optional reference digest algorithm identifier
129          */
130         virtual long encode(
131             xmltooling::GenericResponse& genericResponse,
132             xmltooling::XMLObject* xmlObject,
133             const char* destination,
134             const saml2md::EntityDescriptor* recipient=nullptr,
135             const char* relayState=nullptr,
136             const ArtifactGenerator* artifactGenerator=nullptr,
137             const xmltooling::Credential* credential=nullptr,
138             const XMLCh* signatureAlg=nullptr,
139             const XMLCh* digestAlg=nullptr
140             ) const=0;
141
142     protected:
143         MessageEncoder();
144     };
145
146     /**
147      * Registers MessageEncoder plugins into the runtime.
148      */
149     void SAML_API registerMessageEncoders();
150 };
151
152 #endif /* __saml_encoder_h__ */