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 "Include" or "Exclude" 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              * @param deprecationSupport true iff deprecated features and settings should be supported
77              */
78             DiscoverableMetadataProvider(const xercesc::DOMElement* e=nullptr, bool deprecationSupport=true);
79 
80             /**
81              * Generates a JSON feed of IdP discovery information for the current metadata.
82              * <p>The provider <strong>MUST</strong> be write-locked.
83              */
84             virtual void generateFeed();
85 
86         public:
87             virtual ~DiscoverableMetadataProvider();
88 
89             /**
90              * Returns the ETag associated with the cached feed.
91              * <p>The provider <strong>MUST</strong> be locked.
92              *
93              * @return the ETag value for the current feed state
94              */
95             virtual std::string getCacheTag() const;
96 
97             /**
98              * Outputs the cached feed.
99              * <p>The provider <strong>MUST</strong> be locked.
100              *
101              * @param os        stream to output feed into
102              * @param first     on input, indicates if the feed is first in position,
103              *                  on output will be false if the feed was non-empty
104              * @param wrapArray true iff the feed array should be opened/closed by this provider
105              */
106             virtual void outputFeed(std::ostream& os, bool& first, bool wrapArray=true) const;
107 
108         protected:
109             /** Storage for feed. */
110             std::string m_feed;
111 
112             /** ETag for feed. */
113             mutable std::string m_feedTag;
114 
115         private:
116             void discoEntity(std::string& s, const EntityDescriptor* entity, bool& first) const;
117             void discoGroup(std::string& s, const EntitiesDescriptor* group, bool& first) const;
118             void discoEntityAttributes(std::string& s, const EntityAttributes& ea, bool& first) const;
119             void discoAttributes(std::string& s, const std::vector<saml2::Attribute*>& attrs, bool& first) const;
120 
121             bool m_legacyOrgNames, m_entityAttributes;
122             std::vector< std::pair< bool, boost::shared_ptr<EntityMatcher> > > m_discoFilters;
123         };
124 
125 #if defined (_MSC_VER)
126         #pragma warning( pop )
127 #endif
128 
129     };
130 };
131 
132 #endif /* __saml2_discometadataprov_h__ */
133