f60242491c99f29916d50393ca02cb065a9c3e42
[shibboleth/cpp-opensaml.git] / saml / profile / impl / IgnoreRule.cpp
1 /*
2  *  Copyright 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  * IgnoreRule.cpp
19  *
20  * SecurityPolicyRule that ignores a message while indicating "success".
21  */
22
23 #include "internal.h"
24 #include "exceptions.h"
25 #include "binding/SecurityPolicyRule.h"
26
27 #include <xmltooling/logging.h>
28 #include <xmltooling/util/XMLHelper.h>
29
30 using namespace opensaml;
31 using namespace xmltooling::logging;
32 using namespace xmltooling;
33 using namespace std;
34
35
36 namespace opensaml {
37     class SAML_DLLLOCAL IgnoreRule : public SecurityPolicyRule
38     {
39     public:
40         IgnoreRule(const DOMElement* e)
41             : m_log(Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.Ignore")), m_qname(XMLHelper::getNodeValueAsQName(e)) {
42             if (!m_qname)
43                 throw SecurityPolicyException("No schema type or element name supplied to Ignore rule.");
44         }
45         virtual ~IgnoreRule() {
46             delete m_qname;
47         }
48
49         const char* getType() const {
50             return IGNORE_POLICY_RULE;
51         }
52         bool evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const {
53             if (message.getSchemaType()) {
54                 if (*m_qname != *(message.getSchemaType()))
55                     return false;
56                 m_log.info("ignoring condition with type (%s)", message.getSchemaType()->toString().c_str());
57             }
58             else {
59                 if (*m_qname != message.getElementQName())
60                     return false;
61                 m_log.info("ignoring condition (%s)", message.getElementQName().toString().c_str());
62             }
63             return true;
64         }
65
66     private:
67         Category& m_log;
68         xmltooling::QName* m_qname;
69     };
70
71     SecurityPolicyRule* SAML_DLLLOCAL IgnoreRuleFactory(const DOMElement* const & e)
72     {
73         return new IgnoreRule(e);
74     }
75 };