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 {
40 #if defined (_MSC_VER)
41 #pragma warning( push )
42 #pragma warning( disable : 4251 )
46 * Class for specifying criteria by which a CredentialResolver should resolve credentials.
48 class XMLTOOL_API CredentialCriteria
50 MAKE_NONCOPYABLE(CredentialCriteria);
52 /** Default constructor. */
55 virtual ~CredentialCriteria();
58 * Determines whether the supplied Credential matches this CredentialCriteria.
60 * @param credential the Credential to evaluate
61 * @return true iff the Credential is consistent with this criteria
63 virtual bool matches(const Credential& credential) const;
66 * Get key usage criteria.
68 * @return the usage mask
70 unsigned int getUsage() const {
75 * Set key usage criteria.
77 * @param usage the usage mask to set
79 void setUsage(unsigned int usage) {
84 * Get the peer name criteria.
86 * @return the peer name
88 const char* getPeerName() const {
89 return m_peerName.c_str();
93 * Set the peer name criteria.
95 * @param peerName peer name to set
97 void setPeerName(const char* peerName) {
100 m_peerName = peerName;
104 * Get the key algorithm criteria.
106 * @return the key algorithm
108 const char* getKeyAlgorithm() const {
109 return m_keyAlgorithm.c_str();
113 * Set the key algorithm criteria.
115 * @param keyAlgorithm The key algorithm to set
117 void setKeyAlgorithm(const char* keyAlgorithm) {
118 m_keyAlgorithm.erase();
120 m_keyAlgorithm = keyAlgorithm;
124 * Get the key size criteria.
126 * @return the key size, or 0
128 unsigned int getKeySize() const {
133 * Set the key size criteria.
135 * @param keySize Key size to set
137 void setKeySize(unsigned int keySize) {
142 * Set the key algorithm and size criteria based on an XML algorithm specifier.
144 * @param algorithm XML algorithm specifier
146 void setXMLAlgorithm(const XMLCh* algorithm);
149 * Gets key name criteria.
151 * @return an immutable set of key names
153 const std::set<std::string>& getKeyNames() const {
158 * Gets key name criteria.
160 * @return a mutable set of key names
162 std::set<std::string>& getKeyNames() {
167 * Returns the public key criteria.
169 * @return a public key
171 virtual XSECCryptoKey* getPublicKey() const {
176 * Sets the public key criteria.
178 * <p>The lifetime of the key <strong>MUST</strong> extend
179 * for the lifetime of this object.
181 * @param key a public key
183 void setPublicKey(XSECCryptoKey* key) {
188 * Bitmask constants controlling the kinds of criteria set automatically
189 * based on a KeyInfo object.
191 enum keyinfo_extraction_t {
192 KEYINFO_EXTRACTION_KEY = 1,
193 KEYINFO_EXTRACTION_KEYNAMES = 2
197 * Gets the KeyInfo criteria.
199 * @return the KeyInfo criteria
201 const xmlsignature::KeyInfo* getKeyInfo() const {
206 * Sets the KeyInfo criteria.
208 * @param keyInfo the KeyInfo criteria
209 * @param extraction bitmask of criteria to auto-extract from KeyInfo
211 virtual void setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction=0);
214 * Gets the native KeyInfo criteria.
216 * @return the native KeyInfo criteria
218 DSIGKeyInfoList* getNativeKeyInfo() const {
219 return m_nativeKeyInfo;
223 * Sets the KeyInfo criteria.
225 * @param keyInfo the KeyInfo criteria
226 * @param extraction bitmask of criteria to auto-extract from KeyInfo
228 virtual void setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction=0);
231 * Sets the KeyInfo criteria from an XML Signature.
233 * @param sig the Signature containing KeyInfo criteria
234 * @param extraction bitmask of criteria to auto-extract from KeyInfo
236 void setSignature(const xmlsignature::Signature& sig, int extraction=0);
239 unsigned int m_keyUsage;
240 unsigned int m_keySize;
241 std::string m_peerName,m_keyAlgorithm;
242 std::set<std::string> m_keyNames;
243 XSECCryptoKey* m_key;
244 const xmlsignature::KeyInfo* m_keyInfo;
245 DSIGKeyInfoList* m_nativeKeyInfo;
246 Credential* m_credential;
249 #if defined (_MSC_VER)
250 #pragma warning( pop )
254 #endif /* __xmltooling_credcrit_h__ */