68a736e03d946f50642b0db3997d27dca2c7e081
[shibboleth/cpp-opensaml.git] / saml / profile / impl / IgnoreRule.cpp
1 /**
2  * Licensed to the University Corporation for Advanced Internet
3  * Development, Inc. (UCAID) under one or more contributor license
4  * agreements. See the NOTICE file distributed with this work for
5  * additional information regarding copyright ownership.
6  *
7  * UCAID licenses this file to you under the Apache License,
8  * Version 2.0 (the "License"); you may not use this file except
9  * in compliance with the License. You may obtain a copy of the
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17  * either express or implied. See the License for the specific
18  * language governing permissions and limitations under the License.
19  */
20
21 /**
22  * IgnoreRule.cpp
23  *
24  * SecurityPolicyRule that ignores a message while indicating "success".
25  */
26
27 #include "internal.h"
28 #include "exceptions.h"
29 #include "binding/SecurityPolicyRule.h"
30
31 #include <memory>
32 #include <xmltooling/logging.h>
33 #include <xmltooling/QName.h>
34 #include <xmltooling/XMLObject.h>
35 #include <xmltooling/util/XMLHelper.h>
36
37 using namespace opensaml;
38 using namespace xmltooling::logging;
39 using namespace xmltooling;
40 using namespace std;
41
42
43 namespace opensaml {
44     class SAML_DLLLOCAL IgnoreRule : public SecurityPolicyRule
45     {
46     public:
47         IgnoreRule(const DOMElement* e)
48             : m_log(Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.Ignore")), m_qname(XMLHelper::getNodeValueAsQName(e)) {
49             if (!m_qname.get())
50                 throw SecurityPolicyException("No schema type or element name supplied to Ignore rule.");
51         }
52         virtual ~IgnoreRule() {}
53
54         const char* getType() const {
55             return IGNORE_POLICY_RULE;
56         }
57         bool evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const {
58             if (message.getSchemaType()) {
59                 if (*m_qname.get() != *(message.getSchemaType()))
60                     return false;
61                 m_log.info("ignoring condition with type (%s)", message.getSchemaType()->toString().c_str());
62             }
63             else {
64                 if (*m_qname.get() != message.getElementQName())
65                     return false;
66                 m_log.info("ignoring condition (%s)", message.getElementQName().toString().c_str());
67             }
68             return true;
69         }
70
71     private:
72         Category& m_log;
73         auto_ptr<xmltooling::QName> m_qname;
74     };
75
76     SecurityPolicyRule* SAML_DLLLOCAL IgnoreRuleFactory(const DOMElement* const & e)
77     {
78         return new IgnoreRule(e);
79     }
80 };