Boost related changes
[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.get())
49                 throw SecurityPolicyException("No schema type or element name supplied to Ignore rule.");
50         }
51         virtual ~IgnoreRule() {}
52
53         const char* getType() const {
54             return IGNORE_POLICY_RULE;
55         }
56         bool evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const {
57             if (message.getSchemaType()) {
58                 if (*m_qname.get() != *(message.getSchemaType()))
59                     return false;
60                 m_log.info("ignoring condition with type (%s)", message.getSchemaType()->toString().c_str());
61             }
62             else {
63                 if (*m_qname.get() != message.getElementQName())
64                     return false;
65                 m_log.info("ignoring condition (%s)", message.getElementQName().toString().c_str());
66             }
67             return true;
68         }
69
70     private:
71         Category& m_log;
72         auto_ptr<xmltooling::QName> m_qname;
73     };
74
75     SecurityPolicyRule* SAML_DLLLOCAL IgnoreRuleFactory(const DOMElement* const & e)
76     {
77         return new IgnoreRule(e);
78     }
79 };