2 * Copyright 2001-2009 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file xmltooling/security/CredentialCriteria.h
20 * Class for specifying criteria by which a CredentialResolver should resolve credentials.
23 #if !defined(__xmltooling_credcrit_h__) && !defined(XMLTOOLING_NO_XMLSEC)
24 #define __xmltooling_credcrit_h__
26 #include <xmltooling/base.h>
30 class DSIGKeyInfoList;
32 namespace xmlsignature {
33 class XMLTOOL_API KeyInfo;
34 class XMLTOOL_API Signature;
37 namespace xmltooling {
40 * Class for specifying criteria by which a CredentialResolver should resolve credentials.
42 class XMLTOOL_API CredentialCriteria
44 MAKE_NONCOPYABLE(CredentialCriteria);
46 /** Default constructor. */
49 virtual ~CredentialCriteria();
52 * Determines whether the supplied Credential matches this CredentialCriteria.
54 * @param credential the Credential to evaluate
55 * @return true iff the Credential is consistent with this criteria
57 virtual bool matches(const Credential& credential) const;
60 * Get key usage criteria.
62 * @return the usage mask
64 unsigned int getUsage() const {
69 * Set key usage criteria.
71 * @param usage the usage mask to set
73 void setUsage(unsigned int usage) {
78 * Get the peer name criteria.
80 * @return the peer name
82 const char* getPeerName() const {
83 return m_peerName.c_str();
87 * Set the peer name criteria.
89 * @param peerName peer name to set
91 void setPeerName(const char* peerName) {
94 m_peerName = peerName;
98 * Get the key algorithm criteria.
100 * @return the key algorithm
102 const char* getKeyAlgorithm() const {
103 return m_keyAlgorithm.c_str();
107 * Set the key algorithm criteria.
109 * @param keyAlgorithm The key algorithm to set
111 void setKeyAlgorithm(const char* keyAlgorithm) {
112 m_keyAlgorithm.erase();
114 m_keyAlgorithm = keyAlgorithm;
118 * Get the key size criteria.
120 * @return the key size, or 0
122 unsigned int getKeySize() const {
127 * Set the key size criteria.
129 * @param keySize Key size to set
131 void setKeySize(unsigned int keySize) {
136 * Set the key algorithm and size criteria based on an XML algorithm specifier.
138 * @param algorithm XML algorithm specifier
140 void setXMLAlgorithm(const XMLCh* algorithm);
143 * Gets key name criteria.
145 * @return an immutable set of key names
147 const std::set<std::string>& getKeyNames() const {
152 * Gets key name criteria.
154 * @return a mutable set of key names
156 std::set<std::string>& getKeyNames() {
161 * Returns the public key criteria.
163 * @return a public key
165 virtual XSECCryptoKey* getPublicKey() const {
170 * Sets the public key criteria.
172 * <p>The lifetime of the key <strong>MUST</strong> extend
173 * for the lifetime of this object.
175 * @param key a public key
177 void setPublicKey(XSECCryptoKey* key) {
182 * Bitmask constants controlling the kinds of criteria set automatically
183 * based on a KeyInfo object.
185 enum keyinfo_extraction_t {
186 KEYINFO_EXTRACTION_KEY = 1,
187 KEYINFO_EXTRACTION_KEYNAMES = 2
191 * Gets the KeyInfo criteria.
193 * @return the KeyInfo criteria
195 const xmlsignature::KeyInfo* getKeyInfo() const {
200 * Sets the KeyInfo criteria.
202 * @param keyInfo the KeyInfo criteria
203 * @param extraction bitmask of criteria to auto-extract from KeyInfo
205 virtual void setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction=0);
208 * Gets the native KeyInfo criteria.
210 * @return the native KeyInfo criteria
212 DSIGKeyInfoList* getNativeKeyInfo() const {
213 return m_nativeKeyInfo;
217 * Sets the KeyInfo criteria.
219 * @param keyInfo the KeyInfo criteria
220 * @param extraction bitmask of criteria to auto-extract from KeyInfo
222 virtual void setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction=0);
225 * Sets the KeyInfo criteria from an XML Signature.
227 * @param sig the Signature containing KeyInfo criteria
228 * @param extraction bitmask of criteria to auto-extract from KeyInfo
230 void setSignature(const xmlsignature::Signature& sig, int extraction=0);
233 unsigned int m_keyUsage;
234 unsigned int m_keySize;
235 std::string m_peerName,m_keyAlgorithm;
236 std::set<std::string> m_keyNames;
237 XSECCryptoKey* m_key;
238 const xmlsignature::KeyInfo* m_keyInfo;
239 DSIGKeyInfoList* m_nativeKeyInfo;
240 Credential* m_credential;
244 #endif /* __xmltooling_credcrit_h__ */