Policy rule redesign for factor out issuer handling.
[shibboleth/cpp-opensaml.git] / saml / binding / SecurityPolicyRule.h
1 /*
2  *  Copyright 2001-2006 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  * @file saml/binding/SecurityPolicyRule.h
19  * 
20  * Policy rules that secure and authenticate bindings.
21  */
22
23 #ifndef __saml_secrule_h__
24 #define __saml_secrule_h__
25
26 #include <saml/binding/SecurityPolicy.h>
27
28 namespace opensaml {
29     
30     /**
31      * A rule that a protocol request and message must meet in order to be valid and secure.
32      * 
33      * <p>Rules must be stateless and thread-safe across evaluations. Evaluation should not
34      * result in an exception if the request/message properties do not apply to the rule
35      * (e.g. particular security mechanisms that are not present). 
36      */
37     class SAML_API SecurityPolicyRule
38     {
39         MAKE_NONCOPYABLE(SecurityPolicyRule);
40     protected:
41         SecurityPolicyRule() {}
42     public:
43         virtual ~SecurityPolicyRule() {}
44
45         /**
46          * Evaluates the rule against the given request and message. If an Issuer is
47          * returned, the caller is responsible for freeing the Issuer object.
48          * 
49          * @param message   the incoming message
50          * @param request   the protocol request
51          * @param policy    SecurityPolicy to provide various components and track message data
52          * 
53          * @throws BindingException thrown if the request/message do not meet the requirements of this rule
54          */
55         virtual void evaluate(
56             const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy
57             ) const=0;
58     };
59
60     /**
61      * Registers SecurityPolicyRule plugins into the runtime.
62      */
63     void SAML_API registerSecurityPolicyRules();
64
65     /**
66      * SecurityPolicyRule for processing SAML 1.x messages.
67      * 
68      * Extracts message ID, timestamp, and issuer information.
69      */
70     #define SAML1MESSAGE_POLICY_RULE  "org.opensaml.saml1.binding.SAML1MessageRule"
71
72     /**
73      * SecurityPolicyRule for processing SAML 2.0 messages.
74      * 
75      * Extracts message ID, timestamp, and issuer information.
76      */
77     #define SAML2MESSAGE_POLICY_RULE  "org.opensaml.saml2.binding.SAML2MessageRule"
78
79     /**
80      * SecurityPolicyRule for TLS client certificate authentication.
81      * 
82      * Evaluates client certificates against the issuer's metadata.
83      */
84     #define CLIENTCERTAUTH_POLICY_RULE  "org.opensaml.binding.ClientCertAuthRule"
85
86     /**
87      * SecurityPolicyRule for replay detection and freshness checking.
88      * 
89      * <p>A ReplayCache instance must be available from the runtime, unless
90      * a "checkReplay" XML attribute is set to "0" or "false" when instantiating
91      * the policy rule.
92      * 
93      * <p>Messages must have been issued in the past, but no more than 60 seconds ago,
94      * or up to a number of seconds set by an "expires" XML attribute when
95      * instantiating the policy rule.
96      */
97     #define MESSAGEFLOW_POLICY_RULE  "org.opensaml.binding.MessageFlowRule"
98
99     /**
100      * SecurityPolicyRule for protocol message "blob" signing.
101      * 
102      * Allows the message issuer to be authenticated using a non-XML digital signature
103      * over the message body. The transport layer is not considered.
104      */
105     #define SIMPLESIGNING_POLICY_RULE  "org.opensaml.binding.SimpleSigningRule"
106
107     /**
108      * SecurityPolicyRule for protocol message XML signing.
109      * 
110      * Allows the message issuer to be authenticated using an XML digital signature
111      * over the message. The transport layer is not considered.
112      */
113     #define XMLSIGNING_POLICY_RULE  "org.opensaml.binding.XMLSigningRule"
114 };
115
116 #endif /* __saml_secrule_h__ */