Set fourth file version digit to signify rebuild.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / DiscoverableMetadataProvider.h
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  * @file saml/saml2/metadata/DiscoverableMetadataProvider.h
23  * 
24  * A metadata provider that provides a JSON feed of IdP discovery information.
25  */
26
27 #ifndef __saml2_discometadataprov_h__
28 #define __saml2_discometadataprov_h__
29
30 #include <saml/saml2/metadata/MetadataProvider.h>
31
32 #include <boost/shared_ptr.hpp>
33
34 namespace opensaml {
35     
36     namespace saml2 {
37         class SAML_API Attribute;
38     };
39
40     namespace saml2md {
41
42         class SAML_API EntityAttributes;
43         class SAML_API EntityMatcher;
44         
45 #if defined (_MSC_VER)
46         #pragma warning( push )
47         #pragma warning( disable : 4251 )
48 #endif
49         /**
50          * A metadata provider that provides a JSON feed of IdP discovery information.
51          */
52         class SAML_API DiscoverableMetadataProvider : public virtual MetadataProvider
53         {
54         protected:
55             /**
56              * Constructor.
57              *
58              * If a DOM is supplied, the following XML content is supported:
59              *
60              * <dl>
61              *   <dt>legacyOrgNames</dt>
62              *   <dd>true iff IdPs without a UIInfo extension should
63              *      be identified using &lt;md:OrganizationDisplayName&gt;</dd>
64              *   <dt>entityAttributes</dt>
65              *   <dd>true iff tags found in &lt;mdattr:EntityAttributes&gt;
66              *      extensions should be included in the feed</dd>
67              *   <dt>&lt;DiscoveryFilter type="..." matcher="..." &gt;</dt>
68              *   <dd>Zero or more filters of type "Whitelist" or "Blacklist" that
69              *      affect which entities get exposed by the feed. The actual matching
70              *      is driven by an EntityMatcher plugin identified by the matcher
71              *      attribute. Other element content will be present to configure
72              *      that plugin.</dd>
73              * </dl>
74              *
75              * @param e DOM to supply configuration for provider
76              */
77             DiscoverableMetadataProvider(const xercesc::DOMElement* e=nullptr);
78             
79             /**
80              * Generates a JSON feed of IdP discovery information for the current metadata.
81              * <p>The provider <strong>MUST</strong> be write-locked.
82              */
83             virtual void generateFeed();
84
85         public:
86             virtual ~DiscoverableMetadataProvider();
87
88             /**
89              * Returns the ETag associated with the cached feed.
90              * <p>The provider <strong>MUST</strong> be locked.
91              *
92              * @return the ETag value for the current feed state
93              */
94             virtual std::string getCacheTag() const;
95
96             /**
97              * Outputs the cached feed.
98              * <p>The provider <strong>MUST</strong> be locked.
99              *
100              * @param os        stream to output feed into
101              * @param first     on input, indicates if the feed is first in position,
102              *                  on output will be false if the feed was non-empty
103              * @param wrapArray true iff the feed array should be opened/closed by this provider
104              */
105             virtual void outputFeed(std::ostream& os, bool& first, bool wrapArray=true) const;
106
107         protected:
108             /** Storage for feed. */
109             std::string m_feed;
110
111             /** ETag for feed. */
112             mutable std::string m_feedTag;
113
114         private:
115             void discoEntity(std::string& s, const EntityDescriptor* entity, bool& first) const;
116             void discoGroup(std::string& s, const EntitiesDescriptor* group, bool& first) const;
117             void discoEntityAttributes(std::string& s, const EntityAttributes& ea, bool& first) const;
118             void discoAttributes(std::string& s, const std::vector<saml2::Attribute*>& attrs, bool& first) const;
119
120             bool m_legacyOrgNames, m_entityAttributes;
121             std::vector< std::pair< bool, boost::shared_ptr<EntityMatcher> > > m_discoFilters;
122         };
123
124 #if defined (_MSC_VER)
125         #pragma warning( pop )
126 #endif
127
128     };
129 };
130
131 #endif /* __saml2_discometadataprov_h__ */