MessageEncoder, ArtifactMap, and SAML 1.x encoder classes.
[shibboleth/cpp-opensaml.git] / saml / SAMLConfig.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * @file saml/SAMLConfig.h\r
19  * \r
20  * Library configuration \r
21  */\r
22 \r
23 #ifndef __saml_config_h__\r
24 #define __saml_config_h__\r
25 \r
26 #include <saml/base.h>\r
27 #include <saml/binding/ArtifactMap.h>\r
28 \r
29 #include <xmltooling/PluginManager.h>\r
30 #include <xmltooling/XMLToolingConfig.h>\r
31 \r
32 #include <string>\r
33 \r
34 /**\r
35  * @namespace opensaml\r
36  * Common classes for OpenSAML library\r
37  */\r
38 namespace opensaml {\r
39 \r
40     class SAML_API MessageEncoder;\r
41     class SAML_API MessageDecoder;\r
42     class SAML_API SAMLArtifact;\r
43     class SAML_API TrustEngine;\r
44 \r
45     namespace saml2md {\r
46         class SAML_API MetadataProvider;\r
47         class SAML_API MetadataFilter;\r
48     };\r
49 \r
50 #if defined (_MSC_VER)\r
51     #pragma warning( push )\r
52     #pragma warning( disable : 4250 4251 )\r
53 #endif\r
54 \r
55     /**\r
56      * Singleton object that manages library startup/shutdown.configuration.\r
57      */\r
58     class SAML_API SAMLConfig\r
59     {\r
60     MAKE_NONCOPYABLE(SAMLConfig);\r
61     public:\r
62         virtual ~SAMLConfig() {}\r
63 \r
64         /**\r
65          * Returns the global configuration object for the library.\r
66          * \r
67          * @return reference to the global library configuration object\r
68          */\r
69         static SAMLConfig& getConfig();\r
70         \r
71         /**\r
72          * Initializes library\r
73          * \r
74          * Each process using the library MUST call this function exactly once\r
75          * before using any library classes. The flag controls whether this is the\r
76          * "dominant" library or not and can allow the SAML library to be loaded\r
77          * as an extension of XMLTooling rather than subsuming it.\r
78          * \r
79          * @param initXMLTooling true iff this method should initialize the XMLTooling layer\r
80          * @return true iff initialization was successful \r
81          */\r
82         virtual bool init(bool initXMLTooling=true)=0;\r
83         \r
84         /**\r
85          * Shuts down library\r
86          * \r
87          * Each process using the library SHOULD call this function exactly once\r
88          * before terminating itself. The flag controls whether this is the\r
89          * "dominant" library or not and can allow the SAML library to be loaded\r
90          * as an extension of XMLTooling rather than subsuming it.\r
91          * \r
92          * @param termXMLTooling true iff this method should shutdown the XMLTooling layer\r
93          */\r
94         virtual void term(bool termXMLTooling=true)=0;\r
95         \r
96         /**\r
97          * Sets the global ArtifactMap instance.\r
98          * This method must be externally synchronized with any code that uses the object.\r
99          * Any previously set object is destroyed.\r
100          * \r
101          * @param artifactMap   new ArtifactMap instance to store\r
102          */\r
103         void setArtifactMap(ArtifactMap* artifactMap) {\r
104             delete m_artifactMap;\r
105             m_artifactMap = artifactMap;\r
106         }\r
107         \r
108         /**\r
109          * Returns the global ArtifactMap instance.\r
110          * \r
111          * @return  global ArtifactMap\r
112          */\r
113         ArtifactMap* getArtifactMap() const {\r
114             return m_artifactMap;\r
115         }\r
116         \r
117         /**\r
118          * Generate random information using the underlying security library\r
119          * \r
120          * @param buf   buffer for the information\r
121          * @param len   number of bytes to write into buffer\r
122          */\r
123         virtual void generateRandomBytes(void* buf, unsigned int len)=0;\r
124 \r
125         /**\r
126          * Generate random information using the underlying security library\r
127          * \r
128          * @param buf   string buffer for the information\r
129          * @param len   number of bytes to write into buffer\r
130          */\r
131         virtual void generateRandomBytes(std::string& buf, unsigned int len)=0;\r
132 \r
133         /**\r
134          * Generate a valid XML identifier of the form _X{32} where X is a\r
135          * random hex character. The caller is responsible for freeing the result.\r
136          * \r
137          * @return a valid null-terminated XML ID\r
138          */\r
139         virtual XMLCh* generateIdentifier()=0;\r
140         \r
141         /**\r
142          * Generate the SHA-1 hash of a string\r
143          * \r
144          * @param s     NULL-terminated string to hash\r
145          * @param toHex true iff the result should be encoded in hexadecimal form or left as raw bytes\r
146          *  \r
147          * @return  SHA-1 hash of the data\r
148          */\r
149         virtual std::string hashSHA1(const char* s, bool toHex=false)=0;\r
150 \r
151         /**\r
152          * Manages factories for MessageDecoder plugins.\r
153          */\r
154         xmltooling::PluginManager<MessageDecoder,const DOMElement*> MessageDecoderManager;\r
155 \r
156         /**\r
157          * Manages factories for MessageEncoder plugins.\r
158          */\r
159         xmltooling::PluginManager<MessageEncoder,const DOMElement*> MessageEncoderManager;        \r
160 \r
161         /**\r
162          * Manages factories for SAMLArtifact plugins.\r
163          */\r
164         xmltooling::PluginManager<SAMLArtifact,const char*> SAMLArtifactManager;\r
165 \r
166         /**\r
167          * Manages factories for TrustEngine plugins.\r
168          */\r
169         xmltooling::PluginManager<TrustEngine,const DOMElement*> TrustEngineManager;\r
170 \r
171         /**\r
172          * Manages factories for MetadataProvider plugins.\r
173          */\r
174         xmltooling::PluginManager<saml2md::MetadataProvider,const DOMElement*> MetadataProviderManager;\r
175         \r
176         /**\r
177          * Manages factories for MetadataFilter plugins.\r
178          */\r
179         xmltooling::PluginManager<saml2md::MetadataFilter,const DOMElement*> MetadataFilterManager;\r
180 \r
181     protected:\r
182         SAMLConfig() : m_artifactMap(NULL) {}\r
183         \r
184         /** Global ArtifactMap instance for use by artifact-related functions. */\r
185         ArtifactMap* m_artifactMap;\r
186     };\r
187 \r
188 #if defined (_MSC_VER)\r
189     #pragma warning( pop )\r
190 #endif\r
191     \r
192 };\r
193 \r
194 #endif /* __saml_config_h__ */\r