Add policy rules for SAML 1 SSO and SAML 2 Bearer confirmation, with unit tests.
[shibboleth/cpp-opensaml.git] / saml / binding / SecurityPolicyRule.h
1 /*
2  *  Copyright 2001-2009 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          * <p>The return value is used to indicate whether a message was ignored or
59          * successfully processed. A false value signals that the rule wasn't successful
60          * but was also not unsuccessful, because the rule was inapplicable to the message.
61          *
62          * @param message   the incoming message
63          * @param request   the protocol request
64          * @param policy    SecurityPolicy to provide various components and track message data
65          * @return  indicator as to whether a message was understood and processed
66          */
67         virtual bool evaluate(
68             const xmltooling::XMLObject& message,
69             const xmltooling::GenericRequest* request,
70             SecurityPolicy& policy
71             ) const=0;
72     };
73
74     /**
75      * Registers SecurityPolicyRule plugins into the runtime.
76      */
77     void SAML_API registerSecurityPolicyRules();
78
79     /**
80      * SecurityPolicyRule for evaluation of SAML AudienceRestriction Conditions.
81      */
82     #define AUDIENCE_POLICY_RULE        "Audience"
83
84     /**
85      * SecurityPolicyRule for TLS client certificate authentication.
86      *
87      * Evaluates client certificates against the issuer's metadata.
88      */
89     #define CLIENTCERTAUTH_POLICY_RULE  "ClientCertAuth"
90
91     /**
92      * SecurityPolicyRule for evaluation of SAML Conditions.
93      */
94     #define CONDITIONS_POLICY_RULE      "Conditions"
95
96     /**
97      * SecurityPolicyRule for ignoring a SAML Condition.
98      */
99     #define IGNORE_POLICY_RULE          "Ignore"
100
101     /**
102      * SecurityPolicyRule for replay detection and freshness checking.
103      *
104      * <p>A ReplayCache instance must be available from the runtime, unless
105      * a "checkReplay" XML attribute is set to "0" or "false" when instantiating
106      * the policy rule.
107      *
108      * <p>Messages must have been issued in the past, but no more than 60 seconds ago,
109      * or up to a number of seconds set by an "expires" XML attribute when
110      * instantiating the policy rule.
111      */
112     #define MESSAGEFLOW_POLICY_RULE     "MessageFlow"
113
114     /**
115      * SecurityPolicyRule for disabling security.
116      *
117      * Allows the message issuer to be authenticated regardless of the message or
118      * transport. Used mainly for debugging or in situations that I wouldn't care to
119      * comment on.
120      */
121     #define NULLSECURITY_POLICY_RULE    "NullSecurity"
122
123     /**
124      * SecurityPolicyRule for protocol message "blob" signing.
125      *
126      * Allows the message issuer to be authenticated using a non-XML digital signature
127      * over the message body. The transport layer is not considered.
128      */
129     #define SIMPLESIGNING_POLICY_RULE   "SimpleSigning"
130
131     /**
132      * SecurityPolicyRule for protocol message XML signing.
133      *
134      * Allows the message issuer to be authenticated using an XML digital signature
135      * over the message. The transport layer is not considered.
136      */
137     #define XMLSIGNING_POLICY_RULE      "XMLSigning"
138
139     /**
140      * SecurityPolicyRule for SAML 1.x Browser SSO profile validation.
141      *
142      * Enforces presence of time conditions and proper subject confirmation.
143      */
144     #define SAML1BROWSERSSO_POLICY_RULE "SAML1BrowserSSO"
145
146     /**
147      * SecurityPolicyRule for SAML 2.0 bearer SubjectConfirmation.
148      *
149      * <p>Optionally enforces message delivery requirements based on SubjectConfirmationData.
150      *
151      * <p>The XML attributes "checkValidity", "checkRecipient", and "checkCorrelation" can be set
152      * "false" to disable checks of NotBefore/NotOnOrAfter, Recipient, and InResponseTo confirmation
153      * data respectively.
154      */
155     #define BEARER_POLICY_RULE "Bearer"
156 };
157
158 #endif /* __saml_secrule_h__ */