Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-opensaml.git] / saml / binding / ArtifactMap.h
1 /*
2  *  Copyright 2001-2009 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/ArtifactMap.h
19  * 
20  * Helper class for SAMLArtifact mapping and retrieval.
21  */
22
23 #ifndef __saml_artmap_h__
24 #define __saml_artmap_h__
25
26 #include <saml/base.h>
27
28 namespace xmltooling {
29     class XMLTOOL_API StorageService;
30     class XMLTOOL_API XMLObject;
31 };
32
33 namespace opensaml {
34
35     class SAML_API SAMLArtifact;
36     class SAML_DLLLOCAL ArtifactMappings;
37     
38     /**
39      * Helper class for SAMLArtifact mapping and retrieval.
40      */
41     class SAML_API ArtifactMap
42     {
43         MAKE_NONCOPYABLE(ArtifactMap);
44     public:
45         
46         /**
47          * Creates a map on top of a particular storage service context, or in-memory.
48          * 
49          * @param storage       pointer to a StorageService, or NULL to keep map in memory
50          * @param context       optional label for storage context
51          * @param artifactTTL   time to live in seconds, determines how long artifact remains valid
52          */
53         ArtifactMap(xmltooling::StorageService* storage=NULL, const char* context=NULL, unsigned int artifactTTL=180);
54
55         /**
56          * Creates a map on top of a particular storage service context, or in-memory.
57          * 
58          * @param e         root of a DOM with optional XML attributes for context and artifactTTL
59          * @param storage   pointer to a StorageService, or NULL to keep map in memory
60          */
61         ArtifactMap(const xercesc::DOMElement* e, xmltooling::StorageService* storage=NULL);
62
63         virtual ~ArtifactMap();
64         
65         /**
66          * Associates XML content with an artifact and optionally a specific relying party.
67          * Specifying no relying party means that the first attempt to resolve the artifact
68          * will succeed. The XML content cannot have a parent object, and any existing references
69          * to the content will be invalidated.
70          * 
71          * @param content       the XML content to map to an artifact
72          * @param artifact      the artifact representing the XML content
73          * @param relyingParty  entityID of the party authorized to resolve the artifact
74          * @return the generated artifact
75          */
76         virtual void storeContent(xmltooling::XMLObject* content, const SAMLArtifact* artifact, const char* relyingParty=NULL);
77         
78         /**
79          * Retrieves the XML content represented by the artifact. The identity of the
80          * relying party can be supplied, if known. If the wrong party tries to resolve
81          * an artifact, an exception will be thrown and the mapping will be removed.
82          * The caller is responsible for freeing the XML content returned.
83          * 
84          * @param artifact      the artifact representing the XML content
85          * @param relyingParty  entityID of the party trying to resolve the artifact
86          * @return the XML content
87          */
88         virtual xmltooling::XMLObject* retrieveContent(const SAMLArtifact* artifact, const char* relyingParty=NULL);
89
90         /**
91          * Retrieves the relying party to whom the artifact was issued.
92          *
93          * @param artifact  the artifact to check
94          * @return  entityID of the party to whom the artifact was issued, if any
95          */
96         virtual std::string getRelyingParty(const SAMLArtifact* artifact);
97
98     private:
99         xmltooling::StorageService* m_storage;
100         std::string m_context;
101         ArtifactMappings* m_mappings;
102         unsigned int m_artifactTTL;
103     };
104 };
105
106 #endif /* __saml_artmap_h__ */