Update ctors to use new attribute shortcuts.
[shibboleth/cpp-opensaml.git] / saml / binding / impl / MessageFlowRule.cpp
index f371f1f..123921a 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *  Copyright 2001-2009 Internet2
- * 
+ *  Copyright 2001-2010 Internet2
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 
 /**
  * MessageFlowRule.cpp
- * 
- * SAML replay and freshness checking SecurityPolicyRule
+ *
+ * SAML replay and freshness checking SecurityPolicyRule.
  */
 
 #include "internal.h"
 #include "exceptions.h"
+#include "binding/SecurityPolicy.h"
 #include "binding/SecurityPolicyRule.h"
 
 #include <xmltooling/logging.h>
+#include <xmltooling/XMLToolingConfig.h>
 #include <xmltooling/util/ReplayCache.h>
+#include <xmltooling/util/XMLHelper.h>
 #include <xercesc/util/XMLUniDefs.hpp>
 
 using namespace opensaml;
@@ -39,12 +42,12 @@ namespace opensaml {
     public:
         MessageFlowRule(const DOMElement* e);
         virtual ~MessageFlowRule() {}
-        
+
         const char* getType() const {
             return MESSAGEFLOW_POLICY_RULE;
         }
         bool evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const;
-    
+
     private:
         bool m_checkReplay;
         time_t m_expires;
@@ -60,16 +63,9 @@ static const XMLCh checkReplay[] = UNICODE_LITERAL_11(c,h,e,c,k,R,e,p,l,a,y);
 static const XMLCh expires[] = UNICODE_LITERAL_7(e,x,p,i,r,e,s);
 
 MessageFlowRule::MessageFlowRule(const DOMElement* e)
-    : m_checkReplay(true), m_expires(XMLToolingConfig::getConfig().clock_skew_secs)
+    : m_checkReplay(XMLHelper::getAttrBool(e, true, checkReplay)),
+        m_expires(XMLHelper::getAttrInt(e, XMLToolingConfig::getConfig().clock_skew_secs, expires))
 {
-    if (e) {
-        const XMLCh* attr = e->getAttributeNS(NULL, checkReplay);
-        if (attr && (*attr==chLatin_f || *attr==chDigit_0))
-            m_checkReplay = false;
-        attr = e->getAttributeNS(NULL, expires);
-        if (attr)
-            m_expires = XMLString::parseInt(attr);
-    }
 }
 
 bool MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* request, SecurityPolicy& policy) const
@@ -77,7 +73,7 @@ bool MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* r
     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);
 
-    time_t now = time(NULL);
+    time_t now = policy.getTime();
     time_t skew = XMLToolingConfig::getConfig().clock_skew_secs;
     time_t issueInstant = policy.getIssueInstant();
     if (issueInstant == 0) {
@@ -95,7 +91,7 @@ bool MessageFlowRule::evaluate(const XMLObject& message, const GenericRequest* r
             throw SecurityPolicyException("Message expired, was issued too long ago.");
         }
     }
-    
+
     // Check replay.
     if (m_checkReplay) {
         const XMLCh* id = policy.getMessageID();