Add missing class declaration.
[shibboleth/cpp-xmltooling.git] / xmltooling / security / CredentialCriteria.h
1 /*
2  *  Copyright 2001-2009 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/CredentialCriteria.h
19  * 
20  * Class for specifying criteria by which a CredentialResolver should resolve credentials.
21  */
22
23 #if !defined(__xmltooling_credcrit_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_credcrit_h__
25
26 #include <xmltooling/base.h>
27
28 #include <set>
29
30 class DSIGKeyInfoList;
31 class XSECCryptoKey;
32
33 namespace xmlsignature {
34     class XMLTOOL_API Credential;
35     class XMLTOOL_API KeyInfo;
36     class XMLTOOL_API Signature;
37 };
38
39 namespace xmltooling {
40
41 #if defined (_MSC_VER)
42     #pragma warning( push )
43     #pragma warning( disable : 4251 )
44 #endif
45
46     /**
47      * Class for specifying criteria by which a CredentialResolver should resolve credentials.
48      */
49     class XMLTOOL_API CredentialCriteria
50     {
51         MAKE_NONCOPYABLE(CredentialCriteria);
52     public:
53         /** Default constructor. */
54         CredentialCriteria();
55
56         virtual ~CredentialCriteria();
57
58         /**
59          * Determines whether the supplied Credential matches this CredentialCriteria.
60          *
61          * @param credential    the Credential to evaluate
62          * @return true iff the Credential is consistent with this criteria
63          */
64         virtual bool matches(const Credential& credential) const;
65        
66         /**
67          * Get key usage criteria.
68          * 
69          * @return the usage mask
70          */
71         unsigned int getUsage() const {
72             return m_keyUsage;
73         }
74     
75         /**
76          * Set key usage criteria.
77          * 
78          * @param usage the usage mask to set
79          */
80         void setUsage(unsigned int usage) {
81             m_keyUsage = usage;
82         }
83
84         /**
85          * Get the peer name criteria.
86          * 
87          * @return the peer name
88          */
89         const char* getPeerName() const {
90             return m_peerName.c_str();
91         }
92     
93         /**
94          * Set the peer name criteria.
95          * 
96          * @param peerName peer name to set
97          */
98         void setPeerName(const char* peerName) {
99             m_peerName.erase();
100             if (peerName)
101                 m_peerName = peerName;
102         }
103     
104         /**
105          * Get the key algorithm criteria.
106          * 
107          * @return the key algorithm
108          */
109         const char* getKeyAlgorithm() const {
110             return m_keyAlgorithm.c_str();
111         }
112     
113         /**
114          * Set the key algorithm criteria.
115          * 
116          * @param keyAlgorithm The key algorithm to set
117          */
118         void setKeyAlgorithm(const char* keyAlgorithm) {
119             m_keyAlgorithm.erase();
120             if (keyAlgorithm)
121                 m_keyAlgorithm = keyAlgorithm;
122         }
123
124         /**
125          * Get the key size criteria.
126          *
127          * @return  the key size, or 0
128          */
129         unsigned int getKeySize() const {
130             return m_keySize;
131         }
132
133         /**
134          * Set the key size criteria.
135          *
136          * @param keySize Key size to set
137          */
138         void setKeySize(unsigned int keySize) {
139             m_keySize = keySize;
140         }
141     
142         /**
143          * Set the key algorithm and size criteria based on an XML algorithm specifier.
144          *
145          * @param algorithm XML algorithm specifier
146          */
147         void setXMLAlgorithm(const XMLCh* algorithm);
148
149         /**
150          * Gets key name criteria.
151          * 
152          * @return an immutable set of key names
153          */
154         const std::set<std::string>& getKeyNames() const {
155             return m_keyNames;
156         }
157
158         /**
159          * Gets key name criteria.
160          * 
161          * @return a mutable set of key names
162          */
163         std::set<std::string>& getKeyNames() {
164             return m_keyNames;
165         }
166
167         /**
168          * Returns the public key criteria.
169          * 
170          * @return  a public key
171          */
172         virtual XSECCryptoKey* getPublicKey() const {
173             return m_key;
174         }
175
176         /**
177          * Sets the public key criteria.
178          *
179          * <p>The lifetime of the key <strong>MUST</strong> extend
180          * for the lifetime of this object.
181          * 
182          * @param key a public key
183          */
184         void setPublicKey(XSECCryptoKey* key) {
185             m_key = key;
186         }
187
188         /**
189          * Bitmask constants controlling the kinds of criteria set automatically
190          * based on a KeyInfo object.
191          */
192         enum keyinfo_extraction_t {
193             KEYINFO_EXTRACTION_KEY = 1,
194             KEYINFO_EXTRACTION_KEYNAMES = 2
195         };
196
197         /**
198          * Gets the KeyInfo criteria.
199          * 
200          * @return the KeyInfo criteria
201          */
202         const xmlsignature::KeyInfo* getKeyInfo() const {
203             return m_keyInfo;
204         }
205     
206         /**
207          * Sets the KeyInfo criteria.
208          * 
209          * @param keyInfo       the KeyInfo criteria
210          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
211          */
212         virtual void setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction=0);
213
214         /**
215          * Gets the native KeyInfo criteria.
216          * 
217          * @return the native KeyInfo criteria
218          */
219         DSIGKeyInfoList* getNativeKeyInfo() const {
220             return m_nativeKeyInfo;
221         }
222
223         /**
224          * Sets the KeyInfo criteria.
225          * 
226          * @param keyInfo       the KeyInfo criteria
227          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
228          */
229         virtual void setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction=0);
230
231         /**
232          * Sets the KeyInfo criteria from an XML Signature.
233          * 
234          * @param sig           the Signature containing KeyInfo criteria
235          * @param extraction    bitmask of criteria to auto-extract from KeyInfo
236          */
237         void setSignature(const xmlsignature::Signature& sig, int extraction=0);
238
239     private:
240         unsigned int m_keyUsage;
241         unsigned int m_keySize;
242         std::string m_peerName,m_keyAlgorithm;
243         std::set<std::string> m_keyNames;
244         XSECCryptoKey* m_key;
245         const xmlsignature::KeyInfo* m_keyInfo;
246         DSIGKeyInfoList* m_nativeKeyInfo;
247         Credential* m_credential;
248     };
249
250 #if defined (_MSC_VER)
251     #pragma warning( pop )
252 #endif
253 };
254
255 #endif /* __xmltooling_credcrit_h__ */