Return results from policy rules.
authorScott Cantor <cantor.2@osu.edu>
Tue, 12 Dec 2006 04:22:41 +0000 (04:22 +0000)
committerScott Cantor <cantor.2@osu.edu>
Tue, 12 Dec 2006 04:22:41 +0000 (04:22 +0000)
13 files changed:
saml/binding/ClientCertAuthRule.h
saml/binding/MessageFlowRule.h
saml/binding/SecurityPolicyRule.h
saml/binding/SimpleSigningRule.h
saml/binding/XMLSigningRule.h
saml/binding/impl/ClientCertAuthRule.cpp
saml/binding/impl/MessageFlowRule.cpp
saml/binding/impl/SimpleSigningRule.cpp
saml/binding/impl/XMLSigningRule.cpp
saml/saml1/binding/SAML1MessageRule.h
saml/saml1/binding/impl/SAML1MessageRule.cpp
saml/saml2/binding/SAML2MessageRule.h
saml/saml2/binding/impl/SAML2MessageRule.cpp

index 737e52b..6d94823 100644 (file)
@@ -33,6 +33,6 @@ namespace opensaml {
         ClientCertAuthRule(const DOMElement* e) {}
         virtual ~ClientCertAuthRule() {}
         
-        void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+        bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
     };
 };
index accd60c..fc3e816 100644 (file)
@@ -36,7 +36,7 @@ namespace opensaml {
         MessageFlowRule(const DOMElement* e);
         virtual ~MessageFlowRule() {}
         
-        void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+        bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
 
         /**
          * Controls whether rule executes replay checking.
index f15d263..68760f7 100644 (file)
@@ -43,16 +43,20 @@ namespace opensaml {
         virtual ~SecurityPolicyRule() {}
 
         /**
-         * Evaluates the rule against the given request and message. If an Issuer is
-         * returned, the caller is responsible for freeing the Issuer object.
+         * Evaluates the rule against the given request and message.
+         * 
+         * <p>Exceptions should be reserved for fatal request processing errors;
+         * otherwise rules should return false to indicate they were not applicable
+         * or unsuccessful.
          * 
          * @param message   the incoming message
          * @param request   the protocol request
          * @param policy    SecurityPolicy to provide various components and track message data
+         * @return  true iff the rule ran successfully, false otherwise
          * 
-         * @throws BindingException thrown if the request/message do not meet the requirements of this rule
+         * @throws BindingException thrown if the request/message is invalid in some way
          */
-        virtual void evaluate(
+        virtual bool evaluate(
             const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy
             ) const=0;
     };
index ac82b33..b8a42a4 100644 (file)
@@ -34,7 +34,7 @@ namespace opensaml {
         SimpleSigningRule(const DOMElement* e) {}
         virtual ~SimpleSigningRule() {}
         
-        void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+        bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
     };
     
 };
index 0469914..0b65c62 100644 (file)
@@ -33,7 +33,7 @@ namespace opensaml {
         XMLSigningRule(const DOMElement* e) {}
         virtual ~XMLSigningRule() {}
         
-        void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+        bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
     };
     
 };
index 6337b19..aaa3c8c 100644 (file)
@@ -43,37 +43,38 @@ namespace opensaml {
     }
 };
 
-void ClientCertAuthRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool ClientCertAuthRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.ClientCertAuth");
     log.debug("evaluating client certificate authentication policy");
     
     if (!request) {
         log.debug("ignoring message, no protocol request available");
-        return;
+        return false;
     }
     else if (!policy.getIssuerMetadata()) {
         log.debug("ignoring message, no issuer metadata supplied");
-        return;
+        return false;
     }
 
     const X509TrustEngine* x509trust;
     if (!(x509trust=dynamic_cast<const X509TrustEngine*>(policy.getTrustEngine()))) {
         log.debug("ignoring message, no X509TrustEngine supplied");
-        return;
+        return false;
     }
     
     const std::vector<XSECCryptoX509*>& chain = request->getClientCertificates();
     if (chain.empty()) {
         log.debug("ignoring message, no client certificates in request");
-        return;
+        return false;
     }
     
     if (!x509trust->validate(chain.front(), chain, *(policy.getIssuerMetadata()), true,
             policy.getMetadataProvider()->getKeyResolver())) {
         log.error("unable to verify certificate chain with supplied trust engine");
-        return;
+        return false;
     }
     
     log.debug("client certificate verified against message issuer");
+    return true;
 }
index ce04682..b5e0882 100644 (file)
@@ -56,7 +56,7 @@ MessageFlowRule::MessageFlowRule(const DOMElement* e)
     }
 }
 
-void MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.MessageFlow");
     log.debug("evaluating message flow policy (replay checking %s, expiration %lu)", m_checkReplay ? "on" : "off", m_expires);
@@ -94,4 +94,6 @@ void MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* r
             throw BindingException("Rejecting replayed message ID ($1).", params(1,temp.get()));
         }
     }
+
+    return true;
 }
index 394802b..1079e88 100644 (file)
@@ -62,36 +62,36 @@ namespace opensaml {
 };
 
 
-void SimpleSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SimpleSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SimpleSigning");
     log.debug("evaluating simple signing policy");
     
     if (!policy.getIssuerMetadata()) {
         log.debug("ignoring message, no issuer metadata supplied");
-        return;
+        return false;
     }
     else if (!policy.getTrustEngine()) {
         log.debug("ignoring message, no TrustEngine supplied");
-        return;
+        return false;
     }
 
     const HTTPRequest* httpRequest = dynamic_cast<const HTTPRequest*>(request);
     if (!request || !httpRequest) {
         log.debug("ignoring message, no HTTP protocol request available");
-        return;
+        return false;
     }
 
     const char* signature = request->getParameter("Signature");
     if (!signature) {
         log.debug("ignoring unsigned message");
-        return;
+        return false;
     }
     
     const char* sigAlgorithm = request->getParameter("SigAlg");
     if (!sigAlgorithm) {
         log.error("SigAlg parameter not found, no way to verify the signature");
-        return;
+        return false;
     }
 
     string input;
@@ -148,8 +148,9 @@ void SimpleSigningRule::evaluate(const XMLObject& message, const GenericRequest*
             *(policy.getIssuerMetadata()), policy.getMetadataProvider()->getKeyResolver()
             )) {
         log.error("unable to verify message signature with supplied trust engine");
-        return;
+        return false;
     }
 
     log.debug("signature verified against message issuer");
+    return true;
 }
index 029f14c..8675fc6 100644 (file)
@@ -43,24 +43,24 @@ namespace opensaml {
     }
 };
 
-void XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.XMLSigning");
     log.debug("evaluating message signing policy");
     
     if (!policy.getIssuerMetadata()) {
         log.debug("ignoring message, no issuer metadata supplied");
-        return;
+        return false;
     }
     else if (!policy.getTrustEngine()) {
         log.debug("ignoring message, no TrustEngine supplied");
-        return;
+        return false;
     }
     
     const SignableObject* signable = dynamic_cast<const SignableObject*>(&message);
     if (!signable || !signable->getSignature()) {
         log.debug("ignoring unsigned or unrecognized message");
-        return;
+        return false;
     }
     
     log.debug("validating signature profile");
@@ -70,15 +70,16 @@ void XMLSigningRule::evaluate(const XMLObject& message, const GenericRequest* re
     }
     catch (ValidationException& ve) {
         log.error("signature profile failed to validate: %s", ve.what());
-        return;
+        return false;
     }
     
     if (!policy.getTrustEngine()->validate(
             *(signable->getSignature()), *(policy.getIssuerMetadata()), policy.getMetadataProvider()->getKeyResolver()
             )) {
         log.error("unable to verify message signature with supplied trust engine");
-        return;
+        return false;
     }
 
     log.debug("signature verified against message issuer");
+    return true;
 }
index 0027921..ad3f685 100644 (file)
@@ -34,7 +34,7 @@ namespace opensaml {
             SAML1MessageRule(const DOMElement* e) {}
             virtual ~SAML1MessageRule() {}
             
-            void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+            bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
         };
     };
 };
index 3d70d87..c821225 100644 (file)
@@ -47,7 +47,7 @@ namespace opensaml {
     }
 };
 
-void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SAML1Message");
     
@@ -87,7 +87,7 @@ void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest*
         
         if (!protocol) {
             log.warn("issuer identity not extracted");
-            return;
+            return false;
         }
 
         if (log.isDebugEnabled()) {
@@ -101,20 +101,23 @@ void SAML1MessageRule::evaluate(const XMLObject& message, const GenericRequest*
             if (!entity) {
                 auto_ptr_char temp(policy.getIssuer()->getName());
                 log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get());
-                return;
+                return false;
             }
     
             log.debug("matched message issuer against metadata, searching for applicable role...");
             const RoleDescriptor* roledesc=entity->getRoleDescriptor(*policy.getRole(), protocol);
             if (!roledesc) {
                 log.warn("unable to find compatible role (%s) in metadata", policy.getRole()->toString().c_str());
-                return;
+                return false;
             }
             policy.setIssuerMetadata(roledesc);
+            return true;
         }
     }
     catch (bad_cast&) {
         // Just trap it.
         log.warn("caught a bad_cast while examining message");
     }
+
+    return false;
 }
index 20e785e..1d5a6ba 100644 (file)
@@ -34,7 +34,7 @@ namespace opensaml {
             SAML2MessageRule(const DOMElement* e) {}
             virtual ~SAML2MessageRule() {}
             
-            void evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
+            bool evaluate(const xmltooling::XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
         };
     };
 };
index fe604c2..fc297cf 100644 (file)
@@ -45,7 +45,7 @@ namespace opensaml {
     }
 };
 
-void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
+bool SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
 {
     Category& log=Category::getInstance(SAML_LOGCAT".SecurityPolicyRule.SAML2Message");
     
@@ -85,7 +85,7 @@ void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest*
 
         if (!policy.getIssuer()) {
             log.warn("issuer identity not extracted");
-            return;
+            return false;
         }
 
         if (log.isDebugEnabled()) {
@@ -96,7 +96,7 @@ void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest*
         if (policy.getMetadataProvider() && policy.getRole()) {
             if (policy.getIssuer()->getFormat() && !XMLString::equals(policy.getIssuer()->getFormat(), saml2::NameIDType::ENTITY)) {
                 log.warn("non-system entity issuer, skipping metadata lookup");
-                return;
+                return false;
             }
             
             log.debug("searching metadata for message issuer...");
@@ -104,20 +104,23 @@ void SAML2MessageRule::evaluate(const XMLObject& message, const GenericRequest*
             if (!entity) {
                 auto_ptr_char temp(policy.getIssuer()->getName());
                 log.warn("no metadata found, can't establish identity of issuer (%s)", temp.get());
-                return;
+                return false;
             }
     
             log.debug("matched message issuer against metadata, searching for applicable role...");
             const RoleDescriptor* roledesc=entity->getRoleDescriptor(*policy.getRole(), samlconstants::SAML20P_NS);
             if (!roledesc) {
                 log.warn("unable to find compatible role (%s) in metadata", policy.getRole()->toString().c_str());
-                return;
+                return false;
             }
             policy.setIssuerMetadata(roledesc);
+            return true;
         }
     }
     catch (bad_cast&) {
         // Just trap it.
         log.warn("caught a bad_cast while examining message");
     }
+
+    return false;
 }