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