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