Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / saml / saml2 / profile / impl / DelegationRestrictionRule.cpp
index cad245a..304d4b2 100644 (file)
@@ -1,23 +1,27 @@
-/*
- *  Copyright 2009 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * 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
+ * UCAID licenses this file to you 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
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
  * DelegationRestrictionRule.cpp
  *
- * SAML DelegationRestriction SecurityPolicyRule
+ * SAML DelegationRestriction SecurityPolicyRule.
  */
 
 #include "internal.h"
 #include "saml2/core/Assertions.h"
 #include "util/SAMLConstants.h"
 
+#include <ctime>
+#include <xercesc/util/XMLUniDefs.hpp>
 #include <xmltooling/logging.h>
+#include <xmltooling/XMLToolingConfig.h>
 
 using namespace opensaml::saml2;
 using namespace opensaml;
@@ -82,7 +89,7 @@ namespace opensaml {
                         XMLString::equals(n1->getSPNameQualifier(), n2->getSPNameQualifier()));
             }
         public:
-            _isSameDelegate() : m_operand(NULL) {}
+            _isSameDelegate() : m_operand(nullptr) {}
             _isSameDelegate(const Delegate* d) : m_operand(d) {}
 
             // d1 is the input from the message, d2 is from the policy
@@ -113,19 +120,17 @@ namespace opensaml {
     }
 };
 
-DelegationRestrictionRule::DelegationRestrictionRule(const DOMElement* e) : m_match(MATCH_ANY), m_maxTime(0)
+DelegationRestrictionRule::DelegationRestrictionRule(const DOMElement* e)
+    : m_match(MATCH_ANY), m_maxTime(XMLHelper::getAttrInt(e, 0, maxTimeSinceDelegation))
 {
     if (e) {
-        const XMLCh* m = e->getAttributeNS(NULL, match);
+        const XMLCh* m = e ? e->getAttributeNS(nullptr, match) : nullptr;
         if (XMLString::equals(m, newest))
             m_match = MATCH_NEWEST;
         else if (XMLString::equals(m, oldest))
             m_match = MATCH_OLDEST;
         else if (m && *m && !XMLString::equals(m, any))
             throw SecurityPolicyException("Invalid value for \"match\" attribute in Delegation rule.");
-        m = e->getAttributeNS(NULL, maxTimeSinceDelegation);
-        if (m && *m)
-            m_maxTime = XMLString::parseInt(m);
 
         try {
             DOMElement* d = XMLHelper::getFirstChildElement(e, samlconstants::SAML20_DELEGATION_CONDITION_NS, Delegate::LOCAL_NAME);
@@ -173,7 +178,7 @@ bool DelegationRestrictionRule::evaluate(const XMLObject& message, const Generic
 
     if (m_maxTime > 0) {
         return (!dels.empty() && dels.front()->getDelegationInstant() &&
-            (time(NULL) - dels.front()->getDelegationInstantEpoch() - XMLToolingConfig::getConfig().clock_skew_secs <= m_maxTime));
+            (time(nullptr) - dels.front()->getDelegationInstantEpoch() - XMLToolingConfig::getConfig().clock_skew_secs <= m_maxTime));
     }
 
     return true;