2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 * @file saml/binding/MessageEncoder.h
\r
20 * Interface to SAML protocol binding message encoders.
\r
23 #ifndef __saml_encoder_h__
\r
24 #define __saml_encoder_h__
\r
26 #include <saml/base.h>
\r
30 #include <xmltooling/XMLObject.h>
\r
31 #include <xmltooling/signature/CredentialResolver.h>
\r
32 #include <xmltooling/util/StorageService.h>
\r
34 namespace opensaml {
\r
36 class SAML_API SAMLArtifact;
\r
38 class SAML_API SAML2Artifact;
\r
42 * Interface to SAML protocol binding message encoders.
\r
44 class SAML_API MessageEncoder
\r
46 MAKE_NONCOPYABLE(MessageEncoder);
\r
48 virtual ~MessageEncoder() {}
\r
51 * Interface to caller-supplied URL-encoding mechanism.
\r
53 * Since URL-encoding is not canonical, it's important that the same
\r
54 * encoder is used during some binding-specific signature operations.
\r
56 class SAML_API URLEncoder {
\r
57 MAKE_NONCOPYABLE(URLEncoder);
\r
61 virtual ~URLEncoder() {}
\r
64 * Produce a URL-safe but equivalent version of the input string.
\r
66 * @param s input string to encode
\r
67 * @return a string object containing the result of encoding the input
\r
69 virtual std::string encode(const char* s) const=0;
\r
73 * Provides a URLEncoder implementation for the MessageEncoder to use.
\r
74 * The implementation's lifetime must be longer than the lifetime of this object.
\r
75 * This method must be externally synchronized.
\r
77 * @param urlEncoder a URLEncoder implementation to use
\r
79 void setURLEncoder(const URLEncoder* urlEncoder) {
\r
80 m_urlEncoder = urlEncoder;
\r
84 * Interface to caller-supplied artifact generation mechanism.
\r
86 * Generating an artifact for storage and retrieval requires knowledge of
\r
87 * the sender's SourceID (or sometimes SourceLocation), and the relying party's
\r
88 * preferred artifact type. This information can be supplied using whatever
\r
89 * configuration or defaults are appropriate for the SAML application.
\r
90 * An ArtifactMap implementation will invoke the supplied generator interface
\r
91 * when it requires an artifact be created.
\r
93 class SAML_API ArtifactGenerator {
\r
94 MAKE_NONCOPYABLE(ArtifactGenerator);
\r
96 ArtifactGenerator() {}
\r
98 virtual ~ArtifactGenerator() {}
\r
101 * Generate a SAML 1.x artifact suitable for consumption by the relying party.
\r
103 * @param relyingParty the party that will recieve the artifact
\r
104 * @return a SAML 1.x artifact with a random assertion handle
\r
106 virtual SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const=0;
\r
109 * Generate a SAML 2.0 artifact suitable for consumption by the relying party.
\r
111 * @param relyingParty the party that will recieve the artifact
\r
112 * @return a SAML 2.0 artifact with a random message handle
\r
114 virtual saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const=0;
\r
118 * Provides an ArtifactGenerator implementation for the MessageEncoder to use.
\r
119 * The implementation's lifetime must be longer than the lifetime of this object.
\r
120 * This method must be externally synchronized.
\r
122 * @param artifactGenerator an ArtifactGenerator implementation to use
\r
124 void setArtifactGenerator(ArtifactGenerator* artifactGenerator) {
\r
125 m_artifactGenerator = artifactGenerator;
\r
129 * Encodes an XML object/message into a set of binding-specific data "fields".
\r
130 * The XML content cannot have a parent object, and any existing references to
\r
131 * the content will be invalidated if the encode method returns successfully.
\r
133 * If a CredentialResolver is supplied, the message is also signed in a
\r
134 * binding-specific manner. The CredentialResolver <strong>MUST</strong>
\r
135 * be locked by the caller.
\r
137 * <p>An embedded URLEncoder instance may be required by some bindings
\r
138 * in order to produce predictable signature input.
\r
140 * <p>Artifact-based bindings require an ArtifactGenerator be set to
\r
141 * produce an artifact suitable for the intended recipient.
\r
143 * <p>Note that the name/value pairs resulting from the encoding operation are
\r
144 * <strong>NOT</strong> URL-encoded or otherwise transformed. It is the caller's
\r
145 * responsibility to apply any necessary encoding when preparing the data for
\r
148 * @param outputFields name/value pairs containing the results of encoding the message
\r
149 * @param xmlObject XML object/message to encode
\r
150 * @param recipientID optional entityID of message recipient
\r
151 * @param relayState optional RelayState value to accompany message
\r
152 * @param credResolver optional CredentialResolver instance to supply signing material
\r
153 * @param sigAlgorithm optional signature algorithm identifier
\r
155 virtual void encode(
\r
156 std::map<std::string,std::string>& outputFields,
\r
157 xmltooling::XMLObject* xmlObject,
\r
158 const char* recipientID=NULL,
\r
159 const char* relayState=NULL,
\r
160 const xmlsignature::CredentialResolver* credResolver=NULL,
\r
161 const XMLCh* sigAlgorithm=NULL
\r
165 MessageEncoder() : m_urlEncoder(NULL), m_artifactGenerator(NULL) {}
\r
167 /** Pointer to a URLEncoder implementation. */
\r
168 const URLEncoder* m_urlEncoder;
\r
170 /** Pointer to an ArtifactGenerator implementation. */
\r
171 const ArtifactGenerator* m_artifactGenerator;
\r
175 * Registers MessageEncoder plugins into the runtime.
\r
177 void SAML_API registerMessageEncoders();
\r
179 /** MessageEncoder for SAML 1.x Browser/Artifact "binding" (really part of profile) */
\r
180 #define SAML1_ARTIFACT_ENCODER "urn:oasis:names:tc:SAML:1.0:profiles:artifact-01"
\r
182 /** MessageEncoder for SAML 1.x Browser/POST "binding" (really part of profile) */
\r
183 #define SAML1_POST_ENCODER "urn:oasis:names:tc:SAML:1.0:profiles:browser-post"
\r
186 #endif /* __saml_encoder_h__ */
\r