Starting SAML 1.x implementation.
[shibboleth/cpp-opensaml.git] / saml / SAMLConfig.cpp
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  * SAMLConfig.cpp
19  * 
20  * Library configuration 
21  */
22
23 #define SAML_DECLARE_VALIDATORS
24
25 #include "internal.h"
26 #include "exceptions.h"
27 #include "SAMLConfig.h"
28 #include "saml1/core/Assertions.h"
29 #include "util/XMLConstants.h"
30
31 #include <log4cpp/Category.hh>
32 #include <xmltooling/XMLToolingConfig.h>
33 #include <xmltooling/util/NDC.h>
34
35 using namespace opensaml::saml1;
36 using namespace opensaml;
37 using namespace xmltooling;
38 using namespace log4cpp;
39
40 #define REGISTER_ELEMENT(namespaceURI,cname) \
41     q=QName(namespaceURI,cname::LOCAL_NAME); \
42     XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
43     Validator::registerValidator(q,new cname##SchemaValidator())
44     
45 #define REGISTER_TYPE(namespaceURI,cname) \
46     q=QName(namespaceURI,cname::TYPE_NAME); \
47     XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
48     Validator::registerValidator(q,new cname##SchemaValidator())
49
50
51 //DECL_EXCEPTION_FACTORY(XMLParserException,xmltooling);
52
53 namespace opensaml {
54    SAMLInternalConfig g_config;
55 }
56
57 SAMLConfig& SAMLConfig::getConfig()
58 {
59     return g_config;
60 }
61
62 SAMLInternalConfig& SAMLInternalConfig::getInternalConfig()
63 {
64     return g_config;
65 }
66
67 bool SAMLInternalConfig::init()
68 {
69 #ifdef _DEBUG
70     xmltooling::NDC ndc("init");
71 #endif
72     Category& log=Category::getInstance(SAML_LOGCAT".SAMLConfig");
73     log.debug("library initialization started");
74
75     XMLToolingConfig::getConfig().init();
76     log.debug("XMLTooling library initialized");
77
78     QName q;
79     REGISTER_ELEMENT(XMLConstants::SAML1_NS,AssertionIDReference);
80     REGISTER_ELEMENT(XMLConstants::SAML1_NS,Audience);
81     REGISTER_ELEMENT(XMLConstants::SAML1_NS,ConfirmationMethod);
82
83     log.info("library initialization complete");
84     return true;
85 }
86
87 void SAMLInternalConfig::term()
88 {
89 #ifdef _DEBUG
90     xmltooling::NDC ndc("term");
91 #endif
92     XMLToolingConfig::getConfig().term();
93     Category::getInstance(SAML_LOGCAT".SAMLConfig").info("library shutdown complete");
94 }