Removed ValidatingXMLObject interface and implementations, first draft of metadata...
[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 metadata for a given entity. If a valid entity is returned,
82              * the provider will be left in a locked state. The caller MUST unlock the
83              * provider when finished with the entity.
84              *  
85              * @param id                    the ID of the entity
86              * @param requireValidMetadata  indicates whether the metadata for the entity must be valid/current
87              * 
88              * @return the entity's metadata or NULL if there is no metadata or no valid metadata
89              */
90             virtual const EntityDescriptor* lookup(const XMLCh* id, bool requireValidMetadata=true) const=0;
91
92             /**
93              * Gets the metadata for a given entity. If a valid entity is returned,
94              * the provider will be left in a locked state. The caller MUST unlock the
95              * provider when finished with the entity.
96              *  
97              * @param id                    the ID of the entity
98              * @param requireValidMetadata  indicates whether the metadata for the entity must be valid/current
99              * 
100              * @return the entity's metadata or NULL if there is no metadata or no valid metadata
101              */
102             virtual const EntityDescriptor* lookup(const char* id, bool requireValidMetadata=true) const=0;
103
104             /**
105              * Gets the metadata for a given group of entities. If a valid group is returned,
106              * the resolver will be left in a locked state. The caller MUST unlock the
107              * resolver when finished with the group.
108              * 
109              * @param name                  the name of the group
110              * @param requireValidMetadata  indicates whether the metadata for the group must be valid/current
111              * 
112              * @return the group's metadata or NULL if there is no metadata or no valid metadata
113              */
114             virtual const EntitiesDescriptor* lookupGroup(const XMLCh* name, bool requireValidMetadata=true) const=0;
115
116             /**
117              * Gets the metadata for a given group of entities. If a valid group is returned,
118              * the resolver will be left in a locked state. The caller MUST unlock the
119              * resolver when finished with the group.
120              * 
121              * @param name                  the name of the group
122              * @param requireValidMetadata  indicates whether the metadata for the group must be valid/current
123              * 
124              * @return the group's metadata or NULL if there is no metadata or no valid metadata
125              */
126             virtual const EntitiesDescriptor* lookupGroup(const char* name, bool requireValidMetadata=true) const=0;
127
128         protected:
129             MetadataFilter* m_filter;
130         };
131         
132         /**
133          * Registers MetadataProvider classes into the runtime.
134          */
135         void SAML_API registerMetadataProviders();
136         
137         /** MetadataProvider based on local XML files */
138         #define FILESYSTEM_METADATA_PROVIDER  "org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider"
139     };
140 };
141
142 #endif /* __saml2_metadataprov_h__ */