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