d175ba40406da7de8e6f29daa7ec9fd9dec18bb5
[shibboleth/sp.git] / shibsp / metadata / MetadataExtSchemaValidators.cpp
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  * MetadataExtSchemaValidators.cpp
19  * 
20  * Schema-based validators for Shibboleth metadata extension classes
21  */
22
23 #include "internal.h"
24 #include "exceptions.h"
25 #include "metadata/MetadataExt.h"
26
27 #include <saml/SAMLConfig.h>
28 #include <saml/saml2/metadata/MetadataProvider.h>
29 #include <xmltooling/validation/ValidatorSuite.h>
30
31 using namespace shibsp;
32 using namespace opensaml::saml2md;
33 using namespace xmltooling;
34 using namespace std;
35
36 using shibspconstants::SHIBMD_NS;
37
38 namespace shibsp {
39     XMLOBJECTVALIDATOR_SIMPLE(SHIBSP_DLLLOCAL,Scope);
40
41     BEGIN_XMLOBJECTVALIDATOR(SHIBSP_DLLLOCAL,KeyAuthority);
42         XMLOBJECTVALIDATOR_NONEMPTY(KeyAuthority,KeyInfo);
43     END_XMLOBJECTVALIDATOR;
44     
45     SHIBSP_DLLLOCAL PluginManager<MetadataProvider,string,const DOMElement*>::Factory DynamicMetadataProviderFactory;
46 };
47
48 #define REGISTER_ELEMENT(cname) \
49     q=QName(SHIBMD_NS,cname::LOCAL_NAME); \
50     XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \
51     SchemaValidators.registerValidator(q,new cname##SchemaValidator())
52     
53 void shibsp::registerMetadataExtClasses() {
54     QName q;
55     REGISTER_ELEMENT(Scope);
56     REGISTER_ELEMENT(KeyAuthority);
57
58     opensaml::SAMLConfig::getConfig().MetadataProviderManager.registerFactory(DYNAMIC_METADATA_PROVIDER, DynamicMetadataProviderFactory);
59 }