Add credential context APIs, refactor criteria matching, auto-extract criteria from...
[shibboleth/cpp-xmltooling.git] / xmltooling / security / KeyInfoResolver.h
1 /*
2  *  Copyright 2001-2007 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/KeyInfoResolver.h
19  * 
20  * Resolves credentials from KeyInfo information.
21  */
22
23 #if !defined(__xmltooling_keyres_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_keyres_h__
25
26 #include <xsec/dsig/DSIGKeyInfoList.hpp>
27
28 namespace xmlsignature {
29     class XMLTOOL_API KeyInfo;
30     class XMLTOOL_API Signature;
31 };
32
33 namespace xmltooling {
34
35     class XMLTOOL_API Credential;
36     class XMLTOOL_API CredentialCriteria;
37     class XMLTOOL_API KeyInfoCredentialContext;
38
39     /**
40      * Resolves credentials from KeyInfo information.
41      *
42      * <p>Credential-specific bitmasks can be provided to control what to resolve.
43      *
44      * <p>Implementations should only establish KeyNames on the basis of explicit names
45      * within the KeyInfo object, never by extracting names out of physical credentials
46      * found within it.
47      */
48     class XMLTOOL_API KeyInfoResolver {
49         MAKE_NONCOPYABLE(KeyInfoResolver);
50     protected:
51         KeyInfoResolver() {}
52     public:
53         virtual ~KeyInfoResolver() {}
54         
55         /**
56          * Returns a credential based on the supplied KeyInfo information.
57          * The caller must release the credential when done with it.
58          * 
59          * @param keyInfo   the key information
60          * @param types     types of credentials to resolve, or 0 for any/all
61          * @return  the resolved credential, or NULL
62          */
63         virtual Credential* resolve(const xmlsignature::KeyInfo* keyInfo, int types=0) const=0;
64
65         /**
66          * Returns a credential based on the supplied KeyInfo information.
67          * The caller must release the credential when done with it.
68          * 
69          * @param keyInfo   the key information
70          * @param types     types of credentials to resolve, or 0 for any/all
71          * @return  the resolved credential, or NULL
72          */
73         virtual Credential* resolve(DSIGKeyInfoList* keyInfo, int types=0) const=0;
74
75         /**
76          * Returns a credential based on the KeyInfo information in the supplied
77          * context. The caller must release the credential when done with it.
78          *
79          * <p>The context object will be owned by the Credential and freed with it.
80          * 
81          * @param context   context containing the key information
82          * @param types types of credentials to resolve, or 0 for any/all
83          * @return  the resolved credential, or NULL
84          */
85         virtual Credential* resolve(KeyInfoCredentialContext* context, int types=0) const=0;
86
87         /**
88          * Returns a credential based on the supplied KeyInfo information.
89          * The caller must release the credential when done with it.
90          * 
91          * @param sig   signature containing the key information
92          * @param types types of credentials to resolve, or 0 for any/all
93          * @return  the resolved credential, or NULL
94          */
95         Credential* resolve(const xmlsignature::Signature* sig, int types=0) const;
96
97         /**
98          * Returns a credential based on the KeyInfo information in the supplied
99          * criteria. The caller must release the credential when done with it.
100          * 
101          * @param criteria   criteria containing the key information
102          * @param types types of credentials to resolve, or 0 for any/all
103          * @return  the resolved credential, or NULL
104          */
105         Credential* resolve(const CredentialCriteria& criteria, int types=0) const;
106     };
107
108     /**
109      * Registers KeyInfoResolver classes into the runtime.
110      */
111     void XMLTOOL_API registerKeyInfoResolvers();
112
113     /** KeyInfoResolver based on extracting by value directly out of a KeyInfo */
114     #define INLINE_KEYINFO_RESOLVER  "Inline"
115 };
116
117 #endif /* __xmltooling_keyres_h__ */