Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / saml / binding / SecurityPolicyRule.h
1 /*
2  *  Copyright 2001-2007 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          * Returns the rule's class/type.
47          *
48          * @return  the class/type of the object
49          */
50         virtual const char* getType() const=0;
51
52         /**
53          * Evaluates the rule against the given request and message.
54          * 
55          * <p>An exception will be raised if the message is invalid according to
56          * a policy rule.
57          * 
58          * @param message   the incoming message
59          * @param request   the protocol request
60          * @param policy    SecurityPolicy to provide various components and track message data
61          */
62         virtual void evaluate(
63             const xmltooling::XMLObject& message,
64             const xmltooling::GenericRequest* request,
65             SecurityPolicy& policy
66             ) const=0;
67     };
68
69     /**
70      * Registers SecurityPolicyRule plugins into the runtime.
71      */
72     void SAML_API registerSecurityPolicyRules();
73
74     /**
75      * SecurityPolicyRule for TLS client certificate authentication.
76      * 
77      * Evaluates client certificates against the issuer's metadata.
78      */
79     #define CLIENTCERTAUTH_POLICY_RULE  "ClientCertAuth"
80
81     /**
82      * SecurityPolicyRule for replay detection and freshness checking.
83      * 
84      * <p>A ReplayCache instance must be available from the runtime, unless
85      * a "checkReplay" XML attribute is set to "0" or "false" when instantiating
86      * the policy rule.
87      * 
88      * <p>Messages must have been issued in the past, but no more than 60 seconds ago,
89      * or up to a number of seconds set by an "expires" XML attribute when
90      * instantiating the policy rule.
91      */
92     #define MESSAGEFLOW_POLICY_RULE  "MessageFlow"
93
94     /**
95      * SecurityPolicyRule for disabling security.
96      * 
97      * Allows the message issuer to be authenticated regardless of the message or
98      * transport. Used mainly for debugging or in situations that I wouldn't care to
99      * comment on.
100      */
101     #define NULLSECURITY_POLICY_RULE  "NullSecurity"
102
103     /**
104      * SecurityPolicyRule for protocol message "blob" signing.
105      * 
106      * Allows the message issuer to be authenticated using a non-XML digital signature
107      * over the message body. The transport layer is not considered.
108      */
109     #define SIMPLESIGNING_POLICY_RULE  "SimpleSigning"
110
111     /**
112      * SecurityPolicyRule for protocol message XML signing.
113      * 
114      * Allows the message issuer to be authenticated using an XML digital signature
115      * over the message. The transport layer is not considered.
116      */
117     #define XMLSIGNING_POLICY_RULE  "XMLSigning"
118 };
119
120 #endif /* __saml_secrule_h__ */