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