b65f0a35a2898d35187ab04a5a23b1a9072b177b
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / Metadata.h
1 /*
2  *  Copyright 2001-2009 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  * @file saml/saml2/metadata/Metadata.h
19  *
20  * XMLObjects representing the SAML 2.0 Metadata schema.
21  */
22
23 #ifndef __saml2_metadata_h__
24 #define __saml2_metadata_h__
25
26 #include <saml/saml2/core/Assertions.h>
27
28 #include <ctime>
29 #include <xercesc/util/XMLUniDefs.hpp>
30 #include <xmltooling/util/Predicates.h>
31
32
33 #define DECL_SAML2MDOBJECTBUILDER(cname) \
34     DECL_XMLOBJECTBUILDER(SAML_API,cname,samlconstants::SAML20MD_NS,samlconstants::SAML20MD_PREFIX)
35
36 namespace xmlencryption {
37     class XMLTOOL_API EncryptionMethod;
38 };
39
40 namespace opensaml {
41
42     /**
43      * @namespace opensaml::saml2md
44      * SAML 2.0 metadata namespace
45      */
46     namespace saml2md {
47
48         /**
49          * Base class for metadata objects that feature a cacheDuration attribute.
50          */
51         class SAML_API CacheableSAMLObject : public virtual xmltooling::XMLObject
52         {
53         protected:
54             CacheableSAMLObject() {}
55         public:
56             ~CacheableSAMLObject() {}
57             DECL_DATETIME_ATTRIB(CacheDuration,CACHEDURATION);
58         };
59
60         /**
61          * Base class for metadata objects that feature a validUntil attribute.
62          */
63         class SAML_API TimeBoundSAMLObject : public virtual xmltooling::XMLObject
64         {
65         protected:
66             TimeBoundSAMLObject() {}
67         public:
68             ~TimeBoundSAMLObject() {}
69             DECL_DATETIME_ATTRIB(ValidUntil,VALIDUNTIL);
70             /** Returns true iff the object is valid at the current time. */
71             bool isValid() const {
72                 return time(NULL) <= getValidUntilEpoch();
73             }
74             /** Returns true iff the object is valid at the supplied time. */
75             bool isValid(time_t t) const {
76                 return t <= getValidUntilEpoch();
77             }
78         };
79
80         DECL_XMLOBJECT_SIMPLE(SAML_API,AffiliateMember,ID,SAML 2.0 AffiliateMember element);
81         DECL_XMLOBJECT_SIMPLE(SAML_API,AttributeProfile,ProfileURI,SAML 2.0 AttributeProfile element);
82         DECL_XMLOBJECT_SIMPLE(SAML_API,Company,Name,SAML 2.0 Company element);
83         DECL_XMLOBJECT_SIMPLE(SAML_API,EmailAddress,Address,SAML 2.0 EmailAddress element);
84         DECL_XMLOBJECT_SIMPLE(SAML_API,GivenName,Name,SAML 2.0 GivenName element);
85         DECL_XMLOBJECT_SIMPLE(SAML_API,NameIDFormat,Format,SAML 2.0 NameIDFormat element);
86         DECL_XMLOBJECT_SIMPLE(SAML_API,SurName,Name,SAML 2.0 SurName element);
87         DECL_XMLOBJECT_SIMPLE(SAML_API,TelephoneNumber,Number,SAML 2.0 TelephoneNumber element);
88
89         DECL_XMLOBJECT_SIMPLE(SAML_API,ActionNamespace,Namespace,SAML 2.0 Metadata Extension ActionNamespace element);
90         DECL_XMLOBJECT_SIMPLE(SAML_API,SourceID,ID,SAML 1.x Metadata Profile SourceID element);
91
92         BEGIN_XMLOBJECT(SAML_API,localizedNameType,xmltooling::XMLObject,SAML 2.0 localizedNameType type);
93             DECL_STRING_ATTRIB(Lang,LANG);
94             /** localizedNameType local name */
95             static const XMLCh TYPE_NAME[];
96         END_XMLOBJECT;
97
98         BEGIN_XMLOBJECT(SAML_API,localizedURIType,xmltooling::XMLObject,SAML 2.0 localizedURIType type);
99             DECL_STRING_ATTRIB(Lang,LANG);
100             /** localizedURIType local name */
101             static const XMLCh TYPE_NAME[];
102         END_XMLOBJECT;
103
104         BEGIN_XMLOBJECT(SAML_API,OrganizationName,localizedNameType,SAML 2.0 OrganizationName element);
105             DECL_SIMPLE_CONTENT(Name);
106         END_XMLOBJECT;
107
108         BEGIN_XMLOBJECT(SAML_API,OrganizationDisplayName,localizedNameType,SAML 2.0 OrganizationDisplayName element);
109             DECL_SIMPLE_CONTENT(Name);
110         END_XMLOBJECT;
111
112         BEGIN_XMLOBJECT(SAML_API,OrganizationURL,localizedURIType,SAML 2.0 OrganizationURL element);
113             DECL_SIMPLE_CONTENT(URL);
114         END_XMLOBJECT;
115
116         BEGIN_XMLOBJECT(SAML_API,Extensions,xmltooling::ElementExtensibleXMLObject,SAML 2.0 Extensions element);
117             /** ExtensionsType local name */
118             static const XMLCh TYPE_NAME[];
119         END_XMLOBJECT;
120
121         BEGIN_XMLOBJECT(SAML_API,Organization,xmltooling::AttributeExtensibleXMLObject,SAML 2.0 Organization element);
122             DECL_TYPED_CHILD(Extensions);
123             DECL_TYPED_CHILDREN(OrganizationName);
124             DECL_TYPED_CHILDREN(OrganizationDisplayName);
125             DECL_TYPED_CHILDREN(OrganizationURL);
126             /** OrganizationType local name */
127             static const XMLCh TYPE_NAME[];
128         END_XMLOBJECT;
129
130         BEGIN_XMLOBJECT(SAML_API,ContactPerson,xmltooling::AttributeExtensibleXMLObject,SAML 2.0 ContactPerson element);
131             DECL_STRING_ATTRIB(ContactType,CONTACTTYPE);
132             DECL_TYPED_CHILD(Extensions);
133             DECL_TYPED_CHILD(Company);
134             DECL_TYPED_CHILD(GivenName);
135             DECL_TYPED_CHILD(SurName);
136             DECL_TYPED_CHILDREN(EmailAddress);
137             DECL_TYPED_CHILDREN(TelephoneNumber);
138             /** ContactType local name */
139             static const XMLCh TYPE_NAME[];
140             /** technical Contact Type */
141             static const XMLCh CONTACT_TECHNICAL[];
142             /** support Contact Type */
143             static const XMLCh CONTACT_SUPPORT[];
144             /** administrative Contact Type */
145             static const XMLCh CONTACT_ADMINISTRATIVE[];
146             /** billing Contact Type */
147             static const XMLCh CONTACT_BILLING[];
148             /** other Contact Type */
149             static const XMLCh CONTACT_OTHER[];
150         END_XMLOBJECT;
151
152         BEGIN_XMLOBJECT(SAML_API,AdditionalMetadataLocation,xmltooling::XMLObject,SAML 2.0 AdditionalMetadataLocation element);
153             DECL_STRING_ATTRIB(Namespace,NAMESPACE);
154             DECL_SIMPLE_CONTENT(Location);
155             /** AdditionalMetadataLocationType local name */
156             static const XMLCh TYPE_NAME[];
157         END_XMLOBJECT;
158
159         BEGIN_XMLOBJECT(SAML_API,KeyDescriptor,xmltooling::XMLObject,SAML 2.0 KeyDescriptor element);
160             DECL_STRING_ATTRIB(Use,USE);
161             DECL_TYPED_FOREIGN_CHILD(KeyInfo,xmlsignature);
162             DECL_TYPED_FOREIGN_CHILDREN(EncryptionMethod,xmlencryption);
163             /** KeyDescriptorType local name */
164             static const XMLCh TYPE_NAME[];
165             /** encryption Key Type */
166             static const XMLCh KEYTYPE_ENCRYPTION[];
167             /** signing Key Type */
168             static const XMLCh KEYTYPE_SIGNING[];
169         END_XMLOBJECT;
170
171         BEGIN_XMLOBJECT4(SAML_API,RoleDescriptor,xmltooling::AttributeExtensibleXMLObject,SignableObject,
172                 CacheableSAMLObject,TimeBoundSAMLObject,SAML 2.0 RoleDescriptor abstract element);
173             DECL_STRING_ATTRIB(ID,ID);
174             DECL_STRING_ATTRIB(ProtocolSupportEnumeration,PROTOCOLSUPPORTENUMERATION);
175             /** Searches the ProtocolSupportEnumeration attribute for the indicated protocol. */
176             virtual bool hasSupport(const XMLCh* protocol) const=0;
177             /** Adds the indicated protocol to the ProtocolSupportEnumeration attribute. */
178             virtual void addSupport(const XMLCh* protocol)=0;
179             DECL_STRING_ATTRIB(ErrorURL,ERRORURL);
180             DECL_TYPED_CHILD(Extensions);
181             DECL_TYPED_CHILDREN(KeyDescriptor);
182             DECL_TYPED_CHILD(Organization);
183             DECL_TYPED_CHILDREN(ContactPerson);
184         END_XMLOBJECT;
185
186         BEGIN_XMLOBJECT2(SAML_API,RoleDescriptorType,RoleDescriptor,xmltooling::ElementExtensibleXMLObject,SAML 2.0 RoleDescriptor extension);
187         END_XMLOBJECT;
188
189         BEGIN_XMLOBJECT(SAML_API,EndpointType,xmltooling::ElementProxy,SAML 2.0 EndpointType type);
190             DECL_STRING_ATTRIB(Binding,BINDING);
191             DECL_STRING_ATTRIB(Location,LOCATION);
192             DECL_STRING_ATTRIB(ResponseLocation,RESPONSELOCATION);
193             /** EndpointType local name */
194             static const XMLCh TYPE_NAME[];
195         END_XMLOBJECT;
196
197         BEGIN_XMLOBJECT(SAML_API,IndexedEndpointType,EndpointType,SAML 2.0 IndexedEndpointType type);
198             DECL_INTEGER_ATTRIB(Index,INDEX);
199             DECL_BOOLEAN_ATTRIB(isDefault,ISDEFAULT,false);
200             /** IndexedEndpointType local name */
201             static const XMLCh TYPE_NAME[];
202         END_XMLOBJECT;
203
204         BEGIN_XMLOBJECT(SAML_API,ArtifactResolutionService,IndexedEndpointType,SAML 2.0 ArtifactResolutionService element);
205         END_XMLOBJECT;
206
207         BEGIN_XMLOBJECT(SAML_API,SingleLogoutService,EndpointType,SAML 2.0 SingleLogoutService element);
208         END_XMLOBJECT;
209
210         BEGIN_XMLOBJECT(SAML_API,ManageNameIDService,EndpointType,SAML 2.0 ManageNameIDService element);
211         END_XMLOBJECT;
212
213         BEGIN_XMLOBJECT(SAML_API,SSODescriptorType,RoleDescriptor,SAML 2.0 SSODescriptorType abstract type);
214             DECL_TYPED_CHILDREN(ArtifactResolutionService);
215             DECL_TYPED_CHILDREN(SingleLogoutService);
216             DECL_TYPED_CHILDREN(ManageNameIDService);
217             DECL_TYPED_CHILDREN(NameIDFormat);
218             /** SSODescriptorType local name */
219             static const XMLCh TYPE_NAME[];
220         END_XMLOBJECT;
221
222         BEGIN_XMLOBJECT(SAML_API,SingleSignOnService,EndpointType,SAML 2.0 SingleSignOnService element);
223         END_XMLOBJECT;
224
225         BEGIN_XMLOBJECT(SAML_API,NameIDMappingService,EndpointType,SAML 2.0 NameIDMappingService element);
226         END_XMLOBJECT;
227
228         BEGIN_XMLOBJECT(SAML_API,AssertionIDRequestService,EndpointType,SAML 2.0 AssertionIDRequestService element);
229         END_XMLOBJECT;
230
231         BEGIN_XMLOBJECT(SAML_API,IDPSSODescriptor,SSODescriptorType,SAML 2.0 IDPSSODescriptor element);
232             DECL_BOOLEAN_ATTRIB(WantAuthnRequestsSigned,WANTAUTHNREQUESTSSIGNED,false);
233             DECL_TYPED_CHILDREN(SingleSignOnService);
234             DECL_TYPED_CHILDREN(NameIDMappingService);
235             DECL_TYPED_CHILDREN(AssertionIDRequestService);
236             DECL_TYPED_CHILDREN(AttributeProfile);
237             DECL_TYPED_FOREIGN_CHILDREN(Attribute,saml2);
238             /** IDPSSODescriptorType local name */
239             static const XMLCh TYPE_NAME[];
240             DECL_ELEMENT_QNAME;
241         END_XMLOBJECT;
242
243         BEGIN_XMLOBJECT(SAML_API,ServiceName,localizedNameType,SAML 2.0 ServiceName element);
244             DECL_SIMPLE_CONTENT(Name);
245         END_XMLOBJECT;
246
247         BEGIN_XMLOBJECT(SAML_API,ServiceDescription,localizedNameType,SAML 2.0 ServiceDescription element);
248             DECL_SIMPLE_CONTENT(Description);
249         END_XMLOBJECT;
250
251         BEGIN_XMLOBJECT(SAML_API,RequestedAttribute,saml2::Attribute,SAML 2.0 RequestedAttribute element);
252             DECL_BOOLEAN_ATTRIB(isRequired,ISREQUIRED,false);
253             /** RequestedAttributeType local name */
254             static const XMLCh TYPE_NAME[];
255         END_XMLOBJECT;
256
257         BEGIN_XMLOBJECT(SAML_API,AttributeConsumingService,xmltooling::XMLObject,SAML 2.0 AttributeConsumingService element);
258             DECL_INTEGER_ATTRIB(Index,INDEX);
259             DECL_BOOLEAN_ATTRIB(isDefault,ISDEFAULT,false);
260             DECL_TYPED_CHILDREN(ServiceName);
261             DECL_TYPED_CHILDREN(ServiceDescription);
262             DECL_TYPED_CHILDREN(RequestedAttribute);
263             /** AttributeConsumingServiceType local name */
264             static const XMLCh TYPE_NAME[];
265         END_XMLOBJECT;
266
267         BEGIN_XMLOBJECT(SAML_API,AssertionConsumerService,IndexedEndpointType,SAML 2.0 AssertionConsumerService element);
268         END_XMLOBJECT;
269
270         BEGIN_XMLOBJECT(SAML_API,SPSSODescriptor,SSODescriptorType,SAML 2.0 SPSSODescriptor element);
271             DECL_BOOLEAN_ATTRIB(AuthnRequestsSigned,AUTHNREQUESTSSIGNED,false);
272             DECL_BOOLEAN_ATTRIB(WantAssertionsSigned,WANTASSERTIONSSIGNED,false);
273             DECL_TYPED_CHILDREN(AssertionConsumerService);
274             DECL_TYPED_CHILDREN(AttributeConsumingService);
275             /** SPSSODescriptorType local name */
276             static const XMLCh TYPE_NAME[];
277             DECL_ELEMENT_QNAME;
278         END_XMLOBJECT;
279
280         BEGIN_XMLOBJECT(SAML_API,AuthnQueryService,EndpointType,SAML 2.0 AuthnQueryService element);
281         END_XMLOBJECT;
282
283         BEGIN_XMLOBJECT(SAML_API,AuthnAuthorityDescriptor,RoleDescriptor,SAML 2.0 AuthnAuthorityDescriptor element);
284             DECL_TYPED_CHILDREN(AuthnQueryService);
285             DECL_TYPED_CHILDREN(AssertionIDRequestService);
286             DECL_TYPED_CHILDREN(NameIDFormat);
287             /** AuthnAuthorityDescriptorType local name */
288             static const XMLCh TYPE_NAME[];
289             DECL_ELEMENT_QNAME;
290         END_XMLOBJECT;
291
292         BEGIN_XMLOBJECT(SAML_API,AuthzService,EndpointType,SAML 2.0 AuthzService element);
293         END_XMLOBJECT;
294
295         BEGIN_XMLOBJECT(SAML_API,PDPDescriptor,RoleDescriptor,SAML 2.0 PDPDescriptor element);
296             DECL_TYPED_CHILDREN(AuthzService);
297             DECL_TYPED_CHILDREN(AssertionIDRequestService);
298             DECL_TYPED_CHILDREN(NameIDFormat);
299             /** PDPDescriptorType local name */
300             static const XMLCh TYPE_NAME[];
301             DECL_ELEMENT_QNAME;
302         END_XMLOBJECT;
303
304         BEGIN_XMLOBJECT(SAML_API,AttributeService,EndpointType,SAML 2.0 AttributeService element);
305         END_XMLOBJECT;
306
307         BEGIN_XMLOBJECT(SAML_API,AttributeAuthorityDescriptor,RoleDescriptor,SAML 2.0 AttributeAuthorityDescriptor element);
308             DECL_TYPED_CHILDREN(AttributeService);
309             DECL_TYPED_CHILDREN(AssertionIDRequestService);
310             DECL_TYPED_CHILDREN(NameIDFormat);
311             DECL_TYPED_CHILDREN(AttributeProfile);
312             DECL_TYPED_FOREIGN_CHILDREN(Attribute,saml2);
313             /** AttributeAuthorityDescriptorType local name */
314             static const XMLCh TYPE_NAME[];
315             DECL_ELEMENT_QNAME;
316         END_XMLOBJECT;
317
318         BEGIN_XMLOBJECT(SAML_API,QueryDescriptorType,RoleDescriptor,SAML 2.0 QueryDescriptorType abstract type);
319             DECL_BOOLEAN_ATTRIB(WantAssertionsSigned,WANTASSERTIONSSIGNED,false);
320             DECL_TYPED_CHILDREN(NameIDFormat);
321             /** QueryDescriptorType local name */
322             static const XMLCh TYPE_NAME[];
323         END_XMLOBJECT;
324
325         BEGIN_XMLOBJECT(SAML_API,AuthnQueryDescriptorType,QueryDescriptorType,SAML 2.0 AuthnQueryDescriptorType extension type);
326             /** AuthnQueryDescriptorType local name */
327             static const XMLCh TYPE_NAME[];
328             DECL_TYPE_QNAME;
329         END_XMLOBJECT;
330
331         BEGIN_XMLOBJECT(SAML_API,AttributeQueryDescriptorType,QueryDescriptorType,SAML 2.0 AttributeQueryDescriptorType extension type);
332             DECL_TYPED_CHILDREN(AttributeConsumingService);
333             /** AttributeQueryDescriptorType local name */
334             static const XMLCh TYPE_NAME[];
335             DECL_TYPE_QNAME;
336         END_XMLOBJECT;
337
338         BEGIN_XMLOBJECT(SAML_API,AuthzDecisionQueryDescriptorType,QueryDescriptorType,SAML 2.0 AuthzDecisionQueryDescriptorType extension type);
339             DECL_TYPED_CHILDREN(ActionNamespace);
340             /** AuthzDecisionQueryDescriptorType local name */
341             static const XMLCh TYPE_NAME[];
342             DECL_TYPE_QNAME;
343         END_XMLOBJECT;
344
345         BEGIN_XMLOBJECT4(SAML_API,AffiliationDescriptor,xmltooling::AttributeExtensibleXMLObject,SignableObject,
346                 CacheableSAMLObject,TimeBoundSAMLObject,SAML 2.0 AffiliationDescriptor element);
347             DECL_STRING_ATTRIB(ID,ID);
348             DECL_STRING_ATTRIB(AffiliationOwnerID,AFFILIATIONOWNERID);
349             DECL_TYPED_CHILD(Extensions);
350             DECL_TYPED_CHILDREN(AffiliateMember);
351             DECL_TYPED_CHILDREN(KeyDescriptor);
352             /** AffiliationDescriptorType local name */
353             static const XMLCh TYPE_NAME[];
354         END_XMLOBJECT;
355
356         BEGIN_XMLOBJECT4(SAML_API,EntityDescriptor,xmltooling::AttributeExtensibleXMLObject,SignableObject,
357                 CacheableSAMLObject,TimeBoundSAMLObject,SAML 2.0 EntityDescriptor element);
358             DECL_STRING_ATTRIB(ID,ID);
359             DECL_STRING_ATTRIB(EntityID,ENTITYID);
360             DECL_TYPED_CHILD(Extensions);
361             DECL_TYPED_CHILD(AffiliationDescriptor);
362             DECL_TYPED_CHILDREN(RoleDescriptor);
363             DECL_TYPED_CHILDREN(IDPSSODescriptor);
364             DECL_TYPED_CHILDREN(SPSSODescriptor);
365             DECL_TYPED_CHILDREN(AuthnAuthorityDescriptor);
366             DECL_TYPED_CHILDREN(AttributeAuthorityDescriptor);
367             DECL_TYPED_CHILDREN(PDPDescriptor);
368             DECL_TYPED_CHILDREN(AuthnQueryDescriptorType);
369             DECL_TYPED_CHILDREN(AttributeQueryDescriptorType);
370             DECL_TYPED_CHILDREN(AuthzDecisionQueryDescriptorType);
371             DECL_TYPED_CHILD(Organization);
372             DECL_TYPED_CHILDREN(ContactPerson);
373             DECL_TYPED_CHILDREN(AdditionalMetadataLocation);
374             /** Finds an arbitrary role type supporting a given protocol. */
375             virtual const RoleDescriptor* getRoleDescriptor(const xmltooling::QName& qname, const XMLCh* protocol) const=0;
376             /** EntityDescriptorType local name */
377             static const XMLCh TYPE_NAME[];
378         END_XMLOBJECT;
379
380         BEGIN_XMLOBJECT3(SAML_API,EntitiesDescriptor,SignableObject,CacheableSAMLObject,
381                 TimeBoundSAMLObject,SAML 2.0 EntitiesDescriptor element);
382             DECL_STRING_ATTRIB(ID,ID);
383             DECL_STRING_ATTRIB(Name,NAME);
384             DECL_TYPED_CHILD(Extensions);
385             DECL_TYPED_CHILDREN(EntityDescriptor);
386             DECL_TYPED_CHILDREN(EntitiesDescriptor);
387             /** EntitiesDescriptorType local name */
388             static const XMLCh TYPE_NAME[];
389         END_XMLOBJECT;
390
391         BEGIN_XMLOBJECT(SAML_API,EntityAttributes,xmltooling::XMLObject,SAML Metadata Extension for Entity Attributes element);
392             DECL_TYPED_FOREIGN_CHILDREN(Attribute,saml2);
393             DECL_TYPED_FOREIGN_CHILDREN(Assertion,saml2);
394             /** EntityAttributesType local name */
395             static const XMLCh TYPE_NAME[];
396         END_XMLOBJECT;
397
398         /**
399          * Predicate to test a role for validity and protocol support.
400          */
401         class isValidForProtocol
402         {
403         public:
404             /**
405              * Constructor.
406              *
407              * @param protocol  support constant to test for
408              */
409             isValidForProtocol(const XMLCh* protocol) : m_time(time(NULL)), m_protocol(protocol) {
410             }
411
412             /**
413              * Returns true iff the supplied role is valid now and supports the right protocol.
414              *
415              * @param role  role to test
416              * @return  result of predicate
417              */
418             bool operator()(const RoleDescriptor* role) const {
419                 return role ? (role->isValid(m_time) && role->hasSupport(m_protocol)) : false;
420             }
421
422         private:
423             time_t m_time;
424             const XMLCh* m_protocol;
425         };
426
427         /**
428          * Predicate to test a role for type equivalence, validity, and protocol support.
429          */
430         class ofTypeValidForProtocol : public isValidForProtocol, public xmltooling::hasSchemaType
431         {
432         public:
433             /**
434              * Constructor.
435              *
436              * @param q         schema type to test for
437              * @param protocol  support constant to test for
438              */
439             ofTypeValidForProtocol(const xmltooling::QName& q, const XMLCh* protocol)
440                 : isValidForProtocol(protocol), xmltooling::hasSchemaType(q)  {
441             }
442
443             /**
444              * Returns true iff the supplied role is of the right type, valid now, and supports the right protocol.
445              *
446              * @param role  role to test
447              * @return  result of predicate
448              */
449             bool operator()(const RoleDescriptor* role) const {
450                 return xmltooling::hasSchemaType::operator()(role) && isValidForProtocol::operator()(role);
451             }
452         };
453
454         DECL_SAML2MDOBJECTBUILDER(AdditionalMetadataLocation);
455         DECL_SAML2MDOBJECTBUILDER(AffiliateMember);
456         DECL_SAML2MDOBJECTBUILDER(AffiliationDescriptor);
457         DECL_SAML2MDOBJECTBUILDER(ArtifactResolutionService);
458         DECL_SAML2MDOBJECTBUILDER(AssertionConsumerService);
459         DECL_SAML2MDOBJECTBUILDER(AssertionIDRequestService);
460         DECL_SAML2MDOBJECTBUILDER(AttributeAuthorityDescriptor);
461         DECL_SAML2MDOBJECTBUILDER(AttributeConsumingService);
462         DECL_SAML2MDOBJECTBUILDER(AttributeProfile);
463         DECL_SAML2MDOBJECTBUILDER(AttributeService);
464         DECL_SAML2MDOBJECTBUILDER(AuthnAuthorityDescriptor);
465         DECL_SAML2MDOBJECTBUILDER(AuthnQueryService);
466         DECL_SAML2MDOBJECTBUILDER(AuthzService);
467         DECL_SAML2MDOBJECTBUILDER(Company);
468         DECL_SAML2MDOBJECTBUILDER(ContactPerson);
469         DECL_SAML2MDOBJECTBUILDER(EmailAddress);
470         DECL_SAML2MDOBJECTBUILDER(EntitiesDescriptor);
471         DECL_SAML2MDOBJECTBUILDER(EntityDescriptor);
472         DECL_SAML2MDOBJECTBUILDER(Extensions);
473         DECL_SAML2MDOBJECTBUILDER(GivenName);
474         DECL_SAML2MDOBJECTBUILDER(IDPSSODescriptor);
475         DECL_SAML2MDOBJECTBUILDER(KeyDescriptor);
476         DECL_SAML2MDOBJECTBUILDER(ManageNameIDService);
477         DECL_SAML2MDOBJECTBUILDER(NameIDFormat);
478         DECL_SAML2MDOBJECTBUILDER(NameIDMappingService);
479         DECL_SAML2MDOBJECTBUILDER(Organization);
480         DECL_SAML2MDOBJECTBUILDER(OrganizationName);
481         DECL_SAML2MDOBJECTBUILDER(OrganizationDisplayName);
482         DECL_SAML2MDOBJECTBUILDER(OrganizationURL);
483         DECL_SAML2MDOBJECTBUILDER(PDPDescriptor);
484         DECL_SAML2MDOBJECTBUILDER(RequestedAttribute);
485         DECL_SAML2MDOBJECTBUILDER(ServiceDescription);
486         DECL_SAML2MDOBJECTBUILDER(ServiceName);
487         DECL_SAML2MDOBJECTBUILDER(SingleLogoutService);
488         DECL_SAML2MDOBJECTBUILDER(SingleSignOnService);
489         DECL_SAML2MDOBJECTBUILDER(SPSSODescriptor);
490         DECL_SAML2MDOBJECTBUILDER(SurName);
491         DECL_SAML2MDOBJECTBUILDER(TelephoneNumber);
492
493         DECL_XMLOBJECTBUILDER(SAML_API,ActionNamespace,samlconstants::SAML20MD_QUERY_EXT_NS,samlconstants::SAML20MD_QUERY_EXT_PREFIX);
494         DECL_XMLOBJECTBUILDER(SAML_API,SourceID,samlconstants::SAML1MD_NS,samlconstants::SAML1MD_PREFIX);
495         DECL_XMLOBJECTBUILDER(SAML_API,EntityAttributes,samlconstants::SAML20MD_ENTITY_ATTRIBUTE_NS,samlconstants::SAML20MD_ENTITY_ATTRIBUTE_PREFIX);
496
497         /**
498          * Builder for localizedNameType objects.
499          *
500          * This is customized to force the element name to be specified.
501          */
502         class SAML_API localizedNameTypeBuilder : public xmltooling::XMLObjectBuilder {
503         public:
504             virtual ~localizedNameTypeBuilder() {}
505             /** Builder that allows element/type override. */
506 #ifdef HAVE_COVARIANT_RETURNS
507             virtual localizedNameType* buildObject(
508 #else
509             virtual xmltooling::XMLObject* buildObject(
510 #endif
511                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
512                 ) const;
513
514             /** Singleton builder. */
515             static localizedNameType* buildlocalizedNameType(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL) {
516                 const localizedNameTypeBuilder* b = dynamic_cast<const localizedNameTypeBuilder*>(
517                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_NS,localizedNameType::TYPE_NAME))
518                     );
519                 if (b) {
520                     xmltooling::QName schemaType(samlconstants::SAML20MD_NS,localizedNameType::TYPE_NAME,samlconstants::SAML20MD_PREFIX);
521 #ifdef HAVE_COVARIANT_RETURNS
522                     return b->buildObject(nsURI, localName, prefix, &schemaType);
523 #else
524                     return dynamic_cast<localizedNameType*>(b->buildObject(nsURI, localName, prefix, &schemaType));
525 #endif
526                 }
527                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for localizedNameType.");
528             }
529         };
530
531         /**
532          * Builder for localizedURIType objects.
533          *
534          * This is customized to force the element name to be specified.
535          */
536         class SAML_API localizedURITypeBuilder : public xmltooling::XMLObjectBuilder {
537         public:
538             virtual ~localizedURITypeBuilder() {}
539             /** Builder that allows element/type override. */
540 #ifdef HAVE_COVARIANT_RETURNS
541             virtual localizedURIType* buildObject(
542 #else
543             virtual xmltooling::XMLObject* buildObject(
544 #endif
545                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
546                 ) const;
547
548             /** Singleton builder. */
549             static localizedURIType* buildlocalizedURIType(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL) {
550                 const localizedURITypeBuilder* b = dynamic_cast<const localizedURITypeBuilder*>(
551                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_NS,localizedURIType::TYPE_NAME))
552                     );
553                 if (b) {
554                     xmltooling::QName schemaType(samlconstants::SAML20MD_NS,localizedURIType::TYPE_NAME,samlconstants::SAML20MD_PREFIX);
555 #ifdef HAVE_COVARIANT_RETURNS
556                     return b->buildObject(nsURI, localName, prefix, &schemaType);
557 #else
558                     return dynamic_cast<localizedURIType*>(b->buildObject(nsURI, localName, prefix, &schemaType));
559 #endif
560                 }
561                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for localizedURIType.");
562             }
563         };
564
565         /**
566          * Builder for EndpointType objects.
567          *
568          * This is customized to force the element name to be specified.
569          */
570         class SAML_API EndpointTypeBuilder : public xmltooling::XMLObjectBuilder {
571         public:
572             virtual ~EndpointTypeBuilder() {}
573             /** Builder that allows element/type override. */
574 #ifdef HAVE_COVARIANT_RETURNS
575             virtual EndpointType* buildObject(
576 #else
577             virtual xmltooling::XMLObject* buildObject(
578 #endif
579                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
580                 ) const;
581
582             /** Singleton builder. */
583             static EndpointType* buildEndpointType(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL) {
584                 const EndpointTypeBuilder* b = dynamic_cast<const EndpointTypeBuilder*>(
585                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_NS,EndpointType::TYPE_NAME))
586                     );
587                 if (b) {
588                     xmltooling::QName schemaType(samlconstants::SAML20MD_NS,EndpointType::TYPE_NAME,samlconstants::SAML20MD_PREFIX);
589 #ifdef HAVE_COVARIANT_RETURNS
590                     return b->buildObject(nsURI, localName, prefix, &schemaType);
591 #else
592                     return dynamic_cast<EndpointType*>(b->buildObject(nsURI, localName, prefix, &schemaType));
593 #endif
594                 }
595                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for EndpointType.");
596             }
597         };
598
599         /**
600          * Builder for IndexedEndpointType objects.
601          *
602          * This is customized to force the element name to be specified.
603          */
604         class SAML_API IndexedEndpointTypeBuilder : public xmltooling::XMLObjectBuilder {
605         public:
606             virtual ~IndexedEndpointTypeBuilder() {}
607             /** Builder that allows element/type override. */
608 #ifdef HAVE_COVARIANT_RETURNS
609             virtual IndexedEndpointType* buildObject(
610 #else
611             virtual xmltooling::XMLObject* buildObject(
612 #endif
613                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
614                 ) const;
615
616             /** Singleton builder. */
617             static IndexedEndpointType* buildIndexedEndpointType(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL) {
618                 const IndexedEndpointTypeBuilder* b = dynamic_cast<const IndexedEndpointTypeBuilder*>(
619                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_NS,IndexedEndpointType::TYPE_NAME))
620                     );
621                 if (b) {
622                     xmltooling::QName schemaType(samlconstants::SAML20MD_NS,IndexedEndpointType::TYPE_NAME,samlconstants::SAML20MD_PREFIX);
623 #ifdef HAVE_COVARIANT_RETURNS
624                     return b->buildObject(nsURI, localName, prefix, &schemaType);
625 #else
626                     return dynamic_cast<IndexedEndpointType*>(b->buildObject(nsURI, localName, prefix, &schemaType));
627 #endif
628                 }
629                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for IndexedEndpointType.");
630             }
631         };
632
633         /**
634          * Builder for RoleDescriptor extension objects.
635          *
636          * This is customized to force the schema type to be specified.
637          */
638         class SAML_API RoleDescriptorBuilder : public xmltooling::XMLObjectBuilder {
639         public:
640             virtual ~RoleDescriptorBuilder() {}
641             /** Builder that allows element/type override. */
642 #ifdef HAVE_COVARIANT_RETURNS
643             virtual RoleDescriptor* buildObject(
644 #else
645             virtual xmltooling::XMLObject* buildObject(
646 #endif
647                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
648                 ) const;
649
650             /** Singleton builder. */
651             static RoleDescriptor* buildRoleDescriptor(const xmltooling::QName& schemaType) {
652                 const RoleDescriptorBuilder* b = dynamic_cast<const RoleDescriptorBuilder*>(
653                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_NS,RoleDescriptor::LOCAL_NAME))
654                     );
655                 if (b) {
656 #ifdef HAVE_COVARIANT_RETURNS
657                     return b->buildObject(samlconstants::SAML20MD_NS, RoleDescriptor::LOCAL_NAME, samlconstants::SAML20MD_PREFIX, &schemaType);
658 #else
659                     return dynamic_cast<RoleDescriptor*>(b->buildObject(samlconstants::SAML20MD_NS, RoleDescriptor::LOCAL_NAME, samlconstants::SAML20MD_PREFIX, &schemaType));
660 #endif
661                 }
662                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for RoleDescriptor.");
663             }
664         };
665
666         /**
667          * Builder for AuthnQueryDescriptorType objects.
668          *
669          * This is customized to return a RoleDescriptor element with an
670          * xsi:type of AuthnQueryDescriptorType.
671          */
672         class SAML_API AuthnQueryDescriptorTypeBuilder : public xmltooling::ConcreteXMLObjectBuilder {
673         public:
674             virtual ~AuthnQueryDescriptorTypeBuilder() {}
675             /** Default builder. */
676 #ifdef HAVE_COVARIANT_RETURNS
677             virtual AuthnQueryDescriptorType* buildObject() const {
678 #else
679             virtual xmltooling::XMLObject* buildObject() const {
680 #endif
681                 xmltooling::QName schemaType(
682                     samlconstants::SAML20MD_QUERY_EXT_NS,AuthnQueryDescriptorType::TYPE_NAME,samlconstants::SAML20MD_QUERY_EXT_PREFIX
683                     );
684                 return buildObject(
685                     samlconstants::SAML20MD_NS,AuthnQueryDescriptorType::LOCAL_NAME,samlconstants::SAML20MD_PREFIX,&schemaType
686                     );
687             }
688             /** Builder that allows element/type override. */
689 #ifdef HAVE_COVARIANT_RETURNS
690             virtual AuthnQueryDescriptorType* buildObject(
691 #else
692             virtual xmltooling::XMLObject* buildObject(
693 #endif
694                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
695                 ) const;
696
697             /** Singleton builder. */
698             static AuthnQueryDescriptorType* buildAuthnQueryDescriptorType() {
699                 const AuthnQueryDescriptorTypeBuilder* b = dynamic_cast<const AuthnQueryDescriptorTypeBuilder*>(
700                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_QUERY_EXT_NS,AuthnQueryDescriptorType::TYPE_NAME))
701                     );
702                 if (b) {
703 #ifdef HAVE_COVARIANT_RETURNS
704                     return b->buildObject();
705 #else
706                     return dynamic_cast<AuthnQueryDescriptorType*>(b->buildObject());
707 #endif
708                 }
709                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for AuthnQueryDescriptorType.");
710             }
711         };
712
713         /**
714          * Builder for AttributeQueryDescriptorType objects.
715          *
716          * This is customized to return a RoleDescriptor element with an
717          * xsi:type of AttributeQueryDescriptorType.
718          */
719         class SAML_API AttributeQueryDescriptorTypeBuilder : public xmltooling::ConcreteXMLObjectBuilder {
720         public:
721             virtual ~AttributeQueryDescriptorTypeBuilder() {}
722             /** Default builder. */
723 #ifdef HAVE_COVARIANT_RETURNS
724             virtual AttributeQueryDescriptorType* buildObject() const {
725 #else
726             virtual xmltooling::XMLObject* buildObject() const {
727 #endif
728                 xmltooling::QName schemaType(
729                     samlconstants::SAML20MD_QUERY_EXT_NS,AttributeQueryDescriptorType::TYPE_NAME,samlconstants::SAML20MD_QUERY_EXT_PREFIX
730                     );
731                 return buildObject(
732                     samlconstants::SAML20MD_NS,AttributeQueryDescriptorType::LOCAL_NAME,samlconstants::SAML20MD_PREFIX,&schemaType
733                     );
734             }
735             /** Builder that allows element/type override. */
736 #ifdef HAVE_COVARIANT_RETURNS
737             virtual AttributeQueryDescriptorType* buildObject(
738 #else
739             virtual xmltooling::XMLObject* buildObject(
740 #endif
741                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
742                 ) const;
743
744             /** Singleton builder. */
745             static AttributeQueryDescriptorType* buildAttributeQueryDescriptorType() {
746                 const AttributeQueryDescriptorTypeBuilder* b = dynamic_cast<const AttributeQueryDescriptorTypeBuilder*>(
747                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_QUERY_EXT_NS,AttributeQueryDescriptorType::TYPE_NAME))
748                     );
749                 if (b) {
750 #ifdef HAVE_COVARIANT_RETURNS
751                     return b->buildObject();
752 #else
753                     return dynamic_cast<AttributeQueryDescriptorType*>(b->buildObject());
754 #endif
755                 }
756                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for AttributeQueryDescriptorType.");
757             }
758         };
759
760         /**
761          * Builder for AuthzDecisionQueryDescriptorType objects.
762          *
763          * This is customized to return a RoleDescriptor element with an
764          * xsi:type of AuthzDecisionQueryDescriptorType.
765          */
766         class SAML_API AuthzDecisionQueryDescriptorTypeBuilder : public xmltooling::ConcreteXMLObjectBuilder {
767         public:
768             virtual ~AuthzDecisionQueryDescriptorTypeBuilder() {}
769             /** Default builder. */
770 #ifdef HAVE_COVARIANT_RETURNS
771             virtual AuthzDecisionQueryDescriptorType* buildObject() const {
772 #else
773             virtual xmltooling::XMLObject* buildObject() const {
774 #endif
775                 xmltooling::QName schemaType(
776                     samlconstants::SAML20MD_QUERY_EXT_NS,AuthzDecisionQueryDescriptorType::TYPE_NAME,samlconstants::SAML20MD_QUERY_EXT_PREFIX
777                     );
778                 return buildObject(
779                     samlconstants::SAML20MD_NS,AuthzDecisionQueryDescriptorType::LOCAL_NAME,samlconstants::SAML20MD_PREFIX,&schemaType
780                     );
781             }
782             /** Builder that allows element/type override. */
783 #ifdef HAVE_COVARIANT_RETURNS
784             virtual AuthzDecisionQueryDescriptorType* buildObject(
785 #else
786             virtual xmltooling::XMLObject* buildObject(
787 #endif
788                 const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const xmltooling::QName* schemaType=NULL
789                 ) const;
790
791             /** Singleton builder. */
792             static AuthzDecisionQueryDescriptorType* buildAuthzDecisionQueryDescriptorType() {
793                 const AuthzDecisionQueryDescriptorTypeBuilder* b = dynamic_cast<const AuthzDecisionQueryDescriptorTypeBuilder*>(
794                     XMLObjectBuilder::getBuilder(xmltooling::QName(samlconstants::SAML20MD_QUERY_EXT_NS,AuthzDecisionQueryDescriptorType::TYPE_NAME))
795                     );
796                 if (b) {
797 #ifdef HAVE_COVARIANT_RETURNS
798                     return b->buildObject();
799 #else
800                     return dynamic_cast<AuthzDecisionQueryDescriptorType*>(b->buildObject());
801 #endif
802                 }
803                 throw xmltooling::XMLObjectException("Unable to obtain typed builder for AuthzDecisionQueryDescriptorType.");
804             }
805         };
806
807         /**
808          * Registers builders and validators for SAML 2.0 Metadata classes into the runtime.
809          */
810         void SAML_API registerMetadataClasses();
811     };
812 };
813
814 #endif /* __saml2_metadata_h__ */