2 * Copyright 2001-2010 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/MessageDecoder.h
20 * Interface to SAML protocol binding message decoders.
23 #ifndef __saml_decoder_h__
24 #define __saml_decoder_h__
26 #include <saml/base.h>
29 #include <xercesc/util/XMLUniDefs.hpp>
31 namespace xmltooling {
32 class XMLTOOL_API GenericRequest;
33 class XMLTOOL_API XMLObject;
38 class SAML_API SAMLArtifact;
39 class SAML_API SecurityPolicy;
41 class SAML_API Response;
44 class SAML_API SAML2Artifact;
45 class SAML_API ArtifactResponse;
48 class SAML_API MetadataProvider;
49 class SAML_API IDPSSODescriptor;
50 class SAML_API RoleDescriptor;
51 class SAML_API SSODescriptorType;
55 * Interface to SAML protocol binding message decoders.
57 class SAML_API MessageDecoder
59 MAKE_NONCOPYABLE(MessageDecoder);
61 virtual ~MessageDecoder();
64 * Returns identifier for the protocol family associated with the decoder.
66 * @return a protocol family identifier, or nullptr
68 virtual const XMLCh* getProtocolFamily() const;
71 * Indicates whether a web browser or similar user agent delivered the message.
73 * @return true iff the message was delivered by a user agent
75 virtual bool isUserAgentPresent() const;
78 * Interface to caller-supplied artifact resolution mechanism.
80 * Resolving artifacts requires internally performing a SOAP-based
81 * call to the artifact source, usually in a mutually authenticated fashion.
82 * The potential options vary widely, so the work is encapsulated by this
83 * interface, though of course other library facilities may be used.
85 * <p>A MessageDecoder implementation will invoke the supplied interface
86 * when it requires an artifact be resolved.
88 class SAML_API ArtifactResolver {
89 MAKE_NONCOPYABLE(ArtifactResolver);
94 virtual ~ArtifactResolver();
97 * Resolves one or more SAML 1.x artifacts into a response containing a set of
98 * resolved Assertions. The caller is responsible for the resulting Response.
99 * The supplied SecurityPolicy is used to access caller-supplied infrastructure
100 * and to pass back the result of authenticating the resolution process.
102 * @param artifacts one or more SAML 1.x artifacts
103 * @param idpDescriptor reference to IdP role of artifact issuer
104 * @param policy reference to policy containing rules, MetadataProvider, TrustEngine, etc.
105 * @return the corresponding SAML Assertions wrapped in a Response.
107 virtual saml1p::Response* resolve(
108 const std::vector<SAMLArtifact*>& artifacts,
109 const saml2md::IDPSSODescriptor& idpDescriptor,
110 SecurityPolicy& policy
114 * Resolves a SAML 2.0 artifact into the corresponding SAML protocol message.
115 * The caller is responsible for the resulting ArtifactResponse message.
116 * The supplied SecurityPolicy is used to access caller-supplied infrastructure
117 * and to pass back the result of authenticating the resolution process.
119 * @param artifact reference to a SAML 2.0 artifact
120 * @param ssoDescriptor reference to SSO role of artifact issuer (may be SP or IdP)
121 * @param policy reference to policy containing rules, MetadataProvider, TrustEngine, etc.
122 * @return the corresponding SAML protocol message or nullptr
124 virtual saml2p::ArtifactResponse* resolve(
125 const saml2p::SAML2Artifact& artifact,
126 const saml2md::SSODescriptorType& ssoDescriptor,
127 SecurityPolicy& policy
131 * Returns true iff the metadata provided includes a supported artifact resolution service.
133 * @param ssoDescriptor reference to SSO role of artifact issuer (may be SP or IdP)
134 * @return true iff the artifact issuer offers endpoints supported by this resolver
136 virtual bool isSupported(const saml2md::SSODescriptorType& ssoDescriptor) const;
140 * Provides an ArtifactResolver implementation for the MessageDecoder to use.
141 * The implementation's lifetime must be longer than the lifetime of this object.
142 * This method must be externally synchronized.
144 * @param artifactResolver an ArtifactResolver implementation to use
146 void setArtifactResolver(const ArtifactResolver* artifactResolver);
149 * Decodes a transport request into a SAML protocol message, and evaluates it
150 * against a supplied SecurityPolicy. If the transport request does not contain
151 * the information necessary to decode the request, nullptr will be returned.
152 * Errors during the decoding process will be raised as exceptions.
154 * <p>Artifact-based bindings require an ArtifactResolver be set to
155 * turn an artifact into the corresponding message.
157 * @param relayState will be set to RelayState/TARGET value accompanying message
158 * @param genericRequest reference to interface for accessing transport request to decode
159 * @param policy reference to policy containing rules, MetadataProvider, TrustEngine, etc.
160 * @return the decoded message, or nullptr if the decoder did not recognize the request content
162 virtual xmltooling::XMLObject* decode(
163 std::string& relayState,
164 const xmltooling::GenericRequest& genericRequest,
165 SecurityPolicy& policy
171 /** Pointer to an ArtifactResolver implementation. */
172 const ArtifactResolver* m_artifactResolver;
175 * Extracts policy-relevant message details.
177 * @param message the incoming message
178 * @param request the protocol request
179 * @param protocol the protocol family in use
180 * @param policy SecurityPolicy to provide various components and track message data
182 virtual void extractMessageDetails (
183 const xmltooling::XMLObject& message,
184 const xmltooling::GenericRequest& request,
185 const XMLCh* protocol,
186 SecurityPolicy& policy
191 * Registers MessageDecoder plugins into the runtime.
193 void SAML_API registerMessageDecoders();
196 #endif /* __saml_decoder_h__ */