b95424e07a13d482c0edc85c362a1d2e2c86d62a
[shibboleth/cpp-sp.git] / shibsp / metadata / MetadataExtImpl.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  * MetadataExtImpl.cpp
23  * 
24  * Implementation classes for Shibboleth metadata extensions schema.
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "metadata/MetadataExt.h"
30
31 #include <xmltooling/AbstractComplexElement.h>
32 #include <xmltooling/AbstractSimpleElement.h>
33 #include <xmltooling/impl/AnyElement.h>
34 #include <xmltooling/io/AbstractXMLObjectMarshaller.h>
35 #include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
36 #include <xmltooling/signature/KeyInfo.h>
37 #include <xmltooling/util/XMLHelper.h>
38
39 using namespace shibsp;
40 using namespace xmlsignature;
41 using namespace xmltooling;
42 using namespace std;
43
44 using xmlconstants::XMLSIG_NS;
45 using xmlconstants::XML_BOOL_NULL;
46 using shibspconstants::SHIBMD_NS;
47
48 #if defined (_MSC_VER)
49     #pragma warning( push )
50     #pragma warning( disable : 4250 4251 )
51 #endif
52
53 namespace shibsp {
54
55     class SHIBSP_DLLLOCAL ScopeImpl : public virtual Scope,
56         public AbstractSimpleElement,
57         public AbstractDOMCachingXMLObject,
58         public AbstractXMLObjectMarshaller,
59         public AbstractXMLObjectUnmarshaller
60     {
61         void init() {
62             m_Regexp=XML_BOOL_NULL;
63         }
64
65     public:
66
67         ScopeImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
68                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
69             init();
70         }
71             
72         ScopeImpl(const ScopeImpl& src)
73                 : AbstractXMLObject(src), AbstractSimpleElement(src), AbstractDOMCachingXMLObject(src) {
74             init();
75             Regexp(src.m_Regexp);
76         }
77         
78         IMPL_XMLOBJECT_CLONE(Scope);
79         IMPL_BOOLEAN_ATTRIB(Regexp);
80
81     protected:
82         void marshallAttributes(DOMElement* domElement) const {
83             MARSHALL_BOOLEAN_ATTRIB(Regexp,REGEXP,nullptr);
84         }
85
86         void processAttribute(const DOMAttr* attribute) {
87             PROC_BOOLEAN_ATTRIB(Regexp,REGEXP,nullptr);
88             AbstractXMLObjectUnmarshaller::processAttribute(attribute);
89         }
90     };
91
92     class SHIBSP_DLLLOCAL KeyAuthorityImpl : public virtual KeyAuthority,
93             public AbstractComplexElement,
94             public AbstractAttributeExtensibleXMLObject,
95             public AbstractDOMCachingXMLObject,
96             public AbstractXMLObjectMarshaller,
97             public AbstractXMLObjectUnmarshaller
98     {
99         void init() {
100             m_VerifyDepth=nullptr;
101         }
102     public:
103         virtual ~KeyAuthorityImpl() {
104             XMLString::release(&m_VerifyDepth);
105         }
106
107         KeyAuthorityImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType)
108                 : AbstractXMLObject(nsURI, localName, prefix, schemaType) {
109             init();
110         }
111             
112         KeyAuthorityImpl(const KeyAuthorityImpl& src)
113                 : AbstractXMLObject(src), AbstractComplexElement(src),
114                     AbstractAttributeExtensibleXMLObject(src), AbstractDOMCachingXMLObject(src) {
115             init();
116             setVerifyDepth(src.m_VerifyDepth);
117             VectorOf(KeyInfo) v=getKeyInfos();
118             for (vector<KeyInfo*>::const_iterator i=src.m_KeyInfos.begin(); i!=src.m_KeyInfos.end(); ++i)
119                 v.push_back((*i)->cloneKeyInfo());
120         }
121         
122         IMPL_XMLOBJECT_CLONE(KeyAuthority);
123         IMPL_INTEGER_ATTRIB(VerifyDepth);
124         IMPL_TYPED_CHILDREN(KeyInfo,m_children.end());
125         
126     public:
127         void setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID=false) {
128             if (!qualifiedName.hasNamespaceURI()) {
129                 if (XMLString::equals(qualifiedName.getLocalPart(),VERIFYDEPTH_ATTRIB_NAME)) {
130                     setVerifyDepth(value);
131                     return;
132                 }
133             }
134             AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value, ID);
135         }
136
137     protected:
138         void marshallAttributes(DOMElement* domElement) const {
139             MARSHALL_INTEGER_ATTRIB(VerifyDepth,VERIFYDEPTH,nullptr);
140             marshallExtensionAttributes(domElement);
141         }
142
143         void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
144             PROC_TYPED_CHILDREN(KeyInfo,XMLSIG_NS,false);
145             AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root);
146         }
147
148         void processAttribute(const DOMAttr* attribute) {
149             unmarshallExtensionAttribute(attribute);
150         }
151     };
152
153 };
154
155 #if defined (_MSC_VER)
156     #pragma warning( pop )
157 #endif
158
159 // Builder Implementations
160
161 IMPL_XMLOBJECTBUILDER(Scope);
162 IMPL_XMLOBJECTBUILDER(KeyAuthority);
163
164 const XMLCh Scope::LOCAL_NAME[] =                       UNICODE_LITERAL_5(S,c,o,p,e);
165 const XMLCh Scope::REGEXP_ATTRIB_NAME[] =               UNICODE_LITERAL_6(r,e,g,e,x,p);
166 const XMLCh KeyAuthority::LOCAL_NAME[] =                UNICODE_LITERAL_12(K,e,y,A,u,t,h,o,r,i,t,y);
167 const XMLCh KeyAuthority::VERIFYDEPTH_ATTRIB_NAME[] =   UNICODE_LITERAL_11(V,e,r,i,f,y,D,e,p,t,h);