Bump lib version.
[shibboleth/cpp-opensaml.git] / saml / SAMLConfig.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/SAMLConfig.h
19  * 
20  * Library configuration 
21  */
22
23 #ifndef __saml_config_h__
24 #define __saml_config_h__
25
26 #include <saml/base.h>
27
28 #include <xmltooling/PluginManager.h>
29 #include <xmltooling/XMLToolingConfig.h>
30
31 #include <string>
32
33 /**
34  * @namespace opensaml
35  * Common classes for OpenSAML library
36  */
37 namespace opensaml {
38
39     class SAML_API ArtifactMap;
40     class SAML_API MessageEncoder;
41     class SAML_API MessageDecoder;
42     class SAML_API SAMLArtifact;
43     class SAML_API SecurityPolicyRule;
44
45     namespace saml2md {
46         class SAML_API MetadataProvider;
47         class SAML_API MetadataFilter;
48     };
49
50 #if defined (_MSC_VER)
51     #pragma warning( push )
52     #pragma warning( disable : 4250 4251 )
53 #endif
54
55     /**
56      * Singleton object that manages library startup/shutdown.configuration.
57      */
58     class SAML_API SAMLConfig
59     {
60     MAKE_NONCOPYABLE(SAMLConfig);
61     public:
62         virtual ~SAMLConfig() {}
63
64         /**
65          * Returns the global configuration object for the library.
66          * 
67          * @return reference to the global library configuration object
68          */
69         static SAMLConfig& getConfig();
70         
71         /**
72          * Initializes library
73          * 
74          * Each process using the library MUST call this function exactly once
75          * before using any library classes. The flag controls whether this is the
76          * "dominant" library or not and can allow the SAML library to be loaded
77          * as an extension of XMLTooling rather than subsuming it.
78          * 
79          * @param initXMLTooling true iff this method should initialize the XMLTooling layer
80          * @return true iff initialization was successful 
81          */
82         virtual bool init(bool initXMLTooling=true)=0;
83         
84         /**
85          * Shuts down library
86          * 
87          * Each process using the library SHOULD call this function exactly once
88          * before terminating itself. The flag controls whether this is the
89          * "dominant" library or not and can allow the SAML library to be loaded
90          * as an extension of XMLTooling rather than subsuming it.
91          * 
92          * @param termXMLTooling true iff this method should shutdown the XMLTooling layer
93          */
94         virtual void term(bool termXMLTooling=true)=0;
95         
96         /**
97          * Sets the global ArtifactMap instance.
98          * This method must be externally synchronized with any code that uses the object.
99          * Any previously set object is destroyed.
100          * 
101          * @param artifactMap   new ArtifactMap instance to store
102          */
103         void setArtifactMap(ArtifactMap* artifactMap);
104         
105         /**
106          * Returns the global ArtifactMap instance.
107          * 
108          * @return  global ArtifactMap or NULL
109          */
110         ArtifactMap* getArtifactMap() const {
111             return m_artifactMap;
112         }
113
114         /**
115          * Generate random information using the underlying security library
116          * 
117          * @param buf   buffer for the information
118          * @param len   number of bytes to write into buffer
119          */
120         virtual void generateRandomBytes(void* buf, unsigned int len)=0;
121
122         /**
123          * Generate random information using the underlying security library
124          * 
125          * @param buf   string buffer for the information
126          * @param len   number of bytes to write into buffer
127          */
128         virtual void generateRandomBytes(std::string& buf, unsigned int len)=0;
129
130         /**
131          * Generate a valid XML identifier of the form _X{32} where X is a
132          * random hex character. The caller is responsible for freeing the result.
133          * 
134          * @return a valid null-terminated XML ID
135          */
136         virtual XMLCh* generateIdentifier()=0;
137         
138         /**
139          * Generate the SHA-1 hash of a string
140          * 
141          * @param s     NULL-terminated string to hash
142          * @param toHex true iff the result should be encoded in hexadecimal form or left as raw bytes
143          *  
144          * @return  SHA-1 hash of the data
145          */
146         virtual std::string hashSHA1(const char* s, bool toHex=false)=0;
147
148         /** Manages factories for MessageDecoder plugins. */
149         xmltooling::PluginManager< MessageDecoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageDecoderManager;
150
151         /** Manages factories for MessageEncoder plugins. */
152         xmltooling::PluginManager< MessageEncoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageEncoderManager;
153
154         /** Manages factories for SAMLArtifact plugins. */
155         xmltooling::PluginManager<SAMLArtifact,std::string,const char*> SAMLArtifactManager;
156
157         /** Manages factories for SecurityPolicyRule plugins. */
158         xmltooling::PluginManager<SecurityPolicyRule,std::string,const xercesc::DOMElement*> SecurityPolicyRuleManager;
159
160         /** Manages factories for MetadataProvider plugins. */
161         xmltooling::PluginManager<saml2md::MetadataProvider,std::string,const xercesc::DOMElement*> MetadataProviderManager;
162         
163         /** Manages factories for MetadataFilter plugins. */
164         xmltooling::PluginManager<saml2md::MetadataFilter,std::string,const xercesc::DOMElement*> MetadataFilterManager;
165
166     protected:
167         SAMLConfig() : m_artifactMap(NULL) {}
168         
169         /** Global ArtifactMap instance for use by artifact-related functions. */
170         ArtifactMap* m_artifactMap;
171     };
172
173 #if defined (_MSC_VER)
174     #pragma warning( pop )
175 #endif
176     
177 };
178
179 #endif /* __saml_config_h__ */