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