Allow message-only policy rules, basic SAML SOAP client.
[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/GenericRequest.h>
27 #include <xmltooling/XMLObject.h>
28 #include <xmltooling/security/TrustEngine.h>
29
30 namespace opensaml {
31     namespace saml2 {
32         class SAML_API Issuer;
33     };
34     namespace saml2md {
35         class SAML_API MetadataProvider;
36         class SAML_API RoleDescriptor;
37     };
38     
39     /**
40      * A rule that a protocol request and message must meet in order to be valid and secure.
41      * 
42      * <p>Rules must be stateless and thread-safe across evaluations. Evaluation should not
43      * result in an exception if the request/message properties do not apply to the rule
44      * (e.g. particular security mechanisms that are not present). 
45      */
46     class SAML_API SecurityPolicyRule
47     {
48         MAKE_NONCOPYABLE(SecurityPolicyRule);
49     protected:
50         SecurityPolicyRule() {}
51     public:
52         virtual ~SecurityPolicyRule() {}
53
54         /**
55          * Evaluates the rule against the given request and message. If an Issuer is
56          * returned, the caller is responsible for freeing the Issuer object.
57          * 
58          * @param message           the incoming message
59          * @param request           the protocol request
60          * @param metadataProvider  locked MetadataProvider instance to authenticate the message
61          * @param role              identifies the role (generally IdP or SP) of the peer who issued the message 
62          * @param trustEngine       TrustEngine to authenticate the message
63          * @param extractor         MessageExtractor to use in examining message
64          * @return the identity of the message issuer, in two forms, or NULL
65          * 
66          * @throws BindingException thrown if the request/message do not meet the requirements of this rule
67          */
68         virtual std::pair<saml2::Issuer*,const saml2md::RoleDescriptor*> evaluate(
69             const xmltooling::XMLObject& message,
70             const GenericRequest* request,
71             const saml2md::MetadataProvider* metadataProvider,
72             const xmltooling::QName* role,
73             const xmltooling::TrustEngine* trustEngine
74             ) const=0;
75     };
76
77     /**
78      * Registers SecurityPolicyRule plugins into the runtime.
79      */
80     void SAML_API registerSecurityPolicyRules();
81
82     /**
83      * SecurityPolicyRule for TLS client certificate authentication.
84      * 
85      * Requires that messages carry information about the issuer, and then
86      * evaluates the claimed certificates against the issuer's metadata.
87      */
88     #define CLIENTCERTAUTH_POLICY_RULE  "org.opensaml.binding.ClientCertAuthRule"
89
90     /**
91      * SecurityPolicyRule for replay detection and freshness checking.
92      * 
93      * <p>A ReplayCache instance must be available from the runtime, unless
94      * a "checkReplay" XML attribute is set to "0" or "false" when instantiating
95      * the policy rule.
96      * 
97      * <p>Messages must have been issued in the past, but no more than 60 seconds ago,
98      * or up to a number of seconds set by an "expires" XML attribute when
99      * instantiating the policy rule.
100      */
101     #define MESSAGEFLOW_POLICY_RULE  "org.opensaml.binding.MessageFlowRule"
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  "org.opensaml.binding.SimpleSigningRule"
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  "org.opensaml.binding.XMLSigningRule"
118 };
119
120 #endif /* __saml_secrule_h__ */