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;
33 namespace xmlsignature {
34 class XMLTOOL_API KeyInfo;
35 class XMLTOOL_API Signature;
38 namespace xmltooling {
41 * Class for specifying criteria by which a CredentialResolver should resolve credentials.
43 class XMLTOOL_API CredentialCriteria
45 MAKE_NONCOPYABLE(CredentialCriteria);
47 /** Default constructor. */
50 virtual ~CredentialCriteria();
53 * Determines whether the supplied Credential matches this CredentialCriteria.
55 * @param credential the Credential to evaluate
56 * @return true iff the Credential is consistent with this criteria
58 virtual bool matches(const Credential& credential) const;
61 * Get key usage criteria.
63 * @return the usage mask
65 unsigned int getUsage() const {
70 * Set key usage criteria.
72 * @param usage the usage mask to set
74 void setUsage(unsigned int usage) {
79 * Get the peer name criteria.
81 * @return the peer name
83 const char* getPeerName() const {
84 return m_peerName.c_str();
88 * Set the peer name criteria.
90 * @param peerName peer name to set
92 void setPeerName(const char* peerName) {
95 m_peerName = peerName;
99 * Get the key algorithm criteria.
101 * @return the key algorithm
103 const char* getKeyAlgorithm() const {
104 return m_keyAlgorithm.c_str();
108 * Set the key algorithm criteria.
110 * @param keyAlgorithm The key algorithm to set
112 void setKeyAlgorithm(const char* keyAlgorithm) {
113 m_keyAlgorithm.erase();
115 m_keyAlgorithm = keyAlgorithm;
119 * Get the key size criteria.
121 * @return the key size, or 0
123 unsigned int getKeySize() const {
128 * Set the key size criteria.
130 * @param keySize Key size to set
132 void setKeySize(unsigned int keySize) {
137 * Set the key algorithm and size criteria based on an XML algorithm specifier.
139 * @param algorithm XML algorithm specifier
141 void setXMLAlgorithm(const XMLCh* algorithm);
144 * Gets key name criteria.
146 * @return an immutable set of key names
148 const std::set<std::string>& getKeyNames() const {
153 * Gets key name criteria.
155 * @return a mutable set of key names
157 std::set<std::string>& getKeyNames() {
162 * Returns the public key criteria.
164 * @return a public key
166 virtual XSECCryptoKey* getPublicKey() const {
171 * Sets the public key criteria.
173 * <p>The lifetime of the key <strong>MUST</strong> extend
174 * for the lifetime of this object.
176 * @param key a public key
178 void setPublicKey(XSECCryptoKey* key) {
183 * Bitmask constants controlling the kinds of criteria set automatically
184 * based on a KeyInfo object.
186 enum keyinfo_extraction_t {
187 KEYINFO_EXTRACTION_KEY = 1,
188 KEYINFO_EXTRACTION_KEYNAMES = 2
192 * Gets the KeyInfo criteria.
194 * @return the KeyInfo criteria
196 const xmlsignature::KeyInfo* getKeyInfo() const {
201 * Sets the KeyInfo criteria.
203 * @param keyInfo the KeyInfo criteria
204 * @param extraction bitmask of criteria to auto-extract from KeyInfo
206 virtual void setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction=0);
209 * Gets the native KeyInfo criteria.
211 * @return the native KeyInfo criteria
213 DSIGKeyInfoList* getNativeKeyInfo() const {
214 return m_nativeKeyInfo;
218 * Sets the KeyInfo criteria.
220 * @param keyInfo the KeyInfo criteria
221 * @param extraction bitmask of criteria to auto-extract from KeyInfo
223 virtual void setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction=0);
226 * Sets the KeyInfo criteria from an XML Signature.
228 * @param sig the Signature containing KeyInfo criteria
229 * @param extraction bitmask of criteria to auto-extract from KeyInfo
231 void setSignature(const xmlsignature::Signature& sig, int extraction=0);
234 unsigned int m_keyUsage;
235 unsigned int m_keySize;
236 std::string m_peerName,m_keyAlgorithm;
237 std::set<std::string> m_keyNames;
238 XSECCryptoKey* m_key;
239 const xmlsignature::KeyInfo* m_keyInfo;
240 DSIGKeyInfoList* m_nativeKeyInfo;
241 Credential* m_credential;
245 #endif /* __xmltooling_credcrit_h__ */