Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / saml / binding / MessageEncoder.h
index 536acf4..14fb908 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2006 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
+ *
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
 
 #include <saml/base.h>
 
-#include <map>
-#include <string>
-#include <istream>
-#include <xmltooling/XMLObject.h>
-#include <xmltooling/signature/CredentialResolver.h>
+namespace xmltooling {
+    class XMLTOOL_API Credential;
+    class XMLTOOL_API GenericResponse;
+    class XMLTOOL_API XMLObject;
+};
 
 namespace opensaml {
 
@@ -37,6 +41,9 @@ namespace opensaml {
     namespace saml2p {
         class SAML_API SAML2Artifact;
     };
+    namespace saml2md {
+        class SAML_API EntityDescriptor;
+    };
 
     /**
      * Interface to SAML protocol binding message encoders.
@@ -45,60 +52,28 @@ namespace opensaml {
     {
         MAKE_NONCOPYABLE(MessageEncoder);
     public:
-        virtual ~MessageEncoder() {}
+        virtual ~MessageEncoder();
 
         /**
-         * Interface to caller-supplied shim for issuing an HTTP response.
-         * 
-         * <p>To supply information to the surrounding web server environment,
-         * a shim must be supplied in the form of this interface to adapt the
-         * library to different proprietary server APIs.
-         * 
-         * <p>This interface need not be threadsafe.
+         * Indicates whether the encoding format requires that messages be as compact as possible.
+         *
+         * @return  true iff the encoding has size constraints
          */
-        class SAML_API HTTPResponse {
-            MAKE_NONCOPYABLE(HTTPResponse);
-        protected:
-            HTTPResponse() {}
-        public:
-            virtual ~HTTPResponse() {}
-            
-            /**
-             * Sets or clears a response header.
-             * 
-             * @param name  header name
-             * @param value value to set, or NULL to clear
-             */
-            virtual void setHeader(const char* name, const char* value)=0;
+        virtual bool isCompact() const;
 
-            /**
-             * Sets a client cookie.
-             * 
-             * @param name  cookie name
-             * @param value value to set, or NULL to clear
-             */
-            virtual void setCookie(const char* name, const char* value)=0;
-            
-            /**
-             * Redirect the client to the specified URL and complete the response.
-             * Any headers previously set will be sent ahead of the redirect.
-             * 
-             * @param url   location to redirect client
-             * @return a result code to return from the calling MessageEncoder
-             */
-            virtual long sendRedirect(const char* url)=0;
+        /**
+         * Indicates whether a web browser or similar user agent will receive the message.
+         *
+         * @return true iff the message will be handled by a user agent
+         */
+        virtual bool isUserAgentPresent() const;
 
-            /**
-             * Sends a completed response to the client. Any headers previously set
-             * will be sent ahead of the data.
-             * 
-             * @param inputStream   reference to source of response data
-             * @param status        HTTP status code to return
-             * @param contentType   Content-Type header to return
-             * @return a result code to return from the calling MessageEncoder
-             */
-            virtual long sendResponse(std::istream& inputStream, int status = 200, const char* contentType = "text/html")=0;
-        };
+        /**
+         * Returns identifier for the protocol family associated with the encoder.
+         *
+         * @return  a protocol family identifier, or nullptr
+         */
+        virtual const XMLCh* getProtocolFamily() const;
 
         /**
          * Interface to caller-supplied artifact generation mechanism.
@@ -113,9 +88,9 @@ namespace opensaml {
         class SAML_API ArtifactGenerator {
             MAKE_NONCOPYABLE(ArtifactGenerator);
         protected:
-            ArtifactGenerator() {}
+            ArtifactGenerator();
         public:
-            virtual ~ArtifactGenerator() {}
+            virtual ~ArtifactGenerator();
             
             /**
              * Generate a SAML 1.x artifact suitable for consumption by the relying party.
@@ -123,7 +98,7 @@ namespace opensaml {
              * @param relyingParty  the party that will recieve the artifact
              * @return a SAML 1.x artifact with a random assertion handle
              */
-            virtual SAMLArtifact* generateSAML1Artifact(const char* relyingParty) const=0;
+            virtual SAMLArtifact* generateSAML1Artifact(const saml2md::EntityDescriptor* relyingParty) const=0;
 
             /**
              * Generate a SAML 2.0 artifact suitable for consumption by the relying party.
@@ -131,22 +106,11 @@ namespace opensaml {
              * @param relyingParty  the party that will recieve the artifact
              * @return a SAML 2.0 artifact with a random message handle
              */
-            virtual saml2p::SAML2Artifact* generateSAML2Artifact(const char* relyingParty) const=0;
+            virtual saml2p::SAML2Artifact* generateSAML2Artifact(const saml2md::EntityDescriptor* relyingParty) const=0;
         };
 
         /**
-         * Provides an ArtifactGenerator implementation for the MessageEncoder to use.
-         * The implementation's lifetime must be longer than the lifetime of this object. 
-         * This method must be externally synchronized. 
-         * 
-         * @param artifactGenerator   an ArtifactGenerator implementation to use
-         */
-        void setArtifactGenerator(ArtifactGenerator* artifactGenerator) {
-            m_artifactGenerator = artifactGenerator;
-        }
-        
-        /**
-         * Encodes an XML object/message into a binding-specific HTTP response.
+         * Encodes an XML object/message into a binding- and transport-specific response.
          * The XML content cannot have a parent object, and any existing references to
          * the content will be invalidated if the encode method returns successfully.
          * 
@@ -157,42 +121,30 @@ namespace opensaml {
          * <p>Artifact-based bindings require an ArtifactGenerator be set to
          * produce an artifact suitable for the intended recipient.
          * 
-         * @param httpResponse      reference to interface for sending encoded response to client      
+         * @param genericResponse   reference to interface for sending transport response      
          * @param xmlObject         XML message to encode
          * @param destination       destination URL for message
-         * @param recipientID       optional entityID of message recipient
+         * @param recipient         optional message recipient
          * @param relayState        optional RelayState value to accompany message
-         * @param credResolver      optional CredentialResolver instance to supply signing material
-         * @param sigAlgorithm      optional signature algorithm identifier
+         * @param artifactGenerator optional interface for generation of artifacts
+         * @param credential        optional Credential to supply signing key
+         * @param signatureAlg      optional signature algorithm identifier
+         * @param digestAlg         optional reference digest algorithm identifier
          */
         virtual long encode(
-            HTTPResponse& httpResponse,
+            xmltooling::GenericResponse& genericResponse,
             xmltooling::XMLObject* xmlObject,
             const char* destination,
-            const char* recipientID=NULL,
-            const char* relayState=NULL,
-            const xmlsignature::CredentialResolver* credResolver=NULL,
-            const XMLCh* sigAlgorithm=NULL
+            const saml2md::EntityDescriptor* recipient=nullptr,
+            const char* relayState=nullptr,
+            const ArtifactGenerator* artifactGenerator=nullptr,
+            const xmltooling::Credential* credential=nullptr,
+            const XMLCh* signatureAlg=nullptr,
+            const XMLCh* digestAlg=nullptr
             ) const=0;
 
     protected:
-        MessageEncoder() : m_artifactGenerator(NULL) {}
-        
-        /**
-         * Helper function to build a new XML Signature with KeyInfo, based
-         * on the supplied CredentialResolver.
-         * 
-         * @param credResolver      CredentialResolver instance to supply signing material
-         * @param sigAlgorithm      optional signature algorithm identifier
-         * @return  a new Signature object
-         */
-        xmlsignature::Signature* buildSignature(
-            const xmlsignature::CredentialResolver* credResolver,
-            const XMLCh* sigAlgorithm=NULL
-            ) const;
-        
-        /** Pointer to an ArtifactGenerator implementation. */
-        const ArtifactGenerator* m_artifactGenerator;
+        MessageEncoder();
     };
 
     /**