2 * Copyright 2001-2006 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * @file saml/binding/SecurityPolicy.h
20 * Overall policy used to verify the security of an incoming message.
23 #ifndef __saml_secpol_h__
24 #define __saml_secpol_h__
26 #include <saml/binding/SecurityPolicyRule.h>
29 #if defined (_MSC_VER)
30 #pragma warning( push )
31 #pragma warning( disable : 4250 4251 )
37 class SAML_API MetadataProvider;
41 * A policy used to verify the security of an incoming message.
43 * <p>Its security mechanisms may be used to examine the transport layer
44 * (e.g client certificates and HTTP basic auth passwords) or to check the
45 * payload of a request to ensure it meets certain criteria (e.g. valid
46 * digital signature, freshness, replay).
48 * <p>Policy objects can be reused, but are not thread-safe.
50 class SAML_API SecurityPolicy
52 MAKE_NONCOPYABLE(SecurityPolicy);
55 * Constructor for policy.
57 * @param rules reference to array of policy rules to use
58 * @param metadataProvider locked MetadataProvider instance
59 * @param role identifies the role (generally IdP or SP) of the policy peer
60 * @param trustEngine TrustEngine to authenticate policy peer
63 const std::vector<const SecurityPolicyRule*>& rules,
64 const saml2md::MetadataProvider* metadataProvider=NULL,
65 const xmltooling::QName* role=NULL,
66 const TrustEngine* trustEngine=NULL
67 ) : m_issuer(NULL), m_issuerRole(NULL), m_rules(rules), m_metadata(metadataProvider),
68 m_role(role ? *role : xmltooling::QName()), m_trust(trustEngine) {
70 virtual ~SecurityPolicy();
73 * Returns the locked MetadataProvider supplied to the policy.
75 * @return the supplied MetadataProvider or NULL
77 const saml2md::MetadataProvider* getMetadataProvider() const {
82 * Returns the peer role element/type supplied to the policy.
84 * @return the peer role element/type, or an empty QName
86 const xmltooling::QName* getRole() const {
91 * Returns the TrustEngine supplied to the policy.
93 * @return the supplied TrustEngine or NULL
95 const TrustEngine* getTrustEngine() const {
100 * Evaluates the rule against the given request and message,
101 * possibly populating issuer information in the policy object.
103 * @param request the protocol request
104 * @param message the incoming message
105 * @return the identity of the message issuer, in one or more of two forms, or NULL
107 * @throws BindingException thrown if the request/message do not meet the requirements of this rule
109 void evaluate(const GenericRequest& request, const xmltooling::XMLObject& message);
112 * Gets the issuer of the message as determined by the registered policies.
114 * @return issuer of the message as determined by the registered policies
116 const saml2::Issuer* getIssuer() const {
121 * Gets the metadata for the role the issuer is operating in.
123 * @return metadata for the role the issuer is operating in
125 const saml2md::RoleDescriptor* getIssuerMetadata() const {
130 * Sets the issuer of the message as determined by external factors.
131 * The policy object takes ownership of the Issuer object.
133 * @param issuer issuer of the message
135 void setIssuer(saml2::Issuer* issuer);
138 * Sets the metadata for the role the issuer is operating in.
140 * @param issuerRole metadata for the role the issuer is operating in
142 void setIssuerMetadata(const saml2md::RoleDescriptor* issuerRole);
146 * Returns true iff the two operands "match". Applications can override this method to
147 * support non-standard issuer matching for complex policies.
149 * <p>The default implementation does a basic comparison of the XML content, treating
150 * an unsupplied Format as "entityID".
152 * @param issuer1 the first Issuer to match
153 * @param issuer2 the second Issuer to match
154 * @return true iff the operands match
156 virtual bool issuerMatches(const saml2::Issuer* issuer1, const saml2::Issuer* issuer2) const;
159 saml2::Issuer* m_issuer;
160 const saml2md::RoleDescriptor* m_issuerRole;
162 std::vector<const SecurityPolicyRule*> m_rules;
163 const saml2md::MetadataProvider* m_metadata;
164 xmltooling::QName m_role;
165 const TrustEngine* m_trust;
170 #if defined (_MSC_VER)
171 #pragma warning( pop )
174 #endif /* __saml_secpol_h__ */