public validateMetadata ( string $xml ) : Array | ||
$xml | string | Metadata's XML that will be validate |
Результат | Array | The list of found errors |
public function validateMetadata($xml)
{
assert('is_string($xml)');
$errors = array();
$res = OneLogin_Saml2_Utils::validateXML($xml, 'saml-schema-metadata-2.0.xsd', $this->_debug);
if (!$res instanceof DOMDocument) {
$errors[] = $res;
} else {
$dom = $res;
$element = $dom->documentElement;
if ($element->tagName !== 'md:EntityDescriptor') {
$errors[] = 'noEntityDescriptor_xml';
} else {
$validUntil = $cacheDuration = $expireTime = null;
if ($element->hasAttribute('validUntil')) {
$validUntil = OneLogin_Saml2_Utils::parseSAML2Time($element->getAttribute('validUntil'));
}
if ($element->hasAttribute('cacheDuration')) {
$cacheDuration = $element->getAttribute('cacheDuration');
}
$expireTime = OneLogin_Saml2_Utils::getExpireTime($cacheDuration, $validUntil);
if (isset($expireTime) && time() > $expireTime) {
$errors[] = 'expired_xml';
}
}
}
// TODO: Support Metadata Sign Validation
return $errors;
}
/** * Returns the metadata of this Service Provider in xml. * @return string Metadata in xml * @throws \Exception * @throws \OneLogin_Saml2_Error */ public function getMetadata() { $oneLoginSetting = new \OneLogin_Saml2_Settings($this->config, true); $metadata = $oneLoginSetting->getSPMetadata(); $errors = $oneLoginSetting->validateMetadata($metadata); if (!empty($errors)) { throw new \Exception('Invalid Metadata Service Provider'); } return $metadata; }