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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 * @file saml/SAMLConfig.h
24 * Library configuration.
27 #ifndef __saml_config_h__
28 #define __saml_config_h__
30 #include <saml/base.h>
33 #include <xercesc/dom/DOM.hpp>
34 #include <xmltooling/PluginManager.h>
38 * Common classes for OpenSAML library
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;
49 class SAML_API ContactPerson;
50 class SAML_API EntityDescriptor;
51 class SAML_API EntityMatcher;
52 class SAML_API MetadataProvider;
53 class SAML_API MetadataFilter;
54 class SAML_API RoleDescriptor;
57 #if defined (_MSC_VER)
58 #pragma warning( push )
59 #pragma warning( disable : 4250 4251 )
63 * Singleton object that manages library startup/shutdown.configuration.
65 class SAML_API SAMLConfig
67 MAKE_NONCOPYABLE(SAMLConfig);
69 virtual ~SAMLConfig();
72 * Returns the global configuration object for the library.
74 * @return reference to the global library configuration object
76 static SAMLConfig& getConfig();
81 * Each process using the library MUST call this function exactly once
82 * before using any library classes. The flag controls whether this is the
83 * "dominant" library or not and can allow the SAML library to be loaded
84 * as an extension of XMLTooling rather than subsuming it.
86 * @param initXMLTooling true iff this method should initialize the XMLTooling layer
87 * @return true iff initialization was successful
89 virtual bool init(bool initXMLTooling=true)=0;
94 * Each process using the library SHOULD call this function exactly once
95 * before terminating itself. The flag controls whether this is the
96 * "dominant" library or not and can allow the SAML library to be loaded
97 * as an extension of XMLTooling rather than subsuming it.
99 * @param termXMLTooling true iff this method should shutdown the XMLTooling layer
101 virtual void term(bool termXMLTooling=true)=0;
104 * Sets the global ArtifactMap instance.
105 * This method must be externally synchronized with any code that uses the object.
106 * Any previously set object is destroyed.
108 * @param artifactMap new ArtifactMap instance to store
110 void setArtifactMap(ArtifactMap* artifactMap);
113 * Returns the global ArtifactMap instance.
115 * @return global ArtifactMap or nullptr
117 ArtifactMap* getArtifactMap() const;
120 * Generate random information using the underlying security library
122 * @param buf buffer for the information
123 * @param len number of bytes to write into buffer
125 virtual void generateRandomBytes(void* buf, unsigned int len)=0;
128 * Generate random information using the underlying security library
130 * @param buf string buffer for the information
131 * @param len number of bytes to write into buffer
133 virtual void generateRandomBytes(std::string& buf, unsigned int len)=0;
136 * Generate a valid XML identifier of the form _X{32} where X is a
137 * random hex character. The caller is responsible for freeing the result.
139 * @return a valid null-terminated XML ID
141 virtual XMLCh* generateIdentifier()=0;
145 * Generate the SHA-1 hash of a string
147 * @param s NULL-terminated string to hash
148 * @param toHex true iff the result should be encoded in hexadecimal form or left as raw bytes
150 * @return SHA-1 hash of the data
152 virtual std::string hashSHA1(const char* s, bool toHex=false)=0;
155 * Sets the order of contact types to use in annotating exceptions with contact information.
157 * @param contactTypes whitespace-delimited list of contact types
159 virtual void setContactPriority(const XMLCh* contactTypes)=0;
162 * Returns the appropriate contact to use for the entity.
164 * @param entity the entity to search
165 * @return a contact to use, or nullptr
167 virtual const saml2md::ContactPerson* getContactPerson(const saml2md::EntityDescriptor& entity) const=0;
170 * Returns the appropriate contact to use for the role.
172 * @param entity the role to search
173 * @return a contact to use, or nullptr
175 virtual const saml2md::ContactPerson* getContactPerson(const saml2md::RoleDescriptor& role) const=0;
177 /** Manages factories for MessageDecoder plugins. */
178 xmltooling::PluginManager< MessageDecoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageDecoderManager;
180 /** Manages factories for MessageEncoder plugins. */
181 xmltooling::PluginManager< MessageEncoder,std::string,std::pair<const xercesc::DOMElement*,const XMLCh*> > MessageEncoderManager;
183 /** Manages factories for SAMLArtifact plugins. */
184 xmltooling::PluginManager<SAMLArtifact,std::string,const char*> SAMLArtifactManager;
186 /** Manages factories for SecurityPolicyRule plugins. */
187 xmltooling::PluginManager<SecurityPolicyRule,std::string,const xercesc::DOMElement*> SecurityPolicyRuleManager;
189 /** Manages factories for MetadataProvider plugins. */
190 xmltooling::PluginManager<saml2md::MetadataProvider,std::string,const xercesc::DOMElement*> MetadataProviderManager;
192 /** Manages factories for MetadataFilter plugins. */
193 xmltooling::PluginManager<saml2md::MetadataFilter,std::string,const xercesc::DOMElement*> MetadataFilterManager;
195 /** Manages factories for EntityMatcher plugins. */
196 xmltooling::PluginManager<saml2md::EntityMatcher,std::string,const xercesc::DOMElement*> EntityMatcherManager;
201 /** Global ArtifactMap instance for use by artifact-related functions. */
202 ArtifactMap* m_artifactMap;
205 #if defined (_MSC_VER)
206 #pragma warning( pop )
211 #endif /* __saml_config_h__ */