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