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 * NullMetadataProvider.cpp
23 *
24 * Dummy provider that returns an empty entity supporting any role.
25 */
26
27 #include "internal.h"
28 #include "saml2/metadata/Metadata.h"
29 #include "saml2/metadata/AbstractDynamicMetadataProvider.h"
30
31 #include <xmltooling/util/XMLHelper.h>
32
33 using namespace opensaml::saml2md;
34 using namespace xmltooling;
35 using namespace std;
36
37 using boost::scoped_ptr;
38
39 namespace opensaml {
40 namespace saml2md {
41 class SAML_DLLLOCAL NullMetadataProvider : public AbstractDynamicMetadataProvider
42 {
43 public:
NullMetadataProvider(const DOMElement * e)44 NullMetadataProvider(const DOMElement* e) : AbstractDynamicMetadataProvider(true, e), MetadataProvider(e) {
45 e = XMLHelper::getFirstChildElement(e, samlconstants::SAML20MD_NS, EntityDescriptor::LOCAL_NAME);
46 if (e)
47 m_template.reset(dynamic_cast<EntityDescriptor*>(XMLObjectBuilder::buildOneFromElement(const_cast<DOMElement*>(e))));
48 }
49
~NullMetadataProvider()50 virtual ~NullMetadataProvider() {}
51
init()52 void init() {}
53
54 protected:
55 EntityDescriptor* resolve(const MetadataProvider::Criteria& criteria, string& cacheTag) const;
56
57 private:
58 scoped_ptr<EntityDescriptor> m_template;
59 };
60
NullMetadataProviderFactory(const DOMElement * const & e,bool deprecationSupport)61 MetadataProvider* SAML_DLLLOCAL NullMetadataProviderFactory(const DOMElement* const & e, bool deprecationSupport)
62 {
63 return new NullMetadataProvider(e);
64 }
65 };
66 };
67
resolve(const MetadataProvider::Criteria & criteria,string & cacheTag) const68 EntityDescriptor* NullMetadataProvider::resolve(const MetadataProvider::Criteria& criteria, string& cacheTag) const
69 {
70 // Resolving for us just means fabricating a new dummy element.
71 EntityDescriptor* entity = m_template.get() ? m_template->cloneEntityDescriptor() : EntityDescriptorBuilder::buildEntityDescriptor();
72
73 if (criteria.entityID_ascii) {
74 auto_ptr_XMLCh temp(criteria.entityID_ascii);
75 entity->setEntityID(temp.get());
76 }
77 else if (criteria.entityID_unicode)
78 entity->setEntityID(criteria.entityID_unicode);
79 else if (criteria.artifact)
80 throw MetadataException("Unable to resolve Null metadata from an artifact.");
81 return entity;
82 }
83