2 * Copyright 2001-2007 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/XMLToolingConfig.h>
27 #include <xmltooling/signature/KeyInfo.h>
28 #include <xmltooling/signature/Signature.h>
31 #include <xsec/dsig/DSIGKeyInfoList.hpp>
32 #include <xsec/dsig/DSIGKeyInfoName.hpp>
34 namespace xmltooling {
37 * Class for specifying criteria by which a CredentialResolver should resolve credentials.
39 class XMLTOOL_API CredentialCriteria
41 MAKE_NONCOPYABLE(CredentialCriteria);
43 CredentialCriteria() : m_keyUsage(UNSPECIFIED_CREDENTIAL), m_keySize(0), m_keyInfo(NULL), m_nativeKeyInfo(NULL) {}
44 virtual ~CredentialCriteria() {}
47 UNSPECIFIED_CREDENTIAL,
54 * Get the key usage criteria.
58 UsageType getUsage() const {
63 * Set the key usage criteria.
65 * @param usage the usage to set
67 void setUsage(UsageType usage) {
72 * Get the peer name criteria.
74 * @return the peer name
76 const char* getPeerName() const {
77 return m_peerName.c_str();
81 * Set the peer name criteria.
83 * @param peerName peer name to set
85 void setPeerName(const char* peerName) {
88 m_peerName = peerName;
92 * Get the key algorithm criteria.
94 * @return the key algorithm
96 const char* getKeyAlgorithm() const {
97 return m_keyAlgorithm.c_str();
101 * Set the key algorithm criteria.
103 * @param keyAlgorithm The key algorithm to set
105 void setKeyAlgorithm(const char* keyAlgorithm) {
106 m_keyAlgorithm.erase();
108 m_keyAlgorithm = keyAlgorithm;
112 * Get the key size criteria.
114 * @return the key size, or 0
116 unsigned int getKeySize() const {
121 * Set the key size criteria.
123 * @param keySize Key size to set
125 void setKeySize(unsigned int keySize) {
130 * Set the key algorithm and size criteria based on an XML algorithm specifier.
132 * @param algorithm XML algorithm specifier
134 void setXMLAlgorithm(const XMLCh* algorithm) {
136 std::pair<const char*,unsigned int> mapped =
137 XMLToolingConfig::getConfig().mapXMLAlgorithmToKeyAlgorithm(algorithm);
138 setKeyAlgorithm(mapped.first);
139 setKeySize(mapped.second);
142 setKeyAlgorithm(NULL);
148 * Get the key name criteria.
150 * @return the key name
152 const char* getKeyName() const {
153 return m_keyName.c_str();
157 * Set the key name criteria.
159 * @param keyName key name to set
161 void setKeyName(const char* keyName) {
168 * Gets the KeyInfo criteria.
170 * @return the KeyInfo criteria
172 const xmlsignature::KeyInfo* getKeyInfo() const {
177 * Sets the KeyInfo criteria.
179 * @param keyInfo the KeyInfo criteria
181 void setKeyInfo(const xmlsignature::KeyInfo* keyInfo) {
186 * Gets the native KeyInfo criteria.
188 * @return the native KeyInfo criteria
190 DSIGKeyInfoList* getNativeKeyInfo() const {
191 return m_nativeKeyInfo;
195 * Sets the KeyInfo criteria.
197 * @param keyInfo the KeyInfo criteria
199 void setNativeKeyInfo(DSIGKeyInfoList* keyInfo) {
200 m_nativeKeyInfo = keyInfo;
203 void setSignature(const xmlsignature::Signature& sig) {
204 setXMLAlgorithm(sig.getSignatureAlgorithm());
205 xmlsignature::KeyInfo* k = sig.getKeyInfo();
207 return setKeyInfo(k);
208 DSIGSignature* dsig = sig.getXMLSignature();
210 setNativeKeyInfo(dsig->getKeyInfoList());
214 UsageType m_keyUsage;
215 unsigned int m_keySize;
216 std::string m_peerName,m_keyAlgorithm,m_keyName;
217 const xmlsignature::KeyInfo* m_keyInfo;
218 DSIGKeyInfoList* m_nativeKeyInfo;
222 #endif /* __xmltooling_credcrit_h__ */