SimpleSAML_Utilities::checkDateConditions PHP Method

checkDateConditions() public static method

Deprecation: This method will be removed in SSP 2.0.
public static checkDateConditions ( $start = null, $end = null )
    public static function checkDateConditions($start = null, $end = null)
    {
        $currentTime = time();
        if (!empty($start)) {
            $startTime = \SAML2\Utils::xsDateTimeToTimestamp($start);
            // Allow for a 10 minute difference in Time
            if ($startTime < 0 || $startTime - 600 > $currentTime) {
                return false;
            }
        }
        if (!empty($end)) {
            $endTime = \SAML2\Utils::xsDateTimeToTimestamp($end);
            if ($endTime < 0 || $endTime <= $currentTime) {
                return false;
            }
        }
        return true;
    }

Usage Example

 public function getAttributes()
 {
     $metadata = SimpleSAML_Metadata_MetaDataStorageHandler::getMetadataHandler();
     $md = $metadata->getMetadata($this->getIssuer(), 'shib13-idp-remote');
     $base64 = isset($md['base64attributes']) ? $md['base64attributes'] : false;
     if (!$this->dom instanceof DOMDocument) {
         return array();
     }
     $attributes = array();
     $assertions = $this->doXPathQuery('/shibp:Response/shib:Assertion');
     foreach ($assertions as $assertion) {
         if (!$this->isNodeValidated($assertion)) {
             throw new Exception('Shib13 AuthnResponse contained an unsigned assertion.');
         }
         $conditions = $this->doXPathQuery('shib:Conditions', $assertion);
         if ($conditions && $conditions->length > 0) {
             $condition = $conditions->item(0);
             $start = $condition->getAttribute('NotBefore');
             $end = $condition->getAttribute('NotOnOrAfter');
             if ($start && $end) {
                 if (!SimpleSAML_Utilities::checkDateConditions($start, $end)) {
                     error_log('Date check failed ... (from ' . $start . ' to ' . $end . ')');
                     continue;
                 }
             }
         }
         $attribute_nodes = $this->doXPathQuery('shib:AttributeStatement/shib:Attribute/shib:AttributeValue', $assertion);
         foreach ($attribute_nodes as $attribute) {
             $value = $attribute->textContent;
             $name = $attribute->parentNode->getAttribute('AttributeName');
             if ($attribute->hasAttribute('Scope')) {
                 $scopePart = '@' . $attribute->getAttribute('Scope');
             } else {
                 $scopePart = '';
             }
             if (!is_string($name)) {
                 throw new Exception('Shib13 Attribute node without an AttributeName.');
             }
             if (!array_key_exists($name, $attributes)) {
                 $attributes[$name] = array();
             }
             if ($base64) {
                 $encodedvalues = explode('_', $value);
                 foreach ($encodedvalues as $v) {
                     $attributes[$name][] = base64_decode($v) . $scopePart;
                 }
             } else {
                 $attributes[$name][] = $value . $scopePart;
             }
         }
     }
     return $attributes;
 }
All Usage Examples Of SimpleSAML_Utilities::checkDateConditions