Reducing header overuse, non-inlining selected methods (CPPOST-35).
[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/base.h>
27
28 namespace xmltooling {
29     class XMLTOOL_API GenericRequest;
30     class XMLTOOL_API XMLObject;
31 };
32
33 namespace opensaml {
34     class SAML_API SecurityPolicy;
35
36     /**
37      * A rule that a protocol request and message must meet in order to be valid and secure.
38      *
39      * <p>Rules must be stateless and thread-safe across evaluations. Evaluation should not
40      * result in an exception if the request/message properties do not apply to the rule
41      * (e.g. particular security mechanisms that are not present).
42      */
43     class SAML_API SecurityPolicyRule
44     {
45         MAKE_NONCOPYABLE(SecurityPolicyRule);
46     protected:
47         SecurityPolicyRule();
48     public:
49         virtual ~SecurityPolicyRule();
50
51         /**
52          * Returns the rule's class/type.
53          *
54          * @return  the class/type of the object
55          */
56         virtual const char* getType() const=0;
57
58         /**
59          * Evaluates the rule against the given request and message.
60          *
61          * <p>An exception will be raised if the message is fatally invalid according to
62          * a policy rule.
63          *
64          * <p>The return value is used to indicate whether a message was ignored or
65          * successfully processed. A false value signals that the rule wasn't successful
66          * because the rule was inapplicable to the message, but allows other rules to
67          * return an alternate result.
68          *
69          * @param message   the incoming message
70          * @param request   the protocol request
71          * @param policy    SecurityPolicy to provide various components and track message data
72          * @return  indicator as to whether a message was understood and processed
73          */
74         virtual bool evaluate(
75             const xmltooling::XMLObject& message,
76             const xmltooling::GenericRequest* request,
77             SecurityPolicy& policy
78             ) const=0;
79     };
80
81     /**
82      * Registers SecurityPolicyRule plugins into the runtime.
83      */
84     void SAML_API registerSecurityPolicyRules();
85
86     /**
87      * SecurityPolicyRule for evaluation of SAML AudienceRestriction Conditions.
88      */
89     #define AUDIENCE_POLICY_RULE        "Audience"
90
91     /**
92      * SecurityPolicyRule for evaluation of SAML DelegationRestriction Conditions.
93      */
94     #define DELEGATION_POLICY_RULE        "Delegation"
95
96     /**
97      * SecurityPolicyRule for TLS client certificate authentication.
98      *
99      * Evaluates client certificates against the issuer's metadata.
100      */
101     #define CLIENTCERTAUTH_POLICY_RULE  "ClientCertAuth"
102
103     /**
104      * SecurityPolicyRule for evaluation of SAML Conditions.
105      */
106     #define CONDITIONS_POLICY_RULE      "Conditions"
107
108     /**
109      * SecurityPolicyRule for ignoring a SAML Condition.
110      */
111     #define IGNORE_POLICY_RULE          "Ignore"
112
113     /**
114      * SecurityPolicyRule for replay detection and freshness checking.
115      *
116      * <p>A ReplayCache instance must be available from the runtime, unless
117      * a "checkReplay" XML attribute is set to "0" or "false" when instantiating
118      * the policy rule.
119      *
120      * <p>Messages must have been issued in the past, but no more than 60 seconds ago,
121      * or up to a number of seconds set by an "expires" XML attribute when
122      * instantiating the policy rule.
123      */
124     #define MESSAGEFLOW_POLICY_RULE     "MessageFlow"
125
126     /**
127      * SecurityPolicyRule for disabling security.
128      *
129      * Allows the message issuer to be authenticated regardless of the message or
130      * transport. Used mainly for debugging or in situations that I wouldn't care to
131      * comment on.
132      */
133     #define NULLSECURITY_POLICY_RULE    "NullSecurity"
134
135     /**
136      * SecurityPolicyRule for protocol message "blob" signing.
137      *
138      * Allows the message issuer to be authenticated using a non-XML digital signature
139      * over the message body. The transport layer is not considered.
140      */
141     #define SIMPLESIGNING_POLICY_RULE   "SimpleSigning"
142
143     /**
144      * SecurityPolicyRule for protocol message XML signing.
145      *
146      * Allows the message issuer to be authenticated using an XML digital signature
147      * over the message. The transport layer is not considered.
148      */
149     #define XMLSIGNING_POLICY_RULE      "XMLSigning"
150
151     /**
152      * SecurityPolicyRule for SAML 1.x Browser SSO profile validation.
153      *
154      * Enforces presence of time conditions and proper subject confirmation.
155      */
156     #define SAML1BROWSERSSO_POLICY_RULE "SAML1BrowserSSO"
157
158     /**
159      * SecurityPolicyRule for SAML 2.0 bearer SubjectConfirmation.
160      *
161      * <p>Optionally enforces message delivery requirements based on SubjectConfirmationData.
162      *
163      * <p>The XML attributes "checkValidity", "checkRecipient", and "checkCorrelation" can be set
164      * "false" to disable checks of NotBefore/NotOnOrAfter, Recipient, and InResponseTo confirmation
165      * data respectively.
166      */
167     #define BEARER_POLICY_RULE "Bearer"
168 };
169
170 #endif /* __saml_secrule_h__ */