2ad4ffcaf97bc40e5a8e0d3381902ea4c1821e0f
[shibboleth/cpp-xmltooling.git] / xmltooling / security / CredentialResolver.h
1 /*
2  *  Copyright 2001-2010 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 xmltooling/security/CredentialResolver.h
19  * 
20  * An API for resolving keys and certificates based on application criteria.
21  */
22
23 #if !defined(__xmltooling_credres_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_credres_h__
25
26 #include <xmltooling/Lockable.h>
27
28 namespace xmltooling {
29
30     class XMLTOOL_API Credential;
31     class XMLTOOL_API CredentialCriteria;
32
33     /**
34      * An API for resolving keys and certificates based on application criteria.
35      */
36     class XMLTOOL_API CredentialResolver : public virtual Lockable
37     {
38         MAKE_NONCOPYABLE(CredentialResolver);
39     protected:
40         CredentialResolver();
41         
42     public:
43         virtual ~CredentialResolver();
44         
45         /**
46          * Returns a single Credential according to the supplied criteria.
47          * 
48          * @param criteria   an optional CredentialCriteria object 
49          * @return  a Credential, or nullptr if none could be found
50          */
51         virtual const Credential* resolve(const CredentialCriteria* criteria=nullptr) const=0;
52
53         /**
54          * Returns all matching Credentials according to the supplied criteria.
55          * 
56          * @param results   array to store matching Credentials
57          * @param criteria  an optional CredentialCriteria object 
58          * @return  number of credentials found
59          */
60         virtual std::vector<const Credential*>::size_type resolve(
61             std::vector<const Credential*>& results, const CredentialCriteria* criteria=nullptr
62             ) const=0;
63     };
64
65     /**
66      * Registers CredentialResolver classes into the runtime.
67      */
68     void XMLTOOL_API registerCredentialResolvers();
69
70     /** CredentialResolver based on local files with no criteria support. */
71     #define FILESYSTEM_CREDENTIAL_RESOLVER  "File"
72
73     /** CredentialResolver based on chaining together other resolvers. */
74     #define CHAINING_CREDENTIAL_RESOLVER    "Chaining"
75 };
76
77 #endif /* __xmltooling_credres_h__ */