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