Port Java provider API, fix to protocol support check.
[shibboleth/cpp-opensaml.git] / saml / saml2 / metadata / MetadataProvider.h
1 /*
2  *  Copyright 2001-2006 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 MetadataProvider.h
19  * 
20  * Supplies an individual source of metadata.
21  */
22
23 #ifndef __saml2_metadataprov_h__
24 #define __saml2_metadataprov_h__
25
26 #include <xmltooling/Lockable.h>
27 #include <saml/saml2/metadata/MetadataFilter.h>
28
29 namespace opensaml {
30
31     namespace saml2md {
32         
33         /**
34          * Supplies an individual source of metadata.
35          * 
36          * The source can be a local file, remote service, or the result of a
37          * dynamic lookup, can include local caching, etc.
38          */
39         class SAML_API MetadataProvider : public virtual xmltooling::Lockable
40         {
41             MAKE_NONCOPYABLE(MetadataProvider);
42         protected:
43             MetadataProvider() : m_filter(NULL) {}
44             
45         public:
46             virtual ~MetadataProvider() {
47                 delete m_filter;
48             }
49             
50             /**
51              * Gets the metadata filter applied to the resolved metadata.
52              * 
53              * @return the metadata filter applied to the resolved metadata
54              */
55             const MetadataFilter* getMetadataFilter() const {
56                 return m_filter;
57             }
58         
59             /**
60              * Sets the metadata filter applied to the resolved metadata.
61              * 
62              * @param newFilter the metadata filter applied to the resolved metadata
63              */
64             void setMetadataFilter(MetadataFilter* newFilter) {
65                 delete m_filter;
66                 m_filter=newFilter;
67             }
68             
69             /**
70              * Should be called after instantiating provider and setting filter, but before
71              * performing any lookup operations. Allows the provider to defer initialization
72              * processes that are likely to result in exceptions until after the provider is
73              * safely created. Providers SHOULD perform as much processing as possible in
74              * this method so as to report/log any errors that would affect later processing.
75              * Also, any inputs supplied to the factory MUST persist until the completion of
76              * this method, but the caller is then free to modify or delete them.
77              */
78             virtual void init()=0;
79             
80             /**
81              * Gets the entire metadata tree, after the registered filter has been applied.
82              * The caller MUST unlock the provider when finished with the data.
83              * 
84              * @return the entire metadata tree
85              */
86             virtual const xmltooling::XMLObject* getMetadata() const=0;
87         
88             /**
89              * Gets the metadata for a given entity. If a valid entity is returned,
90              * the provider will be left in a locked state. The caller MUST unlock the
91              * provider when finished with the entity.
92              *  
93              * @param id                    the ID of the entity
94              * @param requireValidMetadata  indicates whether the metadata for the entity must be valid/current
95              * 
96              * @return the entity's metadata or NULL if there is no metadata or no valid metadata
97              */
98             virtual const EntityDescriptor* getEntityDescriptor(const XMLCh* id, bool requireValidMetadata=true) const=0;
99
100             /**
101              * Gets the metadata for a given entity. If a valid entity is returned,
102              * the provider will be left in a locked state. The caller MUST unlock the
103              * provider when finished with the entity.
104              *  
105              * @param id                    the ID of the entity
106              * @param requireValidMetadata  indicates whether the metadata for the entity must be valid/current
107              * 
108              * @return the entity's metadata or NULL if there is no metadata or no valid metadata
109              */
110             virtual const EntityDescriptor* getEntityDescriptor(const char* id, bool requireValidMetadata=true) const=0;
111
112             /**
113              * Gets the metadata for a given group of entities. If a valid group is returned,
114              * the resolver will be left in a locked state. The caller MUST unlock the
115              * resolver when finished with the group.
116              * 
117              * @param name                  the name of the group
118              * @param requireValidMetadata  indicates whether the metadata for the group must be valid/current
119              * 
120              * @return the group's metadata or NULL if there is no metadata or no valid metadata
121              */
122             virtual const EntitiesDescriptor* getEntitiesDescriptor(const XMLCh* name, bool requireValidMetadata=true) const=0;
123
124             /**
125              * Gets the metadata for a given group of entities. If a valid group is returned,
126              * the resolver will be left in a locked state. The caller MUST unlock the
127              * resolver when finished with the group.
128              * 
129              * @param name                  the name of the group
130              * @param requireValidMetadata  indicates whether the metadata for the group must be valid/current
131              * 
132              * @return the group's metadata or NULL if there is no metadata or no valid metadata
133              */
134             virtual const EntitiesDescriptor* getEntitiesDescriptor(const char* name, bool requireValidMetadata=true) const=0;
135
136         protected:
137             MetadataFilter* m_filter;
138         };
139         
140         /**
141          * Registers MetadataProvider classes into the runtime.
142          */
143         void SAML_API registerMetadataProviders();
144         
145         /** MetadataProvider based on local XML files */
146         #define FILESYSTEM_METADATA_PROVIDER  "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
147     };
148 };
149
150 #endif /* __saml2_metadataprov_h__ */