2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file saml/binding/MessageEncoder.h
20 * Interface to SAML protocol binding message encoders.
23 #ifndef __saml_encoder_h__
24 #define __saml_encoder_h__
26 #include <saml/binding/GenericResponse.h>
29 #include <xmltooling/XMLObject.h>
30 #include <xmltooling/security/CredentialResolver.h>
34 class SAML_API SAMLArtifact;
36 class SAML_API SAML2Artifact;
40 * Interface to SAML protocol binding message encoders.
42 class SAML_API MessageEncoder
44 MAKE_NONCOPYABLE(MessageEncoder);
46 virtual ~MessageEncoder() {}
49 * Interface to caller-supplied artifact generation mechanism.
51 * Generating an artifact for storage and retrieval requires knowledge of
52 * the sender's SourceID (or sometimes SourceLocation), and the relying party's
53 * preferred artifact type. This information can be supplied using whatever
54 * configuration or defaults are appropriate for the SAML application.
55 * A MessageEncoder implementation will invoke the supplied generator interface
56 * when it requires an artifact be created.
58 class SAML_API ArtifactGenerator {
59 MAKE_NONCOPYABLE(ArtifactGenerator);
61 ArtifactGenerator() {}
63 virtual ~ArtifactGenerator() {}
66 * Generate a SAML 1.x artifact suitable for consumption by the relying party.
68 * @param relyingParty the party that will recieve the artifact
69 * @return a SAML 1.x artifact with a random assertion handle
71 virtual SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const=0;
74 * Generate a SAML 2.0 artifact suitable for consumption by the relying party.
76 * @param relyingParty the party that will recieve the artifact
77 * @return a SAML 2.0 artifact with a random message handle
79 virtual saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const=0;
83 * Provides an ArtifactGenerator implementation for the MessageEncoder to use.
84 * The implementation's lifetime must be longer than the lifetime of this object.
85 * This method must be externally synchronized.
87 * @param artifactGenerator an ArtifactGenerator implementation to use
89 void setArtifactGenerator(ArtifactGenerator* artifactGenerator) {
90 m_artifactGenerator = artifactGenerator;
94 * Encodes an XML object/message into a binding- and transport-specific response.
95 * The XML content cannot have a parent object, and any existing references to
96 * the content will be invalidated if the encode method returns successfully.
98 * If a CredentialResolver is supplied, the message is also signed in a
99 * binding-specific manner. The CredentialResolver <strong>MUST</strong>
100 * be locked by the caller.
102 * <p>Artifact-based bindings require an ArtifactGenerator be set to
103 * produce an artifact suitable for the intended recipient.
105 * @param genericResponse reference to interface for sending transport response
106 * @param xmlObject XML message to encode
107 * @param destination destination URL for message
108 * @param recipientID optional entityID of message recipient
109 * @param relayState optional RelayState value to accompany message
110 * @param credResolver optional CredentialResolver instance to supply signing material
111 * @param sigAlgorithm optional signature algorithm identifier
114 GenericResponse& genericResponse,
115 xmltooling::XMLObject* xmlObject,
116 const char* destination,
117 const char* recipientID=NULL,
118 const char* relayState=NULL,
119 const xmltooling::CredentialResolver* credResolver=NULL,
120 const XMLCh* sigAlgorithm=NULL
124 MessageEncoder() : m_artifactGenerator(NULL) {}
127 * Helper function to build a new XML Signature with KeyInfo, based
128 * on the supplied CredentialResolver.
130 * @param credResolver CredentialResolver instance to supply signing material
131 * @param sigAlgorithm optional signature algorithm identifier
132 * @return a new Signature object
134 xmlsignature::Signature* buildSignature(
135 const xmltooling::CredentialResolver* credResolver,
136 const XMLCh* sigAlgorithm=NULL
139 /** Pointer to an ArtifactGenerator implementation. */
140 const ArtifactGenerator* m_artifactGenerator;
144 * Registers MessageEncoder plugins into the runtime.
146 void SAML_API registerMessageEncoders();
149 #endif /* __saml_encoder_h__ */