diff --git a/src/SAML2/Assertion.php b/src/SAML2/Assertion.php index dd970b558..f7f0dcb2c 100644 --- a/src/SAML2/Assertion.php +++ b/src/SAML2/Assertion.php @@ -256,16 +256,16 @@ class Assertion implements SignedElement */ public function __construct(\DOMElement $xml = null) { - $this->id = Utils::getContainer()->generateId(); - $this->issueInstant = Temporal::getTime(); - $this->issuer = ''; - $this->authnInstant = Temporal::getTime(); - $this->attributes = []; - $this->nameFormat = Constants::NAMEFORMAT_UNSPECIFIED; - $this->certificates = []; - $this->AuthenticatingAuthority = []; - $this->SubjectConfirmation = []; - $this->requiredEncAttributes = false; + $this->setId(Utils::getContainer()->generateId()); + $this->setIssueInstant(Temporal::getTime()); + $this->setIssuer(''); + $this->setAuthnInstant(Temporal::getTime()); + $this->setAttributes([]); + $this->setAttributeNameFormat(Constants::NAMEFORMAT_UNSPECIFIED); + $this->setCertificates([]); + $this->setAuthenticatingAuthority([]); + $this->setSubjectConfirmation([]); + $this->setRequiredEncAttributes(false); if ($xml === null) { return; @@ -278,7 +278,7 @@ public function __construct(\DOMElement $xml = null) if ($xml->getAttribute('Version') !== '2.0') { /* Currently a very strict check. */ - throw new \Exception('Unsupported version: ' . $xml->getAttribute('Version')); + throw new \Exception('Unsupported version: '.$xml->getAttribute('Version')); } $this->issueInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('IssueInstant')); @@ -364,14 +364,14 @@ private function parseConditions(\DOMElement $xml) if ($conditions->hasAttribute('NotBefore')) { $notBefore = Utils::xsDateTimeToTimestamp($conditions->getAttribute('NotBefore')); - if ($this->notBefore === null || $this->notBefore < $notBefore) { - $this->notBefore = $notBefore; + if ($this->getNotBefore() === null || $this->getNotBefore() < $notBefore) { + $this->setNotBefore($notBefore); } } if ($conditions->hasAttribute('NotOnOrAfter')) { $notOnOrAfter = Utils::xsDateTimeToTimestamp($conditions->getAttribute('NotOnOrAfter')); - if ($this->notOnOrAfter === null || $this->notOnOrAfter > $notOnOrAfter) { - $this->notOnOrAfter = $notOnOrAfter; + if ($this->getNotOnOrAfter() === null || $this->getNotOnOrAfter() > $notOnOrAfter) { + $this->setNotOnOrAfter($notOnOrAfter); } } @@ -380,7 +380,7 @@ private function parseConditions(\DOMElement $xml) continue; } if ($node->namespaceURI !== Constants::NS_SAML) { - throw new \Exception('Unknown namespace of condition: ' . var_export($node->namespaceURI, true)); + throw new \Exception('Unknown namespace of condition: '.var_export($node->namespaceURI, true)); } switch ($node->localName) { case 'AudienceRestriction': @@ -403,7 +403,7 @@ private function parseConditions(\DOMElement $xml) /* Currently ignored. */ break; default: - throw new \Exception('Unknown condition: ' . var_export($node->localName, true)); + throw new \Exception('Unknown condition: '.var_export($node->localName, true)); } } } @@ -559,7 +559,9 @@ private function parseAttributeValue($attribute, $attributeName) } else { /* Fall back for legacy IdPs sending string value (e.g. SSP < 1.15) */ Utils::getContainer()->getLogger()->warning(sprintf("Attribute %s (EPTI) value %d is not an XML NameId", $attributeName, $index)); - $this->attributes[$attributeName][] = XML\saml\NameID::fromArray(['Value' => $eptiAttributeValue->textContent]); + $nameId = new XML\saml\NameID(); + $nameId->setValue($eptiAttributeValue->textContent); + $this->attributes[$attributeName][] = $nameId; } } @@ -588,7 +590,7 @@ private function parseAttributeValue($attribute, $attributeName) } if ($type === 'xs:integer') { - $this->attributes[$attributeName][] = (int)$value->textContent; + $this->attributes[$attributeName][] = (int) $value->textContent; } else { $this->attributes[$attributeName][] = trim($value->textContent); } @@ -602,10 +604,10 @@ private function parseAttributeValue($attribute, $attributeName) */ private function parseEncryptedAttributes(\DOMElement $xml) { - $this->encryptedAttributes = Utils::xpQuery( + $this->setEncryptedAttributes(Utils::xpQuery( $xml, './saml_assertion:AttributeStatement/saml_assertion:EncryptedAttribute' - ); + )); } /** @@ -621,10 +623,10 @@ private function parseSignature(\DOMElement $xml) /* Validate the signature element of the message. */ $sig = Utils::validateElement($xml); if ($sig !== false) { - $this->wasSignedAtConstruction = true; - $this->certificates = $sig['Certificates']; - $this->signatureData = $sig; - $this->signatureMethod = $signatureMethod[0]->value; + $this->setWasSignedAtConstruction(true); + $this->setCertificates($sig['Certificates']); + $this->setSignatureData($sig); + $this->setSignatureMethod($signatureMethod[0]->value); } } @@ -642,11 +644,11 @@ public function validate(XMLSecurityKey $key) { assert($key->type === \RobRichards\XMLSecLibs\XMLSecurityKey::RSA_SHA256); - if ($this->signatureData === null) { + if ($this->getSignatureData() === null) { return false; } - Utils::validateSignature($this->signatureData, $key); + Utils::validateSignature($this->getSignatureData(), $key); return true; } @@ -746,6 +748,7 @@ public function setNameId($nameId) assert(is_array($nameId) || is_null($nameId) || $nameId instanceof XML\saml\NameID); if (is_array($nameId)) { + // @deprecated behaviour $nameId = XML\saml\NameID::fromArray($nameId); } $this->nameId = $nameId; @@ -836,7 +839,7 @@ public function decryptAttributes(XMLSecurityKey $key, array $blacklist = []) return; } $firstAttribute = true; - $attributes = $this->encryptedAttributes; + $attributes = $this->getEncryptedAttributes(); foreach ($attributes as $attributeEnc) { /*Decrypt node */ $attribute = Utils::decryptElement( @@ -928,12 +931,23 @@ public function setNotOnOrAfter($notOnOrAfter) } /** - * Set $EncryptedAttributes if attributes will send encrypted + * Retrieve $requiredEncAttributes if attributes will be send encrypted + * + * @return boolean Rrue to encrypt attributes in the assertion. + */ + public function getRequiredEncAttributes() + { + return $this->requiredEncAttributes; + } + + /** + * Set $requiredEncAttributes if attributes will be send encrypted * * @param boolean $ea true to encrypt attributes in the assertion. */ - public function setEncryptedAttributes($ea) + public function setRequiredEncAttributes($ea) { + assert(is_bool($ea)); $this->requiredEncAttributes = $ea; } @@ -1103,6 +1117,28 @@ public function setAuthnContextClassRef($authnContextClassRef) $this->authnContextClassRef = $authnContextClassRef; } + /** + * Retrieve the signature method. + * + * @return string|null The signature method. + */ + public function getSignatureMethod() + { + return $this->signatureMethod; + } + + /** + * Set the signature method used. + * + * @param string|null $signatureMethod + */ + public function setSignatureMethod($signatureMethod) + { + assert(is_string($signatureMethod) || is_null($signatureMethod)); + + $this->signatureMethod = $signatureMethod; + } + /** * Set the authentication context declaration. * @@ -1136,7 +1172,7 @@ public function getAuthnContextDecl() /** * Set the authentication context declaration reference. * - * @param string $authnContextDeclRef + * @param string|\SAML2\XML\Chunk $authnContextDeclRef * @throws \Exception */ public function setAuthnContextDeclRef($authnContextDeclRef) @@ -1204,6 +1240,22 @@ public function setAttributes(array $attributes) $this->attributes = $attributes; } + /** + * @return array + */ + public function getSignatureData() + { + return $this->signatureData; + } + + /** + * @param array|null $signatureData + */ + public function setSignatureData(array $signatureData = null) + { + $this->signatureData = $signatureData; + } + /** * Retrieve all attributes value types. * @@ -1269,6 +1321,26 @@ public function setSubjectConfirmation(array $SubjectConfirmation) $this->SubjectConfirmation = $SubjectConfirmation; } + /** + * Retrieve the encryptedAttributes elements we have. + * + * @return array Array of \DOMElement elements. + */ + public function getEncryptedAttributes() + { + return $this->encryptedAttributes; + } + + /** + * Set the encryptedAttributes elements + * + * @param array $encAttrs Array of \DOMElement elements. + */ + public function setEncryptedAttributes(array $encAttrs) + { + $this->encryptedAttributes = $encAttrs; + } + /** * Retrieve the private key we should use to sign the assertion. * @@ -1337,17 +1409,18 @@ public function getCertificates() /** * @return bool */ - public function getWasSignedAtConstruction() + public function wasSignedAtConstruction() { return $this->wasSignedAtConstruction; } /** - * @return null|string + * @param bool $flag */ - public function getSignatureMethod() + public function setWasSignedAtConstruction($flag) { - return $this->signatureMethod; + assert(is_bool($flag)); + $this->wasSignedAtConstruction = $flag; } /** @@ -1365,7 +1438,7 @@ public function toXML(\DOMNode $parentElement = null) $document = $parentElement->ownerDocument; } - $root = $document->createElementNS(Constants::NS_SAML, 'saml:' . 'Assertion'); + $root = $document->createElementNS(Constants::NS_SAML, 'saml:'.'Assertion'); $parentElement->appendChild($root); /* Ugly hack to add another namespace declaration to the root element. */ @@ -1389,7 +1462,7 @@ public function toXML(\DOMNode $parentElement = null) $this->addSubject($root); $this->addConditions($root); $this->addAuthnStatement($root); - if ($this->requiredEncAttributes === false) { + if ($this->getRequiredEncAttributes() === false) { $this->addAttributeStatement($root); } else { $this->addEncryptedAttributeStatement($root); @@ -1421,7 +1494,7 @@ private function addSubject(\DOMElement $root) if ($this->encryptedNameId === null) { $this->nameId->toXML($subject); } else { - $eid = $subject->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:' . 'EncryptedID'); + $eid = $subject->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:'.'EncryptedID'); $subject->appendChild($eid); $eid->appendChild($subject->ownerDocument->importNode($this->encryptedNameId, true)); } @@ -1573,7 +1646,7 @@ private function addAttributeStatement(\DOMElement $root) if (is_array($this->attributesValueTypes) && array_key_exists($name, $this->attributesValueTypes)) { $valueTypes = $this->attributesValueTypes[$name]; if (is_array($valueTypes) && count($valueTypes) != count($values)) { - throw new \Exception('Array of value types and array of values have different size for attribute '. var_export($name, true)); + throw new \Exception('Array of value types and array of values have different size for attribute '.var_export($name, true)); } } else { // if no type(s), default behaviour @@ -1634,7 +1707,7 @@ private function addAttributeStatement(\DOMElement $root) */ private function addEncryptedAttributeStatement(\DOMElement $root) { - if ($this->requiredEncAttributes === false) { + if ($this->getRequiredEncAttributes() === false) { return; } @@ -1650,7 +1723,7 @@ private function addEncryptedAttributeStatement(\DOMElement $root) $document2->appendChild($attribute); if ($this->nameFormat !== Constants::NAMEFORMAT_UNSPECIFIED) { - $attribute->setAttribute('NameFormat', $this->nameFormat); + $attribute->setAttribute('NameFormat', $this->getAttributeNameFormat()); } foreach ($values as $value) { diff --git a/src/SAML2/Assertion/Processor.php b/src/SAML2/Assertion/Processor.php index 882d73c30..da22a2925 100644 --- a/src/SAML2/Assertion/Processor.php +++ b/src/SAML2/Assertion/Processor.php @@ -97,7 +97,7 @@ public function process($assertion) { $assertion = $this->decryptAssertion($assertion); - if (!$assertion->getWasSignedAtConstruction()) { + if (!$assertion->wasSignedAtConstruction()) { $this->logger->info(sprintf( 'Assertion with id "%s" was not signed at construction, not verifying the signature', $assertion->getId() diff --git a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBefore.php b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBefore.php index 41f72ba42..29ca794a9 100644 --- a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBefore.php +++ b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBefore.php @@ -14,7 +14,7 @@ public function validate( SubjectConfirmation $subjectConfirmation, Result $result ) { - $notBefore = $subjectConfirmation->SubjectConfirmationData->NotBefore; + $notBefore = $subjectConfirmation->getSubjectConfirmationData()->getNotBefore(); if ($notBefore && $notBefore > Temporal::getTime() + 60) { $result->addError('NotBefore in SubjectConfirmationData is in the future'); } diff --git a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfter.php b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfter.php index 43262b1d0..49f36b3a6 100644 --- a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfter.php +++ b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfter.php @@ -14,7 +14,7 @@ public function validate( SubjectConfirmation $subjectConfirmation, Result $result ) { - $notOnOrAfter = $subjectConfirmation->SubjectConfirmationData->NotOnOrAfter; + $notOnOrAfter = $subjectConfirmation->getSubjectConfirmationData()->getNotOnOrAfter(); if ($notOnOrAfter && $notOnOrAfter <= Temporal::getTime() - 60) { $result->addError('NotOnOrAfter in SubjectConfirmationData is in the past'); } diff --git a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMatches.php b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMatches.php index 140ab969a..7dfc27f92 100644 --- a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMatches.php +++ b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMatches.php @@ -24,7 +24,7 @@ public function validate( SubjectConfirmation $subjectConfirmation, Result $result ) { - $recipient = $subjectConfirmation->SubjectConfirmationData->Recipient; + $recipient = $subjectConfirmation->getSubjectConfirmationData()->getRecipient(); if ($recipient && !$this->destination->equals(new Destination($recipient))) { $result->addError(sprintf( 'Recipient in SubjectConfirmationData ("%s") does not match the current destination ("%s")', diff --git a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatches.php b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatches.php index 519a7a1d5..b4bb5e7b3 100644 --- a/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatches.php +++ b/src/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatches.php @@ -21,7 +21,7 @@ public function validate( SubjectConfirmation $subjectConfirmation, Result $result ) { - $inResponseTo = $subjectConfirmation->SubjectConfirmationData->InResponseTo; + $inResponseTo = $subjectConfirmation->getSubjectConfirmationData()->getInResponseTo(); if ($inResponseTo && ($this->getInResponseTo() !== false) && ($this->getInResponseTo() !== $inResponseTo)) { $result->addError(sprintf( 'InResponseTo in SubjectConfirmationData ("%s") does not match the Response InResponseTo ("%s")', diff --git a/src/SAML2/AttributeQuery.php b/src/SAML2/AttributeQuery.php index 6d37d32b2..1bc4c87d9 100644 --- a/src/SAML2/AttributeQuery.php +++ b/src/SAML2/AttributeQuery.php @@ -159,7 +159,7 @@ public function toUnsignedXML() $type = null; } - $attributeValue = Utils::addString($attribute, Constants::NS_SAML, 'saml:AttributeValue', (string)$value); + $attributeValue = Utils::addString($attribute, Constants::NS_SAML, 'saml:AttributeValue', strval($value)); if ($type !== null) { $attributeValue->setAttributeNS(Constants::NS_XSI, 'xsi:type', $type); } diff --git a/src/SAML2/AuthnRequest.php b/src/SAML2/AuthnRequest.php index 9d4730e89..d91befc33 100644 --- a/src/SAML2/AuthnRequest.php +++ b/src/SAML2/AuthnRequest.php @@ -40,7 +40,7 @@ class AuthnRequest extends Request /** * Set to true if this request is passive. * - * @var bool. + * @var bool */ private $isPassive; @@ -113,7 +113,7 @@ class AuthnRequest extends Request * * @var array */ - private $audiences; + private $audiences = []; /** * @var \SAML2\XML\saml\SubjectConfirmation[] @@ -441,7 +441,7 @@ public function setIsPassive($isPassive) * * This may be null, in which case no audience is included. * - * @return array|null The audiences. + * @return array The audiences. */ public function getAudiences() { @@ -455,7 +455,7 @@ public function getAudiences() * * @param array|null $audiences The audiences. */ - public function setAudiences(array $audiences = null) + public function setAudiences(array $audiences) { $this->audiences = $audiences; } @@ -474,7 +474,7 @@ public function setAudiences(array $audiences = null) * be a string instead of an array, where each string * is mapped to the value of attribute ProviderID. * - * @param array List of idpEntries to scope the request to. + * @param array $IDPList List of idpEntries to scope the request to. */ public function setIDPList(array $IDPList) { @@ -626,11 +626,11 @@ public function getRequestedAuthnContext() /** * Set the RequestedAuthnContext. * - * @param array|null $requestedAuthnContext The RequestedAuthnContext. + * @param array $requestedAuthnContext The RequestedAuthnContext. */ public function setRequestedAuthnContext($requestedAuthnContext) { - assert(is_array($requestedAuthnContext) || is_null($requestedAuthnContext)); + assert(is_array($requestedAuthnContext)); $this->requestedAuthnContext = $requestedAuthnContext; } @@ -872,7 +872,7 @@ private function addSubject(\DOMElement $root) */ private function addConditions(\DOMElement $root) { - if ($this->audiences !== null) { + if ($this->audiences !== []) { $document = $root->ownerDocument; $conditions = $document->createElementNS(Constants::NS_SAML, 'saml:Conditions'); @@ -881,7 +881,7 @@ private function addConditions(\DOMElement $root) $ar = $document->createElementNS(Constants::NS_SAML, 'saml:AudienceRestriction'); $conditions->appendChild($ar); - Utils::addStrings($ar, Constants::NS_SAML, 'saml:Audience', false, $this->audiences); + Utils::addStrings($ar, Constants::NS_SAML, 'saml:Audience', false, $this->getAudiences()); } } } diff --git a/src/SAML2/Binding.php b/src/SAML2/Binding.php index 21d2f3572..83e666f3d 100644 --- a/src/SAML2/Binding.php +++ b/src/SAML2/Binding.php @@ -44,7 +44,7 @@ public static function getBinding($urn) case Constants::BINDING_PAOS: return new SOAP(); default: - throw new \Exception('Unsupported binding: ' . var_export($urn, true)); + throw new \Exception('Unsupported binding: '.var_export($urn, true)); } } @@ -90,15 +90,15 @@ public static function getCurrentBinding() $logger = Utils::getContainer()->getLogger(); $logger->warning('Unable to find the SAML 2 binding used for this request.'); - $logger->warning('Request method: ' . var_export($_SERVER['REQUEST_METHOD'], true)); + $logger->warning('Request method: '.var_export($_SERVER['REQUEST_METHOD'], true)); if (!empty($_GET)) { - $logger->warning("GET parameters: '" . implode("', '", array_map('addslashes', array_keys($_GET))) . "'"); + $logger->warning("GET parameters: '".implode("', '", array_map('addslashes', array_keys($_GET)))."'"); } if (!empty($_POST)) { - $logger->warning("POST parameters: '" . implode("', '", array_map('addslashes', array_keys($_POST))) . "'"); + $logger->warning("POST parameters: '".implode("', '", array_map('addslashes', array_keys($_POST)))."'"); } if (isset($_SERVER['CONTENT_TYPE'])) { - $logger->warning('Content-Type: ' . var_export($_SERVER['CONTENT_TYPE'], true)); + $logger->warning('Content-Type: '.var_export($_SERVER['CONTENT_TYPE'], true)); } throw new \Exception('Unable to find the current binding.'); diff --git a/src/SAML2/Certificate/KeyCollection.php b/src/SAML2/Certificate/KeyCollection.php index ca4d296ce..f0b33508a 100644 --- a/src/SAML2/Certificate/KeyCollection.php +++ b/src/SAML2/Certificate/KeyCollection.php @@ -17,7 +17,7 @@ class KeyCollection extends ArrayCollection */ public function add($key) { - if (!$key instanceof Key) { + if (!($key instanceof Key)) { throw InvalidArgumentException::invalidType( 'SAML2\Certificate\Key', $key diff --git a/src/SAML2/Certificate/KeyLoader.php b/src/SAML2/Certificate/KeyLoader.php index 7fede6310..f33336b5b 100644 --- a/src/SAML2/Certificate/KeyLoader.php +++ b/src/SAML2/Certificate/KeyLoader.php @@ -29,8 +29,8 @@ public function __construct() * Prioritisation order is keys > certData > certificate * * @param \SAML2\Configuration\CertificateProvider $config - * @param null $usage - * @param bool $required + * @param string|null $usage + * @param bool $required * * @return \SAML2\Certificate\KeyCollection */ diff --git a/src/SAML2/Compat/AbstractContainer.php b/src/SAML2/Compat/AbstractContainer.php index a3f193497..6765cb47a 100644 --- a/src/SAML2/Compat/AbstractContainer.php +++ b/src/SAML2/Compat/AbstractContainer.php @@ -24,7 +24,7 @@ abstract public function generateId(); * - **encrypt** XML that is about to be encrypted * - **decrypt** XML that was just decrypted * - * @param string $message + * @param string|\DOMNode $message * @param string $type * @return void */ diff --git a/src/SAML2/Compat/ContainerSingleton.php b/src/SAML2/Compat/ContainerSingleton.php index 652487f90..28e49d76c 100644 --- a/src/SAML2/Compat/ContainerSingleton.php +++ b/src/SAML2/Compat/ContainerSingleton.php @@ -7,12 +7,12 @@ class ContainerSingleton { /** - * @var \SAML2\Compat\Ssp\Container + * @var \SAML2\Compat\AbstractContainer */ protected static $container; /** - * @return \SAML2\Compat\Ssp\Container + * @return \SAML2\Compat\AbstractContainer */ public static function getInstance() { diff --git a/src/SAML2/Compat/Ssp/Logger.php b/src/SAML2/Compat/Ssp/Logger.php index 627ceab20..4e7b528bf 100644 --- a/src/SAML2/Compat/Ssp/Logger.php +++ b/src/SAML2/Compat/Ssp/Logger.php @@ -16,7 +16,7 @@ class Logger implements LoggerInterface */ public function emergency($message, array $context = []) { - \SimpleSAML\Logger::emergency($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::emergency($message.($context ? " ".var_export($context, true) : "")); } /** @@ -31,7 +31,7 @@ public function emergency($message, array $context = []) */ public function alert($message, array $context = []) { - \SimpleSAML\Logger::alert($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::alert($message.($context ? " ".var_export($context, true) : "")); } /** @@ -45,7 +45,7 @@ public function alert($message, array $context = []) */ public function critical($message, array $context = []) { - \SimpleSAML\Logger::critical($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::critical($message.($context ? " ".var_export($context, true) : "")); } /** @@ -58,7 +58,7 @@ public function critical($message, array $context = []) */ public function error($message, array $context = []) { - \SimpleSAML\Logger::error($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::error($message.($context ? " ".var_export($context, true) : "")); } /** @@ -73,7 +73,7 @@ public function error($message, array $context = []) */ public function warning($message, array $context = []) { - \SimpleSAML\Logger::warning($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::warning($message.($context ? " ".var_export($context, true) : "")); } /** @@ -85,7 +85,7 @@ public function warning($message, array $context = []) */ public function notice($message, array $context = []) { - \SimpleSAML\Logger::notice($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::notice($message.($context ? " ".var_export($context, true) : "")); } /** @@ -99,7 +99,7 @@ public function notice($message, array $context = []) */ public function info($message, array $context = []) { - \SimpleSAML\Logger::info($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::info($message.($context ? " ".var_export($context, true) : "")); } /** @@ -111,7 +111,7 @@ public function info($message, array $context = []) */ public function debug($message, array $context = []) { - \SimpleSAML\Logger::debug($message . ($context ? " " . var_export($context, true) : "")); + \SimpleSAML\Logger::debug($message.($context ? " ".var_export($context, true) : "")); } /** diff --git a/src/SAML2/Configuration/SimpleSAMLConverter.php b/src/SAML2/Configuration/SimpleSAMLConverter.php index 275ca245d..295eaad1b 100644 --- a/src/SAML2/Configuration/SimpleSAMLConverter.php +++ b/src/SAML2/Configuration/SimpleSAMLConverter.php @@ -67,13 +67,13 @@ protected static function pluckConfiguration(Configuration $configuration, $pref // ported from // https://github.com/simplesamlphp/simplesamlphp/blob/3d735912342767d391297cc5e13272a76730aca0/lib/SimpleSAML/Configuration.php#L1119 - if ($configuration->hasValue($prefix . 'certificate')) { + if ($configuration->hasValue($prefix.'certificate')) { $extracted['certificateData'] = $configuration->getString($prefix.'certificate'); } // ported from // https://github.com/simplesamlphp/simplesamlphp/blob/3d735912342767d391297cc5e13272a76730aca0/modules/saml/lib/Message.php#L161 - if ($configuration->hasValue($prefix . 'certFingerprint')) { + if ($configuration->hasValue($prefix.'certFingerprint')) { $extracted['certificateFingerprint'] = $configuration->getArrayizeString('certFingerprint'); } diff --git a/src/SAML2/Constants.php b/src/SAML2/Constants.php index 7cb5c2363..004aef520 100644 --- a/src/SAML2/Constants.php +++ b/src/SAML2/Constants.php @@ -60,8 +60,8 @@ class Constants const CM_BEARER = 'urn:oasis:names:tc:SAML:2.0:cm:bearer'; /** - * Holder-of-Key subject confirmation method. - */ + * Holder-of-Key subject confirmation method. + */ const CM_HOK = 'urn:oasis:names:tc:SAML:2.0:cm:holder-of-key'; /** diff --git a/src/SAML2/EncryptedAssertion.php b/src/SAML2/EncryptedAssertion.php index e741d082b..f71520983 100644 --- a/src/SAML2/EncryptedAssertion.php +++ b/src/SAML2/EncryptedAssertion.php @@ -75,7 +75,7 @@ public function setAssertion(Assertion $assertion, XMLSecurityKey $key) break; default: - throw new \Exception('Unknown key type for encryption: ' . $key->type); + throw new \Exception('Unknown key type for encryption: '.$key->type); } $this->encryptedData = $enc->encryptNode($symmetricKey); @@ -112,7 +112,7 @@ public function toXML(\DOMNode $parentElement = null) $document = $parentElement->ownerDocument; } - $root = $document->createElementNS(Constants::NS_SAML, 'saml:' . 'EncryptedAssertion'); + $root = $document->createElementNS(Constants::NS_SAML, 'saml:'.'EncryptedAssertion'); $parentElement->appendChild($root); $root->appendChild($document->importNode($this->encryptedData, true)); diff --git a/src/SAML2/HTTPArtifact.php b/src/SAML2/HTTPArtifact.php index 1e29c5d7a..dca87af9a 100644 --- a/src/SAML2/HTTPArtifact.php +++ b/src/SAML2/HTTPArtifact.php @@ -80,7 +80,7 @@ public function receive() { if (array_key_exists('SAMLart', $_REQUEST)) { $artifact = base64_decode($_REQUEST['SAMLart']); - $endpointIndex = bin2hex(substr($artifact, 2, 2)); + $endpointIndex = bin2hex(substr($artifact, 2, 2)); $sourceId = bin2hex(substr($artifact, 4, 20)); } else { throw new \Exception('Missing SAMLart parameter.'); @@ -96,7 +96,7 @@ public function receive() $endpoint = null; foreach ($idpMetadata->getEndpoints('ArtifactResolutionService') as $ep) { - if ($ep['index'] === hexdec($endpointIndex)) { + if ($ep['index'] === hexdec($endpointIndex)) { $endpoint = $ep; break; } @@ -118,7 +118,7 @@ public function receive() $ar->setDestination($endpoint['Location']); /* Sign the request */ - \sspmod_saml_Message::addSign($this->spMetadata, $idpMetadata, $ar); // Shoaib - moved from the SOAPClient. + \SimpleSAML\Module\saml\Message::addSign($this->spMetadata, $idpMetadata, $ar); // Shoaib - moved from the SOAPClient. $soap = new SOAPClient(); diff --git a/src/SAML2/HTTPRedirect.php b/src/SAML2/HTTPRedirect.php index b6f63a677..68df567b2 100644 --- a/src/SAML2/HTTPRedirect.php +++ b/src/SAML2/HTTPRedirect.php @@ -49,21 +49,21 @@ public function getRedirectURL(Message $message) $msg .= urlencode($msgStr); if ($relayState !== null) { - $msg .= '&RelayState=' . urlencode($relayState); + $msg .= '&RelayState='.urlencode($relayState); } if ($key !== null) { /* Add the signature. */ - $msg .= '&SigAlg=' . urlencode($key->type); + $msg .= '&SigAlg='.urlencode($key->type); $signature = $key->signData($msg); - $msg .= '&Signature=' . urlencode(base64_encode($signature)); + $msg .= '&Signature='.urlencode(base64_encode($signature)); } if (strpos($destination, '?') === false) { - $destination .= '?' . $msg; + $destination .= '?'.$msg; } else { - $destination .= '&' . $msg; + $destination .= '&'.$msg; } return $destination; @@ -79,7 +79,7 @@ public function getRedirectURL(Message $message) public function send(Message $message) { $destination = $this->getRedirectURL($message); - Utils::getContainer()->getLogger()->debug('Redirect to ' . strlen($destination) . ' byte URL: ' . $destination); + Utils::getContainer()->getLogger()->debug('Redirect to '.strlen($destination).' byte URL: '.$destination); Utils::getContainer()->redirect($destination); } @@ -106,7 +106,7 @@ public function receive() } if (isset($data['SAMLEncoding']) && $data['SAMLEncoding'] !== self::DEFLATE) { - throw new \Exception('Unknown SAMLEncoding: ' . var_export($data['SAMLEncoding'], true)); + throw new \Exception('Unknown SAMLEncoding: '.var_export($data['SAMLEncoding'], true)); } $message = base64_decode($message); @@ -154,7 +154,7 @@ public function receive() * It also adds a new parameter, SignedQuery, which contains the data that is * signed. * - * @return string The query data that is signed. + * @return array The query data that is signed. */ private static function parseQuery() { @@ -182,18 +182,18 @@ private static function parseQuery() switch ($name) { case 'SAMLRequest': case 'SAMLResponse': - $sigQuery = $name . '=' . $value; + $sigQuery = $name.'='.$value; break; case 'RelayState': - $relayState = '&RelayState=' . $value; + $relayState = '&RelayState='.$value; break; case 'SigAlg': - $sigAlg = '&SigAlg=' . $value; + $sigAlg = '&SigAlg='.$value; break; } } - $data['SignedQuery'] = $sigQuery . $relayState . $sigAlg; + $data['SignedQuery'] = $sigQuery.$relayState.$sigAlg; return $data; } diff --git a/src/SAML2/LogoutRequest.php b/src/SAML2/LogoutRequest.php index 2192f5fad..465576f81 100644 --- a/src/SAML2/LogoutRequest.php +++ b/src/SAML2/LogoutRequest.php @@ -4,6 +4,7 @@ use RobRichards\XMLSecLibs\XMLSecEnc; use RobRichards\XMLSecLibs\XMLSecurityKey; +use SAML2\XML\saml\NameID; /** * Class for SAML 2 logout request messages. @@ -59,7 +60,7 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('NotOnOrAfter')) { - $this->notOnOrAfter = Utils::xsDateTimeToTimestamp($xml->getAttribute('NotOnOrAfter')); + $this->setNotOnOrAfter(Utils::xsDateTimeToTimestamp($xml->getAttribute('NotOnOrAfter'))); } $nameId = Utils::xpQuery($xml, './saml_assertion:NameID | ./saml_assertion:EncryptedID/xenc:EncryptedData'); @@ -71,9 +72,9 @@ public function __construct(\DOMElement $xml = null) $nameId = $nameId[0]; if ($nameId->localName === 'EncryptedData') { /* The NameID element is encrypted. */ - $this->encryptedNameId = $nameId; + $this->setEncryptedNameId($nameId); } else { - $this->nameId = new XML\saml\NameID($nameId); + $this->setNameId(new NameID($nameId)); } $sessionIndexes = Utils::xpQuery($xml, './saml_protocol:SessionIndex'); @@ -107,11 +108,11 @@ public function setNotOnOrAfter($notOnOrAfter) /** * Check whether the NameId is encrypted. * - * @return true if the NameId is encrypted, false if not. + * @return bool True if the NameId is encrypted, false if not. */ public function isNameIdEncrypted() { - if ($this->encryptedNameId !== null) { + if ($this->getEncryptedNameId() !== null) { return true; } @@ -129,7 +130,7 @@ public function encryptNameId(XMLSecurityKey $key) $doc = DOMDocumentFactory::create(); $root = $doc->createElement('root'); $doc->appendChild($root); - $this->nameId->toXML($root); + $this->getNameId()->toXML($root); $nameId = $root->firstChild; Utils::getContainer()->debugMessage($nameId, 'encrypt'); @@ -143,8 +144,8 @@ public function encryptNameId(XMLSecurityKey $key) $symmetricKey->generateSessionKey(); $enc->encryptKey($key, $symmetricKey); - $this->encryptedNameId = $enc->encryptNode($symmetricKey); - $this->nameId = null; + $this->setEncryptedNameId($enc->encryptNode($symmetricKey)); + $this->setNameId(null); } /** @@ -155,17 +156,17 @@ public function encryptNameId(XMLSecurityKey $key) */ public function decryptNameId(XMLSecurityKey $key, array $blacklist = []) { - if ($this->encryptedNameId === null) { + if ($this->getEncryptedNameId() === null) { /* No NameID to decrypt. */ return; } - $nameId = Utils::decryptElement($this->encryptedNameId, $key, $blacklist); + $nameId = Utils::decryptElement($this->getEncryptedNameId(), $key, $blacklist); Utils::getContainer()->debugMessage($nameId, 'decrypt'); - $this->nameId = new XML\saml\NameID($nameId); + $this->setNameId(new NameID($nameId)); - $this->encryptedNameId = null; + $this->setEncryptedNameId(null); } /** @@ -176,7 +177,7 @@ public function decryptNameId(XMLSecurityKey $key, array $blacklist = []) */ public function getNameId() { - if ($this->encryptedNameId !== null) { + if ($this->getEncryptedNameId() !== null) { throw new \Exception('Attempted to retrieve encrypted NameID without decrypting it first.'); } @@ -197,6 +198,25 @@ public function setNameId($nameId) } $this->nameId = $nameId; } + /** + * Retrieve the encrypted name identifier. + * + * @return \DOMElement|null + */ + private function getEncryptedNameId() + { + return $this->encryptedNameId; + } + + /** + * Set the encrypted name identifier. + * + * @param \DOMElement|null $nameId The name identifier of the session that should be terminated. + */ + private function setEncryptedNameId(\DOMElement $nameId = null) + { + $this->encryptedNameId = $nameId; + } /** * Retrieve the SessionIndexes of the sessions that should be terminated. @@ -258,15 +278,15 @@ public function toUnsignedXML() $root = parent::toUnsignedXML(); if ($this->notOnOrAfter !== null) { - $root->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->notOnOrAfter)); + $root->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->getNotOnOrAfter())); } - if ($this->encryptedNameId === null) { + if ($this->getEncryptedNameId() === null) { $this->nameId->toXML($root); } else { - $eid = $root->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:' . 'EncryptedID'); + $eid = $root->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:'.'EncryptedID'); $root->appendChild($eid); - $eid->appendChild($root->ownerDocument->importNode($this->encryptedNameId, true)); + $eid->appendChild($root->ownerDocument->importNode($this->getEncryptedNameId(), true)); } foreach ($this->sessionIndexes as $sessionIndex) { diff --git a/src/SAML2/Message.php b/src/SAML2/Message.php index e4af88048..b27e60de0 100644 --- a/src/SAML2/Message.php +++ b/src/SAML2/Message.php @@ -23,7 +23,7 @@ abstract class Message implements SignedElement * * @var array */ - protected $extensions; + protected $extensions = []; /** * The name of the root element of the DOM tree for the message. @@ -589,7 +589,7 @@ public static function fromXML(\DOMElement $xml) /** * Retrieve the Extensions. * - * @return \SAML2\XML\samlp\Extensions + * @return \SAML2\XML\samlp\Extensions[] */ public function getExtensions() { @@ -599,12 +599,10 @@ public function getExtensions() /** * Set the Extensions. * - * @param array|null $extensions The Extensions + * @param array $extensions The Extensions */ - public function setExtensions($extensions) + public function setExtensions(array $extensions) { - assert(is_array($extensions) || is_null($extensions)); - $this->extensions = $extensions; } diff --git a/src/SAML2/Response.php b/src/SAML2/Response.php index 43a8361f7..dc4c1d76c 100644 --- a/src/SAML2/Response.php +++ b/src/SAML2/Response.php @@ -55,7 +55,7 @@ public function getAssertions() /** * Set the assertions that should be included in this response. * - * @param \SAML2\Assertion[]|\SAML2\EncryptedAssertion[] The assertions. + * @param \SAML2\Assertion[]|\SAML2\EncryptedAssertion[] $assertions The assertions. */ public function setAssertions(array $assertions) { diff --git a/src/SAML2/Response/Processor.php b/src/SAML2/Response/Processor.php index 89275f50f..135b63427 100644 --- a/src/SAML2/Response/Processor.php +++ b/src/SAML2/Response/Processor.php @@ -146,7 +146,7 @@ private function processAssertions(Response $response) if (!$this->responseIsSigned) { foreach ($assertions as $assertion) { - if (!$assertion->getWasSignedAtConstruction()) { + if (!$assertion->wasSignedAtConstruction()) { throw new UnsignedResponseException( 'Both the response and the assertion it contains are not signed.' ); diff --git a/src/SAML2/Response/Validation/ConstraintValidator/IsSuccessful.php b/src/SAML2/Response/Validation/ConstraintValidator/IsSuccessful.php index f744d6536..c376ab9d7 100644 --- a/src/SAML2/Response/Validation/ConstraintValidator/IsSuccessful.php +++ b/src/SAML2/Response/Validation/ConstraintValidator/IsSuccessful.php @@ -33,8 +33,8 @@ private function buildMessage(array $responseStatus) return sprintf( '%s%s%s', $this->truncateStatus($responseStatus['Code']), - $responseStatus['SubCode'] ? '/' . $this->truncateStatus($responseStatus['SubCode']) : '', - $responseStatus['Message'] ? ' ' . $responseStatus['Message'] : '' + $responseStatus['SubCode'] ? '/'.$this->truncateStatus($responseStatus['SubCode']) : '', + $responseStatus['Message'] ? ' '.$responseStatus['Message'] : '' ); } diff --git a/src/SAML2/SOAP.php b/src/SAML2/SOAP.php index 86e288584..583a53004 100644 --- a/src/SAML2/SOAP.php +++ b/src/SAML2/SOAP.php @@ -34,7 +34,7 @@ public function getOutputToSend(Message $message) $header = $doc->getElementsByTagNameNS(Constants::NS_SOAP, 'Header')->item(0); $response = new ECPResponse; - $response->AssertionConsumerServiceURL = $this->getDestination() ?: $message->getDestination(); + $response->setAssertionConsumerServiceURL($this->getDestination() ?: $message->getDestination()); $response->toXML($header); diff --git a/src/SAML2/SOAPClient.php b/src/SAML2/SOAPClient.php index 478c06493..b63eb20a2 100644 --- a/src/SAML2/SOAPClient.php +++ b/src/SAML2/SOAPClient.php @@ -119,7 +119,7 @@ public function send(Message $msg, Configuration $srcMetadata, Configuration $ds Utils::getContainer()->debugMessage($request, 'out'); $action = 'http://www.oasis-open.org/committees/security'; - $version = '1.1'; + $version = SOAP_1_1; $destination = $msg->getDestination(); /* Perform SOAP Request over HTTP */ @@ -224,7 +224,7 @@ public static function validateSSL($data, XMLSecurityKey $key) /* * Extracts the SOAP Fault from SOAP message * @param $soapmessage Soap response needs to be type DOMDocument - * @return $soapfaultstring string|null + * @return string|null $soapfaultstring */ private function getSOAPFault($soapMessage) { diff --git a/src/SAML2/Utilities/ArrayCollection.php b/src/SAML2/Utilities/ArrayCollection.php index 06755cce8..6603833dd 100644 --- a/src/SAML2/Utilities/ArrayCollection.php +++ b/src/SAML2/Utilities/ArrayCollection.php @@ -59,7 +59,7 @@ public function getOnlyElement() { if ($this->count() !== 1) { throw new RuntimeException(sprintf( - __CLASS__ . '::' . __METHOD__ . ' requires that the collection has exactly one element, ' + __CLASS__.'::'.__METHOD__.' requires that the collection has exactly one element, ' . '"%d" elements found', $this->count() )); diff --git a/src/SAML2/Utils.php b/src/SAML2/Utils.php index 582da7a45..f40cd1d30 100644 --- a/src/SAML2/Utils.php +++ b/src/SAML2/Utils.php @@ -256,7 +256,7 @@ public static function copyElement(\DOMElement $element, \DOMElement $parent = n } foreach ($namespaces as $prefix => $uri) { - $newElement->setAttributeNS($uri, $prefix . ':__ns_workaround__', 'tmp'); + $newElement->setAttributeNS($uri, $prefix.':__ns_workaround__', 'tmp'); $newElement->removeAttributeNS($uri, '__ns_workaround__'); } @@ -289,7 +289,7 @@ public static function parseBoolean(\DOMElement $node, $attributeName, $default case 'true': return true; default: - throw new \Exception('Invalid value of boolean attribute ' . var_export($attributeName, true) . ': ' . var_export($value, true)); + throw new \Exception('Invalid value of boolean attribute '.var_export($attributeName, true).': '.var_export($value, true)); } } @@ -320,13 +320,13 @@ public static function addNameId(\DOMElement $node, array $nameId) $nid->value = $nameId['Value']; if (array_key_exists('NameQualifier', $nameId) && $nameId['NameQualifier'] !== null) { - $nid->NameQualifier = $nameId['NameQualifier']; + $nid->setNameQualifier($nameId['NameQualifier']); } if (array_key_exists('SPNameQualifier', $nameId) && $nameId['SPNameQualifier'] !== null) { - $nid->SPNameQualifier = $nameId['SPNameQualifier']; + $nid->setSPNameQualifier($nameId['SPNameQualifier']); } if (array_key_exists('Format', $nameId) && $nameId['Format'] !== null) { - $nid->Format = $nameId['Format']; + $nid->setFormat($nameId['Format']); } $nid->toXML($node); @@ -433,7 +433,7 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity $symKeyInfoAlgo = $symmetricKeyInfo->getAlgorithm(); if (in_array($symKeyInfoAlgo, $blacklist, true)) { - throw new \Exception('Algorithm disabled: ' . var_export($symKeyInfoAlgo, true)); + throw new \Exception('Algorithm disabled: '.var_export($symKeyInfoAlgo, true)); } if ($symKeyInfoAlgo === XMLSecurityKey::RSA_OAEP_MGF1P && $inputKeyAlgo === XMLSecurityKey::RSA_1_5) { @@ -449,9 +449,9 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity /* Make sure that the input key format is the same as the one used to encrypt the key. */ if ($inputKeyAlgo !== $symKeyInfoAlgo) { throw new \Exception( - 'Algorithm mismatch between input key and key used to encrypt ' . - ' the symmetric key for the message. Key was: ' . - var_export($inputKeyAlgo, true) . '; message was: ' . + 'Algorithm mismatch between input key and key used to encrypt '. + ' the symmetric key for the message. Key was: '. + var_export($inputKeyAlgo, true).'; message was: '. var_export($symKeyInfoAlgo, true) ); } @@ -465,20 +465,20 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity /* To protect against "key oracle" attacks, we need to be able to create a * symmetric key, and for that we need to know the key size. */ - throw new \Exception('Unknown key size for encryption algorithm: ' . var_export($symmetricKey->type, true)); + throw new \Exception('Unknown key size for encryption algorithm: '.var_export($symmetricKey->type, true)); } try { $key = $encKey->decryptKey($symmetricKeyInfo); if (strlen($key) != $keySize) { throw new \Exception( - 'Unexpected key size (' . strlen($key) * 8 . 'bits) for encryption algorithm: ' . + 'Unexpected key size ('.strval(strlen($key)*8).'bits) for encryption algorithm: '. var_export($symmetricKey->type, true) ); } } catch (\Exception $e) { /* We failed to decrypt this key. Log it, and substitute a "random" key. */ - Utils::getContainer()->getLogger()->error('Failed to decrypt symmetric key: ' . $e->getMessage()); + Utils::getContainer()->getLogger()->error('Failed to decrypt symmetric key: '.$e->getMessage()); /* Create a replacement key, so that it looks like we fail in the same way as if the key was correctly padded. */ /* We base the symmetric key on the encrypted key and private key, so that we always behave the @@ -487,7 +487,7 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity $encryptedKey = $encKey->getCipherValue(); $pkey = openssl_pkey_get_details($symmetricKeyInfo->key); $pkey = sha1(serialize($pkey), true); - $key = sha1($encryptedKey . $pkey, true); + $key = sha1($encryptedKey.$pkey, true); /* Make sure that the key has the correct length. */ if (strlen($key) > $keySize) { @@ -502,8 +502,8 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity /* Make sure that the input key has the correct format. */ if ($inputKeyAlgo !== $symKeyAlgo) { throw new \Exception( - 'Algorithm mismatch between input key and key in message. ' . - 'Key was: ' . var_export($inputKeyAlgo, true) . '; message was: ' . + 'Algorithm mismatch between input key and key in message. '. + 'Key was: '.var_export($inputKeyAlgo, true).'; message was: '. var_export($symKeyAlgo, true) ); } @@ -512,7 +512,7 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity $algorithm = $symmetricKey->getAlgorithm(); if (in_array($algorithm, $blacklist, true)) { - throw new \Exception('Algorithm disabled: ' . var_export($algorithm, true)); + throw new \Exception('Algorithm disabled: '.var_export($algorithm, true)); } /** @var string $decrypted */ @@ -524,8 +524,8 @@ private static function doDecryptElement(\DOMElement $encryptedData, XMLSecurity * namespaces needed to parse the XML. */ $xml = '' . - $decrypted . + 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'. + $decrypted. ''; try { @@ -564,7 +564,7 @@ public static function decryptElement(\DOMElement $encryptedData, XMLSecurityKey * Something went wrong during decryption, but for security * reasons we cannot tell the user what failed. */ - Utils::getContainer()->getLogger()->error('Decryption failed: ' . $e->getMessage()); + Utils::getContainer()->getLogger()->error('Decryption failed: '.$e->getMessage()); throw new \Exception('Failed to decrypt XML element.', 0, $e); } } @@ -685,13 +685,13 @@ public static function createKeyDescriptor($x509Data) assert(is_string($x509Data)); $x509Certificate = new X509Certificate(); - $x509Certificate->certificate = $x509Data; + $x509Certificate->setCertificate($x509Data); $x509Data = new X509Data(); - $x509Data->data[] = $x509Certificate; + $x509Data->addData($x509Certificate); $keyInfo = new KeyInfo(); - $keyInfo->info[] = $x509Data; + $keyInfo->addInfo($x509Data); $keyDescriptor = new KeyDescriptor(); $keyDescriptor->KeyInfo = $keyInfo; @@ -726,7 +726,7 @@ public static function xsDateTimeToTimestamp($time) $regex = '/^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)T(\\d\\d):(\\d\\d):(\\d\\d)(?:\\.\\d{1,9})?Z$/D'; if (preg_match($regex, $time, $matches) == 0) { throw new \Exception( - 'Invalid SAML2 timestamp passed to xsDateTimeToTimestamp: ' . $time + 'Invalid SAML2 timestamp passed to xsDateTimeToTimestamp: '.$time ); } diff --git a/src/SAML2/XML/Chunk.php b/src/SAML2/XML/Chunk.php index 2f25f4510..5ac21ca49 100644 --- a/src/SAML2/XML/Chunk.php +++ b/src/SAML2/XML/Chunk.php @@ -22,7 +22,7 @@ class Chunk implements \Serializable /** * The namespaceURI of this element. * - * @var string + * @var string|null */ public $namespaceURI; @@ -40,10 +40,10 @@ class Chunk implements \Serializable */ public function __construct(\DOMElement $xml) { - $this->localName = $xml->localName; - $this->namespaceURI = $xml->namespaceURI; + $this->setLocalName($xml->localName); + $this->setNamespaceURI($xml->namespaceURI); - $this->xml = Utils::copyElement($xml); + $this->setXml(Utils::copyElement($xml)); } /** @@ -68,6 +68,54 @@ public function toXML(\DOMElement $parent) return Utils::copyElement($this->xml, $parent); } + /** + * Collect the value of the localName-property + * @return string + */ + public function getLocalName() + { + return $this->localName; + } + + /** + * Set the value of the localName-property + * @param string $localName + */ + public function setLocalName($localName) + { + assert(is_string($localName)); + $this->localName = $localName; + } + + /** + * Collect the value of the namespaceURI-property + * @return string|null + */ + public function getNamespaceURI() + { + return $this->namespaceURI; + } + + /** + * Set the value of the namespaceURI-property + * @param string|null $namespaceURI + */ + public function setNamespaceURI($namespaceURI = null) + { + assert(is_string($namespaceURI) || is_null($namespaceURI)); + $this->namespaceURI = $namespaceURI; + } + + /** + * Set the value of the xml-property + * @param \DOMelement $xml + */ + private function setXml($xml) + { + assert($xml instanceof \DOMElement); + $this->xml = $xml; + } + /** * Serialize this XML chunk. * @@ -75,7 +123,7 @@ public function toXML(\DOMElement $parent) */ public function serialize() { - return serialize($this->xml->ownerDocument->saveXML($this->xml)); + return serialize($this->getXml()->ownerDocument->saveXML($this->getXml())); } /** @@ -86,8 +134,8 @@ public function serialize() public function unserialize($serialized) { $doc = DOMDocumentFactory::fromString(unserialize($serialized)); - $this->xml = $doc->documentElement; - $this->localName = $this->xml->localName; - $this->namespaceURI = $this->xml->namespaceURI; + $this->setXml($doc->documentElement); + $this->setLocalName($this->getXml()->localName); + $this->setNamespaceURI($this->getXml()->namespaceURI); } } diff --git a/src/SAML2/XML/alg/DigestMethod.php b/src/SAML2/XML/alg/DigestMethod.php index ccf70f2a6..5aabddd5e 100644 --- a/src/SAML2/XML/alg/DigestMethod.php +++ b/src/SAML2/XML/alg/DigestMethod.php @@ -35,7 +35,27 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('Algorithm')) { throw new \Exception('Missing required attribute "Algorithm" in alg:DigestMethod element.'); } - $this->Algorithm = $xml->getAttribute('Algorithm'); + $this->setAlgorithm($xml->getAttribute('Algorithm')); + } + + + /** + * Collect the value of the algorithm-property + * @return string + */ + public function getAlgorithm() + { + return $this->Algorithm; + } + + /** + * Set the value of the Algorithm-property + * @param string $algorithm + */ + public function setAlgorithm($algorithm) + { + assert(is_string($algorithm)); + $this->Algorithm = $algorithm; } @@ -47,12 +67,12 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->Algorithm)); + assert(is_string($this->getAlgorithm())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'alg:DigestMethod'); $parent->appendChild($e); - $e->setAttribute('Algorithm', $this->Algorithm); + $e->setAttribute('Algorithm', $this->getAlgorithm()); return $e; } diff --git a/src/SAML2/XML/alg/SigningMethod.php b/src/SAML2/XML/alg/SigningMethod.php index 6e4d54b7e..0381e5f53 100644 --- a/src/SAML2/XML/alg/SigningMethod.php +++ b/src/SAML2/XML/alg/SigningMethod.php @@ -37,6 +37,64 @@ class SigningMethod public $MaxKeySize; + /** + * Collect the value of the Algorithm-property + * @return string + */ + public function getAlgorithm() + { + return $this->Algorithm; + } + + /** + * Set the value of the Algorithm-property + * @param string $algorithm + */ + public function setAlgorithm($algorithm) + { + assert(is_string($algorithm)); + $this->Algorithm = $algorithm; + } + + + /** + * Collect the value of the MinKeySize-property + * @return int|null + */ + public function getMinKeySize() + { + return $this->MinKeySize; + } + + /** + * Set the value of the MinKeySize-property + * @param int|null $minKeySize + */ + public function setMinKeySize($minKeySize = null) + { + assert(is_int($minKeySize) || is_null($minKeySize)); + $this->MinKeySize = $minKeySize; + } + + /** + * Collect the value of the MaxKeySize-property + * @return int|null + */ + public function getMaxKeySize() + { + return $this->MaxKeySize; + } + + /** + * Set the value of the MaxKeySize-property + * @param int|null $maxKeySize + */ + public function setMaxKeySize($maxKeySize = null) + { + assert(is_int($maxKeySize) || is_null($maxKeySize)); + $this->MaxKeySize = $maxKeySize; + } + /** * Create/parse an alg:SigningMethod element. * @@ -53,14 +111,14 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('Algorithm')) { throw new \Exception('Missing required attribute "Algorithm" in alg:SigningMethod element.'); } - $this->Algorithm = $xml->getAttribute('Algorithm'); + $this->setAlgorithm($xml->getAttribute('Algorithm')); if ($xml->hasAttribute('MinKeySize')) { - $this->MinKeySize = intval($xml->getAttribute('MinKeySize')); + $this->setMinKeySize(intval($xml->getAttribute('MinKeySize'))); } if ($xml->hasAttribute('MaxKeySize')) { - $this->MaxKeySize = intval($xml->getAttribute('MaxKeySize')); + $this->setMaxKeySize(intval($xml->getAttribute('MaxKeySize'))); } } @@ -73,21 +131,21 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->Algorithm)); - assert(is_int($this->MinKeySize) || is_null($this->MinKeySize)); - assert(is_int($this->MaxKeySize) || is_null($this->MaxKeySize)); + assert(is_string($this->getAlgorithm())); + assert(is_int($this->getMinKeySize()) || is_null($this->getMinKeySize())); + assert(is_int($this->getMaxKeySize()) || is_null($this->getMaxKeySize())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'alg:SigningMethod'); $parent->appendChild($e); - $e->setAttribute('Algorithm', $this->Algorithm); + $e->setAttribute('Algorithm', $this->getAlgorithm()); - if ($this->MinKeySize !== null) { - $e->setAttribute('MinKeySize', $this->MinKeySize); + if ($this->getMinKeySize() !== null) { + $e->setAttribute('MinKeySize', $this->getMinKeySize()); } - if ($this->MaxKeySize !== null) { - $e->setAttribute('MaxKeySize', $this->MaxKeySize); + if ($this->getMaxKeySize() !== null) { + $e->setAttribute('MaxKeySize', $this->getMaxKeySize()); } return $e; diff --git a/src/SAML2/XML/ds/KeyInfo.php b/src/SAML2/XML/ds/KeyInfo.php index 6594a7900..363b19d03 100644 --- a/src/SAML2/XML/ds/KeyInfo.php +++ b/src/SAML2/XML/ds/KeyInfo.php @@ -41,7 +41,7 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('Id')) { - $this->Id = $xml->getAttribute('Id'); + $this->setId($xml->getAttribute('Id')); } for ($n = $xml->firstChild; $n !== null; $n = $n->nextSibling) { @@ -50,23 +50,70 @@ public function __construct(\DOMElement $xml = null) } if ($n->namespaceURI !== XMLSecurityDSig::XMLDSIGNS) { - $this->info[] = new Chunk($n); + $this->addInfo(new Chunk($n)); continue; } switch ($n->localName) { case 'KeyName': - $this->info[] = new KeyName($n); + $this->addInfo(new KeyName($n)); break; case 'X509Data': - $this->info[] = new X509Data($n); + $this->addInfo(new X509Data($n)); break; default: - $this->info[] = new Chunk($n); + $this->addInfo(new Chunk($n)); break; } } } + /** + * Collect the value of the Id-property + * @return string|null + */ + public function getId() + { + return $this->Id; + } + + /** + * Set the value of the Id-property + * @param string|null $id + */ + public function setId($id = null) + { + assert(is_string($id) || is_null($id)); + $this->Id = $id; + } + + /** + * Collect the value of the info-property + * @return array + */ + public function getInfo() + { + return $this->info; + } + + /** + * Set the value of the info-property + * @param array $info + */ + public function setInfo(array $info) + { + $this->info = $info; + } + + /** + * Add the value to the info-property + * @param \SAML2\XML\Chunk|\SAML2\XML\ds\KeyName|\SAML2\XML\ds\X509Data $info + */ + public function addInfo($info) + { + assert($info instanceof Chunk || $info instanceof KeyName || $info instanceof X509Data); + $this->info[] = $info; + } + /** * Convert this KeyInfo to XML. * @@ -75,20 +122,20 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_null($this->Id) || is_string($this->Id)); - assert(is_array($this->info)); + assert(is_null($this->getId()) || is_string($this->getId())); + assert(is_array($this->getInfo())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(XMLSecurityDSig::XMLDSIGNS, 'ds:KeyInfo'); $parent->appendChild($e); - if (isset($this->Id)) { - $e->setAttribute('Id', $this->Id); + if ($this->getId() !== null) { + $e->setAttribute('Id', $this->getId()); } /** @var \SAML2\XML\Chunk|\SAML2\XML\ds\KeyName|\SAML2\XML\ds\X509Data $n */ - foreach ($this->info as $n) { + foreach ($this->getInfo() as $n) { $n->toXML($e); } diff --git a/src/SAML2/XML/ds/KeyName.php b/src/SAML2/XML/ds/KeyName.php index bd5fd5f2b..d7fbad39e 100644 --- a/src/SAML2/XML/ds/KeyName.php +++ b/src/SAML2/XML/ds/KeyName.php @@ -30,9 +30,29 @@ public function __construct(\DOMElement $xml = null) return; } - $this->name = $xml->textContent; + $this->setName($xml->textContent); } + /** + * Collect the value of the name-property + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set the value of the name-property + * @param string $name + */ + public function setName($name) + { + assert(is_string($name) || is_null($name)); + $this->name = $name; + } + + /** * Convert this KeyName element to XML. * diff --git a/src/SAML2/XML/ds/X509Certificate.php b/src/SAML2/XML/ds/X509Certificate.php index 83d9a4c95..1a8cd2e2c 100644 --- a/src/SAML2/XML/ds/X509Certificate.php +++ b/src/SAML2/XML/ds/X509Certificate.php @@ -30,9 +30,30 @@ public function __construct(\DOMElement $xml = null) return; } - $this->certificate = $xml->textContent; + $this->setCertificate($xml->textContent); } + + /** + * Collect the value of the certificate-property + * @return string + */ + public function getCertificate() + { + return $this->certificate; + } + + /** + * Set the value of the certificate-property + * @param string $certificate + */ + public function setCertificate($certificate) + { + assert(is_string($certificate)); + $this->certificate = $certificate; + } + + /** * Convert this X509Certificate element to XML. * @@ -43,6 +64,6 @@ public function toXML(\DOMElement $parent) { assert(is_string($this->certificate)); - return Utils::addString($parent, XMLSecurityDSig::XMLDSIGNS, 'ds:X509Certificate', $this->certificate); + return Utils::addString($parent, XMLSecurityDSig::XMLDSIGNS, 'ds:X509Certificate', $this->getCertificate()); } } diff --git a/src/SAML2/XML/ds/X509Data.php b/src/SAML2/XML/ds/X509Data.php index 710a558a8..d9a1af170 100644 --- a/src/SAML2/XML/ds/X509Data.php +++ b/src/SAML2/XML/ds/X509Data.php @@ -39,20 +39,48 @@ public function __construct(\DOMElement $xml = null) } if ($n->namespaceURI !== XMLSecurityDSig::XMLDSIGNS) { - $this->data[] = new Chunk($n); + $this->addData(new Chunk($n)); continue; } switch ($n->localName) { case 'X509Certificate': - $this->data[] = new X509Certificate($n); + $this->addData(new X509Certificate($n)); break; default: - $this->data[] = new Chunk($n); + $this->addData(new Chunk($n)); break; } } } + /** + * Collect the value of the data-property + * @return array + */ + public function getData() + { + return $this->data; + } + + /** + * Set the value of the data-property + * @param array $data + */ + public function setData(array $data) + { + $this->data = $data; + } + + /** + * Add the value to the data-property + * @param \SAML2\XML\Chunk|\SAML2\XML\ds\X509Certificate $data + */ + public function addData($data) + { + assert($data instanceof \SAML2\XML\Chunk || $data instanceof \SAML2\XML\ds\X509Certificate); + $this->data[] = $data; + } + /** * Convert this X509Data element to XML. * @@ -61,7 +89,7 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->data)); + assert(is_array($this->getData())); $doc = $parent->ownerDocument; @@ -69,7 +97,7 @@ public function toXML(\DOMElement $parent) $parent->appendChild($e); /** @var \SAML2\XML\Chunk|\SAML2\XML\ds\X509Certificate $n */ - foreach ($this->data as $n) { + foreach ($this->getData() as $n) { $n->toXML($e); } diff --git a/src/SAML2/XML/ecp/Response.php b/src/SAML2/XML/ecp/Response.php index 2bc45f381..4cca4b150 100644 --- a/src/SAML2/XML/ecp/Response.php +++ b/src/SAML2/XML/ecp/Response.php @@ -22,7 +22,7 @@ class Response /** * Create a ECP Response element. * - * @param DOMElement|null $xml The XML element we should load. + * @param \DOMElement|null $xml The XML element we should load. */ public function __construct(DOMElement $xml = null) { @@ -31,34 +31,57 @@ public function __construct(DOMElement $xml = null) } if (!$xml->hasAttributeNS(Constants::NS_SOAP, 'mustUnderstand')) { - throw new Exception('Missing SOAP-ENV:mustUnderstand attribute in .'); + throw new \Exception('Missing SOAP-ENV:mustUnderstand attribute in .'); } if ($xml->getAttributeNS(Constants::NS_SOAP, 'mustUnderstand') !== '1') { - throw new Exception('Invalid value of SOAP-ENV:mustUnderstand attribute in .'); + throw new \Exception('Invalid value of SOAP-ENV:mustUnderstand attribute in .'); } if (!$xml->hasAttributeNS(Constants::NS_SOAP, 'actor')) { - throw new Exception('Missing SOAP-ENV:actor attribute in .'); + throw new \Exception('Missing SOAP-ENV:actor attribute in .'); } if ($xml->getAttributeNS(Constants::NS_SOAP, 'actor') !== 'http://schemas.xmlsoap.org/soap/actor/next') { - throw new Exception('Invalid value of SOAP-ENV:actor attribute in .'); + throw new \Exception('Invalid value of SOAP-ENV:actor attribute in .'); } if (!$xml->hasAttribute('AssertionConsumerServiceURL')) { - throw new Exception('Missing AssertionConsumerServiceURL attribute in .'); + throw new \Exception('Missing AssertionConsumerServiceURL attribute in .'); } - $this->AssertionConsumerServiceURL = $xml->getAttribute('AssertionConsumerServiceURL'); + $this->setAssertionConsumerServiceURL($xml->getAttribute('AssertionConsumerServiceURL')); } + + /** + * Collect the value of the AssertionConsumerServiceURL-property + * @return string + */ + public function getAssertionConsumerServiceURL() + { + return $this->AssertionConsumerServiceURL; + } + + /** + * Set the value of the AssertionConsumerServiceURL-property + * @param string $assertionConsumerServiceURL + */ + public function setAssertionConsumerServiceURL($assertionConsumerServiceURL) + { + assert(is_string($assertionConsumerServiceURL)); + if (!filter_var($assertionConsumerServiceURL, FILTER_VALIDATE_URL)) { + throw new \InvalidArgumentException('Provided argument is not a valid URL.'); + } + $this->AssertionConsumerServiceURL = $assertionConsumerServiceURL; + } + /** * Convert this ECP Response to XML. * - * @param DOMElement $parent The element we should append this element to. + * @param \DOMElement $parent The element we should append this element to. */ - public function toXML(DOMElement $parent) + public function toXML(\DOMElement $parent) { - if (!is_string($this->AssertionConsumerServiceURL)) { - throw new InvalidArgumentException("AssertionConsumerServiceURL must be a string"); + if (!is_string($this->getAssertionConsumerServiceURL())) { + throw new \InvalidArgumentException("AssertionConsumerServiceURL must be a string"); } $doc = $parent->ownerDocument; @@ -68,7 +91,7 @@ public function toXML(DOMElement $parent) $response->setAttributeNS(Constants::NS_SOAP, 'SOAP-ENV:mustUnderstand', '1'); $response->setAttributeNS(Constants::NS_SOAP, 'SOAP-ENV:actor', 'http://schemas.xmlsoap.org/soap/actor/next'); - $response->setAttribute('AssertionConsumerServiceURL', $this->AssertionConsumerServiceURL); + $response->setAttribute('AssertionConsumerServiceURL', $this->getAssertionConsumerServiceURL()); return $response; } diff --git a/src/SAML2/XML/md/AdditionalMetadataLocation.php b/src/SAML2/XML/md/AdditionalMetadataLocation.php index 322f703e0..daee2a799 100644 --- a/src/SAML2/XML/md/AdditionalMetadataLocation.php +++ b/src/SAML2/XML/md/AdditionalMetadataLocation.php @@ -41,9 +41,47 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('namespace')) { throw new \Exception('Missing namespace attribute on AdditionalMetadataLocation element.'); } - $this->namespace = $xml->getAttribute('namespace'); + $this->setNamespace($xml->getAttribute('namespace')); - $this->location = $xml->textContent; + $this->setLocation($xml->textContent); + } + + /** + * Collect the value of the namespace-property + * @return string + */ + public function getNamespace() + { + return $this->namespace; + } + + /** + * Set the value of the namespace-property + * @param string $namespace + */ + public function setNamespace($namespace) + { + assert(is_string($namespace)); + $this->namespace = $namespace; + } + + /** + * Collect the value of the location-property + * @return string + */ + public function getLocation() + { + return $this->location; + } + + /** + * Set the value of the location-property + * @param string $location + */ + public function setLocation($location) + { + assert(is_string($location)); + $this->location = $location; } /** @@ -54,11 +92,11 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->namespace)); - assert(is_string($this->location)); + assert(is_string($this->getNamespace())); + assert(is_string($this->getLocation())); - $e = Utils::addString($parent, Constants::NS_MD, 'md:AdditionalMetadataLocation', $this->location); - $e->setAttribute('namespace', $this->namespace); + $e = Utils::addString($parent, Constants::NS_MD, 'md:AdditionalMetadataLocation', $this->getLocation()); + $e->setAttribute('namespace', $this->getNamespace()); return $e; } diff --git a/src/SAML2/XML/md/AffiliationDescriptor.php b/src/SAML2/XML/md/AffiliationDescriptor.php index a619d4d78..d9537ae23 100644 --- a/src/SAML2/XML/md/AffiliationDescriptor.php +++ b/src/SAML2/XML/md/AffiliationDescriptor.php @@ -46,7 +46,7 @@ class AffiliationDescriptor extends SignedElementHelper * * Array of extension elements. * - * @var array + * @var \SAML2\XML\Chunk[] */ public $Extensions = []; @@ -85,32 +85,171 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('affiliationOwnerID')) { throw new \Exception('Missing affiliationOwnerID on AffiliationDescriptor.'); } - $this->affiliationOwnerID = $xml->getAttribute('affiliationOwnerID'); + $this->setAffiliationOwnerID($xml->getAttribute('affiliationOwnerID')); if ($xml->hasAttribute('ID')) { - $this->ID = $xml->getAttribute('ID'); + $this->setID($xml->getAttribute('ID')); } if ($xml->hasAttribute('validUntil')) { - $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); + $this->setValidUntil(Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'))); } if ($xml->hasAttribute('cacheDuration')) { - $this->cacheDuration = $xml->getAttribute('cacheDuration'); + $this->setCacheDuration($xml->getAttribute('cacheDuration')); } - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); - $this->AffiliateMember = Utils::extractStrings($xml, Constants::NS_MD, 'AffiliateMember'); + $this->setAffiliateMember(Utils::extractStrings($xml, Constants::NS_MD, 'AffiliateMember')); if (empty($this->AffiliateMember)) { throw new \Exception('Missing AffiliateMember in AffiliationDescriptor.'); } foreach (Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) { - $this->KeyDescriptor[] = new KeyDescriptor($kd); + $this->addKeyDescriptor(new KeyDescriptor($kd)); } } + /** + * Collect the value of the affiliationOwnerId-property + * @return string + */ + public function getAffiliationOwnerID() + { + return $this->affiliationOwnerID; + } + + /** + * Set the value of the affiliationOwnerId-property + * @param string $affiliationOwnerId + */ + public function setAffiliationOwnerID($affiliationOwnerId) + { + assert(is_string($affiliationOwnerId)); + $this->affiliationOwnerID = $affiliationOwnerId; + } + + /** + * Collect the value of the ID-property + * @return string|null + */ + public function getID() + { + return $this->ID; + } + + /** + * Set the value of the ID-property + * @param string|null $Id + */ + public function setID($Id = null) + { + assert(is_string($Id) || is_null($Id)); + $this->ID = $Id; + } + + /** + * Collect the value of the validUntil-property + * @return int|null + */ + public function getValidUntil() + { + return $this->validUntil; + } + + /** + * Set the value of the validUntil-property + * @param int|null $validUntil + */ + public function setValidUntil($validUntil = null) + { + assert(is_int($validUntil) || is_null($validUntil)); + $this->validUntil = $validUntil; + } + + /** + * Collect the value of the cacheDuration-property + * @return string|null + */ + public function getCacheDuration() + { + return $this->cacheDuration; + } + + /** + * Set the value of the cacheDuration-property + * @param string|null $cacheDuration + */ + public function setCacheDuration($cacheDuration = null) + { + assert(is_string($cacheDuration) || is_null($cacheDuration)); + $this->cacheDuration = $cacheDuration; + } + + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Collect the value of the AffiliateMember-property + * @return array + */ + public function getAffiliateMember() + { + return $this->AffiliateMember; + } + + /** + * Set the value of the AffiliateMember-property + * @param array $affiliateMember + */ + public function setAffiliateMember(array $affiliateMember) + { + $this->AffiliateMember = $affiliateMember; + } + + /** + * Collect the value of the KeyDescriptor-property + * @return \SAML2\XML\md\KeyDescriptor[] + */ + public function getKeyDescriptor() + { + return $this->KeyDescriptor; + } + + /** + * Set the value of the KeyDescriptor-property + * @param array $keyDescriptor + */ + public function setKeyDescriptor(array $keyDescriptor) + { + $this->KeyDescriptor = $keyDescriptor; + } + + /** + * Add the value to the KeyDescriptor-property + * @param \SAML2\XML\md\KeyDescriptor $keyDescriptor + */ + public function addKeyDescriptor(KeyDescriptor $keyDescriptor) + { + $this->KeyDescriptor[] = $keyDescriptor; + } + /** * Add this AffiliationDescriptor to an EntityDescriptor. * @@ -119,37 +258,37 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->affiliationOwnerID)); - assert(is_null($this->ID) || is_string($this->ID)); - assert(is_null($this->validUntil) || is_int($this->validUntil)); - assert(is_null($this->cacheDuration) || is_string($this->cacheDuration)); - assert(is_array($this->Extensions)); - assert(is_array($this->AffiliateMember)); - assert(!empty($this->AffiliateMember)); - assert(is_array($this->KeyDescriptor)); + assert(is_string($this->getAffiliationOwnerID())); + assert(is_null($this->getID()) || is_string($this->getID())); + assert(is_null($this->getValidUntil()) || is_int($this->getValidUntil())); + assert(is_null($this->getCacheDuration()) || is_string($this->getCacheDuration())); + assert(is_array($this->getExtensions())); + assert(is_array($affiliateMember = $this->getAffiliateMember())); + assert(!empty($affiliateMember)); + assert(is_array($this->getKeyDescriptor())); $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, 'md:AffiliationDescriptor'); $parent->appendChild($e); - $e->setAttribute('affiliationOwnerID', $this->affiliationOwnerID); + $e->setAttribute('affiliationOwnerID', $this->getAffiliationOwnerID()); - if (isset($this->ID)) { - $e->setAttribute('ID', $this->ID); + if ($this->getID() !== null) { + $e->setAttribute('ID', $this->getID()); } - if (isset($this->validUntil)) { - $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil)); + if ($this->getValidUntil() !== null) { + $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->getValidUntil())); } - if (isset($this->cacheDuration)) { - $e->setAttribute('cacheDuration', $this->cacheDuration); + if ($this->getCacheDuration() !== null) { + $e->setAttribute('cacheDuration', $this->getCacheDuration()); } - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); - Utils::addStrings($e, Constants::NS_MD, 'md:AffiliateMember', false, $this->AffiliateMember); + Utils::addStrings($e, Constants::NS_MD, 'md:AffiliateMember', false, $this->getAffiliateMember()); - foreach ($this->KeyDescriptor as $kd) { + foreach ($this->getKeyDescriptor() as $kd) { $kd->toXML($e); } diff --git a/src/SAML2/XML/md/AttributeAuthorityDescriptor.php b/src/SAML2/XML/md/AttributeAuthorityDescriptor.php index 4f158046d..fcc022ebe 100644 --- a/src/SAML2/XML/md/AttributeAuthorityDescriptor.php +++ b/src/SAML2/XML/md/AttributeAuthorityDescriptor.php @@ -73,25 +73,145 @@ public function __construct(\DOMElement $xml = null) } foreach (Utils::xpQuery($xml, './saml_metadata:AttributeService') as $ep) { - $this->AttributeService[] = new EndpointType($ep); + $this->addAttributeService(new EndpointType($ep)); } - if (empty($this->AttributeService)) { + if ($this->getAttributeService() === []) { throw new \Exception('Must have at least one AttributeService in AttributeAuthorityDescriptor.'); } foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) { - $this->AssertionIDRequestService[] = new EndpointType($ep); + $this->addAssertionIDRequestService(new EndpointType($ep)); } - $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat'); + $this->setNameIDFormat(Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat')); - $this->AttributeProfile = Utils::extractStrings($xml, Constants::NS_MD, 'AttributeProfile'); + $this->setAttributeProfile(Utils::extractStrings($xml, Constants::NS_MD, 'AttributeProfile')); foreach (Utils::xpQuery($xml, './saml_assertion:Attribute') as $a) { - $this->Attribute[] = new Attribute($a); + $this->addAttribute(new Attribute($a)); } } + /** + * Collect the value of the AttributeService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAttributeService() + { + return $this->AttributeService; + } + + /** + * Set the value of the AttributeService-property + * @param \SAML2\XML\md\EndpointType[] $attributeService + */ + public function setAttributeService(array $attributeService) + { + $this->AttributeService = $attributeService; + } + + /** + * Add the value to the AttributeService-property + * @param \SAML2\XML\md\EndpointType $attributeService + */ + public function addAttributeService(EndpointType $attributeService) + { + assert($attributeService instanceof EndpointType); + $this->AttributeService[] = $attributeService; + } + + /** + * Collect the value of the NameIDFormat-property + * @return string[] + */ + public function getNameIDFormat() + { + return $this->NameIDFormat; + } + + /** + * Set the value of the NameIDFormat-property + * @param string[] $nameIDFormat + */ + public function setNameIDFormat(array $nameIDFormat) + { + $this->NameIDFormat = $nameIDFormat; + } + + /** + * Collect the value of the AssertionIDRequestService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAssertionIDRequestService() + { + return $this->AssertionIDRequestService; + } + + /** + * Set the value of the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType[] $assertionIDRequestService + */ + public function setAssertionIDRequestService(array $assertionIDRequestService) + { + $this->AssertionIDRequestService = $assertionIDRequestService; + } + + /** + * Add the value to the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType $assertionIDRequestService + */ + public function addAssertionIDRequestService(EndpointType $assertionIDRequestService) + { + assert($assertionIDRequestService instanceof EndpointType); + $this->AssertionIDRequestService[] = $assertionIDRequestService; + } + + /** + * Collect the value of the AttributeProfile-property + * @return string[] + */ + public function getAttributeProfile() + { + return $this->AttributeProfile; + } + + /** + * Set the value of the AttributeProfile-property + * @param string[] $attributeProfile + */ + public function setAttributeProfile(array $attributeProfile) + { + $this->AttributeProfile = $attributeProfile; + } + + /** + * Collect the value of the Attribute-property + * @return \SAML2\XML\saml\Attribute[] + */ + public function getAttribute() + { + return $this->Attribute; + } + + /** + * Set the value of the Attribute-property + * @param \SAML2\XML\saml\Attribute[] $attribute + */ + public function setAttribute(array $attribute) + { + $this->Attribute = $attribute; + } + + /** + * Add the value to the Attribute-property + * @param \SAML2\XML\saml\Attribute $attribute + */ + public function addAttribute(Attribute $attribute) + { + assert($attribute instanceof Attribute); + $this->Attribute[] = $attribute; + } + /** * Add this AttributeAuthorityDescriptor to an EntityDescriptor. * @@ -100,28 +220,28 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->AttributeService)); - assert(!empty($this->AttributeService)); - assert(is_array($this->AssertionIDRequestService)); - assert(is_array($this->NameIDFormat)); - assert(is_array($this->AttributeProfile)); + assert(is_array($attributeService = $this->getAttributeService())); + assert(!empty($attributeService)); + assert(is_array($this->getAssertionIDRequestService())); + assert(is_array($this->getNameIDFormat())); + assert(is_array($this->getAttributeProfile())); assert(is_array($this->Attribute)); $e = parent::toXML($parent); - foreach ($this->AttributeService as $ep) { + foreach ($this->getAttributeService() as $ep) { $ep->toXML($e, 'md:AttributeService'); } - foreach ($this->AssertionIDRequestService as $ep) { + foreach ($this->getAssertionIDRequestService() as $ep) { $ep->toXML($e, 'md:AssertionIDRequestService'); } - Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat); + Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->getNameIDFormat()); - Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->AttributeProfile); + Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->getAttributeProfile()); - foreach ($this->Attribute as $a) { + foreach ($this->getAttribute() as $a) { $a->toXML($e); } diff --git a/src/SAML2/XML/md/AttributeConsumingService.php b/src/SAML2/XML/md/AttributeConsumingService.php index 5ec4403b3..894878113 100644 --- a/src/SAML2/XML/md/AttributeConsumingService.php +++ b/src/SAML2/XML/md/AttributeConsumingService.php @@ -68,22 +68,123 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('index')) { throw new \Exception('Missing index on AttributeConsumingService.'); } - $this->index = (int) $xml->getAttribute('index'); + $this->setIndex(intval($xml->getAttribute('index'))); - $this->isDefault = Utils::parseBoolean($xml, 'isDefault', null); + $this->setIsDefault(Utils::parseBoolean($xml, 'isDefault', null)); - $this->ServiceName = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceName'); - if (empty($this->ServiceName)) { + $this->setServiceName(Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceName')); + if ($this->getServiceName() === []) { throw new \Exception('Missing ServiceName in AttributeConsumingService.'); } - $this->ServiceDescription = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceDescription'); + $this->setServiceDescription(Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'ServiceDescription')); foreach (Utils::xpQuery($xml, './saml_metadata:RequestedAttribute') as $ra) { - $this->RequestedAttribute[] = new RequestedAttribute($ra); + $this->addRequestedAttribute(new RequestedAttribute($ra)); } } + /** + * Collect the value of the index-property + * @return int + */ + public function getIndex() + { + return $this->index; + } + + /** + * Set the value of the index-property + * @param int $index + */ + public function setIndex($index) + { + assert(is_int($index)); + $this->index = $index; + } + + /** + * Collect the value of the isDefault-property + * @return boolean|null + */ + public function getIsDefault() + { + return $this->isDefault; + } + + /** + * Set the value of the isDefault-property + * @param boolean|null $flag + */ + public function setIsDefault($flag = null) + { + assert(is_bool($flag)); + $this->isDefault = $flag; + } + + /** + * Collect the value of the ServiceName-property + * @return string[] + */ + public function getServiceName() + { + return $this->ServiceName; + } + + /** + * Set the value of the ServiceName-property + * @param string[] $serviceName + */ + public function setServiceName(array $serviceName) + { + $this->ServiceName = $serviceName; + } + + /** + * Collect the value of the ServiceDescription-property + * @return string[] + */ + public function getServiceDescription() + { + return $this->ServiceDescription; + } + + /** + * Set the value of the ServiceDescription-property + * @param string[] $serviceDescription + */ + public function setServiceDescription(array $serviceDescription) + { + $this->ServiceDescription = $serviceDescription; + } + + /** + * Collect the value of the RequestedAttribute-property + * @return \SAML2\XML\md\RequestedAttribute[] + */ + public function getRequestedAttribute() + { + return $this->RequestedAttribute; + } + + /** + * Set the value of the RequestedAttribute-property + * @param \SAML2\XML\md\RequestedAttribute[] $requestedAttribute + */ + public function setRequestedAttribute(array $requestedAttribute) + { + $this->RequestedAttribute = $requestedAttribute; + } + + /** + * Add the value to the RequestedAttribute-property + * @param \SAML2\XML\md\RequestedAttribute $requestedAttribute + */ + public function addRequestedAttribute(RequestedAttribute $requestedAttribute) + { + $this->RequestedAttribute[] = $requestedAttribute; + } + /** * Convert to \DOMElement. * @@ -92,29 +193,29 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_int($this->index)); - assert(is_null($this->isDefault) || is_bool($this->isDefault)); - assert(is_array($this->ServiceName)); - assert(is_array($this->ServiceDescription)); - assert(is_array($this->RequestedAttribute)); + assert(is_int($this->getIndex())); + assert(is_null($this->getIsDefault()) || is_bool($this->getIsDefault())); + assert(is_array($this->getServiceName())); + assert(is_array($this->getServiceDescription())); + assert(is_array($this->getRequestedAttribute())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Constants::NS_MD, 'md:AttributeConsumingService'); $parent->appendChild($e); - $e->setAttribute('index', (string) $this->index); + $e->setAttribute('index', strval($this->getIndex())); - if ($this->isDefault === true) { + if ($this->getIsDefault() === true) { $e->setAttribute('isDefault', 'true'); - } elseif ($this->isDefault === false) { + } elseif ($this->getIsDefault() === false) { $e->setAttribute('isDefault', 'false'); } - Utils::addStrings($e, Constants::NS_MD, 'md:ServiceName', true, $this->ServiceName); - Utils::addStrings($e, Constants::NS_MD, 'md:ServiceDescription', true, $this->ServiceDescription); + Utils::addStrings($e, Constants::NS_MD, 'md:ServiceName', true, $this->getServiceName()); + Utils::addStrings($e, Constants::NS_MD, 'md:ServiceDescription', true, $this->getServiceDescription()); - foreach ($this->RequestedAttribute as $ra) { + foreach ($this->getRequestedAttribute() as $ra) { $ra->toXML($e); } diff --git a/src/SAML2/XML/md/AuthnAuthorityDescriptor.php b/src/SAML2/XML/md/AuthnAuthorityDescriptor.php index 7070fa1cd..74813f63a 100644 --- a/src/SAML2/XML/md/AuthnAuthorityDescriptor.php +++ b/src/SAML2/XML/md/AuthnAuthorityDescriptor.php @@ -54,17 +54,91 @@ public function __construct(\DOMElement $xml = null) } foreach (Utils::xpQuery($xml, './saml_metadata:AuthnQueryService') as $ep) { - $this->AuthnQueryService[] = new EndpointType($ep); + $this->addAuthnQueryService(new EndpointType($ep)); } - if (empty($this->AuthnQueryService)) { + if ($this->getAuthnQueryService() === []) { throw new \Exception('Must have at least one AuthnQueryService in AuthnAuthorityDescriptor.'); } foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) { - $this->AssertionIDRequestService[] = new EndpointType($ep); + $this->addAssertionIDRequestService(new EndpointType($ep)); } - $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat'); + $this->setNameIDFormat(Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat')); + } + + /** + * Collect the value of the AuthnQueryService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAuthnQueryService() + { + return $this->AuthnQueryService; + } + + /** + * Set the value of the AuthnQueryService-property + * @param \SAML2\XML\md\EndpointType[] $authnQueryService + */ + public function setAuthnQueryService(array $authnQueryService) + { + $this->AuthnQueryService = $authnQueryService; + } + + /** + * Add the value to the AuthnQueryService-property + * @param \SAML2\XML\md\EndpointType $authnQueryService + */ + public function addAuthnQueryService(EndpointType $authnQueryService) + { + assert($authnQueryService instanceof EndpointType); + $this->AuthnQueryService[] = $authnQueryService; + } + + /** + * Collect the value of the AssertionIDRequestService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAssertionIDRequestService() + { + return $this->AssertionIDRequestService; + } + + /** + * Set the value of the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType[] $assertionIDRequestService + */ + public function setAssertionIDRequestService(array $assertionIDRequestService) + { + $this->AssertionIDRequestService = $assertionIDRequestService; + } + + /** + * Add the value to the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType $assertionIDRequestService + */ + public function addAssertionIDRequestService(EndpointType $assertionIDRequestService) + { + assert($assertionIDRequestService instanceof EndpointType); + $this->AssertionIDRequestService[] = $assertionIDRequestService; + } + + /** + * Collect the value of the NameIDFormat-property + * @return string[] + */ + public function getNameIDFormat() + { + return $this->NameIDFormat; + } + + /** + * Set the value of the NameIDFormat-property + * @param string[] $nameIDFormat + */ + public function setNameIDFormat(array $nameIDFormat) + { + $this->NameIDFormat = $nameIDFormat; } /** @@ -75,22 +149,22 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->AuthnQueryService)); - assert(!empty($this->AuthnQueryService)); - assert(is_array($this->AssertionIDRequestService)); + assert(is_array($authnQueryService = $this->getAuthnQueryService())); + assert(!empty($authnQueryService)); + assert(is_array($this->getAssertionIDRequestService())); assert(is_array($this->NameIDFormat)); $e = parent::toXML($parent); - foreach ($this->AuthnQueryService as $ep) { + foreach ($this->getAuthnQueryService() as $ep) { $ep->toXML($e, 'md:AuthnQueryService'); } - foreach ($this->AssertionIDRequestService as $ep) { + foreach ($this->getAssertionIDRequestService() as $ep) { $ep->toXML($e, 'md:AssertionIDRequestService'); } - Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat); + Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->getNameIDFormat()); return $e; } diff --git a/src/SAML2/XML/md/ContactPerson.php b/src/SAML2/XML/md/ContactPerson.php index 14cc1db45..0911441cd 100644 --- a/src/SAML2/XML/md/ContactPerson.php +++ b/src/SAML2/XML/md/ContactPerson.php @@ -85,22 +85,22 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('contactType')) { throw new \Exception('Missing contactType on ContactPerson.'); } - $this->contactType = $xml->getAttribute('contactType'); + $this->setContactType($xml->getAttribute('contactType')); - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); - $this->Company = self::getStringElement($xml, 'Company'); - $this->GivenName = self::getStringElement($xml, 'GivenName'); - $this->SurName = self::getStringElement($xml, 'SurName'); - $this->EmailAddress = self::getStringElements($xml, 'EmailAddress'); - $this->TelephoneNumber = self::getStringElements($xml, 'TelephoneNumber'); + $this->setCompany(self::getStringElement($xml, 'Company')); + $this->setGivenName(self::getStringElement($xml, 'GivenName')); + $this->setSurName(self::getStringElement($xml, 'SurName')); + $this->setEmailAddress(self::getStringElements($xml, 'EmailAddress')); + $this->setTelephoneNumber(self::getStringElements($xml, 'TelephoneNumber')); foreach ($xml->attributes as $attr) { if ($attr->nodeName == "contactType") { continue; } - $this->ContactPersonAttributes[$attr->nodeName] = $attr->nodeValue; + $this->addContactPersonAttributes($attr->nodeName, $attr->nodeValue); } } @@ -148,6 +148,166 @@ private static function getStringElement(\DOMElement $parent, $name) return $e[0]; } + /** + * Collect the value of the contactType-property + * @return string + */ + public function getContactType() + { + return $this->contactType; + } + + /** + * Set the value of the contactType-property + * @param string $contactType + */ + public function setContactType($contactType) + { + assert(is_string($contactType)); + $this->contactType = $contactType; + } + + /** + * Collect the value of the Company-property + * @return string|null + */ + public function getCompany() + { + return $this->Company; + } + + /** + * Set the value of the Company-property + * @param string|null $company + */ + public function setCompany($company) + { + assert(is_string($company) || is_null($company)); + $this->Company = $company; + } + + /** + * Collect the value of the GivenName-property + * @return string|null + */ + public function getGivenName() + { + return $this->GivenName; + } + + /** + * Set the value of the GivenName-property + * @param string|null $givenName + */ + public function setGivenName($givenName) + { + assert(is_string($givenName) || is_null($givenName)); + $this->GivenName = $givenName; + } + + /** + * Collect the value of the SurName-property + * @return string|null + */ + public function getSurName() + { + return $this->SurName; + } + + /** + * Set the value of the SurName-property + * @param string|null $surName + */ + public function setSurName($surName) + { + assert(is_string($surName) || is_null($surName)); + $this->SurName = $surName; + } + + /** + * Collect the value of the EmailAddress-property + * @return string[] + */ + public function getEmailAddress() + { + return $this->EmailAddress; + } + + /** + * Set the value of the EmailAddress-property + * @param string[] $emailAddress + */ + public function setEmailAddress(array $emailAddress) + { + $this->EmailAddress = $emailAddress; + } + + /** + * Collect the value of the TelephoneNumber-property + * @return string[] + */ + public function getTelephoneNumber() + { + return $this->TelephoneNumber; + } + + /** + * Set the value of the TelephoneNumber-property + * @param string[] $telephoneNumber + */ + public function setTelephoneNumber(array $telephoneNumber) + { + $this->TelephoneNumber = $telephoneNumber; + } + + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Collect the value of the ContactPersonAttributes-property + * @return string[] + */ + public function getContactPersonAttributes() + { + return $this->ContactPersonAttributes; + } + + /** + * Set the value of the ContactPersonAttributes-property + * @param string[] $contactPersonAttributes + */ + public function setContactPersonAttributes(array $contactPersonAttributes) + { + $this->ContactPersonAttributes = $contactPersonAttributes; + } + + /** + * Add the key/value of the ContactPersonAttributes-property + * @param string $attr + * @param string $value + */ + public function addContactPersonAttributes($attr, $value) + { + assert(is_string($attr)); + assert(is_string($value)); + $this->ContactPersonAttributes[$attr] = $value; + } + /** * Convert this ContactPerson to XML. * @@ -156,42 +316,42 @@ private static function getStringElement(\DOMElement $parent, $name) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->contactType)); - assert(is_array($this->Extensions)); - assert(is_null($this->Company) || is_string($this->Company)); - assert(is_null($this->GivenName) || is_string($this->GivenName)); - assert(is_null($this->SurName) || is_string($this->SurName)); - assert(is_array($this->EmailAddress)); - assert(is_array($this->TelephoneNumber)); - assert(is_array($this->ContactPersonAttributes)); + assert(is_string($this->getContactType())); + assert(is_array($this->getExtensions())); + assert(is_null($this->getCompany()) || is_string($this->getCompany())); + assert(is_null($this->getGivenName()) || is_string($this->getGivenName())); + assert(is_null($this->getSurName()) || is_string($this->getSurName())); + assert(is_array($this->getEmailAddress())); + assert(is_array($this->getTelephoneNumber())); + assert(is_array($this->getContactPersonAttributes())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Constants::NS_MD, 'md:ContactPerson'); $parent->appendChild($e); - $e->setAttribute('contactType', $this->contactType); + $e->setAttribute('contactType', $this->getContactType()); - foreach ($this->ContactPersonAttributes as $attr => $val) { + foreach ($this->getContactPersonAttributes() as $attr => $val) { $e->setAttribute($attr, $val); } - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); - if (isset($this->Company)) { - Utils::addString($e, Constants::NS_MD, 'md:Company', $this->Company); + if ($this->getCompany() !== null) { + Utils::addString($e, Constants::NS_MD, 'md:Company', $this->getCompany()); } - if (isset($this->GivenName)) { - Utils::addString($e, Constants::NS_MD, 'md:GivenName', $this->GivenName); + if ($this->getGivenName() !== null) { + Utils::addString($e, Constants::NS_MD, 'md:GivenName', $this->getGivenName()); } - if (isset($this->SurName)) { - Utils::addString($e, Constants::NS_MD, 'md:SurName', $this->SurName); + if ($this->getSurName() !== null) { + Utils::addString($e, Constants::NS_MD, 'md:SurName', $this->getSurName()); } - if (!empty($this->EmailAddress)) { - Utils::addStrings($e, Constants::NS_MD, 'md:EmailAddress', false, $this->EmailAddress); + if ($this->getEmailAddress() !== null) { + Utils::addStrings($e, Constants::NS_MD, 'md:EmailAddress', false, $this->getEmailAddress()); } - if (!empty($this->TelephoneNumber)) { - Utils::addStrings($e, Constants::NS_MD, 'md:TelephoneNumber', false, $this->TelephoneNumber); + if ($this->getTelephoneNumber() !== null) { + Utils::addStrings($e, Constants::NS_MD, 'md:TelephoneNumber', false, $this->getTelephoneNumber()); } return $e; diff --git a/src/SAML2/XML/md/EndpointType.php b/src/SAML2/XML/md/EndpointType.php index 0be34671c..8a1f516a0 100644 --- a/src/SAML2/XML/md/EndpointType.php +++ b/src/SAML2/XML/md/EndpointType.php @@ -54,15 +54,15 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('Binding')) { throw new \Exception('Missing Binding on '.$xml->tagName); } - $this->Binding = $xml->getAttribute('Binding'); + $this->setBinding($xml->getAttribute('Binding')); if (!$xml->hasAttribute('Location')) { throw new \Exception('Missing Location on '.$xml->tagName); } - $this->Location = $xml->getAttribute('Location'); + $this->setLocation($xml->getAttribute('Location')); if ($xml->hasAttribute('ResponseLocation')) { - $this->ResponseLocation = $xml->getAttribute('ResponseLocation'); + $this->setResponseLocation($xml->getAttribute('ResponseLocation')); } foreach ($xml->attributes as $a) { @@ -157,6 +157,63 @@ public function removeAttributeNS($namespaceURI, $localName) unset($this->attributes[$fullName]); } + /** + * Collect the value of the Binding-property + * @return string + */ + public function getBinding() + { + return $this->Binding; + } + + /** + * Set the value of the Binding-property + * @param string $binding + */ + public function setBinding($binding) + { + assert(is_string($binding)); + $this->Binding = $binding; + } + + /** + * Collect the value of the Location-property + * @return string|null + */ + public function getLocation() + { + return $this->Location; + } + + /** + * Set the value of the Location-property + * @param string|null $location + */ + public function setLocation($location) + { + assert(is_string($location) || is_null($location)); + $this->Location = $location; + } + + /** + * Collect the value of the ResponseLocation-property + * @return string|null + */ + public function getResponseLocation() + { + return $this->ResponseLocation; + } + + /** + * Set the value of the ResponseLocation-property + * @param string|null $responseLocation + */ + public function setResponseLocation($responseLocation) + { + assert(is_string($responseLocation) || is_null($responseLocation)); + $this->ResponseLocation = $responseLocation; + } + /** * Add this endpoint to an XML element. * @@ -167,18 +224,18 @@ public function removeAttributeNS($namespaceURI, $localName) public function toXML(\DOMElement $parent, $name) { assert(is_string($name)); - assert(is_string($this->Binding)); - assert(is_string($this->Location)); - assert(is_null($this->ResponseLocation) || is_string($this->ResponseLocation)); + assert(is_string($this->getBinding())); + assert(is_string($this->getLocation())); + assert(is_null($this->getResponseLocation()) || is_string($this->getResponseLocation())); $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, $name); $parent->appendChild($e); - $e->setAttribute('Binding', $this->Binding); - $e->setAttribute('Location', $this->Location); + $e->setAttribute('Binding', $this->getBinding()); + $e->setAttribute('Location', $this->getLocation()); - if (isset($this->ResponseLocation)) { - $e->setAttribute('ResponseLocation', $this->ResponseLocation); + if ($this->getResponseLocation() !== null) { + $e->setAttribute('ResponseLocation', $this->getResponseLocation()); } foreach ($this->attributes as $a) { diff --git a/src/SAML2/XML/md/EntitiesDescriptor.php b/src/SAML2/XML/md/EntitiesDescriptor.php index 58540cec1..79fc0db92 100644 --- a/src/SAML2/XML/md/EntitiesDescriptor.php +++ b/src/SAML2/XML/md/EntitiesDescriptor.php @@ -72,19 +72,19 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('ID')) { - $this->ID = $xml->getAttribute('ID'); + $this->setID($xml->getAttribute('ID')); } if ($xml->hasAttribute('validUntil')) { - $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); + $this->setValidUntil(Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'))); } if ($xml->hasAttribute('cacheDuration')) { - $this->cacheDuration = $xml->getAttribute('cacheDuration'); + $this->setCacheDuration($xml->getAttribute('cacheDuration')); } if ($xml->hasAttribute('Name')) { - $this->Name = $xml->getAttribute('Name'); + $this->setName($xml->getAttribute('Name')); } - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); foreach (Utils::xpQuery($xml, './saml_metadata:EntityDescriptor|./saml_metadata:EntitiesDescriptor') as $node) { if ($node->localName === 'EntityDescriptor') { @@ -95,6 +95,128 @@ public function __construct(\DOMElement $xml = null) } } + /** + * Collect the value of the Name-property + * @return string|null + */ + public function getName() + { + return $this->Name; + } + + /** + * Set the value of the Name-property + * @param string|null $name + */ + public function setName($name = null) + { + assert(is_string($name) || is_null($name)); + $this->Name = $name; + } + + /** + * Collect the value of the ID-property + * @return string|null + */ + public function getID() + { + return $this->ID; + } + + /** + * Set the value of the ID-property + * @param string|null $Id + */ + public function setID($Id = null) + { + assert(is_string($Id) || is_null($Id)); + $this->ID = $Id; + } + + /** + * Collect the value of the validUntil-property + * @return int|null + */ + public function getValidUntil() + { + return $this->validUntil; + } + + /** + * Set the value of the validUntil-property + * @param int|null $validUntil + */ + public function setValidUntil($validUntil = null) + { + assert(is_int($validUntil) || is_null($validUntil)); + $this->validUntil = $validUntil; + } + + /** + * Collect the value of the cacheDuration-property + * @return string|null + */ + public function getCacheDuration() + { + return $this->cacheDuration; + } + + /** + * Set the value of the cacheDuration-property + * @param string|null $cacheDuration + */ + public function setCacheDuration($cacheDuration = null) + { + assert(is_string($cacheDuration) || is_null($cacheDuration)); + $this->cacheDuration = $cacheDuration; + } + + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Collect the value of the children-property + * @return (\SAML2\XML\md\EntityDescriptor|\SAML2\XML\md\EntitiesDescriptor)[] + */ + public function getChildren() + { + return $this->children; + } + + /** + * Set the value of the childen-property + * @param array $children + */ + public function setChildren(array $children) + { + $this->children = $children; + } + + /** + * Add the value to the children-property + * @param \SAML2\XML\md\EntityDescriptor|\SAML2\XML\md\EntitiesDescriptor $child + */ + public function addChildren($child) + { + assert($child instanceof EntityDescriptor || $child instanceof EntitiesDescriptor); + $this->children[] = $child; + } + /** * Convert this EntitiesDescriptor to XML. * @@ -103,12 +225,12 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent = null) { - assert(is_null($this->ID) || is_string($this->ID)); - assert(is_null($this->validUntil) || is_int($this->validUntil)); - assert(is_null($this->cacheDuration) || is_string($this->cacheDuration)); - assert(is_null($this->Name) || is_string($this->Name)); - assert(is_array($this->Extensions)); - assert(is_array($this->children)); + assert(is_null($this->getID()) || is_string($this->getID())); + assert(is_null($this->getValidUntil()) || is_int($this->getValidUntil())); + assert(is_null($this->getCacheDuration()) || is_string($this->getCacheDuration())); + assert(is_null($this->getName()) || is_string($this->getName())); + assert(is_array($this->getExtensions())); + assert(is_array($this->getChildren())); if ($parent === null) { $doc = DOMDocumentFactory::create(); @@ -119,26 +241,26 @@ public function toXML(\DOMElement $parent = null) $parent->appendChild($e); } - if (isset($this->ID)) { - $e->setAttribute('ID', $this->ID); + if ($this->getID() !== null) { + $e->setAttribute('ID', $this->getID()); } - if (isset($this->validUntil)) { - $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil)); + if ($this->getValidUntil() !== null) { + $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->getValidUntil())); } - if (isset($this->cacheDuration)) { - $e->setAttribute('cacheDuration', $this->cacheDuration); + if ($this->getCacheDuration() !== null) { + $e->setAttribute('cacheDuration', $this->getCacheDuration()); } - if (isset($this->Name)) { - $e->setAttribute('Name', $this->Name); + if ($this->getName() !== null) { + $e->setAttribute('Name', $this->getName()); } - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); /** @var \SAML2\XML\md\EntityDescriptor|\SAML2\XML\md\EntitiesDescriptor $node */ - foreach ($this->children as $node) { + foreach ($this->getChildren() as $node) { $node->toXML($e); } diff --git a/src/SAML2/XML/md/EntityDescriptor.php b/src/SAML2/XML/md/EntityDescriptor.php index b05d47c6c..943aa4aeb 100644 --- a/src/SAML2/XML/md/EntityDescriptor.php +++ b/src/SAML2/XML/md/EntityDescriptor.php @@ -105,19 +105,19 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('entityID')) { throw new \Exception('Missing required attribute entityID on EntityDescriptor.'); } - $this->entityID = $xml->getAttribute('entityID'); + $this->setEntityID($xml->getAttribute('entityID')); if ($xml->hasAttribute('ID')) { - $this->ID = $xml->getAttribute('ID'); + $this->setID($xml->getAttribute('ID')); } if ($xml->hasAttribute('validUntil')) { - $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); + $this->setValidUntil(Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'))); } if ($xml->hasAttribute('cacheDuration')) { - $this->cacheDuration = $xml->getAttribute('cacheDuration'); + $this->setCacheDuration($xml->getAttribute('cacheDuration')); } - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); for ($node = $xml->firstChild; $node !== null; $node = $node->nextSibling) { if (!($node instanceof \DOMElement)) { @@ -130,22 +130,22 @@ public function __construct(\DOMElement $xml = null) switch ($node->localName) { case 'RoleDescriptor': - $this->RoleDescriptor[] = new UnknownRoleDescriptor($node); + $this->addRoleDescriptor(new UnknownRoleDescriptor($node)); break; case 'IDPSSODescriptor': - $this->RoleDescriptor[] = new IDPSSODescriptor($node); + $this->addRoleDescriptor(new IDPSSODescriptor($node)); break; case 'SPSSODescriptor': - $this->RoleDescriptor[] = new SPSSODescriptor($node); + $this->addRoleDescriptor(new SPSSODescriptor($node)); break; case 'AuthnAuthorityDescriptor': - $this->RoleDescriptor[] = new AuthnAuthorityDescriptor($node); + $this->addRoleDescriptor(new AuthnAuthorityDescriptor($node)); break; case 'AttributeAuthorityDescriptor': - $this->RoleDescriptor[] = new AttributeAuthorityDescriptor($node); + $this->addRoleDescriptor(new AttributeAuthorityDescriptor($node)); break; case 'PDPDescriptor': - $this->RoleDescriptor[] = new PDPDescriptor($node); + $this->addRoleDescriptor(new PDPDescriptor($node)); break; } } @@ -154,12 +154,13 @@ public function __construct(\DOMElement $xml = null) if (count($affiliationDescriptor) > 1) { throw new \Exception('More than one AffiliationDescriptor in the entity.'); } elseif (!empty($affiliationDescriptor)) { - $this->AffiliationDescriptor = new AffiliationDescriptor($affiliationDescriptor[0]); + $this->setAffiliationDescriptor(new AffiliationDescriptor($affiliationDescriptor[0])); } - if (empty($this->RoleDescriptor) && is_null($this->AffiliationDescriptor)) { + $roleDescriptor = $this->getRoleDescriptor(); + if (empty($roleDescriptor) && is_null($this->getAffiliationDescriptor())) { throw new \Exception('Must have either one of the RoleDescriptors or an AffiliationDescriptor in EntityDescriptor.'); - } elseif (!empty($this->RoleDescriptor) && !is_null($this->AffiliationDescriptor)) { + } elseif (!empty($roleDescriptor) && !is_null($this->getAffiliationDescriptor())) { throw new \Exception('AffiliationDescriptor cannot be combined with other RoleDescriptor elements in EntityDescriptor.'); } @@ -167,18 +168,231 @@ public function __construct(\DOMElement $xml = null) if (count($organization) > 1) { throw new \Exception('More than one Organization in the entity.'); } elseif (!empty($organization)) { - $this->Organization = new Organization($organization[0]); + $this->setOrganization(new Organization($organization[0])); } foreach (Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) { - $this->ContactPerson[] = new ContactPerson($cp); + $this->addContactPerson(new ContactPerson($cp)); } foreach (Utils::xpQuery($xml, './saml_metadata:AdditionalMetadataLocation') as $aml) { - $this->AdditionalMetadataLocation[] = new AdditionalMetadataLocation($aml); + $this->addAdditionalMetadataLocation(new AdditionalMetadataLocation($aml)); } } + /** + * Collect the value of the entityID-property + * @return string + */ + public function getEntityID() + { + return $this->entityID; + } + + /** + * Set the value of the entityID-property + * @param string|null $entityId + */ + public function setEntityID($entityId) + { + assert(is_string($entityId) || is_null($entityId)); + $this->entityID = $entityId; + } + + /** + * Collect the value of the ID-property + * @return string|null + */ + public function getID() + { + return $this->ID; + } + + /** + * Set the value of the ID-property + * @param string|null $Id + */ + public function setID($Id = null) + { + assert(is_string($Id) || is_null($Id)); + $this->ID = $Id; + } + + /** + * Collect the value of the validUntil-property + * @return int|null + */ + public function getValidUntil() + { + return $this->validUntil; + } + + /** + * Set the value of the validUntil-property + * @param int|null $validUntil + */ + public function setValidUntil($validUntil = null) + { + assert(is_int($validUntil) || is_null($validUntil)); + $this->validUntil = $validUntil; + } + + /** + * Collect the value of the cacheDuration-property + * @return string|null + */ + public function getCacheDuration() + { + return $this->cacheDuration; + } + + /** + * Set the value of the cacheDuration-property + * @param string|null $cacheDuration + */ + public function setCacheDuration($cacheDuration = null) + { + assert(is_string($cacheDuration) || is_null($cacheDuration)); + $this->cacheDuration = $cacheDuration; + } + + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Collect the value of the RoleDescriptor-property + * @return \SAML2\XML\md\RoleDescriptor[] + */ + public function getRoleDescriptor() + { + return $this->RoleDescriptor; + } + + /** + * Set the value of the RoleDescriptor-property + * @param array $roleDescriptor + */ + public function setRoleDescriptor(array $roleDescriptor) + { + $this->RoleDescriptor = $roleDescriptor; + } + + /** + * Add the value to the RoleDescriptor-property + * @param \SAML2\XML\md\RoleDescriptor $roleDescriptor + */ + public function addRoleDescriptor(RoleDescriptor $roleDescriptor) + { + $this->RoleDescriptor[] = $roleDescriptor; + } + + /** + * Collect the value of the AffiliationDescriptor-property + * @return \SAML2\XML\md\AffiliationDescriptor|null + */ + public function getAffiliationDescriptor() + { + return $this->AffiliationDescriptor; + } + + /** + * Set the value of the AffliationDescriptor-property + * @param \SAML2\XML\md\AffiliationDescriptor|null $affiliationDescriptor + */ + public function setAffiliationDescriptor(AffiliationDescriptor $affiliationDescriptor = null) + { + $this->AffiliationDescriptor = $affiliationDescriptor; + } + + /** + * Collect the value of the Organization-property + * @return \SAML2\XML\md\Organization|null + */ + public function getOrganization() + { + return $this->Organization; + } + + /** + * Set the value of the Organization-property + * @param \SAML2\XML\md\Organization|null $organization + */ + public function setOrganization(Organization $organization = null) + { + $this->Organization = $organization; + } + + + /** + * Collect the value of the ContactPerson-property + * @return \SAML2\XML\md\ContactPerson[] + */ + public function getContactPerson() + { + return $this->ContactPerson; + } + + /** + * Set the value of the ContactPerson-property + * @param array $contactPerson + */ + public function setContactPerson(array $contactPerson) + { + $this->ContactPerson = $contactPerson; + } + + /** + * Add the value to the ContactPerson-property + * @param \SAML2\XML\md\ContactPerson $contactPerson + */ + public function addContactPerson(ContactPerson $contactPerson) + { + $this->ContactPerson[] = $contactPerson; + } + + /** + * Collect the value of the AdditionalMetadataLocation-property + * @return \SAML2\XML\md\AdditionalMetadataLocation[] + */ + public function getAdditionalMetadataLocation() + { + return $this->AdditionalMetadataLocation; + } + + /** + * Set the value of the AdditionalMetadataLocation-property + * @param array $additionalMetadataLocation + */ + public function setAdditionalMetadataLocation(array $additionalMetadataLocation) + { + $this->AdditionalMetadataLocation = $additionalMetadataLocation; + } + + /** + * Add the value to the AdditionalMetadataLocation-property + * @param AdditionalMetadataLocation $additionalMetadataLocation + */ + public function addAdditionalMetadataLocation(AdditionalMetadataLocation $additionalMetadataLocation) + { + $this->AdditionalMetadataLocation[] = $additionalMetadataLocation; + } + + /** * Create this EntityDescriptor. * @@ -187,16 +401,16 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent = null) { - assert(is_string($this->entityID)); - assert(is_null($this->ID) || is_string($this->ID)); - assert(is_null($this->validUntil) || is_int($this->validUntil)); - assert(is_null($this->cacheDuration) || is_string($this->cacheDuration)); - assert(is_array($this->Extensions)); - assert(is_array($this->RoleDescriptor)); - assert(is_null($this->AffiliationDescriptor) || $this->AffiliationDescriptor instanceof AffiliationDescriptor); - assert(is_null($this->Organization) || $this->Organization instanceof Organization); - assert(is_array($this->ContactPerson)); - assert(is_array($this->AdditionalMetadataLocation)); + assert(is_string($this->getEntityID())); + assert(is_null($this->getID()) || is_string($this->getID())); + assert(is_null($this->getValidUntil()) || is_int($this->getValidUntil())); + assert(is_null($this->getCacheDuration()) || is_string($this->getCacheDuration())); + assert(is_array($this->getExtensions())); + assert(is_array($this->getRoleDescriptor())); + assert(is_null($this->getAffiliationDescriptor()) || $this->getAffiliationDescriptor() instanceof AffiliationDescriptor); + assert(is_null($this->getOrganization()) || $this->getOrganization() instanceof Organization); + assert(is_array($this->getContactPerson())); + assert(is_array($this->getAdditionalMetadataLocation())); if ($parent === null) { $doc = DOMDocumentFactory::create(); @@ -207,40 +421,40 @@ public function toXML(\DOMElement $parent = null) $parent->appendChild($e); } - $e->setAttribute('entityID', $this->entityID); + $e->setAttribute('entityID', $this->getEntityID()); - if (isset($this->ID)) { - $e->setAttribute('ID', $this->ID); + if ($this->getID() !== null) { + $e->setAttribute('ID', $this->getID()); } - if (isset($this->validUntil)) { - $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil)); + if ($this->getValidUntil() !== null) { + $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->getValidUntil())); } - if (isset($this->cacheDuration)) { - $e->setAttribute('cacheDuration', $this->cacheDuration); + if ($this->getCacheDuration() !== null) { + $e->setAttribute('cacheDuration', $this->getCacheDuration()); } - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); /** @var \SAML2\XML\md\UnknownRoleDescriptor|\SAML2\XML\md\IDPSSODescriptor|\SAML2\XML\md\SPSSODescriptor|\SAML2\XML\md\AuthnAuthorityDescriptor|\SAML2\XML\md\AttributeAuthorityDescriptor|\SAML2\XML\md\PDPDescriptor $n */ - foreach ($this->RoleDescriptor as $n) { + foreach ($this->getRoleDescriptor() as $n) { $n->toXML($e); } - if (isset($this->AffiliationDescriptor)) { - $this->AffiliationDescriptor->toXML($e); + if ($this->getAffiliationDescriptor() !== null) { + $this->getAffiliationDescriptor()->toXML($e); } - if (isset($this->Organization)) { - $this->Organization->toXML($e); + if ($this->getOrganization() !== null) { + $this->getOrganization()->toXML($e); } - foreach ($this->ContactPerson as $cp) { + foreach ($this->getContactPerson() as $cp) { $cp->toXML($e); } - foreach ($this->AdditionalMetadataLocation as $n) { + foreach ($this->getAdditionalMetadataLocation() as $n) { $n->toXML($e); } diff --git a/src/SAML2/XML/md/IDPSSODescriptor.php b/src/SAML2/XML/md/IDPSSODescriptor.php index 6f945c3b5..57d7d4b24 100644 --- a/src/SAML2/XML/md/IDPSSODescriptor.php +++ b/src/SAML2/XML/md/IDPSSODescriptor.php @@ -78,27 +78,172 @@ public function __construct(\DOMElement $xml = null) return; } - $this->WantAuthnRequestsSigned = Utils::parseBoolean($xml, 'WantAuthnRequestsSigned', null); + $this->setWantAuthnRequestsSigned(Utils::parseBoolean($xml, 'WantAuthnRequestsSigned', null)); foreach (Utils::xpQuery($xml, './saml_metadata:SingleSignOnService') as $ep) { - $this->SingleSignOnService[] = new EndpointType($ep); + $this->addSingleSignOnService(new EndpointType($ep)); } foreach (Utils::xpQuery($xml, './saml_metadata:NameIDMappingService') as $ep) { - $this->NameIDMappingService[] = new EndpointType($ep); + $this->addNameIDMappingService(new EndpointType($ep)); } foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) { - $this->AssertionIDRequestService[] = new EndpointType($ep); + $this->addAssertionIDRequestService(new EndpointType($ep)); } - $this->AttributeProfile = Utils::extractStrings($xml, Constants::NS_MD, 'AttributeProfile'); + $this->setAttributeProfile(Utils::extractStrings($xml, Constants::NS_MD, 'AttributeProfile')); foreach (Utils::xpQuery($xml, './saml_assertion:Attribute') as $a) { - $this->Attribute[] = new Attribute($a); + $this->addAttribute(new Attribute($a)); } } + /** + * Collect the value of the WantAuthnRequestsSigned-property + * @return bool|null + */ + public function wantAuthnRequestsSigned() + { + return $this->WantAuthnRequestsSigned; + } + + /** + * Set the value of the WantAuthnRequestsSigned-property + * @param bool|null $flag + */ + public function setWantAuthnRequestsSigned($flag = null) + { + assert(is_bool($flag) || is_null($flag)); + $this->WantAuthnRequestsSigned = $flag; + } + + /** + * Collect the value of the SingleSignOnService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getSingleSignOnService() + { + return $this->SingleSignOnService; + } + + /** + * Set the value of the SingleSignOnService-property + * @param array $singleSignOnService + */ + public function setSingleSignOnService(array $singleSignOnService) + { + $this->SingleSignOnService = $singleSignOnService; + } + + /** + * Add the value to the SingleSignOnService-property + * @param \SAML2\XML\md\EndpointType $singleSignOnService + */ + public function addSingleSignOnService(EndpointType $singleSignOnService) + { + $this->SingleSignOnService[] = $singleSignOnService; + } + + /** + * Collect the value of the NameIDMappingService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getNameIDMappingService() + { + return $this->NameIDMappingService; + } + + /** + * Set the value of the NameIDMappingService-property + * @param array $nameIDMappingService + */ + public function setNameIDMappingService(array $nameIDMappingService) + { + $this->NameIDMappingService = $nameIDMappingService; + } + + /** + * Add the value to the NameIDMappingService-property + * @param \SAML2\XML\md\EndpointType $nameIDMappingService + */ + public function addNameIDMappingService(EndpointType $nameIDMappingService) + { + $this->NameIDMappingService[] = $nameIDMappingService; + } + + /** + * Collect the value of the AssertionIDRequestService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAssertionIDRequestService() + { + return $this->AssertionIDRequestService; + } + + /** + * Set the value of the AssertionIDRequestService-property + * @param array $assertionIDRequestService + */ + public function setAssertionIDRequestService(array $assertionIDRequestService) + { + $this->AssertionIDRequestService = $assertionIDRequestService; + } + + /** + * Add the value to the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType $assertionIDRequestService + */ + public function addAssertionIDRequestService(EndpointType $assertionIDRequestService) + { + $this->AssertionIDRequestService[] = $assertionIDRequestService; + } + + /** + * Collect the value of the AttributeProfile-property + * @return array + */ + public function getAttributeProfile() + { + return $this->AttributeProfile; + } + + /** + * Set the value of the AttributeProfile-property + * @param array $attributeProfile + */ + public function setAttributeProfile(array $attributeProfile) + { + $this->AttributeProfile = $attributeProfile; + } + + /** + * Collect the value of the Attribute-property + * @return \SAML2\XML\saml\Attribute[] + */ + public function getAttribute() + { + return $this->Attribute; + } + + /** + * Set the value of the Attribute-property + * @param array $attribute + */ + public function setAttribute(array $attribute) + { + $this->Attribute = $attribute; + } + + /** + * Addthe value to the Attribute-property + * @param \SAML2\XML\saml\Attribute $attribute + */ + public function addAttribute(Attribute $attribute) + { + $this->Attribute[] = $attribute; + } + /** * Add this IDPSSODescriptor to an EntityDescriptor. * @@ -107,36 +252,36 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_null($this->WantAuthnRequestsSigned) || is_bool($this->WantAuthnRequestsSigned)); - assert(is_array($this->SingleSignOnService)); - assert(is_array($this->NameIDMappingService)); - assert(is_array($this->AssertionIDRequestService)); - assert(is_array($this->AttributeProfile)); - assert(is_array($this->Attribute)); + assert(is_null($this->WantAuthnRequestsSigned()) || is_bool($this->WantAuthnRequestsSigned())); + assert(is_array($this->getSingleSignOnService())); + assert(is_array($this->getNameIDMappingService())); + assert(is_array($this->getAssertionIDRequestService())); + assert(is_array($this->getAttributeProfile())); + assert(is_array($this->getAttribute())); $e = parent::toXML($parent); - if ($this->WantAuthnRequestsSigned === true) { + if ($this->WantAuthnRequestsSigned() === true) { $e->setAttribute('WantAuthnRequestsSigned', 'true'); - } elseif ($this->WantAuthnRequestsSigned === false) { + } elseif ($this->WantAuthnRequestsSigned() === false) { $e->setAttribute('WantAuthnRequestsSigned', 'false'); } - foreach ($this->SingleSignOnService as $ep) { + foreach ($this->getSingleSignOnService() as $ep) { $ep->toXML($e, 'md:SingleSignOnService'); } - foreach ($this->NameIDMappingService as $ep) { + foreach ($this->getNameIDMappingService() as $ep) { $ep->toXML($e, 'md:NameIDMappingService'); } - foreach ($this->AssertionIDRequestService as $ep) { + foreach ($this->getAssertionIDRequestService() as $ep) { $ep->toXML($e, 'md:AssertionIDRequestService'); } - Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->AttributeProfile); + Utils::addStrings($e, Constants::NS_MD, 'md:AttributeProfile', false, $this->getAttributeProfile()); - foreach ($this->Attribute as $a) { + foreach ($this->getAttribute() as $a) { $a->toXML($e); } diff --git a/src/SAML2/XML/md/IndexedEndpointType.php b/src/SAML2/XML/md/IndexedEndpointType.php index 00a0e435a..a43c09976 100644 --- a/src/SAML2/XML/md/IndexedEndpointType.php +++ b/src/SAML2/XML/md/IndexedEndpointType.php @@ -40,13 +40,52 @@ public function __construct(\DOMElement $xml = null) } if (!$xml->hasAttribute('index')) { - throw new \Exception('Missing index on ' . $xml->tagName); + throw new \Exception('Missing index on '.$xml->tagName); } - $this->index = (int) $xml->getAttribute('index'); + $this->setIndex(intval($xml->getAttribute('index'))); - $this->isDefault = Utils::parseBoolean($xml, 'isDefault', null); + $this->setIsDefault(Utils::parseBoolean($xml, 'isDefault', null)); } + /** + * Collect the value of the index-property + * @return int + */ + public function getIndex() + { + return $this->index; + } + + /** + * Set the value of the index-property + * @param int $index + */ + public function setIndex($index) + { + assert(is_int($index)); + $this->index = $index; + } + + /** + * Collect the value of the isDefault-property + * @return bool|null + */ + public function getIsDefault() + { + return $this->isDefault; + } + + /** + * Set the value of the isDefault-property + * @param bool|null $flag + */ + public function setIsDefault($flag = null) + { + assert(is_bool($flag) || is_null($flag)); + $this->isDefault = $flag; + } + + /** * Add this endpoint to an XML element. * @@ -57,15 +96,15 @@ public function __construct(\DOMElement $xml = null) public function toXML(\DOMElement $parent, $name) { assert(is_string($name)); - assert(is_int($this->index)); - assert(is_null($this->isDefault) || is_bool($this->isDefault)); + assert(is_int($this->getIndex())); + assert(is_null($this->getIsDefault()) || is_bool($this->getIsDefault())); $e = parent::toXML($parent, $name); - $e->setAttribute('index', (string) $this->index); + $e->setAttribute('index', (string) $this->getIndex()); - if ($this->isDefault === true) { + if ($this->getIsDefault() === true) { $e->setAttribute('isDefault', 'true'); - } elseif ($this->isDefault === false) { + } elseif ($this->getIsDefault() === false) { $e->setAttribute('isDefault', 'false'); } diff --git a/src/SAML2/XML/md/KeyDescriptor.php b/src/SAML2/XML/md/KeyDescriptor.php index 74ab5bc97..c3760fb79 100644 --- a/src/SAML2/XML/md/KeyDescriptor.php +++ b/src/SAML2/XML/md/KeyDescriptor.php @@ -52,7 +52,7 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('use')) { - $this->use = $xml->getAttribute('use'); + $this->setUse($xml->getAttribute('use')); } $keyInfo = Utils::xpQuery($xml, './ds:KeyInfo'); @@ -61,13 +61,77 @@ public function __construct(\DOMElement $xml = null) } elseif (empty($keyInfo)) { throw new \Exception('No ds:KeyInfo in the KeyDescriptor.'); } - $this->KeyInfo = new KeyInfo($keyInfo[0]); + $this->setKeyInfo(new KeyInfo($keyInfo[0])); foreach (Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) { - $this->EncryptionMethod[] = new Chunk($em); + $this->addEncryptionMethod(new Chunk($em)); } } + /** + * Collect the value of the use-property + * @return string + */ + public function getUse() + { + return $this->use; + } + + /** + * Set the value of the use-property + * @param string|null $use + */ + public function setUse($use) + { + assert(is_string($use) || is_null($use)); + $this->use = $use; + } + + /** + * Collect the value of the KeyInfo-property + * @return \SAML2\XML\ds\KeyInfo + */ + public function getKeyInfo() + { + return $this->KeyInfo; + } + + /** + * Set the value of the KeyInfo-property + * @param \SAML2\XML\ds\KeyInfo $keyInfo + */ + public function setKeyInfo(KeyInfo $keyInfo) + { + $this->KeyInfo = $keyInfo; + } + + /** + * Collect the value of the EncryptionMethod-property + * @return \SAML2\XML\Chunk[] + */ + public function getEncryptionMethod() + { + return $this->EncryptionMethod; + } + + /** + * Set the value of the EncryptionMethod-property + * @param \SAML2\XML\Chunk[] $encryptionMethod + */ + public function setEncryptionMethod(array $encryptionMethod) + { + $this->EncryptionMethod = $encryptionMethod; + } + + /** + * Add the value to the EncryptionMethod-property + * @param \SAML2\XML\Chunk $encryptionMethod + */ + public function addEncryptionMethod(Chunk $encryptionMethod) + { + $this->EncryptionMethod[] = $encryptionMethod; + } + /** * Convert this KeyDescriptor to XML. * @@ -76,22 +140,22 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_null($this->use) || is_string($this->use)); - assert($this->KeyInfo instanceof KeyInfo); - assert(is_array($this->EncryptionMethod)); + assert(is_null($this->getUse()) || is_string($this->getUse())); + assert($this->getKeyInfo() instanceof KeyInfo); + assert(is_array($this->getEncryptionMethod())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Constants::NS_MD, 'md:KeyDescriptor'); $parent->appendChild($e); - if (isset($this->use)) { - $e->setAttribute('use', $this->use); + if ($this->getUse() !== null) { + $e->setAttribute('use', $this->getUse()); } - $this->KeyInfo->toXML($e); + $this->getKeyInfo()->toXML($e); - foreach ($this->EncryptionMethod as $em) { + foreach ($this->getEncryptionMethod() as $em) { $em->toXML($e); } diff --git a/src/SAML2/XML/md/Organization.php b/src/SAML2/XML/md/Organization.php index b3fb5bc83..225fb90af 100644 --- a/src/SAML2/XML/md/Organization.php +++ b/src/SAML2/XML/md/Organization.php @@ -53,24 +53,99 @@ public function __construct(\DOMElement $xml = null) return; } - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); - $this->OrganizationName = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationName'); - if (empty($this->OrganizationName)) { - $this->OrganizationName = ['invalid' => '']; + $this->setOrganizationName(Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationName')); + $organizationName = $this->getOrganizationName(); + if (empty($organizationName)) { + $this->setOrganizationName(['invalid' => '']); } - $this->OrganizationDisplayName = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationDisplayName'); - if (empty($this->OrganizationDisplayName)) { - $this->OrganizationDisplayName = ['invalid' => '']; + $this->setOrganizationDisplayName(Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationDisplayName')); + $organizationDisplayName = $this->getOrganizationDisplayName(); + if (empty($organizationDisplayName)) { + $this->setOrganizationDisplayName(['invalid' => '']); } - $this->OrganizationURL = Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationURL'); - if (empty($this->OrganizationURL)) { - $this->OrganizationURL = ['invalid' => '']; + $this->setOrganizationURL(Utils::extractLocalizedStrings($xml, Constants::NS_MD, 'OrganizationURL')); + $organizationURL = $this->getOrganizationURL(); + if (empty($organizationURL)) { + $this->setOrganizationURL(['invalid' => '']); } } + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Collect the value of the OrganizationName-property + * @return string[] + */ + public function getOrganizationName() + { + return $this->OrganizationName; + } + + /** + * Set the value of the OrganizationName-property + * @param array $organizationName + */ + public function setOrganizationName(array $organizationName) + { + $this->OrganizationName = $organizationName; + } + + /** + * Collect the value of the OrganizationDisplayName-property + * @return string[] + */ + public function getOrganizationDisplayName() + { + return $this->OrganizationDisplayName; + } + + /** + * Set the value of the OrganizationDisplayName-property + * @param array $organizationDisplayName + */ + public function setOrganizationDisplayName(array $organizationDisplayName) + { + $this->OrganizationDisplayName = $organizationDisplayName; + } + + /** + * Collect the value of the OrganizationURL-property + * @return string[] + */ + public function getOrganizationURL() + { + return $this->OrganizationURL; + } + + /** + * Set the value of the OrganizationURL-property + * @param array $organizationURL + */ + public function setOrganizationURL(array $organizationURL) + { + $this->OrganizationURL = $organizationURL; + } + /** * Convert this Organization to XML. * @@ -79,24 +154,24 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->Extensions)); - assert(is_array($this->OrganizationName)); - assert(!empty($this->OrganizationName)); - assert(is_array($this->OrganizationDisplayName)); - assert(!empty($this->OrganizationDisplayName)); - assert(is_array($this->OrganizationURL)); - assert(!empty($this->OrganizationURL)); + assert(is_array($this->getExtensions())); + assert(is_array($organizationName = $this->getOrganizationName())); + assert(!empty($organizationName)); + assert(is_array($organizationDisplayName = $this->getOrganizationDisplayName())); + assert(!empty($organizationDisplayName)); + assert(is_array($organizationURL = $this->getOrganizationURL())); + assert(!empty($organizationURL)); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Constants::NS_MD, 'md:Organization'); $parent->appendChild($e); - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); - Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationName', true, $this->OrganizationName); - Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationDisplayName', true, $this->OrganizationDisplayName); - Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationURL', true, $this->OrganizationURL); + Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationName', true, $this->getOrganizationName()); + Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationDisplayName', true, $this->getOrganizationDisplayName()); + Utils::addStrings($e, Constants::NS_MD, 'md:OrganizationURL', true, $this->getOrganizationURL()); return $e; } diff --git a/src/SAML2/XML/md/PDPDescriptor.php b/src/SAML2/XML/md/PDPDescriptor.php index 3581093a9..889884281 100644 --- a/src/SAML2/XML/md/PDPDescriptor.php +++ b/src/SAML2/XML/md/PDPDescriptor.php @@ -54,17 +54,92 @@ public function __construct(\DOMElement $xml = null) } foreach (Utils::xpQuery($xml, './saml_metadata:AuthzService') as $ep) { - $this->AuthzService[] = new EndpointType($ep); + $this->addAuthzService(new EndpointType($ep)); } - if (empty($this->AuthzService)) { + if ($this->getAuthzService() !== []) { throw new \Exception('Must have at least one AuthzService in PDPDescriptor.'); } foreach (Utils::xpQuery($xml, './saml_metadata:AssertionIDRequestService') as $ep) { - $this->AssertionIDRequestService[] = new EndpointType($ep); + $this->addAssertionIDRequestService(new EndpointType($ep)); } - $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat'); + $this->setNameIDFormat(Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat')); + } + + /** + * Collect the value of the AuthzService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAuthzService() + { + return $this->AuthzService; + } + + /** + * Set the value of the AuthzService-property + * @param \SAML2\XML\md\EndpointType[] $authzService + */ + public function setAuthzService(array $authzService = []) + { + $this->AuthzService = $authzService; + } + + /** + * Add the value to the AuthzService-property + * @param \SAML2\XML\md\EndpointType $authzService + */ + public function addAuthzService(EndpointType $authzService) + { + assert($authzService instanceof EndpointType); + $this->AuthzService[] = $authzService; + } + + /** + * Collect the value of the AssertionIDRequestService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getAssertionIDRequestService() + { + return $this->AssertionIDRequestService; + } + + /** + * Set the value of the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType[] $assertionIDRequestService + */ + public function setAssertionIDRequestService(array $assertionIDRequestService) + { + $this->AssertionIDRequestService = $assertionIDRequestService; + } + + /** + * Add the value to the AssertionIDRequestService-property + * @param \SAML2\XML\md\EndpointType $assertionIDRequestService + */ + public function addAssertionIDRequestService(EndpointType $assertionIDRequestService) + { + assert($assertionIDRequestService instanceof EndpointType); + $this->AssertionIDRequestService[] = $assertionIDRequestService; + } + + + /** + * Collect the value of the NameIDFormat-property + * @return string[] + */ + public function getNameIDFormat() + { + return $this->NameIDFormat; + } + + /** + * Set the value of the NameIDFormat-property + * @param string[] $nameIDFormat + */ + public function setNameIDFormat(array $nameIDFormat) + { + $this->NameIDFormat = $nameIDFormat; } /** @@ -75,22 +150,22 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->AuthzService)); - assert(!empty($this->AuthzService)); - assert(is_array($this->AssertionIDRequestService)); - assert(is_array($this->NameIDFormat)); + assert(is_array($authzService = $this->getAuthzService())); + assert(!empty($authzService)); + assert(is_array($this->getAssertionIDRequestService())); + assert(is_array($this->getNameIDFormat())); $e = parent::toXML($parent); - foreach ($this->AuthzService as $ep) { + foreach ($this->getAuthzService() as $ep) { $ep->toXML($e, 'md:AuthzService'); } - foreach ($this->AssertionIDRequestService as $ep) { + foreach ($this->getAssertionIDRequestService() as $ep) { $ep->toXML($e, 'md:AssertionIDRequestService'); } - Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat); + Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->getNameIDFormat()); return $e; } diff --git a/src/SAML2/XML/md/RequestedAttribute.php b/src/SAML2/XML/md/RequestedAttribute.php index 76e0f8957..b8c51c11a 100644 --- a/src/SAML2/XML/md/RequestedAttribute.php +++ b/src/SAML2/XML/md/RequestedAttribute.php @@ -33,7 +33,26 @@ public function __construct(\DOMElement $xml = null) return; } - $this->isRequired = Utils::parseBoolean($xml, 'isRequired', null); + $this->setIsRequired(Utils::parseBoolean($xml, 'isRequired', null)); + } + + /** + * Collect the value of the isRequired-property + * @return boolean|null + */ + public function getIsRequired() + { + return $this->isRequired; + } + + /** + * Set the value of the isRequired-property + * @param boolean|null $flag + */ + public function setIsRequired($flag = null) + { + assert(is_bool($flag)); + $this->isRequired = $flag; } /** @@ -48,9 +67,9 @@ public function toXML(\DOMElement $parent) $e = $this->toXMLInternal($parent, Constants::NS_MD, 'md:RequestedAttribute'); - if ($this->isRequired === true) { + if ($this->getIsRequired() === true) { $e->setAttribute('isRequired', 'true'); - } elseif ($this->isRequired === false) { + } elseif ($this->getIsRequired() === false) { $e->setAttribute('isRequired', 'false'); } diff --git a/src/SAML2/XML/md/RoleDescriptor.php b/src/SAML2/XML/md/RoleDescriptor.php index 592d57637..c7c07b7eb 100644 --- a/src/SAML2/XML/md/RoleDescriptor.php +++ b/src/SAML2/XML/md/RoleDescriptor.php @@ -108,42 +108,230 @@ protected function __construct($elementName, \DOMElement $xml = null) } if ($xml->hasAttribute('ID')) { - $this->ID = $xml->getAttribute('ID'); + $this->setID($xml->getAttribute('ID')); } if ($xml->hasAttribute('validUntil')) { - $this->validUntil = Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil')); + $this->setValidUntil(Utils::xsDateTimeToTimestamp($xml->getAttribute('validUntil'))); } if ($xml->hasAttribute('cacheDuration')) { - $this->cacheDuration = $xml->getAttribute('cacheDuration'); + $this->setCacheDuration($xml->getAttribute('cacheDuration')); } if (!$xml->hasAttribute('protocolSupportEnumeration')) { - throw new \Exception('Missing protocolSupportEnumeration attribute on ' . $xml->localName); + throw new \Exception('Missing protocolSupportEnumeration attribute on '.$xml->localName); } - $this->protocolSupportEnumeration = preg_split('/[\s]+/', $xml->getAttribute('protocolSupportEnumeration')); + $this->setProtocolSupportEnumeration(preg_split('/[\s]+/', $xml->getAttribute('protocolSupportEnumeration'))); if ($xml->hasAttribute('errorURL')) { - $this->errorURL = $xml->getAttribute('errorURL'); + $this->setErrorURL($xml->getAttribute('errorURL')); } - $this->Extensions = Extensions::getList($xml); + $this->setExtensions(Extensions::getList($xml)); foreach (Utils::xpQuery($xml, './saml_metadata:KeyDescriptor') as $kd) { - $this->KeyDescriptor[] = new KeyDescriptor($kd); + $this->addKeyDescriptor(new KeyDescriptor($kd)); } $organization = Utils::xpQuery($xml, './saml_metadata:Organization'); if (count($organization) > 1) { throw new \Exception('More than one Organization in the entity.'); } elseif (!empty($organization)) { - $this->Organization = new Organization($organization[0]); + $this->setOrganization(new Organization($organization[0])); } foreach (Utils::xpQuery($xml, './saml_metadata:ContactPerson') as $cp) { - $this->contactPersons[] = new ContactPerson($cp); + $this->addContactPerson(new ContactPerson($cp)); } } + /** + * Collect the value of the ID-property + * @return string|null + */ + public function getID() + { + return $this->ID; + } + + /** + * Set the value of the ID-property + * @param string|null $Id + */ + public function setID($Id = null) + { + assert(is_string($Id) || is_null($Id)); + $this->ID = $Id; + } + + /** + * Collect the value of the validUntil-property + * @return int|null + */ + public function getValidUntil() + { + return $this->validUntil; + } + + /** + * Set the value of the validUntil-property + * @param int|null $validUntil + */ + public function setValidUntil($validUntil = null) + { + assert(is_int($validUntil) || is_null($validUntil)); + $this->validUntil = $validUntil; + } + + /** + * Collect the value of the cacheDuration-property + * @return string|null + */ + public function getCacheDuration() + { + return $this->cacheDuration; + } + + /** + * Set the value of the cacheDuration-property + * @param string|null $cacheDuration + */ + public function setCacheDuration($cacheDuration = null) + { + assert(is_string($cacheDuration) || is_null($cacheDuration)); + $this->cacheDuration = $cacheDuration; + } + + /** + * Collect the value of the Extensions-property + * @return \SAML2\XML\Chunk[] + */ + public function getExtensions() + { + return $this->Extensions; + } + + /** + * Set the value of the Extensions-property + * @param array $extensions + */ + public function setExtensions(array $extensions) + { + $this->Extensions = $extensions; + } + + /** + * Set the value of the errorURL-property + * @param string|null $errorURL + */ + public function setErrorURL($errorURL = null) + { + assert(is_string($errorURL) || is_null($errorURL)); + if (!is_null($errorURL) && !filter_var($errorURL, FILTER_VALIDATE_URL)) { + throw new \InvalidArgumentException('Provided argument is not a valid URL.'); + } + $this->errorURL = $errorURL; + } + + /** + * Collect the value of the errorURL-property + * @return string|null + */ + public function getErrorURL() + { + return $this->errorURL; + } + + /** + * Collect the value of the ProtocolSupportEnumeration-property + * @return string[] + */ + public function getProtocolSupportEnumeration() + { + return $this->protocolSupportEnumeration; + } + + /** + * Set the value of the ProtocolSupportEnumeration-property + * @param array $protocols + */ + public function setProtocolSupportEnumeration(array $protocols) + { + $this->protocolSupportEnumeration = $protocols; + } + + /** + * Collect the value of the Organization-property + * @return \SAML2\XML\md\Organization + */ + public function getOrganization() + { + return $this->Organization; + } + + /** + * Set the value of the Organization-property + * @param \SAML2\XML\md\Organization|null $organization + */ + public function setOrganization(Organization $organization = null) + { + $this->Organization = $organization; + } + + + /** + * Collect the value of the ContactPerson-property + * @return \SAML2\XML\md\ContactPerson[] + */ + public function getContactPerson() + { + return $this->ContactPerson; + } + + /** + * Set the value of the ContactPerson-property + * @param array $contactPerson + */ + public function setContactPerson(array $contactPerson) + { + $this->ContactPerson = $contactPerson; + } + + /** + * Add the value to the ContactPerson-property + * @param \SAML2\XML\md\ContactPerson $contactPerson + */ + public function addContactPerson(ContactPerson $contactPerson) + { + $this->ContactPerson[] = $contactPerson; + } + + /** + * Collect the value of the KeyDescriptor-property + * @return \SAML2\XML\md\KeyDescriptor[] + */ + public function getKeyDescriptor() + { + return $this->KeyDescriptor; + } + + /** + * Set the value of the KeyDescriptor-property + * @param array $keyDescriptor + */ + public function setKeyDescriptor(array $keyDescriptor) + { + $this->KeyDescriptor = $keyDescriptor; + } + + /** + * Add the value to the KeyDescriptor-property + * @param \SAML2\XML\md\KeyDescriptor $keyDescriptor + */ + public function addKeyDescriptor(KeyDescriptor $keyDescriptor) + { + $this->KeyDescriptor[] = $keyDescriptor; + } + /** * Add this RoleDescriptor to an EntityDescriptor. * @@ -152,48 +340,48 @@ protected function __construct($elementName, \DOMElement $xml = null) */ protected function toXML(\DOMElement $parent) { - assert(is_null($this->ID) || is_string($this->ID)); - assert(is_null($this->validUntil) || is_int($this->validUntil)); - assert(is_null($this->cacheDuration) || is_string($this->cacheDuration)); - assert(is_array($this->protocolSupportEnumeration)); - assert(is_null($this->errorURL) || is_string($this->errorURL)); - assert(is_array($this->Extensions)); - assert(is_array($this->KeyDescriptor)); - assert(is_null($this->Organization) || $this->Organization instanceof Organization); - assert(is_array($this->ContactPerson)); + assert(is_null($this->getID()) || is_string($this->getID())); + assert(is_null($this->getValidUntil()) || is_int($this->getValidUntil())); + assert(is_null($this->getCacheDuration()) || is_string($this->getcacheDuration())); + assert(is_array($this->getProtocolSupportEnumeration())); + assert(is_null($this->getErrorURL()) || is_string($this->getErrorURL())); + assert(is_array($this->getExtensions())); + assert(is_array($this->getKeyDescriptor())); + assert(is_null($this->getOrganization()) || $this->getOrganization() instanceof Organization); + assert(is_array($this->getContactPerson())); $e = $parent->ownerDocument->createElementNS(Constants::NS_MD, $this->elementName); $parent->appendChild($e); - if (isset($this->ID)) { - $e->setAttribute('ID', $this->ID); + if ($this->getID() !== null) { + $e->setAttribute('ID', $this->getID()); } - if (isset($this->validUntil)) { - $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->validUntil)); + if ($this->getValidUntil() !== null) { + $e->setAttribute('validUntil', gmdate('Y-m-d\TH:i:s\Z', $this->getValidUntil())); } - if (isset($this->cacheDuration)) { - $e->setAttribute('cacheDuration', $this->cacheDuration); + if ($this->getCacheDuration() !== null) { + $e->setAttribute('cacheDuration', $this->getCacheDuration()); } - $e->setAttribute('protocolSupportEnumeration', implode(' ', $this->protocolSupportEnumeration)); + $e->setAttribute('protocolSupportEnumeration', implode(' ', $this->getProtocolSupportEnumeration())); - if (isset($this->errorURL)) { - $e->setAttribute('errorURL', $this->errorURL); + if ($this->getErrorURL() !== null) { + $e->setAttribute('errorURL', $this->getErrorURL()); } - Extensions::addList($e, $this->Extensions); + Extensions::addList($e, $this->getExtensions()); - foreach ($this->KeyDescriptor as $kd) { + foreach ($this->getKeyDescriptor() as $kd) { $kd->toXML($e); } - if (isset($this->Organization)) { - $this->Organization->toXML($e); + if ($this->getOrganization() !== null) { + $this->getOrganization()->toXML($e); } - foreach ($this->ContactPerson as $cp) { + foreach ($this->getContactPerson() as $cp) { $cp->toXML($e); } diff --git a/src/SAML2/XML/md/SPSSODescriptor.php b/src/SAML2/XML/md/SPSSODescriptor.php index e5d3292a4..79014fdda 100644 --- a/src/SAML2/XML/md/SPSSODescriptor.php +++ b/src/SAML2/XML/md/SPSSODescriptor.php @@ -56,18 +56,111 @@ public function __construct(\DOMElement $xml = null) return; } - $this->AuthnRequestsSigned = Utils::parseBoolean($xml, 'AuthnRequestsSigned', null); - $this->WantAssertionsSigned = Utils::parseBoolean($xml, 'WantAssertionsSigned', null); + $this->setAuthnRequestsSigned(Utils::parseBoolean($xml, 'AuthnRequestsSigned', null)); + $this->setWantAssertionsSigned(Utils::parseBoolean($xml, 'WantAssertionsSigned', null)); foreach (Utils::xpQuery($xml, './saml_metadata:AssertionConsumerService') as $ep) { - $this->AssertionConsumerService[] = new IndexedEndpointType($ep); + $this->addAssertionConsumerService(new IndexedEndpointType($ep)); } foreach (Utils::xpQuery($xml, './saml_metadata:AttributeConsumingService') as $acs) { - $this->AttributeConsumingService[] = new AttributeConsumingService($acs); + $this->addAttributeConsumingService(new AttributeConsumingService($acs)); } } + /** + * Collect the value of the AuthnRequestsSigned-property + * @return bool|null + */ + public function getAuthnRequestsSigned() + { + return $this->AuthnRequestsSigned; + } + + /** + * Set the value of the AuthnRequestsSigned-property + * @param bool|null $flag + */ + public function setAuthnRequestsSigned($flag = null) + { + assert(is_bool($flag) || is_null($flag)); + $this->AuthnRequestsSigned = $flag; + } + + /** + * Collect the value of the WantAssertionsSigned-property + * @return bool|null + */ + public function wantAssertionsSigned() + { + return $this->WantAssertionsSigned; + } + + /** + * Set the value of the WantAssertionsSigned-property + * @param bool|null $flag + */ + public function setWantAssertionsSigned($flag = null) + { + assert(is_bool($flag) || is_null($flag)); + $this->WantAssertionsSigned = $flag; + } + + /** + * Collect the value of the AssertionConsumerService-property + * @return array + */ + public function getAssertionConsumerService() + { + return $this->AssertionConsumerService; + } + + /** + * Set the value of the AssertionConsumerService-property + * @param array $acs + */ + public function setAssertionConsumerService(array $acs) + { + $this->AssertionConsumerService = $acs; + } + + /** + * Add the value to the AssertionConsumerService-property + * @param \SAML2\XML\md\IndexedEndpointType $acs + */ + public function addAssertionConsumerService(IndexedEndpointType $acs) + { + $this->AssertionConsumerService[] = $acs; + } + + /** + * Collect the value of the AttributeConsumingService-property + * @return array + */ + public function getAttributeConsumingService() + { + return $this->AttributeConsumingService; + } + + /** + * Add the value to the AttributeConsumingService-property + * @param \SAML2\XML\md\AttributeConsumingService $acs + */ + public function addAttributeConsumingService(AttributeConsumingService $acs) + { + $this->AttributeConsumingService[] = $acs; + } + + /** + * Set the value of the AttributeConsumingService-property + * @param array $acs + */ + public function setAttributeConsumingService(array $acs) + { + $this->AttributeConsumingService = $acs; + } + + /** * Add this SPSSODescriptor to an EntityDescriptor. * @@ -76,30 +169,30 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_null($this->AuthnRequestsSigned) || is_bool($this->AuthnRequestsSigned)); - assert(is_null($this->WantAssertionsSigned) || is_bool($this->WantAssertionsSigned)); - assert(is_array($this->AssertionConsumerService)); - assert(is_array($this->AttributeConsumingService)); + assert(is_null($this->getAuthnRequestsSigned()) || is_bool($this->getAuthnRequestsSigned())); + assert(is_null($this->wantAssertionsSigned()) || is_bool($this->wantAssertionsSigned())); + assert(is_array($this->getAssertionConsumerService())); + assert(is_array($this->getAttributeConsumingService())); $e = parent::toXML($parent); - if ($this->AuthnRequestsSigned === true) { + if ($this->getAuthnRequestsSigned() === true) { $e->setAttribute('AuthnRequestsSigned', 'true'); - } elseif ($this->AuthnRequestsSigned === false) { + } elseif ($this->getAuthnRequestsSigned() === false) { $e->setAttribute('AuthnRequestsSigned', 'false'); } - if ($this->WantAssertionsSigned === true) { + if ($this->wantAssertionsSigned() === true) { $e->setAttribute('WantAssertionsSigned', 'true'); - } elseif ($this->WantAssertionsSigned === false) { + } elseif ($this->wantAssertionsSigned() === false) { $e->setAttribute('WantAssertionsSigned', 'false'); } - foreach ($this->AssertionConsumerService as $ep) { + foreach ($this->getAssertionConsumerService() as $ep) { $ep->toXML($e, 'md:AssertionConsumerService'); } - foreach ($this->AttributeConsumingService as $acs) { + foreach ($this->getAttributeConsumingService() as $acs) { $acs->toXML($e); } } diff --git a/src/SAML2/XML/md/SSODescriptorType.php b/src/SAML2/XML/md/SSODescriptorType.php index 2c3d01304..e32d32c77 100644 --- a/src/SAML2/XML/md/SSODescriptorType.php +++ b/src/SAML2/XML/md/SSODescriptorType.php @@ -65,18 +65,120 @@ protected function __construct($elementName, \DOMElement $xml = null) } foreach (Utils::xpQuery($xml, './saml_metadata:ArtifactResolutionService') as $ep) { - $this->ArtifactResolutionService[] = new IndexedEndpointType($ep); + $this->addArtifactResolutionService(new IndexedEndpointType($ep)); } foreach (Utils::xpQuery($xml, './saml_metadata:SingleLogoutService') as $ep) { - $this->SingleLogoutService[] = new EndpointType($ep); + $this->addSingleLogoutService(new EndpointType($ep)); } foreach (Utils::xpQuery($xml, './saml_metadata:ManageNameIDService') as $ep) { - $this->ManageNameIDService[] = new EndpointType($ep); + $this->addManageNameIDService(new EndpointType($ep)); } - $this->NameIDFormat = Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat'); + $this->setNameIDFormat(Utils::extractStrings($xml, Constants::NS_MD, 'NameIDFormat')); + } + + /** + * Collect the value of the ArtifactResolutionService-property + * @return \SAML2\XML\md\IndexedEndpointType[] + */ + public function getArtifactResolutionService() + { + return $this->ArtifactResolutionService; + } + + /** + * Set the value of the ArtifactResolutionService-property + * @param \SAML2\XML\md\IndexedEndpointType[] $artifactResolutionService + */ + public function setArtifactResolutionService(array $artifactResolutionService) + { + $this->ArtifactResolutionService = $artifactResolutionService; + } + + /** + * Add the value to the ArtifactResolutionService-property + * @param \SAML2\XML\md\IndexedEndpointType $artifactResolutionService + */ + public function addArtifactResolutionService(IndexedEndpointType $artifactResolutionService) + { + assert($artifactResolutionService instanceof IndexedEndpointType); + $this->ArtifactResolutionService[] = $artifactResolutionService; + } + + /** + * Collect the value of the SingleLogoutService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getSingleLogoutService() + { + return $this->SingleLogoutService; + } + + /** + * Set the value of the SingleLogoutService-property + * @param \SAML2\XML\md\EndpointType[] $singleLogoutService + */ + public function setSingleLogoutService(array $singleLogoutService) + { + $this->SingleLogoutService = $singleLogoutService; + } + + /** + * Add the value to the SingleLogoutService-property + * @param \SAML2\XML\md\EndpointType $singleLogoutService + */ + public function addSingleLogoutService(EndpointType $singleLogoutService) + { + assert($singleLogoutService instanceof EndpointType); + $this->SingleLogoutService[] = $singleLogoutService; + } + + /** + * Collect the value of the ManageNameIDService-property + * @return \SAML2\XML\md\EndpointType[] + */ + public function getManageNameIDService() + { + return $this->ManageNameIDService; + } + + /** + * Set the value of the ManageNameIDService-property + * @param \SAML2\XML\md\EndpointType[] $manageNameIDService + */ + public function setManageNameIDService(array $manageNameIDService) + { + $this->ManageNameIDService = $manageNameIDService; + } + + /** + * Add the value to the ManageNameIDService-property + * @param \SAML2\XML\md\EndpointType $manageNameIDService + */ + public function addManageNameIDService(EndpointType $manageNameIDService) + { + assert($manageNameIDService instanceof EndpointType); + $this->ManageNameIDService[] = $manageNameIDService; + } + + /** + * Collect the value of the NameIDFormat-property + * @return string[] + */ + public function getNameIDFormat() + { + return $this->NameIDFormat; + } + + /** + * Set the value of the NameIDFormat-property + * @param string[] $nameIDFormat + */ + public function setNameIDFormat(array $nameIDFormat) + { + $this->NameIDFormat = $nameIDFormat; } /** @@ -87,26 +189,26 @@ protected function __construct($elementName, \DOMElement $xml = null) */ protected function toXML(\DOMElement $parent) { - assert(is_array($this->ArtifactResolutionService)); - assert(is_array($this->SingleLogoutService)); - assert(is_array($this->ManageNameIDService)); - assert(is_array($this->NameIDFormat)); + assert(is_array($this->getArtifactResolutionService())); + assert(is_array($this->getSingleLogoutService())); + assert(is_array($this->getManageNameIDService())); + assert(is_array($this->getNameIDFormat())); $e = parent::toXML($parent); - foreach ($this->ArtifactResolutionService as $ep) { + foreach ($this->getArtifactResolutionService() as $ep) { $ep->toXML($e, 'md:ArtifactResolutionService'); } - foreach ($this->SingleLogoutService as $ep) { + foreach ($this->getSingleLogoutService() as $ep) { $ep->toXML($e, 'md:SingleLogoutService'); } - foreach ($this->ManageNameIDService as $ep) { + foreach ($this->getManageNameIDService() as $ep) { $ep->toXML($e, 'md:ManageNameIDService'); } - Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->NameIDFormat); + Utils::addStrings($e, Constants::NS_MD, 'md:NameIDFormat', false, $this->getNameIDFormat()); return $e; } diff --git a/src/SAML2/XML/mdattr/EntityAttributes.php b/src/SAML2/XML/mdattr/EntityAttributes.php index 896a4d839..a605f6972 100644 --- a/src/SAML2/XML/mdattr/EntityAttributes.php +++ b/src/SAML2/XML/mdattr/EntityAttributes.php @@ -41,13 +41,41 @@ public function __construct(\DOMElement $xml = null) foreach (Utils::xpQuery($xml, './saml_assertion:Attribute|./saml_assertion:Assertion') as $node) { if ($node->localName === 'Attribute') { - $this->children[] = new Attribute($node); + $this->addChildren(new Attribute($node)); } else { - $this->children[] = new Chunk($node); + $this->addChildren(new Chunk($node)); } } } + /** + * Collect the value of the children-property + * @return (\SAML2\XML\Chunk|\SAML2\XML\saml\Attribute)[] + */ + public function getChildren() + { + return $this->children; + } + + /** + * Set the value of the childen-property + * @param array $children + */ + public function setChildren(array $children) + { + $this->children = $children; + } + + /** + * Add the value to the children-property + * @param \SAML2\XML\Chunk|\SAML2\XML\saml\Attribute $child + */ + public function addChildren($child) + { + assert($child instanceof Chunk || $child instanceof Attribute); + $this->children[] = $child; + } + /** * Convert this EntityAttributes to XML. * @@ -56,7 +84,7 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->children)); + assert(is_array($this->getChildren())); $doc = $parent->ownerDocument; @@ -64,7 +92,7 @@ public function toXML(\DOMElement $parent) $parent->appendChild($e); /** @var \SAML2\XML\saml\Attribute|\SAML2\XML\Chunk $child */ - foreach ($this->children as $child) { + foreach ($this->getChildren() as $child) { $child->toXML($e); } diff --git a/src/SAML2/XML/mdrpi/PublicationInfo.php b/src/SAML2/XML/mdrpi/PublicationInfo.php index 14790ad55..4a66ef0bb 100644 --- a/src/SAML2/XML/mdrpi/PublicationInfo.php +++ b/src/SAML2/XML/mdrpi/PublicationInfo.php @@ -57,17 +57,92 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('publisher')) { throw new \Exception('Missing required attribute "publisher" in mdrpi:PublicationInfo element.'); } - $this->publisher = $xml->getAttribute('publisher'); + $this->setPublisher($xml->getAttribute('publisher')); if ($xml->hasAttribute('creationInstant')) { - $this->creationInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('creationInstant')); + $this->setCreationInstant(Utils::xsDateTimeToTimestamp($xml->getAttribute('creationInstant'))); } if ($xml->hasAttribute('publicationId')) { - $this->publicationId = $xml->getAttribute('publicationId'); + $this->setPublicationId($xml->getAttribute('publicationId')); } - $this->UsagePolicy = Utils::extractLocalizedStrings($xml, Common::NS_MDRPI, 'UsagePolicy'); + $this->setUsagePolicy(Utils::extractLocalizedStrings($xml, Common::NS_MDRPI, 'UsagePolicy')); + } + + /** + * Collect the value of the publisher-property + * @return string + */ + public function getPublisher() + { + return $this->publisher; + } + + /** + * Collect the value of the creationInstant-property + * @return int|null + */ + public function getCreationInstant() + { + return $this->creationInstant; + } + + /** + * Collect the value of the publicationId-property + * @return string|null + */ + public function getPublicationId() + { + return $this->publicationId; + } + + /** + * Collect the value of the UsagePolicy-property + * @return array + */ + public function getUsagePolicy() + { + return $this->UsagePolicy; + } + + /** + * Set the value of the publisher-property + * @param string $publisher + */ + public function setPublisher($publisher) + { + assert(is_string($publisher)); + $this->publisher = $publisher; + } + + /** + * Set the value of the creationInstant-property + * @param int|null $creationInstant + */ + public function setCreationInstant($creationInstant = null) + { + assert(is_int($creationInstant) || is_null($creationInstant)); + $this->creationInstant = $creationInstant; + } + + /** + * Set the value of the publicationId-property + * @param string|null $publicationId + */ + public function setPublicationId($publicationId = null) + { + assert(is_string($publicationId) || is_null($publicationId)); + $this->publicationId = $publicationId; + } + + /** + * Set the value of the UsagePolicy-property + * @param array $usagePolicy + */ + public function setUsagePolicy(array $usagePolicy) + { + $this->UsagePolicy = $usagePolicy; } /** @@ -78,27 +153,27 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->publisher)); - assert(is_int($this->creationInstant) || is_null($this->creationInstant)); - assert(is_string($this->publicationId) || is_null($this->publicationId)); - assert(is_array($this->UsagePolicy)); + assert(is_string($this->getPublisher())); + assert(is_int($this->getCreationInstant()) || is_null($this->getCreationInstant())); + assert(is_string($this->getPublicationId()) || is_null($this->getPublicationId())); + assert(is_array($this->getUsagePolicy())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS_MDRPI, 'mdrpi:PublicationInfo'); $parent->appendChild($e); - $e->setAttribute('publisher', $this->publisher); + $e->setAttribute('publisher', $this->getPublisher()); - if ($this->creationInstant !== null) { - $e->setAttribute('creationInstant', gmdate('Y-m-d\TH:i:s\Z', $this->creationInstant)); + if ($this->getCreationInstant() !== null) { + $e->setAttribute('creationInstant', gmdate('Y-m-d\TH:i:s\Z', $this->getCreationInstant())); } - if ($this->publicationId !== null) { - $e->setAttribute('publicationId', $this->publicationId); + if ($this->getPublicationId() !== null) { + $e->setAttribute('publicationId', $this->getPublicationId()); } - Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:UsagePolicy', true, $this->UsagePolicy); + Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:UsagePolicy', true, $this->getUsagePolicy()); return $e; } diff --git a/src/SAML2/XML/mdrpi/RegistrationInfo.php b/src/SAML2/XML/mdrpi/RegistrationInfo.php index b4885e64c..e80a72a05 100644 --- a/src/SAML2/XML/mdrpi/RegistrationInfo.php +++ b/src/SAML2/XML/mdrpi/RegistrationInfo.php @@ -50,13 +50,69 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('registrationAuthority')) { throw new \Exception('Missing required attribute "registrationAuthority" in mdrpi:RegistrationInfo element.'); } - $this->registrationAuthority = $xml->getAttribute('registrationAuthority'); + $this->setRegistrationAuthority($xml->getAttribute('registrationAuthority')); if ($xml->hasAttribute('registrationInstant')) { - $this->registrationInstant = Utils::xsDateTimeToTimestamp($xml->getAttribute('registrationInstant')); + $this->setRegistrationInstant(Utils::xsDateTimeToTimestamp($xml->getAttribute('registrationInstant'))); } - $this->RegistrationPolicy = Utils::extractLocalizedStrings($xml, Common::NS_MDRPI, 'RegistrationPolicy'); + $this->setRegistrationPolicy(Utils::extractLocalizedStrings($xml, Common::NS_MDRPI, 'RegistrationPolicy')); + } + + /** + * Collect the value of the RegistrationAuthority-property + * @return string + */ + public function getRegistrationAuthority() + { + return $this->registrationAuthority; + } + + /** + * Set the value of the registrationAuthority-property + * @param string $registrationAuthority + */ + public function setRegistrationAuthority($registrationAuthority) + { + assert(is_string($registrationAuthority)); + $this->registrationAuthority = $registrationAuthority; + } + + /** + * Collect the value of the registrationInstant-property + * @return int|null + */ + public function getRegistrationInstant() + { + return $this->registrationInstant; + } + + /** + * Set the value of the registrationInstant-property + * @param int|null $registrationInstant + */ + public function setRegistrationInstant($registrationInstant = null) + { + assert(is_int($registrationInstant) || is_null($registrationInstant)); + $this->registrationInstant = $registrationInstant; + } + + /** + * Collect the value of the RegistrationPolicy-property + * @return array + */ + public function getRegistrationPolicy() + { + return $this->RegistrationPolicy; + } + + /** + * Set the value of the RegistrationPolicy-property + * @param array $registrationPolicy + */ + public function setRegistrationPolicy(array $registrationPolicy) + { + $this->RegistrationPolicy = $registrationPolicy; } /** @@ -67,11 +123,12 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->registrationAuthority)); - assert(is_int($this->registrationInstant) || is_null($this->registrationInstant)); - assert(is_array($this->RegistrationPolicy)); + assert(is_string($this->getRegistrationAuthority())); + assert(is_int($this->getRegistrationInstant()) || is_null($this->getRegistrationInstant())); + assert(is_array($this->getRegistrationPolicy())); - if (empty($this->registrationAuthority)) { + $registrationAuthority = $this->getRegistrationAuthority(); + if (empty($registrationAuthority)) { throw new \Exception('Missing required registration authority.'); } @@ -80,13 +137,13 @@ public function toXML(\DOMElement $parent) $e = $doc->createElementNS(Common::NS_MDRPI, 'mdrpi:RegistrationInfo'); $parent->appendChild($e); - $e->setAttribute('registrationAuthority', $this->registrationAuthority); + $e->setAttribute('registrationAuthority', $this->getRegistrationAuthority()); - if ($this->registrationInstant !== null) { - $e->setAttribute('registrationInstant', gmdate('Y-m-d\TH:i:s\Z', $this->registrationInstant)); + if ($this->getRegistrationInstant() !== null) { + $e->setAttribute('registrationInstant', gmdate('Y-m-d\TH:i:s\Z', $this->getRegistrationInstant())); } - Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:RegistrationPolicy', true, $this->RegistrationPolicy); + Utils::addStrings($e, Common::NS_MDRPI, 'mdrpi:RegistrationPolicy', true, $this->getRegistrationPolicy()); return $e; } diff --git a/src/SAML2/XML/mdui/DiscoHints.php b/src/SAML2/XML/mdui/DiscoHints.php index e012aec35..028fd64af 100644 --- a/src/SAML2/XML/mdui/DiscoHints.php +++ b/src/SAML2/XML/mdui/DiscoHints.php @@ -54,15 +54,97 @@ public function __construct(\DOMElement $xml = null) return; } - $this->IPHint = Utils::extractStrings($xml, Common::NS, 'IPHint'); - $this->DomainHint = Utils::extractStrings($xml, Common::NS, 'DomainHint'); - $this->GeolocationHint = Utils::extractStrings($xml, Common::NS, 'GeolocationHint'); + $this->setIPHint(Utils::extractStrings($xml, Common::NS, 'IPHint')); + $this->setDomainHint(Utils::extractStrings($xml, Common::NS, 'DomainHint')); + $this->setGeolocationHint(Utils::extractStrings($xml, Common::NS, 'GeolocationHint')); foreach (Utils::xpQuery($xml, "./*[namespace-uri()!='".Common::NS."']") as $node) { - $this->children[] = new Chunk($node); + $this->addChildren(new Chunk($node)); } } + /** + * Collect the value of the IPHint-property + * @return string[] + */ + public function getIPHint() + { + return $this->IPHint; + } + + /** + * Set the value of the IPHint-property + * @param string[] $hints + */ + public function setIPHint(array $hints) + { + $this->IPHint = $hints; + } + + /** + * Collect the value of the DomainHint-property + * @return string[] + */ + public function getDomainHint() + { + return $this->DomainHint; + } + + /** + * Set the value of the DomainHint-property + * @param string[] $hints + */ + public function setDomainHint(array $hints) + { + $this->DomainHint = $hints; + } + + /** + * Collect the value of the GeolocationHint-property + * @return string[] + */ + public function getGeolocationHint() + { + return $this->GeolocationHint; + } + + /** + * Set the value of the GeolocationHint-property + * @param string[] $hints + */ + public function setGeolocationHint(array $hints) + { + $this->GeolocationHint = $hints; + } + + /** + * Collect the value of the children-property + * @return \SAML2\XML\Chunk[] + */ + public function getChildren() + { + return $this->children; + } + + /** + * Set the value of the childen-property + * @param array $children + */ + public function setChildren(array $children) + { + $this->children = $children; + } + + /** + * Add the value to the children-property + * @param \SAML2\XML\Chunk $child + */ + public function addChildren(Chunk $child) + { + assert($child instanceof Chunk); + $this->children[] = $child; + } + /** * Convert this DiscoHints to XML. * @@ -71,29 +153,29 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->IPHint)); - assert(is_array($this->DomainHint)); - assert(is_array($this->GeolocationHint)); - assert(is_array($this->children)); - - if (!empty($this->IPHint) - || !empty($this->DomainHint) - || !empty($this->GeolocationHint) - || !empty($this->children)) { + assert(is_array($IPHint = $this->getIPHint())); + assert(is_array($DomainHint = $this->getDomainHint())); + assert(is_array($GeolocationHint = $this->getGeolocationHint())); + assert(is_array($children = $this->getChildren())); + + if (!empty($IPHint) + || !empty($DomainHint) + || !empty($GeolocationHint) + || !empty($children)) { $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'mdui:DiscoHints'); $parent->appendChild($e); - if (!empty($this->children)) { - foreach ($this->children as $child) { + if (!empty($children)) { + foreach ($this->getChildren() as $child) { $child->toXML($e); } } - Utils::addStrings($e, Common::NS, 'mdui:IPHint', false, $this->IPHint); - Utils::addStrings($e, Common::NS, 'mdui:DomainHint', false, $this->DomainHint); - Utils::addStrings($e, Common::NS, 'mdui:GeolocationHint', false, $this->GeolocationHint); + Utils::addStrings($e, Common::NS, 'mdui:IPHint', false, $this->getIPHint()); + Utils::addStrings($e, Common::NS, 'mdui:DomainHint', false, $this->getDomainHint()); + Utils::addStrings($e, Common::NS, 'mdui:GeolocationHint', false, $this->getGeolocationHint()); return $e; } diff --git a/src/SAML2/XML/mdui/Keywords.php b/src/SAML2/XML/mdui/Keywords.php index 98d040a6f..858e3a06d 100644 --- a/src/SAML2/XML/mdui/Keywords.php +++ b/src/SAML2/XML/mdui/Keywords.php @@ -44,11 +44,58 @@ public function __construct(\DOMElement $xml = null) if (!is_string($xml->textContent) || !strlen($xml->textContent)) { throw new \Exception('Missing value for Keywords.'); } - $this->Keywords = []; + $this->setKeywords([]); foreach (explode(' ', $xml->textContent) as $keyword) { - $this->Keywords[] = str_replace('+', ' ', $keyword); + $this->addKeyword(str_replace('+', ' ', $keyword)); } - $this->lang = $xml->getAttribute('xml:lang'); + $this->setLanguage($xml->getAttribute('xml:lang')); + } + + /** + * Collect the value of the lang-property + * @return string + */ + public function getLanguage() + { + return $this->lang; + } + + /** + * Set the value of the lang-property + * @param string $lang + */ + public function setLanguage($lang) + { + assert(is_string($lang) || is_null($lang)); + $this->lang = $lang; + } + + /** + * Collect the value of the Keywords-property + * @return string[] + */ + public function getKeywords() + { + return $this->Keywords; + } + + /** + * Set the value of the Keywords-property + * @param string[] $keywords + */ + public function setKeywords(array $keywords) + { + $this->Keywords = $keywords; + } + + /** + * Add the value to the Keywords-property + * @param string $keyword + */ + public function addKeyword($keyword) + { + assert(is_string($keyword)); + $this->Keywords[] = $keyword; } /** @@ -60,19 +107,19 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->lang)); - assert(is_array($this->Keywords)); + assert(is_string($this->getLanguage())); + assert(is_array($this->getKeywords())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'mdui:Keywords'); - $e->setAttribute('xml:lang', $this->lang); + $e->setAttribute('xml:lang', $this->getLanguage()); $value = ''; - foreach ($this->Keywords as $keyword) { + foreach ($this->getKeywords() as $keyword) { if (strpos($keyword, "+") !== false) { throw new \Exception('Keywords may not contain a "+" character.'); } - $value .= str_replace(' ', '+', $keyword) . ' '; + $value .= str_replace(' ', '+', $keyword).' '; } $value = rtrim($value); $e->appendChild($doc->createTextNode($value)); diff --git a/src/SAML2/XML/mdui/Logo.php b/src/SAML2/XML/mdui/Logo.php index 9764fde33..5fba2c431 100644 --- a/src/SAML2/XML/mdui/Logo.php +++ b/src/SAML2/XML/mdui/Logo.php @@ -59,10 +59,89 @@ public function __construct(\DOMElement $xml = null) if (!is_string($xml->textContent) || !strlen($xml->textContent)) { throw new \Exception('Missing url value for Logo.'); } - $this->url = $xml->textContent; - $this->width = (int) $xml->getAttribute('width'); - $this->height = (int) $xml->getAttribute('height'); - $this->lang = $xml->hasAttribute('xml:lang') ? $xml->getAttribute('xml:lang') : null; + $this->setUrl($xml->textContent); + $this->setWidth(intval($xml->getAttribute('width'))); + $this->setHeight(intval($xml->getAttribute('height'))); + $this->setLanguage($xml->hasAttribute('xml:lang') ? $xml->getAttribute('xml:lang') : null); + } + + /** + * Collect the value of the url-property + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set the value of the url-property + * @param string $url + */ + public function setUrl($url) + { + assert(is_string($url)); + if (!filter_var($url, FILTER_VALIDATE_URL)) { + throw new \InvalidArgumentException('Provided argument is not a valid URL.'); + } + $this->url = $url; + } + + /** + * Collect the value of the lang-property + * @return string + */ + public function getLanguage() + { + return $this->lang; + } + + /** + * Set the value of the lang-property + * @param string $lang + */ + public function setLanguage($lang) + { + assert(is_string($lang)); + $this->lang = $lang; + } + + /** + * Collect the value of the height-property + * @return int + */ + public function getHeight() + { + return $this->height; + } + + /** + * Set the value of the height-property + * @param int $height + */ + public function setHeight($height) + { + assert(is_int($height)); + $this->height = $height; + } + + /** + * Collect the value of the width-property + * @return int + */ + public function getWidth() + { + return $this->width; + } + + /** + * Set the value of the width-property + * @param int $width + */ + public function setWidth($width) + { + assert(is_int($width)); + $this->width = $width; } /** @@ -73,18 +152,18 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_int($this->width)); - assert(is_int($this->height)); - assert(is_string($this->url)); + assert(is_int($this->getWidth())); + assert(is_int($this->getHeight())); + assert(is_string($this->getUrl())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'mdui:Logo'); - $e->appendChild($doc->createTextNode($this->url)); - $e->setAttribute('width', (int) $this->width); - $e->setAttribute('height', (int) $this->height); - if (isset($this->lang)) { - $e->setAttribute('xml:lang', $this->lang); + $e->appendChild($doc->createTextNode($this->getUrl())); + $e->setAttribute('width', intval($this->getWidth())); + $e->setAttribute('height', intval($this->getHeight())); + if ($this->getLanguage() !== null) { + $e->setAttribute('xml:lang', $this->getLanguage()); } $parent->appendChild($e); diff --git a/src/SAML2/XML/mdui/UIInfo.php b/src/SAML2/XML/mdui/UIInfo.php index f86961b23..c1faa7ef6 100644 --- a/src/SAML2/XML/mdui/UIInfo.php +++ b/src/SAML2/XML/mdui/UIInfo.php @@ -75,27 +75,180 @@ public function __construct(\DOMElement $xml = null) return; } - $this->DisplayName = Utils::extractLocalizedStrings($xml, Common::NS, 'DisplayName'); - $this->Description = Utils::extractLocalizedStrings($xml, Common::NS, 'Description'); - $this->InformationURL = Utils::extractLocalizedStrings($xml, Common::NS, 'InformationURL'); - $this->PrivacyStatementURL = Utils::extractLocalizedStrings($xml, Common::NS, 'PrivacyStatementURL'); + $this->setDisplayName(Utils::extractLocalizedStrings($xml, Common::NS, 'DisplayName')); + $this->setDescription(Utils::extractLocalizedStrings($xml, Common::NS, 'Description')); + $this->setInformationURL(Utils::extractLocalizedStrings($xml, Common::NS, 'InformationURL')); + $this->setPrivacyStatementURL(Utils::extractLocalizedStrings($xml, Common::NS, 'PrivacyStatementURL')); foreach (Utils::xpQuery($xml, './*') as $node) { if ($node->namespaceURI === Common::NS) { switch ($node->localName) { case 'Keywords': - $this->Keywords[] = new Keywords($node); + $this->addKeyword(new Keywords($node)); break; case 'Logo': - $this->Logo[] = new Logo($node); + $this->addLogo(new Logo($node)); break; } } else { - $this->children[] = new Chunk($node); + $this->addChildren(new Chunk($node)); } } } + /** + * Collect the value of the Keywords-property + * @return \SAML2\XML\mdui\Keywords[] + */ + public function getKeywords() + { + return $this->Keywords; + } + + /** + * Set the value of the Keywords-property + * @param \SAML2\XML\mdui\Keywords[] $keywords + */ + public function setKeywords(array $keywords) + { + $this->Keywords = $keywords; + } + + /** + * Add the value to the Keywords-property + * @param \SAML2\XML\mdui\Keywords $keyword + */ + public function addKeyword(Keywords $keyword) + { + $this->Keywords[] = $keyword; + } + + /** + * Collect the value of the DisplayName-property + * @return string[] + */ + public function getDisplayName() + { + return $this->DisplayName; + } + + /** + * Set the value of the DisplayName-property + * @param array $displayName + */ + public function setDisplayName(array $displayName) + { + $this->DisplayName = $displayName; + } + + /** + * Collect the value of the Description-property + * @return string[] + */ + public function getDescription() + { + return $this->Description; + } + + /** + * Set the value of the Description-property + * @param array $description + */ + public function setDescription(array $description) + { + $this->Description = $description; + } + + /** + * Collect the value of the InformationURL-property + * @return string[] + */ + public function getInformationURL() + { + return $this->InformationURL; + } + + /** + * Set the value of the InformationURL-property + * @param array $informationURL + */ + public function setInformationURL(array $informationURL) + { + $this->InformationURL = $informationURL; + } + + /** + * Collect the value of the PrivacyStatementURL-property + * @return string[] + */ + public function getPrivacyStatementURL() + { + return $this->PrivacyStatementURL; + } + + /** + * Set the value of the PrivacyStatementURL-property + * @param array $privacyStatementURL + */ + public function setPrivacyStatementURL(array $privacyStatementURL) + { + $this->PrivacyStatementURL = $privacyStatementURL; + } + + /** + * Collect the value of the Logo-property + * @return \SAML2\XML\mdui\Logo[] + */ + public function getLogo() + { + return $this->Logo; + } + + /** + * Set the value of the Logo-property + * @param \SAML2\XML\mdui\Logo $logo + */ + public function setLogo(array $logo) + { + $this->Logo = $logo; + } + + /** + * Add the value to the Logo-property + * @param \SAML2\XML\mdui\Logo $logo + */ + public function addLogo(Logo $logo) + { + $this->Logo[] = $logo; + } + + /** + * Collect the value of the children-property + * @return \SAML2\XML\Chunk[] + */ + public function getChildren() + { + return $this->children; + } + + /** + * Set the value of the childen-property + * @param array $children + */ + public function setChildren(array $children) + { + $this->children = $children; + } + + /** + * Add the value to the children-property + * @param \SAML2\XML\Chunk $child + */ + public function addChildren(Chunk $child) + { + $this->children[] = $child; + } + /** * Convert this UIInfo to XML. * @@ -104,45 +257,46 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_array($this->DisplayName)); - assert(is_array($this->InformationURL)); - assert(is_array($this->PrivacyStatementURL)); - assert(is_array($this->Keywords)); - assert(is_array($this->Logo)); - assert(is_array($this->children)); + assert(is_array($displayName = $this->getDisplayName())); + assert(is_array($description = $this->getDescription())); + assert(is_array($informationURL = $this->getInformationURL())); + assert(is_array($privacyStatementURL = $this->getPrivacyStatementURL())); + assert(is_array($keywords = $this->getKeywords())); + assert(is_array($logo = $this->getLogo())); + assert(is_array($children = $this->getChildren())); $e = null; - if (!empty($this->DisplayName) - || !empty($this->Description) - || !empty($this->InformationURL) - || !empty($this->PrivacyStatementURL) - || !empty($this->Keywords) - || !empty($this->Logo) - || !empty($this->children)) { + if (!empty($displayName) + || !empty($description) + || !empty($informationURL) + || !empty($privacyStatementURL) + || !empty($keywords) + || !empty($logo) + || !empty($children)) { $doc = $parent->ownerDocument; $e = $doc->createElementNS(Common::NS, 'mdui:UIInfo'); $parent->appendChild($e); - Utils::addStrings($e, Common::NS, 'mdui:DisplayName', true, $this->DisplayName); - Utils::addStrings($e, Common::NS, 'mdui:Description', true, $this->Description); - Utils::addStrings($e, Common::NS, 'mdui:InformationURL', true, $this->InformationURL); - Utils::addStrings($e, Common::NS, 'mdui:PrivacyStatementURL', true, $this->PrivacyStatementURL); + Utils::addStrings($e, Common::NS, 'mdui:DisplayName', true, $this->getDisplayName()); + Utils::addStrings($e, Common::NS, 'mdui:Description', true, $this->getDescription()); + Utils::addStrings($e, Common::NS, 'mdui:InformationURL', true, $this->getInformationURL()); + Utils::addStrings($e, Common::NS, 'mdui:PrivacyStatementURL', true, $this->getPrivacyStatementURL()); - if (!empty($this->Keywords)) { - foreach ($this->Keywords as $child) { + if ($this->getKeywords() !== null) { + foreach ($this->getKeywords() as $child) { $child->toXML($e); } } - if (!empty($this->Logo)) { - foreach ($this->Logo as $child) { + if ($this->getLogo() !== null) { + foreach ($this->getLogo() as $child) { $child->toXML($e); } } - if (!empty($this->children)) { - foreach ($this->children as $child) { + if ($this->getChildren() !== null) { + foreach ($this->getChildren() as $child) { $child->toXML($e); } } diff --git a/src/SAML2/XML/saml/Attribute.php b/src/SAML2/XML/saml/Attribute.php index 0b5f38659..b1c511084 100644 --- a/src/SAML2/XML/saml/Attribute.php +++ b/src/SAML2/XML/saml/Attribute.php @@ -57,21 +57,105 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('Name')) { throw new \Exception('Missing Name on Attribute.'); } - $this->Name = $xml->getAttribute('Name'); + $this->setName($xml->getAttribute('Name')); if ($xml->hasAttribute('NameFormat')) { - $this->NameFormat = $xml->getAttribute('NameFormat'); + $this->setNameFormat($xml->getAttribute('NameFormat')); } if ($xml->hasAttribute('FriendlyName')) { - $this->FriendlyName = $xml->getAttribute('FriendlyName'); + $this->setFriendlyName($xml->getAttribute('FriendlyName')); } foreach (Utils::xpQuery($xml, './saml_assertion:AttributeValue') as $av) { - $this->AttributeValue[] = new AttributeValue($av); + $this->addAttributeValue(new AttributeValue($av)); } } + /** + * Collect the value of the Name-property + * @return string + */ + public function getName() + { + return $this->Name; + } + + /** + * Set the value of the Name-property + * @param string $name + */ + public function setName($name) + { + assert(is_string($name)); + $this->Name = $name; + } + + /** + * Collect the value of the NameFormat-property + * @return string|null + */ + public function getNameFormat() + { + return $this->NameFormat; + } + + /** + * Set the value of the NameFormat-property + * @param string|null $nameFormat + */ + public function setNameFormat($nameFormat = null) + { + assert(is_string($nameFormat) || is_null($nameFormat)); + $this->NameFormat = $nameFormat; + } + + /** + * Collect the value of the FriendlyName-property + * @return string|null + */ + public function getFriendlyName() + { + return $this->FriendlyName; + } + + /** + * Set the value of the FriendlyName-property + * @param string|null $friendlyName + */ + public function setFriendlyName($friendlyName = null) + { + assert(is_string($friendlyName) || is_null($friendlyName)); + $this->FriendlyName = $friendlyName; + } + + /** + * Collect the value of the AttributeValue-property + * @return \SAML2\XML\saml\AttributeValue[] + */ + public function getAttributeValue() + { + return $this->AttributeValue; + } + + /** + * Set the value of the AttributeValue-property + * @param array $attributeValue + */ + public function setAttributeValue(array $attributeValue) + { + $this->AttributeValue = $attributeValue; + } + + /** + * Add the value to the AttributeValue-property + * @param \SAML2\XML\saml\AttributeValue $attributeValue + */ + public function addAttributeValue(AttributeValue $attributeValue) + { + $this->AttributeValue[] = $attributeValue; + } + /** * Internal implementation of toXML. * This function allows RequestedAttribute to specify the element name and namespace. @@ -81,29 +165,30 @@ public function __construct(\DOMElement $xml = null) * @param string $name The name of the element. * @return \DOMElement */ + protected function toXMLInternal(\DOMElement $parent, $namespace, $name) { assert(is_string($namespace)); assert(is_string($name)); - assert(is_string($this->Name)); - assert(is_null($this->NameFormat) || is_string($this->NameFormat)); - assert(is_null($this->FriendlyName) || is_string($this->FriendlyName)); - assert(is_array($this->AttributeValue)); + assert(is_string($this->getName())); + assert(is_null($this->getNameFormat()) || is_string($this->getNameFormat())); + assert(is_null($this->getFriendlyName()) || is_string($this->getFriendlyName())); + assert(is_array($this->getAttributeValue())); $e = $parent->ownerDocument->createElementNS($namespace, $name); $parent->appendChild($e); - $e->setAttribute('Name', $this->Name); + $e->setAttribute('Name', $this->getName()); - if (isset($this->NameFormat)) { + if ($this->getNameFormat() !== null) { $e->setAttribute('NameFormat', $this->NameFormat); } - if (isset($this->FriendlyName)) { - $e->setAttribute('FriendlyName', $this->FriendlyName); + if ($this->FriendlyName !== null) { + $e->setAttribute('FriendlyName', $this->getFriendlyName()); } - foreach ($this->AttributeValue as $av) { + foreach ($this->getAttributeValue() as $av) { $av->toXML($e); } diff --git a/src/SAML2/XML/saml/AttributeValue.php b/src/SAML2/XML/saml/AttributeValue.php index a4e7e2578..df9e00750 100644 --- a/src/SAML2/XML/saml/AttributeValue.php +++ b/src/SAML2/XML/saml/AttributeValue.php @@ -34,28 +34,44 @@ public function __construct($value) if (is_string($value)) { $doc = DOMDocumentFactory::create(); - $this->element = $doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue'); - $this->element->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:string'); - $this->element->appendChild($doc->createTextNode($value)); + $this->setElement($doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue')); + $this->getElement()->setAttributeNS(Constants::NS_XSI, 'xsi:type', 'xs:string'); + $this->getElement()->appendChild($doc->createTextNode($value)); /* Make sure that the xs-namespace is available in the AttributeValue (for xs:string). */ - $this->element->setAttributeNS(Constants::NS_XS, 'xs:tmp', 'tmp'); - $this->element->removeAttributeNS(Constants::NS_XS, 'tmp'); - + $this->getElement()->setAttributeNS(Constants::NS_XS, 'xs:tmp', 'tmp'); + $this->getElement()->removeAttributeNS(Constants::NS_XS, 'tmp'); return; } if ($value->namespaceURI === Constants::NS_SAML && $value->localName === 'AttributeValue') { - $this->element = Utils::copyElement($value); - + $this->setElement(Utils::copyElement($value)); return; } $doc = DOMDocumentFactory::create(); - $this->element = $doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue'); + $this->setElement($doc->createElementNS(Constants::NS_SAML, 'saml:AttributeValue')); Utils::copyElement($value, $this->element); } + /** + * Collect the value of the element-property + * @return \DOMElement + */ + public function getElement() + { + return $this->element; + } + + /** + * Set the value of the element-property + * @param \DOMElement $element + */ + public function setElement(\DOMElement $element) + { + $this->element = $element; + } + /** * Append this attribute value to an element. * @@ -64,12 +80,10 @@ public function __construct($value) */ public function toXML(\DOMElement $parent) { - assert($this->element instanceof \DOMElement); - assert($this->element->namespaceURI === \SAML2\Constants::NS_SAML && $this->element->localName === "AttributeValue"); - - $v = Utils::copyElement($this->element, $parent); + assert($this->getElement() instanceof \DOMElement); + assert($this->getElement()->namespaceURI === \SAML2\Constants::NS_SAML && $this->element->localName === "AttributeValue"); - return $v; + return Utils::copyElement($this->getElement(), $parent); } /** @@ -89,12 +103,12 @@ public function getString() */ public function __toString() { - assert($this->element instanceof \DOMElement); + assert($this->getElement() instanceof \DOMElement); - $doc = $this->element->ownerDocument; + $doc = $this->getElement()->ownerDocument; $ret = ''; - foreach ($this->element->childNodes as $c) { + foreach ($this->getElement()->childNodes as $c) { $ret .= $doc->saveXML($c); } @@ -109,7 +123,7 @@ public function __toString() */ public function serialize() { - return serialize($this->element->ownerDocument->saveXML($this->element)); + return serialize($this->getElement()->ownerDocument->saveXML($this->getElement())); } @@ -121,6 +135,6 @@ public function serialize() public function unserialize($serialized) { $doc = DOMDocumentFactory::fromString(unserialize($serialized)); - $this->element = $doc->documentElement; + $this->setElement($doc->documentElement); } } diff --git a/src/SAML2/XML/saml/BaseIDType.php b/src/SAML2/XML/saml/BaseIDType.php index 73b9348a9..2ad03a4c5 100644 --- a/src/SAML2/XML/saml/BaseIDType.php +++ b/src/SAML2/XML/saml/BaseIDType.php @@ -62,14 +62,51 @@ public function __construct(\DOMElement $xml = null) $this->element = $xml; if ($xml->hasAttribute('NameQualifier')) { - $this->NameQualifier = $xml->getAttribute('NameQualifier'); + $this->setNameQualifier($xml->getAttribute('NameQualifier')); } if ($xml->hasAttribute('SPNameQualifier')) { - $this->SPNameQualifier = $xml->getAttribute('SPNameQualifier'); + $this->setSPNameQualifier($xml->getAttribute('SPNameQualifier')); } } + /** + * Collect the value of the NameQualifier-property + * @return string|null + */ + public function getNameQualifier() + { + return $this->NameQualifier; + } + + /** + * Set the value of the NameQualifier-property + * @param string|null $nameQualifier + */ + public function setNameQualifier($nameQualifier = null) + { + assert(is_string($nameQualifier) || is_null($nameQualifier)); + $this->NameQualifier = $nameQualifier; + } + + /** + * Collect the value of the SPNameQualifier-property + * @return string|null + */ + public function getSPNameQualifier() + { + return $this->SPNameQualifier; + } + + /** + * Set the value of the SPNameQualifier-property + * @param string|null $spNameQualifier + */ + public function setSPNameQualifier($spNameQualifier = null) + { + assert(is_string($spNameQualifier) || is_null($spNameQualifier)); + $this->SPNameQualifier = $spNameQualifier; + } /** * Convert this BaseID to XML. @@ -79,8 +116,8 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent = null) { - assert(is_string($this->NameQualifier) || is_null($this->NameQualifier)); - assert(is_string($this->SPNameQualifier) || is_null($this->SPNameQualifier)); + assert(is_string($this->getNameQualifier()) || is_null($this->getNameQualifier())); + assert(is_string($this->getSPNameQualifier()) || is_null($this->getSPNameQualifier())); if ($parent === null) { $parent = DOMDocumentFactory::create(); @@ -91,12 +128,12 @@ public function toXML(\DOMElement $parent = null) $element = $doc->createElementNS(Constants::NS_SAML, $this->nodeName); $parent->appendChild($element); - if ($this->NameQualifier !== null) { - $element->setAttribute('NameQualifier', $this->NameQualifier); + if ($this->getNameQualifier() !== null) { + $element->setAttribute('NameQualifier', $this->getNameQualifier()); } - if ($this->SPNameQualifier !== null) { - $element->setAttribute('SPNameQualifier', $this->SPNameQualifier); + if ($this->getSPNameQualifier() !== null) { + $element->setAttribute('SPNameQualifier', $this->getSPNameQualifier()); } return $element; diff --git a/src/SAML2/XML/saml/Issuer.php b/src/SAML2/XML/saml/Issuer.php index e6a83accd..769376ff0 100644 --- a/src/SAML2/XML/saml/Issuer.php +++ b/src/SAML2/XML/saml/Issuer.php @@ -13,28 +13,6 @@ */ class Issuer extends NameIDType { - - /** - * The format of this NameIDType. - * - * Defaults to urn:oasis:names:tc:SAML:2.0:nameid-format:entity: - * - * Indicates that the content of the element is the identifier of an entity that provides SAML-based services (such - * as a SAML authority, requester, or responder) or is a participant in SAML profiles (such as a service provider - * supporting the browser SSO profile). Such an identifier can be used in the element to identify the - * issuer of a SAML request, response, or assertion, or within the element to make assertions about system - * entities that can issue SAML requests, responses, and assertions. It can also be used in other elements and - * attributes whose purpose is to identify a system entity in various protocol exchanges. - * - * The syntax of such an identifier is a URI of not more than 1024 characters in length. It is RECOMMENDED that a - * system entity use a URL containing its own domain name to identify itself. - * - * @see saml-core-2.0-os - * - * @var string - */ - public $Format = Constants::NAMEID_ENTITY; - /** * Set the name of this XML element to "saml:Issuer" * @@ -54,8 +32,56 @@ class Issuer extends NameIDType * @var boolean */ public $Saml2IssuerShowAll = false; //setting true break saml-core-2.0-os 8.3.6 - + /** + * Initialize a saml:NameIDType, either from scratch or from an existing \DOMElement. + * + * @param \DOMElement|null $xml The XML element we should load, if any. + */ + public function __construct(\DOMElement $xml = null) + { + /** + * The format of this NameIDType. + * + * Defaults to urn:oasis:names:tc:SAML:2.0:nameid-format:entity: + * + * Indicates that the content of the element is the identifier of an entity that provides SAML-based services (such + * as a SAML authority, requester, or responder) or is a participant in SAML profiles (such as a service provider + * supporting the browser SSO profile). Such an identifier can be used in the element to identify the + * issuer of a SAML request, response, or assertion, or within the element to make assertions about system + * entities that can issue SAML requests, responses, and assertions. It can also be used in other elements and + * attributes whose purpose is to identify a system entity in various protocol exchanges. + * + * The syntax of such an identifier is a URI of not more than 1024 characters in length. It is RECOMMENDED that a + * system entity use a URL containing its own domain name to identify itself. + * + * @see saml-core-2.0-os + * + * @var string + */ + $this->setFormat(Constants::NAMEID_ENTITY); + + parent::__construct($xml); + } + + /** + * Collect the value of the Saml2IssuerShowAll-property + * @return boolean + */ + public function isSaml2IssuerShowAll() + { + return $this->Saml2IssuerShowAll; + } + + /** + * Set the value of the Saml2IssuerShowAll-property + * @param boolean $saml2IssuerShowAll + */ + public function setSaml2IssuerShowAll($saml2IssuerShowAll) + { + assert(is_bool($saml2IssuerShowAll)); + $this->Saml2IssuerShowAll = $saml2IssuerShowAll; + } /** * Convert this Issuer to XML. @@ -66,15 +92,17 @@ class Issuer extends NameIDType */ public function toXML(\DOMElement $parent = null) { - if ((($this->Saml2IssuerShowAll) && ($this->Format === Constants::NAMEID_ENTITY)) || ($this->Format !== Constants::NAMEID_ENTITY)) { + if (($this->isSaml2IssuerShowAll() && ($this->getFormat() === Constants::NAMEID_ENTITY)) + || ($this->getFormat() !== Constants::NAMEID_ENTITY) + ) { return parent::toXML($parent); } /* - * if $this->SAML2IssuerShowAll is set false + * if $this->isSaml2IssuerShowAll() is set false * From saml-core-2.0-os 8.3.6, when the entity Format is used: "The NameQualifier, SPNameQualifier, and * SPProvidedID attributes MUST be omitted." - * if $this->SAML2IssuerShowAll is set true when the entity Format is used: "The NameQualifier, SPNameQualifier, and + * if $this->isSaml2IssuerShowAll() is set true when the entity Format is used: "The NameQualifier, SPNameQualifier, and * SPProvidedID attributes are not omitted." */ @@ -87,7 +115,7 @@ public function toXML(\DOMElement $parent = null) $element = $doc->createElementNS(Constants::NS_SAML, 'saml:Issuer'); $parent->appendChild($element); - $value = $element->ownerDocument->createTextNode($this->value); + $value = $element->ownerDocument->createTextNode($this->getValue()); $element->appendChild($value); return $element; diff --git a/src/SAML2/XML/saml/NameIDType.php b/src/SAML2/XML/saml/NameIDType.php index a3df61f43..4c5cacf73 100644 --- a/src/SAML2/XML/saml/NameIDType.php +++ b/src/SAML2/XML/saml/NameIDType.php @@ -62,16 +62,72 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('Format')) { - $this->Format = $xml->getAttribute('Format'); + $this->setFormat($xml->getAttribute('Format')); } if ($xml->hasAttribute('SPProvidedID')) { - $this->SPProvidedID = $xml->getAttribute('SPProvidedID'); + $this->setSPProvidedID($xml->getAttribute('SPProvidedID')); } - $this->value = trim($xml->textContent); + $this->setValue(trim($xml->textContent)); } + /** + * Collect the value of the Format-property + * @return string|null + */ + public function getFormat() + { + return $this->Format; + } + + /** + * Set the value of the Format-property + * @param string|null $format + */ + public function setFormat($format = null) + { + assert(is_string($format) || is_null($format)); + $this->Format = $format; + } + + /** + * Collect the value of the value-property + * @return string|null + */ + public function getValue() + { + return $this->value; + } + + /** + * Set the value of the value-property + * @param string|null $value + */ + public function setValue($value) + { + assert(is_string($value) || is_null($value)); + $this->value = $value; + } + + /** + * Collect the value of the SPProvidedID-property + * @return string|null + */ + public function getSPProvidedID() + { + return $this->SPProvidedID; + } + + /** + * Set the value of the SPProvidedID-property + * @param string|null $spProvidedID + */ + public function setSPProvidedID($spProvidedID) + { + assert(is_string($spProvidedID) || is_null($spProvidedID)); + $this->SPProvidedID = $spProvidedID; + } /** * Create a \SAML2\XML\saml\NameID object from an array with its contents. @@ -89,19 +145,19 @@ public static function fromArray(array $nameId) if (!array_key_exists('Value', $nameId)) { throw new \InvalidArgumentException('Missing "Value" in array, cannot create NameID from it.'); } - $nid->value = $nameId['Value']; + $nid->setValue($nameId['Value']); if (array_key_exists('NameQualifier', $nameId) && $nameId['NameQualifier'] !== null) { - $nid->NameQualifier = $nameId['NameQualifier']; + $nid->setNameQualifier($nameId['NameQualifier']); } if (array_key_exists('SPNameQualifier', $nameId) && $nameId['SPNameQualifier'] !== null) { - $nid->SPNameQualifier = $nameId['SPNameQualifier']; + $nid->setSPNameQualifier($nameId['SPNameQualifier']); } if (array_key_exists('SPProvidedID', $nameId) && $nameId['SPProvidedId'] !== null) { - $nid->SPProvidedID = $nameId['SPProvidedID']; + $nid->setSPProvidedID($nameId['SPProvidedID']); } if (array_key_exists('Format', $nameId) && $nameId['Format'] !== null) { - $nid->Format = $nameId['Format']; + $nid->setFormat($nameId['Format']); } return $nid; } @@ -116,21 +172,21 @@ public static function fromArray(array $nameId) */ public function toXML(\DOMElement $parent = null) { - assert(is_string($this->Format) || is_null($this->Format)); - assert(is_string($this->SPProvidedID) || is_null($this->SPProvidedID)); - assert(is_string($this->value)); + assert(is_string($this->getFormat()) || is_null($this->getFormat())); + assert(is_string($this->getSPProvidedID()) || is_null($this->getSPProvidedID())); + assert(is_string($this->getValue())); $element = parent::toXML($parent); - if ($this->Format !== null) { - $element->setAttribute('Format', $this->Format); + if ($this->getFormat() !== null) { + $element->setAttribute('Format', $this->getFormat()); } - if ($this->SPProvidedID !== null) { - $element->setAttribute('SPProvidedID', $this->SPProvidedID); + if ($this->getSPProvidedID() !== null) { + $element->setAttribute('SPProvidedID', $this->getSPProvidedID()); } - $value = $element->ownerDocument->createTextNode($this->value); + $value = $element->ownerDocument->createTextNode($this->getValue()); $element->appendChild($value); return $element; diff --git a/src/SAML2/XML/saml/SubjectConfirmation.php b/src/SAML2/XML/saml/SubjectConfirmation.php index 86a124aa6..bb44bf174 100644 --- a/src/SAML2/XML/saml/SubjectConfirmation.php +++ b/src/SAML2/XML/saml/SubjectConfirmation.php @@ -48,23 +48,78 @@ public function __construct(\DOMElement $xml = null) if (!$xml->hasAttribute('Method')) { throw new \Exception('SubjectConfirmation element without Method attribute.'); } - $this->Method = $xml->getAttribute('Method'); + $this->setMethod($xml->getAttribute('Method')); $nid = Utils::xpQuery($xml, './saml_assertion:NameID'); if (count($nid) > 1) { throw new \Exception('More than one NameID in a SubjectConfirmation element.'); } elseif (!empty($nid)) { - $this->NameID = new NameID($nid[0]); + $this->setNameID(new NameID($nid[0])); } $scd = Utils::xpQuery($xml, './saml_assertion:SubjectConfirmationData'); if (count($scd) > 1) { throw new \Exception('More than one SubjectConfirmationData child in a SubjectConfirmation element.'); } elseif (!empty($scd)) { - $this->SubjectConfirmationData = new SubjectConfirmationData($scd[0]); + $this->setSubjectConfirmationData(new SubjectConfirmationData($scd[0])); } } + /** + * Collect the value of the Method-property + * @return string + */ + public function getMethod() + { + return $this->Method; + } + + /** + * Set the value of the Method-property + * @param string $method + */ + public function setMethod($method) + { + assert(is_string($method)); + $this->Method = $method; + } + + /** + * Collect the value of the NameID-property + * @return \SAML2\XML\saml\NameID + */ + public function getNameID() + { + return $this->NameID; + } + + /** + * Set the value of the NameID-property + * @param \SAML2\XML\saml\NameID $nameId + */ + public function setNameID(NameID $nameId) + { + $this->NameID = $nameId; + } + + /** + * Collect the value of the SubjectConfirmationData-property + * @return \SAML2\XML\saml\SubjectConfirmationData|null + */ + public function getSubjectConfirmationData() + { + return $this->SubjectConfirmationData; + } + + /** + * Set the value of the SubjectConfirmationData-property + * @param \SAML2\XML\saml\SubjectConfirmationData|null $subjectConfirmationData + */ + public function setSubjectConfirmationData($subjectConfirmationData = null) + { + $this->SubjectConfirmationData = $subjectConfirmationData; + } + /** * Convert this element to XML. * @@ -73,20 +128,20 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->Method)); - assert(is_null($this->NameID) || $this->NameID instanceof NameID); - assert(is_null($this->SubjectConfirmationData) || $this->SubjectConfirmationData instanceof SubjectConfirmationData); + assert(is_string($this->getMethod())); + assert(is_null($this->getNameID()) || $this->getNameID() instanceof NameID); + assert(is_null($this->getSubjectConfirmationData()) || $this->getSubjectConfirmationData() instanceof SubjectConfirmationData); $e = $parent->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:SubjectConfirmation'); $parent->appendChild($e); - $e->setAttribute('Method', $this->Method); + $e->setAttribute('Method', $this->getMethod()); - if (isset($this->NameID)) { - $this->NameID->toXML($e); + if ($this->getNameID() !== null) { + $this->getNameID()->toXML($e); } - if (isset($this->SubjectConfirmationData)) { - $this->SubjectConfirmationData->toXML($e); + if ($this->getSubjectConfirmationData() !== null) { + $this->getSubjectConfirmationData()->toXML($e); } return $e; diff --git a/src/SAML2/XML/saml/SubjectConfirmationData.php b/src/SAML2/XML/saml/SubjectConfirmationData.php index 105ad22cc..567871508 100644 --- a/src/SAML2/XML/saml/SubjectConfirmationData.php +++ b/src/SAML2/XML/saml/SubjectConfirmationData.php @@ -60,6 +60,132 @@ class SubjectConfirmationData */ public $info = []; + /** + * Collect the value of the NotBefore-property + * @return int|null + */ + public function getNotBefore() + { + return $this->NotBefore; + } + + /** + * Set the value of the NotBefore-property + * @param int|null $notBefore + */ + public function setNotBefore($notBefore = null) + { + assert(is_int($notBefore) || is_null($notBefore)); + $this->NotBefore = $notBefore; + } + + /** + * Collect the value of the NotOnOrAfter-property + * @return int|null + */ + public function getNotOnOrAfter() + { + return $this->NotOnOrAfter; + } + + /** + * Set the value of the NotOnOrAfter-property + * @param int|null $notOnOrAfter + */ + public function setNotOnOrAfter($notOnOrAfter = null) + { + assert(is_int($notOnOrAfter) || is_null($notOnOrAfter)); + $this->NotOnOrAfter = $notOnOrAfter; + } + + /** + * Collect the value of the Recipient-property + * @return string|null + */ + public function getRecipient() + { + return $this->Recipient; + } + + /** + * Set the value of the Recipient-property + * @param string|null $recipient + */ + public function setRecipient($recipient = null) + { + assert(is_string($recipient) || is_null($recipient)); + $this->Recipient = $recipient; + } + + /** + * Collect the value of the InResponseTo-property + * @return string|null + */ + public function getInResponseTo() + { + return $this->InResponseTo; + } + + /** + * Set the value of the InResponseTo-property + * @param string|null $inResponseTo + */ + public function setInResponseTo($inResponseTo = null) + { + assert(is_string($inResponseTo) || is_null($inResponseTo)); + $this->InResponseTo = $inResponseTo; + } + + /** + * Collect the value of the Address-property + * @return string|null + */ + public function getAddress() + { + return $this->Address; + } + + /** + * Set the value of the Address-property + * @param string|null $address + */ + public function setAddress($address = null) + { + assert(is_string($address) || is_null($address)); + if (!is_null($address) && !filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) { + throw new \InvalidArgumentException('Provided argument is not a valid IP address.'); + } + $this->Address = $address; + } + + /** + * Collect the value of the info-property + * @return (\SAML2\XML\ds\KeyInfo|\SAML2\XML\Chunk)[] + */ + public function getInfo() + { + return $this->info; + } + + /** + * Set the value of the info-property + * @param (\SAML2\XML\ds\KeyInfo|\SAML2\XML\Chunk)[] $info + */ + public function setInfo(array $info) + { + $this->info = $info; + } + + /** + * Add the value to the info-property + * @param \SAML2\XML\Chunk|\SAML2\XML\ds\KeyInfo $info + */ + public function addInfo($info) + { + assert($info instanceof Chunk || $info instanceof KeyInfo); + $this->info[] = $info; + } + /** * Initialize (and parse) a SubjectConfirmationData element. * @@ -72,34 +198,34 @@ public function __construct(\DOMElement $xml = null) } if ($xml->hasAttribute('NotBefore')) { - $this->NotBefore = Utils::xsDateTimeToTimestamp($xml->getAttribute('NotBefore')); + $this->setNotBefore(Utils::xsDateTimeToTimestamp($xml->getAttribute('NotBefore'))); } if ($xml->hasAttribute('NotOnOrAfter')) { - $this->NotOnOrAfter = Utils::xsDateTimeToTimestamp($xml->getAttribute('NotOnOrAfter')); + $this->setNotOnOrAfter(Utils::xsDateTimeToTimestamp($xml->getAttribute('NotOnOrAfter'))); } if ($xml->hasAttribute('Recipient')) { - $this->Recipient = $xml->getAttribute('Recipient'); + $this->setRecipient($xml->getAttribute('Recipient')); } if ($xml->hasAttribute('InResponseTo')) { - $this->InResponseTo = $xml->getAttribute('InResponseTo'); + $this->setInResponseTo($xml->getAttribute('InResponseTo')); } if ($xml->hasAttribute('Address')) { - $this->Address = $xml->getAttribute('Address'); + $this->setAddress($xml->getAttribute('Address')); } for ($n = $xml->firstChild; $n !== null; $n = $n->nextSibling) { if (!($n instanceof \DOMElement)) { continue; } if ($n->namespaceURI !== XMLSecurityDSig::XMLDSIGNS) { - $this->info[] = new Chunk($n); + $this->addInfo(new Chunk($n)); continue; } switch ($n->localName) { case 'KeyInfo': - $this->info[] = new KeyInfo($n); + $this->addInfo(new KeyInfo($n)); break; default: - $this->info[] = new Chunk($n); + $this->addInfo(new Chunk($n)); break; } } @@ -113,32 +239,32 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_null($this->NotBefore) || is_int($this->NotBefore)); - assert(is_null($this->NotOnOrAfter) || is_int($this->NotOnOrAfter)); - assert(is_null($this->Recipient) || is_string($this->Recipient)); - assert(is_null($this->InResponseTo) || is_string($this->InResponseTo)); - assert(is_null($this->Address) || is_string($this->Address)); + assert(is_null($this->getNotBefore()) || is_int($this->getNotBefore())); + assert(is_null($this->getNotOnOrAfter()) || is_int($this->getNotOnOrAfter())); + assert(is_null($this->getRecipient()) || is_string($this->getRecipient())); + assert(is_null($this->getInResponseTo()) || is_string($this->getInResponseTo())); + assert(is_null($this->getAddress()) || is_string($this->getAddress())); $e = $parent->ownerDocument->createElementNS(Constants::NS_SAML, 'saml:SubjectConfirmationData'); $parent->appendChild($e); - if (isset($this->NotBefore)) { - $e->setAttribute('NotBefore', gmdate('Y-m-d\TH:i:s\Z', $this->NotBefore)); + if ($this->getNotBefore() !== null) { + $e->setAttribute('NotBefore', gmdate('Y-m-d\TH:i:s\Z', $this->getNotBefore())); } - if (isset($this->NotOnOrAfter)) { - $e->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->NotOnOrAfter)); + if ($this->getNotOnOrAfter() !== null) { + $e->setAttribute('NotOnOrAfter', gmdate('Y-m-d\TH:i:s\Z', $this->getNotOnOrAfter())); } - if (isset($this->Recipient)) { - $e->setAttribute('Recipient', $this->Recipient); + if ($this->getRecipient() !== null) { + $e->setAttribute('Recipient', $this->getRecipient()); } - if (isset($this->InResponseTo)) { - $e->setAttribute('InResponseTo', $this->InResponseTo); + if ($this->getInResponseTo() !== null) { + $e->setAttribute('InResponseTo', $this->getInResponseTo()); } - if (isset($this->Address)) { - $e->setAttribute('Address', $this->Address); + if ($this->getAddress() !== null) { + $e->setAttribute('Address', $this->getAddress()); } /** @var \SAML2\XML\ds\KeyInfo|\SAML2\XML\Chunk $n */ - foreach ($this->info as $n) { + foreach ($this->getInfo() as $n) { $n->toXML($e); } diff --git a/src/SAML2/XML/shibmd/Scope.php b/src/SAML2/XML/shibmd/Scope.php index 6f9c348ac..ecf4fc47a 100644 --- a/src/SAML2/XML/shibmd/Scope.php +++ b/src/SAML2/XML/shibmd/Scope.php @@ -42,8 +42,46 @@ public function __construct(\DOMElement $xml = null) return; } - $this->scope = $xml->textContent; - $this->regexp = Utils::parseBoolean($xml, 'regexp', false); + $this->setScope($xml->textContent); + $this->setIsRegexpScope(Utils::parseBoolean($xml, 'regexp', false)); + } + + /** + * Collect the value of the scope-property + * @return string + */ + public function getScope() + { + return $this->scope; + } + + /** + * Set the value of the scope-property + * @param string $scope + */ + public function setScope($scope) + { + assert(is_string($scope)); + $this->scope = $scope; + } + + /** + * Collect the value of the regexp-property + * @return boolean + */ + public function isRegexpScope() + { + return $this->regexp; + } + + /** + * Set the value of the regexp-property + * @param boolean $regexp + */ + public function setIsRegexpScope($regexp) + { + assert(is_bool($regexp)); + $this->regexp = $regexp; } /** @@ -54,17 +92,17 @@ public function __construct(\DOMElement $xml = null) */ public function toXML(\DOMElement $parent) { - assert(is_string($this->scope)); - assert(is_bool($this->regexp) || is_null($this->regexp)); + assert(is_string($this->getScope())); + assert(is_bool($this->isRegexpScope()) || is_null($this->isRegexpScope())); $doc = $parent->ownerDocument; $e = $doc->createElementNS(Scope::NS, 'shibmd:Scope'); $parent->appendChild($e); - $e->appendChild($doc->createTextNode($this->scope)); + $e->appendChild($doc->createTextNode($this->getScope())); - if ($this->regexp === true) { + if ($this->isRegexpScope() === true) { $e->setAttribute('regexp', 'true'); } else { $e->setAttribute('regexp', 'false'); diff --git a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationMethodTest.php b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationMethodTest.php index 731a0e800..b1b34f75b 100644 --- a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationMethodTest.php +++ b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationMethodTest.php @@ -2,7 +2,6 @@ namespace SAML2\Assertion\Validation\ConstraintValidator; -use Mockery as m; use SAML2\Assertion\Validation\Result; use SAML2\Constants; @@ -15,7 +14,7 @@ class SubjectConfirmationMethodTest extends \PHPUnit_Framework_TestCase public function setUp() { - $this->subjectConfirmation = m::mock('SAML2\XML\saml\SubjectConfirmation'); + $this->subjectConfirmation = new \SAML2\XML\saml\SubjectConfirmation(); } /** @@ -24,7 +23,7 @@ public function setUp() */ public function a_subject_confirmation_with_bearer_method_is_valid() { - $this->subjectConfirmation->Method = Constants::CM_BEARER; + $this->subjectConfirmation->setMethod(Constants::CM_BEARER); $validator = new SubjectConfirmationMethod(); $result = new Result(); @@ -40,7 +39,7 @@ public function a_subject_confirmation_with_bearer_method_is_valid() */ public function a_subject_confirmation_with_holder_of_key_method_is_not_valid() { - $this->subjectConfirmation->Method = Constants::CM_HOK; + $this->subjectConfirmation->setMethod(Constants::CM_HOK); $validator = new SubjectConfirmationMethod(); $result = new Result(); diff --git a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBeforeTest.php b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBeforeTest.php index 4ff9f3419..a8abbe785 100644 --- a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBeforeTest.php +++ b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotBeforeTest.php @@ -2,7 +2,6 @@ namespace SAML2\Assertion\Validation\ConstraintValidator; -use Mockery as m; use SAML2\Assertion\Validation\Result; use SAML2\ControlledTimeTest; @@ -27,9 +26,9 @@ class SubjectConfirmationNotBeforeTest extends ControlledTimeTest public function setUp() { parent::setUp(); - $this->subjectConfirmation = m::mock('SAML2\XML\saml\SubjectConfirmation'); - $this->subjectConfirmationData = m::mock('SAML2\XML\saml\SubjectConfirmationData'); - $this->subjectConfirmation->SubjectConfirmationData = $this->subjectConfirmationData; + $this->subjectConfirmation = new \SAML2\XML\saml\SubjectConfirmation(); + $this->subjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData(); + $this->subjectConfirmation->setSubjectConfirmationData($this->subjectConfirmationData); } /** @@ -38,7 +37,7 @@ public function setUp() */ public function timestamp_in_the_future_beyond_graceperiod_is_not_valid() { - $this->subjectConfirmation->SubjectConfirmationData->NotBefore = $this->currentTime + 61; + $this->subjectConfirmation->getSubjectConfirmationData()->setNotBefore($this->currentTime + 61); $validator = new SubjectConfirmationNotBefore(); $result = new Result(); @@ -55,7 +54,7 @@ public function timestamp_in_the_future_beyond_graceperiod_is_not_valid() */ public function time_within_graceperiod_is_valid() { - $this->subjectConfirmation->SubjectConfirmationData->NotBefore = $this->currentTime + 60; + $this->subjectConfirmation->getSubjectConfirmationData()->setNotBefore($this->currentTime + 60); $validator = new SubjectConfirmationNotBefore(); $result = new Result(); @@ -71,7 +70,7 @@ public function time_within_graceperiod_is_valid() */ public function current_time_is_valid() { - $this->subjectConfirmation->SubjectConfirmationData->NotBefore = $this->currentTime; + $this->subjectConfirmation->getSubjectConfirmationData()->setNotBefore($this->currentTime); $validator = new SubjectConfirmationNotBefore(); $result = new Result(); diff --git a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfterTest.php b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfterTest.php index 81bcb3308..7b5c541b1 100644 --- a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfterTest.php +++ b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationNotOnOrAfterTest.php @@ -2,12 +2,11 @@ namespace SAML2\Assertion\Validation\ConstraintValidator; -use Mockery as m; use SAML2\Assertion\Validation\Result; use SAML2\ControlledTimeTest; /** - * Because we're mocking a static call, we have to run it in separate processes so as to no contaminate the other + * Because we're mocking a static call, we have to run it in separate processes so as to not contaminate the other * tests. * * @runTestsInSeparateProcesses @@ -27,9 +26,9 @@ class SubjectConfirmationNotOnOrAfterTest extends ControlledTimeTest public function setUp() { parent::setUp(); - $this->subjectConfirmation = m::mock('SAML2\XML\saml\SubjectConfirmation'); - $this->subjectConfirmationData = m::mock('SAML2\XML\saml\SubjectConfirmationData'); - $this->subjectConfirmation->SubjectConfirmationData = $this->subjectConfirmationData; + $this->subjectConfirmation = new \SAML2\XML\saml\SubjectConfirmation(); + $this->subjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData(); + $this->subjectConfirmation->setSubjectConfirmationData($this->subjectConfirmationData); } /** @@ -38,7 +37,7 @@ public function setUp() */ public function timestamp_in_the_past_before_graceperiod_is_not_valid() { - $this->subjectConfirmationData->NotOnOrAfter = $this->currentTime - 60; + $this->subjectConfirmationData->setNotOnOrAfter($this->currentTime - 60); $validator = new SubjectConfirmationNotOnOrAfter(); $result = new Result(); @@ -55,7 +54,7 @@ public function timestamp_in_the_past_before_graceperiod_is_not_valid() */ public function time_within_graceperiod_is_valid() { - $this->subjectConfirmationData->NotOnOrAfter = $this->currentTime - 59; + $this->subjectConfirmationData->setNotOnOrAfter($this->currentTime - 59); $validator = new SubjectConfirmationNotOnOrAfter(); $result = new Result(); @@ -71,7 +70,7 @@ public function time_within_graceperiod_is_valid() */ public function current_time_is_valid() { - $this->subjectConfirmationData->NotOnOrAfter = $this->currentTime; + $this->subjectConfirmationData->setNotOnOrAfter($this->currentTime); $validator = new SubjectConfirmationNotBefore(); $result = new Result(); diff --git a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMathchesTest.php b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMathchesTest.php index 5a98a2433..555983606 100644 --- a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMathchesTest.php +++ b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationRecipientMathchesTest.php @@ -2,7 +2,6 @@ namespace SAML2\Assertion\Validation\ConstraintValidator; -use Mockery as m; use SAML2\Assertion\Validation\Result; use SAML2\Configuration\Destination; @@ -22,9 +21,9 @@ class SubjectConfirmationRecipientMathchesTest extends public function setUp() { parent::setUp(); - $this->subjectConfirmation = m::mock('SAML2\XML\saml\SubjectConfirmation'); - $this->subjectConfirmationData = m::mock('SAML2\XML\saml\SubjectConfirmationData'); - $this->subjectConfirmation->SubjectConfirmationData = $this->subjectConfirmationData; + $this->subjectConfirmation = new \SAML2\XML\saml\SubjectConfirmation(); + $this->subjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData(); + $this->subjectConfirmation->setSubjectConfirmationData($this->subjectConfirmationData); } /** @@ -33,7 +32,7 @@ public function setUp() */ public function when_the_subject_confirmation_recipient_differs_from_the_destination_the_sc_is_invalid() { - $this->subjectConfirmation->SubjectConfirmationData->Recipient = 'someDestination'; + $this->subjectConfirmation->getSubjectConfirmationData()->setRecipient('someDestination'); $validator = new SubjectConfirmationRecipientMatches( new Destination('anotherDestination') @@ -52,7 +51,7 @@ public function when_the_subject_confirmation_recipient_differs_from_the_destina */ public function when_the_subject_confirmation_recipient_equals_the_destination_the_sc_is_invalid() { - $this->subjectConfirmation->SubjectConfirmationData->Recipient = 'theSameDestination'; + $this->subjectConfirmation->getSubjectConfirmationData()->setRecipient('theSameDestination'); $validator = new SubjectConfirmationRecipientMatches( new Destination('theSameDestination') diff --git a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatchesTest.php b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatchesTest.php index 74213bafc..7438ed734 100644 --- a/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatchesTest.php +++ b/tests/SAML2/Assertion/Validation/ConstraintValidator/SubjectConfirmationResponseToMatchesTest.php @@ -26,10 +26,10 @@ class SubjectConfirmationResponseToMatchesTest extends public function setUp() { parent::setUp(); - $this->subjectConfirmation = m::mock('SAML2\XML\saml\SubjectConfirmation'); - $this->subjectConfirmationData = m::mock('SAML2\XML\saml\SubjectConfirmationData'); + $this->subjectConfirmation = new \SAML2\XML\saml\SubjectConfirmation(); + $this->subjectConfirmationData = new \SAML2\XML\saml\SubjectConfirmationData(); $this->subjectConfirmation->SubjectConfirmationData = $this->subjectConfirmationData; - $this->response = m::mock('SAML2\Response'); + $this->response = m::mock('SAML2\Response'); } /** @@ -39,7 +39,7 @@ public function setUp() public function when_the_response_responseto_is_null_the_subject_confirmation_is_valid() { $this->response->shouldReceive('getInResponseTo')->andReturnNull(); - $this->subjectConfirmationData->InResponseTo = 'someValue'; + $this->subjectConfirmationData->setInResponseTo('someValue'); $validator = new SubjectConfirmationResponseToMatches( $this->response @@ -58,7 +58,7 @@ public function when_the_response_responseto_is_null_the_subject_confirmation_is public function when_the_subjectconfirmation_responseto_is_null_the_subjectconfirmation_is_valid() { $this->response->shouldReceive('getInResponseTo')->andReturn('someValue'); - $this->subjectConfirmationData->InResponseTo = null; + $this->subjectConfirmationData->setInResponseTo(null); $validator = new SubjectConfirmationResponseToMatches( $this->response @@ -77,7 +77,7 @@ public function when_the_subjectconfirmation_responseto_is_null_the_subjectconfi public function when_the_subjectconfirmation_and_response_responseto_are_null_the_subjectconfirmation_is_valid() { $this->response->shouldReceive('getInResponseTo')->andReturnNull(); - $this->subjectConfirmationData->InResponseTo = null; + $this->subjectConfirmationData->setInResponseTo(null); $validator = new SubjectConfirmationResponseToMatches( $this->response @@ -96,7 +96,7 @@ public function when_the_subjectconfirmation_and_response_responseto_are_null_th public function when_the_subjectconfirmation_and_response_responseto_are_equal_the_subjectconfirmation_is_valid() { $this->response->shouldReceive('getInResponseTo')->andReturn('theSameValue'); - $this->subjectConfirmationData->InResponseTo = 'theSameValue'; + $this->subjectConfirmationData->setInResponseTo('theSameValue'); $validator = new SubjectConfirmationResponseToMatches( $this->response @@ -115,7 +115,7 @@ public function when_the_subjectconfirmation_and_response_responseto_are_equal_t public function when_the_subjectconfirmation_and_response_responseto_differ_the_subjectconfirmation_is_invalid() { $this->response->shouldReceive('getInResponseTo')->andReturn('someValue'); - $this->subjectConfirmationData->InResponseTo = 'anotherValue'; + $this->subjectConfirmationData->setInResponseTo('anotherValue'); $validator = new SubjectConfirmationResponseToMatches( $this->response diff --git a/tests/SAML2/AssertionTest.php b/tests/SAML2/AssertionTest.php index 1ee7c8b30..2b0a6ad16 100644 --- a/tests/SAML2/AssertionTest.php +++ b/tests/SAML2/AssertionTest.php @@ -78,7 +78,7 @@ public function testUnmarshalling() $assertion = new Assertion($document->firstChild); // Was not signed - $this->assertFalse($assertion->getWasSignedAtConstruction()); + $this->assertFalse($assertion->wasSignedAtConstruction()); // Test for valid audiences $assertionValidAudiences = $assertion->getValidAudiences(); @@ -365,20 +365,20 @@ public function testConvertIssuerToXML() $this->assertEquals($issuer->value, $xml_issuer->textContent); // now, try an Issuer with another format and attributes - $issuer->Format = Constants::NAMEID_UNSPECIFIED; - $issuer->NameQualifier = 'SomeNameQualifier'; - $issuer->SPNameQualifier = 'SomeSPNameQualifier'; - $issuer->SPProvidedID = 'SomeSPProvidedID'; + $issuer->setFormat(Constants::NAMEID_UNSPECIFIED); + $issuer->setNameQualifier('SomeNameQualifier'); + $issuer->setSPNameQualifier('SomeSPNameQualifier'); + $issuer->setSPProvidedID('SomeSPProvidedID'); $assertion->setIssuer($issuer); $xml = $assertion->toXML(); $xml_issuer = Utils::xpQuery($xml, './saml_assertion:Issuer'); $xml_issuer = $xml_issuer[0]; $this->assertTrue($xml_issuer->hasAttributes()); - $this->assertEquals($issuer->value, $xml_issuer->textContent); - $this->assertEquals($issuer->NameQualifier, $xml_issuer->getAttribute('NameQualifier')); - $this->assertEquals($issuer->SPNameQualifier, $xml_issuer->getAttribute('SPNameQualifier')); - $this->assertEquals($issuer->SPProvidedID, $xml_issuer->getAttribute('SPProvidedID')); + $this->assertEquals($issuer->getValue(), $xml_issuer->textContent); + $this->assertEquals($issuer->getNameQualifier(), $xml_issuer->getAttribute('NameQualifier')); + $this->assertEquals($issuer->getSPNameQualifier(), $xml_issuer->getAttribute('SPNameQualifier')); + $this->assertEquals($issuer->getSPProvidedID(), $xml_issuer->getAttribute('SPProvidedID')); } public function testAuthnContextDeclAndRefConstraint() @@ -498,9 +498,9 @@ public function testGetSubjectConfirmationData() $this->assertCount(1, $sc); $this->assertInstanceOf('SAML2\XML\saml\SubjectConfirmation', $sc[0]); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:cm:bearer', $sc[0]->Method); - $this->assertEquals('https://example.org/authentication/consume-assertion', $sc[0]->SubjectConfirmationData->Recipient); - $this->assertEquals(1267796526, $sc[0]->SubjectConfirmationData->NotOnOrAfter); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:cm:bearer', $sc[0]->getMethod()); + $this->assertEquals('https://example.org/authentication/consume-assertion', $sc[0]->getSubjectConfirmationData()->getRecipient()); + $this->assertEquals(1267796526, $sc[0]->getSubjectConfirmationData()->getNotOnOrAfter()); } /** @@ -690,7 +690,7 @@ public function testCorrectSignatureMethodCanBeExtracted() $unsignedAssertion = new Assertion($document->firstChild); $unsignedAssertion->setSignatureKey($privateKey); $unsignedAssertion->setCertificates([CertificatesMock::PUBLIC_KEY_PEM]); - $this->assertFalse($unsignedAssertion->getWasSignedAtConstruction()); + $this->assertFalse($unsignedAssertion->wasSignedAtConstruction()); $this->assertEquals($privateKey, $unsignedAssertion->getSignatureKey()); $signedAssertion = new Assertion($unsignedAssertion->toXML()); @@ -699,7 +699,7 @@ public function testCorrectSignatureMethodCanBeExtracted() $this->assertEquals($privateKey->getAlgorith(), $signatureMethod); - $this->assertTrue($signedAssertion->getWasSignedAtConstruction()); + $this->assertTrue($signedAssertion->wasSignedAtConstruction()); } @@ -743,10 +743,10 @@ public function testEptiAttributeValuesAreParsedCorrectly() $this->assertInstanceOf('SAML2\XML\saml\NameID', $maceValue); $this->assertInstanceOf('SAML2\XML\saml\NameID', $oidValue); - $this->assertEquals('abcd-some-value-xyz', $maceValue->value); - $this->assertEquals('abcd-some-value-xyz', $oidValue->value); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceValue->Format); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $oidValue->Format); + $this->assertEquals('abcd-some-value-xyz', $maceValue->getValue()); + $this->assertEquals('abcd-some-value-xyz', $oidValue->getValue()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceValue->getFormat()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $oidValue->getFormat()); $this->assertXmlStringEqualsXmlString($xml, $assertion->toXML()->ownerDocument->saveXML()); } @@ -807,8 +807,8 @@ public function testEptiLegacyAttributeValuesCanBeString() $oidValue = $attributes['urn:oid:1.3.6.1.4.1.5923.1.1.1.10'][0]; $this->assertInstanceOf('SAML2\XML\saml\NameID', $maceValue); $this->assertInstanceOf('SAML2\XML\saml\NameID', $oidValue); - $this->assertEquals('string-23', $maceValue->value); - $this->assertEquals('string-12', $oidValue->value); + $this->assertEquals('string-23', $maceValue->getValue()); + $this->assertEquals('string-12', $oidValue->getValue()); } /** @@ -854,10 +854,10 @@ public function testEptiAttributeParsingSupportsMultipleValues() $this->assertInstanceOf('SAML2\XML\saml\NameID', $maceFirstValue); $this->assertInstanceOf('SAML2\XML\saml\NameID', $maceSecondValue); - $this->assertEquals('abcd-some-value-xyz', $maceFirstValue->value); - $this->assertEquals('xyz-some-value-abcd', $maceSecondValue->value); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceFirstValue->Format); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceSecondValue->Format); + $this->assertEquals('abcd-some-value-xyz', $maceFirstValue->getValue()); + $this->assertEquals('xyz-some-value-abcd', $maceSecondValue->getValue()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceFirstValue->getFormat()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:persistent', $maceSecondValue->getFormat()); $this->assertXmlStringEqualsXmlString($xml, $assertion->toXML()->ownerDocument->saveXML()); } @@ -964,7 +964,7 @@ public function testEncryptedAttributeValuesWithComplexTypeValuesAreParsedCorrec $assertion = new Assertion(DOMDocumentFactory::fromString($xml)->firstChild); $assertion->setEncryptionKey($privateKey); - $assertion->setEncryptedAttributes(true); + $assertion->setRequiredEncAttributes(true); $this->assertEquals($privateKey, $assertion->getEncryptionKey()); $encryptedAssertion = $assertion->toXML()->ownerDocument->saveXML(); @@ -1011,7 +1011,7 @@ public function testTypedEncryptedAttributeValuesAreParsedCorrectly() $assertion = new Assertion(DOMDocumentFactory::fromString($xml)->firstChild); $assertion->setEncryptionKey($privateKey); - $assertion->setEncryptedAttributes(true); + $assertion->setRequiredEncAttributes(true); $encryptedAssertion = $assertion->toXML()->ownerDocument->saveXML(); $assertionToVerify = new Assertion(DOMDocumentFactory::fromString($encryptedAssertion)->firstChild); @@ -1050,7 +1050,7 @@ public function testVerifySignedAssertion() $this->assertEquals(CertificatesMock::getPlainPublicKeyContents(), $certs[0]); // Was signed - $this->assertTrue($assertion->getWasSignedAtConstruction()); + $this->assertTrue($assertion->wasSignedAtConstruction()); } @@ -1069,7 +1069,7 @@ public function testCommentsInSignedAssertion() $result = $assertion->validate($publicKey); $this->assertTrue($result); - $this->assertEquals("_1bbcf227253269d19a689c53cdd542fe2384a9538b", $assertion->getNameId()->value); + $this->assertEquals("_1bbcf227253269d19a689c53cdd542fe2384a9538b", $assertion->getNameId()->getValue()); } @@ -1152,7 +1152,7 @@ public function testVerifyUnsignedAssertion() $assertion = new Assertion($document->firstChild); // Was not signed - $this->assertFalse($assertion->getWasSignedAtConstruction()); + $this->assertFalse($assertion->wasSignedAtConstruction()); $publicKey = CertificatesMock::getPublicKeySha256(); $result = $assertion->validate($publicKey); @@ -1788,15 +1788,15 @@ public function testNameIDunmarshalling() $assertion = new Assertion($document->documentElement); $nameID = $assertion->getNameID(); - $this->assertEquals('b7de81420a19416', $nameID->value); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->Format); + $this->assertEquals('b7de81420a19416', $nameID->getValue()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->getFormat()); $this->assertFalse($assertion->isNameIdEncrypted()); // Not encrypted, should be a no-op $privateKey = CertificatesMock::getPrivateKey(); $decrypted = $assertion->decryptNameId($privateKey); - $this->assertEquals('b7de81420a19416', $nameID->value); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->Format); + $this->assertEquals('b7de81420a19416', $nameID->getValue()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->getFormat()); $this->assertFalse($assertion->isNameIdEncrypted()); } @@ -1831,8 +1831,8 @@ public function testNameIdEncryption() $assertionToVerify->decryptNameId($privateKey); $this->assertFalse($assertionToVerify->isNameIdEncrypted()); $nameID = $assertionToVerify->getNameID(); - $this->assertEquals('just_a_basic_identifier', $nameID->value); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->Format); + $this->assertEquals('just_a_basic_identifier', $nameID->getValue()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:nameid-format:transient', $nameID->getFormat()); } /** diff --git a/tests/SAML2/LogoutRequestTest.php b/tests/SAML2/LogoutRequestTest.php index 668d16166..c69684bfc 100644 --- a/tests/SAML2/LogoutRequestTest.php +++ b/tests/SAML2/LogoutRequestTest.php @@ -191,9 +191,11 @@ public function testGetNotOnOrAfter() public function testSetNotOnOrAfter() { $time = time(); + $nameId = new XML\saml\NameID(); + $nameId->setValue('NameIDValue'); $logoutRequest = new LogoutRequest(); - $logoutRequest->setNameID(['Value' => 'NameIDValue']); + $logoutRequest->setNameID($nameId); $logoutRequest->setNotOnOrAfter($time); $logoutRequestElement = $logoutRequest->toUnsignedXML(); diff --git a/tests/SAML2/MessageTest.php b/tests/SAML2/MessageTest.php index 9182c7574..9d81ca77c 100644 --- a/tests/SAML2/MessageTest.php +++ b/tests/SAML2/MessageTest.php @@ -71,11 +71,11 @@ public function testIssuerParsedAsNameID() $message = Message::fromXML($authnRequest->documentElement); $issuer = $message->getIssuer(); $this->assertInstanceOf('SAML2\XML\saml\Issuer', $issuer); - $this->assertEquals('https://gateway.stepup.org/saml20/sp/metadata', $issuer->NameQualifier); - $this->assertEquals('https://spnamequalifier.com', $issuer->SPNameQualifier); - $this->assertEquals('ProviderID', $issuer->SPProvidedID); - $this->assertEquals('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', $issuer->Format); - $this->assertEquals('https://gateway.stepup.org/saml20/sp/metadata', $issuer->value); + $this->assertEquals('https://gateway.stepup.org/saml20/sp/metadata', $issuer->getNameQualifier()); + $this->assertEquals('https://spnamequalifier.com', $issuer->getSPNameQualifier()); + $this->assertEquals('ProviderID', $issuer->getSPProvidedID()); + $this->assertEquals('urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified', $issuer->getFormat()); + $this->assertEquals('https://gateway.stepup.org/saml20/sp/metadata', $issuer->getValue()); } /** @@ -115,7 +115,7 @@ public function testConvertIssuerToXML() // first, try with common Issuer objects (Format=entity) $response = new Response(); $issuer = new XML\saml\Issuer(); - $issuer->value = 'https://gateway.stepup.org/saml20/sp/metadata'; + $issuer->setValue('https://gateway.stepup.org/saml20/sp/metadata'); $response->setIssuer($issuer); $xml = $response->toUnsignedXML(); $xml_issuer = Utils::xpQuery($xml, './saml_assertion:Issuer'); @@ -125,20 +125,20 @@ public function testConvertIssuerToXML() $this->assertEquals($issuer->value, $xml_issuer->textContent); // now, try an Issuer with another format and attributes - $issuer->Format = Constants::NAMEID_UNSPECIFIED; - $issuer->NameQualifier = 'SomeNameQualifier'; - $issuer->SPNameQualifier = 'SomeSPNameQualifier'; - $issuer->SPProvidedID = 'SomeSPProvidedID'; + $issuer->setFormat(Constants::NAMEID_UNSPECIFIED); + $issuer->setNameQualifier('SomeNameQualifier'); + $issuer->setSPNameQualifier('SomeSPNameQualifier'); + $issuer->setSPProvidedID('SomeSPProvidedID'); $response->setIssuer($issuer); $xml = $response->toUnsignedXML(); $xml_issuer = Utils::xpQuery($xml, './saml_assertion:Issuer'); $xml_issuer = $xml_issuer[0]; $this->assertTrue($xml_issuer->hasAttributes()); - $this->assertEquals($issuer->value, $xml_issuer->textContent); - $this->assertEquals($issuer->NameQualifier, $xml_issuer->getAttribute('NameQualifier')); - $this->assertEquals($issuer->SPNameQualifier, $xml_issuer->getAttribute('SPNameQualifier')); - $this->assertEquals($issuer->SPProvidedID, $xml_issuer->getAttribute('SPProvidedID')); + $this->assertEquals($issuer->getValue(), $xml_issuer->textContent); + $this->assertEquals($issuer->getNameQualifier(), $xml_issuer->getAttribute('NameQualifier')); + $this->assertEquals($issuer->getSPNameQualifier(), $xml_issuer->getAttribute('SPNameQualifier')); + $this->assertEquals($issuer->getSPProvidedID(), $xml_issuer->getAttribute('SPProvidedID')); // finally, make sure we can skip the Issuer by setting it to null $response->setIssuer(null); diff --git a/tests/SAML2/UtilsTest.php b/tests/SAML2/UtilsTest.php index 6eb8a5c0f..a2a17ac25 100644 --- a/tests/SAML2/UtilsTest.php +++ b/tests/SAML2/UtilsTest.php @@ -280,6 +280,6 @@ public function testCreateKeyDescriptor() $X509Data = "MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMTD2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqKxupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtKTytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFDbStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/67OZfHd7R+POBXhophSMv1ZOo"; $keyDescriptor = Utils::createKeyDescriptor($X509Data); - $this->assertInstanceOf('\SAML2\XML\ds\X509Data', $keyDescriptor->KeyInfo->info[0]); + $this->assertInstanceOf('\SAML2\XML\ds\X509Data', $keyDescriptor->KeyInfo->getInfo()[0]); } } diff --git a/tests/SAML2/XML/ResponseTest.php b/tests/SAML2/XML/ResponseTest.php index 38b7fe7db..ce200b8d1 100644 --- a/tests/SAML2/XML/ResponseTest.php +++ b/tests/SAML2/XML/ResponseTest.php @@ -16,30 +16,7 @@ public function testConstructorWithoutXML() { $response = new Response; - $this->assertNull($response->AssertionConsumerServiceURL); - } - - public function toXMLInvalidACSProvider() - { - return [ - [null], - [1], - [false], - [[]], - [new stdClass], - ]; - } - - /** - * @dataProvider toXMLInvalidACSProvider - */ - public function testToXMLInvalidACS($url) - { - $this->setExpectedException('InvalidArgumentException', 'AssertionConsumerServiceURL'); - - $response = new Response; - $response->AssertionConsumerServiceURL = $url; - $response->toXML(new DOMElement('Foobar')); + $this->assertNull($response->getAssertionConsumerServiceURL()); } public function testToXMLReturnsResponse() @@ -48,7 +25,7 @@ public function testToXMLReturnsResponse() $element = $doc->createElement('Foobar'); $response = new Response; - $response->AssertionConsumerServiceURL = 'https://example.com/ACS'; + $response->setAssertionConsumerServiceURL('https://example.com/ACS'); $return = $response->toXML($element); $this->assertInstanceOf('DOMElement', $return); @@ -63,7 +40,7 @@ public function testToXMLResponseAttributes() $element = $doc->createElement('Foobar'); $response = new Response; - $response->AssertionConsumerServiceURL = $acs; + $response->setAssertionConsumerServiceURL($acs); $return = $response->toXML($element); $this->assertTrue($return->hasAttributeNS(Constants::NS_SOAP, 'mustUnderstand')); @@ -80,7 +57,7 @@ public function testToXMLResponseAppended() $element = $doc->createElement('Foobar'); $response = new Response; - $response->AssertionConsumerServiceURL = 'https://example.com/ACS'; + $response->setAssertionConsumerServiceURL('https://example.com/ACS'); $return = $response->toXML($element); $elements = $element->getElementsByTagNameNS(Constants::NS_ECP, 'Response'); diff --git a/tests/SAML2/XML/alg/DigestMethodTest.php b/tests/SAML2/XML/alg/DigestMethodTest.php index c411d5a2f..dcf1b64d9 100644 --- a/tests/SAML2/XML/alg/DigestMethodTest.php +++ b/tests/SAML2/XML/alg/DigestMethodTest.php @@ -16,7 +16,7 @@ class DigestMethodTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $digestMethod = new DigestMethod(); - $digestMethod->Algorithm = 'http://exampleAlgorithm'; + $digestMethod->setAlgorithm('http://exampleAlgorithm'); $document = DOMDocumentFactory::fromString(''); $xml = $digestMethod->toXML($document->firstChild); @@ -40,7 +40,7 @@ public function testUnmarshalling() ); $digestMethod = new DigestMethod($document->firstChild); - $this->assertEquals('http://exampleAlgorithm', $digestMethod->Algorithm); + $this->assertEquals('http://exampleAlgorithm', $digestMethod->getAlgorithm()); } diff --git a/tests/SAML2/XML/alg/SigningMethodTest.php b/tests/SAML2/XML/alg/SigningMethodTest.php index 5081f56b6..0dc5d009c 100644 --- a/tests/SAML2/XML/alg/SigningMethodTest.php +++ b/tests/SAML2/XML/alg/SigningMethodTest.php @@ -16,7 +16,7 @@ class SigningMethodTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $signingMethod = new SigningMethod(); - $signingMethod->Algorithm = 'http://exampleAlgorithm'; + $signingMethod->setAlgorithm('http://exampleAlgorithm'); $document = DOMDocumentFactory::fromString(''); $xml = $signingMethod->toXML($document->firstChild); @@ -32,8 +32,8 @@ public function testMarshalling() $this->assertFalse($signingMethodElement->hasAttribute('MinKeySize')); $this->assertFalse($signingMethodElement->hasAttribute('MaxKeySize')); - $signingMethod->MinKeySize = 1024; - $signingMethod->MaxKeySize = 4096; + $signingMethod->setMinKeySize(1024); + $signingMethod->setMaxKeySize(4096); $document = DOMDocumentFactory::fromString(''); $xml = $signingMethod->toXML($document->firstChild); @@ -61,9 +61,9 @@ public function testUnmarshalling() ); $signingMethod = new SigningMethod($document->firstChild); - $this->assertEquals('http://exampleAlgorithm', $signingMethod->Algorithm); - $this->assertEquals(1024, $signingMethod->MinKeySize); - $this->assertEquals(4096, $signingMethod->MaxKeySize); + $this->assertEquals('http://exampleAlgorithm', $signingMethod->getAlgorithm()); + $this->assertEquals(1024, $signingMethod->getMinKeySize()); + $this->assertEquals(4096, $signingMethod->getMaxKeySize()); } diff --git a/tests/SAML2/XML/md/AdditionalMetadataLocationTest.php b/tests/SAML2/XML/md/AdditionalMetadataLocationTest.php index dfae62127..b8d7ff25d 100644 --- a/tests/SAML2/XML/md/AdditionalMetadataLocationTest.php +++ b/tests/SAML2/XML/md/AdditionalMetadataLocationTest.php @@ -16,8 +16,8 @@ public function testMarshalling() $document = DOMDocumentFactory::fromString(''); $additionalMetadataLocation = new AdditionalMetadataLocation(); - $additionalMetadataLocation->namespace = 'NamespaceAttribute'; - $additionalMetadataLocation->location = 'TheLocation'; + $additionalMetadataLocation->setNamespace('NamespaceAttribute'); + $additionalMetadataLocation->setLocation('TheLocation'); $additionalMetadataLocationElement = $additionalMetadataLocation->toXML($document->firstChild); $additionalMetadataLocationElements = Utils::xpQuery( @@ -38,8 +38,8 @@ public function testUnmarshalling() ' namespace="TheNamespaceAttribute">LocationText' ); $additionalMetadataLocation = new AdditionalMetadataLocation($document->firstChild); - $this->assertEquals('TheNamespaceAttribute', $additionalMetadataLocation->namespace); - $this->assertEquals('LocationText', $additionalMetadataLocation->location); + $this->assertEquals('TheNamespaceAttribute', $additionalMetadataLocation->getNamespace()); + $this->assertEquals('LocationText', $additionalMetadataLocation->getLocation()); $document->loadXML( ''); $affiliationDescriptorElement = new AffiliationDescriptor(); - $affiliationDescriptorElement->affiliationOwnerID = 'TheOwner'; - $affiliationDescriptorElement->ID = 'TheID'; - $affiliationDescriptorElement->validUntil = 1234567890; - $affiliationDescriptorElement->cacheDuration = 'PT5000S'; - $affiliationDescriptorElement->AffiliateMember = [ + $affiliationDescriptorElement->setAffiliationOwnerID('TheOwner'); + $affiliationDescriptorElement->setID('TheID'); + $affiliationDescriptorElement->setValidUntil(1234567890); + $affiliationDescriptorElement->setCacheDuration('PT5000S'); + $affiliationDescriptorElement->setAffiliateMember([ 'Member1', 'Member2', - ]; + ]); + $affiliationDescriptorElement->setKeyDescriptor([ + Utils::createKeyDescriptor("testCert") + ]); $affiliationDescriptorElement = $affiliationDescriptorElement->toXML($document->firstChild); @@ -54,13 +57,14 @@ public function testUnmarshalling() ); $affiliateDescriptor = new AffiliationDescriptor($document->firstChild); - $this->assertEquals('TheOwner', $affiliateDescriptor->affiliationOwnerID); - $this->assertEquals('TheID', $affiliateDescriptor->ID); - $this->assertEquals(1234567890, $affiliateDescriptor->validUntil); - $this->assertEquals('PT5000S', $affiliateDescriptor->cacheDuration); - $this->assertCount(2, $affiliateDescriptor->AffiliateMember); - $this->assertEquals('Member', $affiliateDescriptor->AffiliateMember[0]); - $this->assertEquals('OtherMember', $affiliateDescriptor->AffiliateMember[1]); + $this->assertEquals('TheOwner', $affiliateDescriptor->getAffiliationOwnerID()); + $this->assertEquals('TheID', $affiliateDescriptor->getID()); + $this->assertEquals(1234567890, $affiliateDescriptor->getValidUntil()); + $this->assertEquals('PT5000S', $affiliateDescriptor->getCacheDuration()); + $affiliateMember = $affiliateDescriptor->getAffiliateMember(); + $this->assertCount(2, $affiliateMember); + $this->assertEquals('Member', $affiliateMember[0]); + $this->assertEquals('OtherMember', $affiliateMember[1]); } public function testUnmarshallingWithoutMembers() diff --git a/tests/SAML2/XML/md/ContactPersonTest.php b/tests/SAML2/XML/md/ContactPersonTest.php index cd74e7451..fbfdfaf4f 100644 --- a/tests/SAML2/XML/md/ContactPersonTest.php +++ b/tests/SAML2/XML/md/ContactPersonTest.php @@ -28,13 +28,13 @@ public function testContactPerson() XML ); $contactPerson = new ContactPerson(); - $contactPerson->contactType = $contactType; - $contactPerson->Company = $Company; - $contactPerson->GivenName = $GivenName; - $contactPerson->SurName = $SurName; - $contactPerson->EmailAddress = $EmailAddress; - $contactPerson->TelephoneNumber = $TelephoneNumber; - $contactPerson->ContactPersonAttributes = $ContactPersonAttributes; + $contactPerson->setContactType($contactType); + $contactPerson->setCompany($Company); + $contactPerson->setGivenName($GivenName); + $contactPerson->setSurName($SurName); + $contactPerson->setEmailAddress($EmailAddress); + $contactPerson->setTelephoneNumber($TelephoneNumber); + $contactPerson->setContactPersonAttributes($ContactPersonAttributes); $contactPerson->toXML($document->firstChild); @@ -81,14 +81,14 @@ public function testContactPersonFromXML() $contactPerson = new ContactPerson($document->getElementsByTagName('ContactPerson')->item(0)); - $this->assertEquals('Test Company', $contactPerson->Company); - $this->assertEquals('John', $contactPerson->GivenName); - $this->assertEquals('Doe', $contactPerson->SurName); - $this->assertTrue(in_array('jdoe@test.company', $contactPerson->EmailAddress)); - $this->assertTrue(in_array('john.doe@test.company', $contactPerson->EmailAddress)); - $this->assertTrue(in_array('1-234-567-8901', $contactPerson->TelephoneNumber)); - $this->assertEquals('testval', $contactPerson->ContactPersonAttributes['testattr']); - $this->assertEquals('testval2', $contactPerson->ContactPersonAttributes['testattr2']); + $this->assertEquals('Test Company', $contactPerson->getCompany()); + $this->assertEquals('John', $contactPerson->getGivenName()); + $this->assertEquals('Doe', $contactPerson->getSurName()); + $this->assertTrue(in_array('jdoe@test.company', $contactPerson->getEmailAddress())); + $this->assertTrue(in_array('john.doe@test.company', $contactPerson->getEmailAddress())); + $this->assertTrue(in_array('1-234-567-8901', $contactPerson->getTelephoneNumber())); + $this->assertEquals('testval', $contactPerson->getContactPersonAttributes()['testattr']); + $this->assertEquals('testval2', $contactPerson->getContactPersonAttributes()['testattr2']); } public function testMultipleNamesXML() @@ -136,7 +136,7 @@ public function testEmptySurNameXML() $contactPerson = new ContactPerson($document->getElementsByTagName('ContactPerson')->item(0)); - $this->assertNull($contactPerson->SurName); + $this->assertNull($contactPerson->getSurName()); } public function testMissingContactTypeXML() diff --git a/tests/SAML2/XML/md/EndpointTypeTest.php b/tests/SAML2/XML/md/EndpointTypeTest.php index 288d97d9d..51cbfc720 100644 --- a/tests/SAML2/XML/md/EndpointTypeTest.php +++ b/tests/SAML2/XML/md/EndpointTypeTest.php @@ -14,8 +14,8 @@ class EndpointTypeTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $endpointType = new EndpointType(); - $endpointType->Binding = 'TestBinding'; - $endpointType->Location = 'TestLocation'; + $endpointType->setBinding('TestBinding'); + $endpointType->setLocation('TestLocation'); $document = DOMDocumentFactory::fromString(''); $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test'); @@ -28,7 +28,7 @@ public function testMarshalling() $this->assertEquals('TestLocation', $endpointTypeElement->getAttribute('Location')); $this->assertFalse($endpointTypeElement->hasAttribute('ResponseLocation')); - $endpointType->ResponseLocation = 'TestResponseLocation'; + $endpointType->setResponseLocation('TestResponseLocation'); $document->loadXML(''); $endpointTypeElement = $endpointType->toXML($document->firstChild, 'md:Test'); diff --git a/tests/SAML2/XML/md/EntityDescriptorTest.php b/tests/SAML2/XML/md/EntityDescriptorTest.php old mode 100755 new mode 100644 index 7d86e09eb..2f7cccd4e --- a/tests/SAML2/XML/md/EntityDescriptorTest.php +++ b/tests/SAML2/XML/md/EntityDescriptorTest.php @@ -95,19 +95,21 @@ public function testUnmarshalling() $entityDescriptor = new EntityDescriptor($document->firstChild); $this->assertTrue($entityDescriptor instanceof EntityDescriptor); - $this->assertEquals('theEntityID', $entityDescriptor->entityID); + $this->assertEquals('theEntityID', $entityDescriptor->getEntityID()); - $this->assertTrue(empty($entityDescriptor->RoleDescriptor)); + $roleDescriptor = $entityDescriptor->getRoleDescriptor(); + $this->assertTrue(empty($roleDescriptor)); - $affiliationDescriptor = $entityDescriptor->AffiliationDescriptor; + $affiliationDescriptor = $entityDescriptor->getAffiliationDescriptor(); $this->assertTrue($affiliationDescriptor instanceof AffiliationDescriptor); - $this->assertEquals('asdf', $affiliationDescriptor->affiliationOwnerID); - $this->assertEquals('theAffiliationDescriptorID', $affiliationDescriptor->ID); - $this->assertEquals(1265027696, $affiliationDescriptor->validUntil); - $this->assertEquals('PT9000S', $affiliationDescriptor->cacheDuration); - $this->assertCount(2, $affiliationDescriptor->AffiliateMember); - $this->assertEquals('test', $affiliationDescriptor->AffiliateMember[0]); - $this->assertEquals('test2', $affiliationDescriptor->AffiliateMember[1]); + $this->assertEquals('asdf', $affiliationDescriptor->getAffiliationOwnerID()); + $this->assertEquals('theAffiliationDescriptorID', $affiliationDescriptor->getID()); + $this->assertEquals(1265027696, $affiliationDescriptor->getValidUntil()); + $this->assertEquals('PT9000S', $affiliationDescriptor->getCacheDuration()); + $affiliateMember = $affiliationDescriptor->getAffiliateMember(); + $this->assertCount(2, $affiliateMember); + $this->assertEquals('test', $affiliateMember[0]); + $this->assertEquals('test2', $affiliateMember[1]); } public function testUnmarshalling2() @@ -133,15 +135,16 @@ public function testUnmarshalling2() $entityDescriptor = new EntityDescriptor($document->firstChild); $this->assertTrue($entityDescriptor instanceof EntityDescriptor); - $this->assertEquals('theEntityID', $entityDescriptor->entityID); - $this->assertEquals('theID', $entityDescriptor->ID); - $this->assertEquals(1262349296, $entityDescriptor->validUntil); - $this->assertEquals('PT5000S', $entityDescriptor->cacheDuration); + $this->assertEquals('theEntityID', $entityDescriptor->getEntityID()); + $this->assertEquals('theID', $entityDescriptor->getID()); + $this->assertEquals(1262349296, $entityDescriptor->getValidUntil()); + $this->assertEquals('PT5000S', $entityDescriptor->getCacheDuration()); - $this->assertCount(1, $entityDescriptor->RoleDescriptor); - $this->assertTrue($entityDescriptor->RoleDescriptor[0] instanceof AttributeAuthorityDescriptor); + $roleDescriptor = $entityDescriptor->getRoleDescriptor(); + $this->assertCount(1, $roleDescriptor); + $this->assertTrue($roleDescriptor[0] instanceof AttributeAuthorityDescriptor); - $o = $entityDescriptor->Organization; + $o = $entityDescriptor->getOrganization(); $this->assertTrue($o instanceof Organization); $this->assertCount(2, $o->OrganizationName); $this->assertEquals('orgNameTest (no)', $o->OrganizationName["no"]); diff --git a/tests/SAML2/XML/md/ExtensionsTest.php b/tests/SAML2/XML/md/ExtensionsTest.php index 4d0aa38a6..e65a1b834 100644 --- a/tests/SAML2/XML/md/ExtensionsTest.php +++ b/tests/SAML2/XML/md/ExtensionsTest.php @@ -4,6 +4,8 @@ use SAML2\Constants; use SAML2\DOMDocumentFactory; +use SAML2\XML\shibmd\Scope; +use SAML2\XML\alg\DigestMethod; /** * Class \SAML2\XML\md\ExtensionsTest. @@ -118,10 +120,10 @@ public function testAddExtensions() $document->formatOutput = true; $r = $document->createElement('root'); $document->appendChild($r); - $scope = new \SAML2\XML\shibmd\Scope(); - $scope->scope = 'SomeScope'; - $digest = new \SAML2\XML\alg\DigestMethod(); - $digest->Algorithm = 'SomeAlgorithm'; + $scope = new Scope(); + $scope->setScope('SomeScope'); + $digest = new DigestMethod(); + $digest->setAlgorithm('SomeAlgorithm'); $extensions = [ $scope, $digest, diff --git a/tests/SAML2/XML/md/IndexedEndpointTypeTest.php b/tests/SAML2/XML/md/IndexedEndpointTypeTest.php index ab396571c..2b054bb85 100644 --- a/tests/SAML2/XML/md/IndexedEndpointTypeTest.php +++ b/tests/SAML2/XML/md/IndexedEndpointTypeTest.php @@ -15,8 +15,8 @@ public function testMarshalling() $indexedEndpointType = new IndexedEndpointType(); $indexedEndpointType->Binding = 'TestBinding'; $indexedEndpointType->Location = 'TestLocation'; - $indexedEndpointType->index = 42; - $indexedEndpointType->isDefault = false; + $indexedEndpointType->setIndex(42); + $indexedEndpointType->setIsDefault(false); $document = DOMDocumentFactory::fromString(''); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); @@ -30,14 +30,14 @@ public function testMarshalling() $this->assertEquals('42', $indexedEndpointElement->getAttribute('index')); $this->assertEquals('false', $indexedEndpointElement->getAttribute('isDefault')); - $indexedEndpointType->isDefault = true; + $indexedEndpointType->setIsDefault(true); $document->loadXML(''); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test'); $this->assertCount(1, $indexedEndpointTypeElement); $this->assertEquals('true', $indexedEndpointTypeElement[0]->getAttribute('isDefault')); - $indexedEndpointType->isDefault = null; + $indexedEndpointType->setIsDefault(null); $document->loadXML(''); $indexedEndpointTypeElement = $indexedEndpointType->toXML($document->firstChild, 'md:Test'); $indexedEndpointTypeElement = Utils::xpQuery($indexedEndpointTypeElement, '/root/saml_metadata:Test'); diff --git a/tests/SAML2/XML/md/RoleDescriptorTest.php b/tests/SAML2/XML/md/RoleDescriptorTest.php index 183a8b420..5eb8194f4 100644 --- a/tests/SAML2/XML/md/RoleDescriptorTest.php +++ b/tests/SAML2/XML/md/RoleDescriptorTest.php @@ -13,14 +13,17 @@ class RoleDescriptorTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $roleDescriptor = new RoleDescriptorMock(); - $roleDescriptor->ID = 'SomeID'; - $roleDescriptor->validUntil = 1234567890; - $roleDescriptor->cacheDuration = 'PT5000S'; - $roleDescriptor->protocolSupportEnumeration = [ + $roleDescriptor->setID('SomeID'); + $roleDescriptor->setValidUntil(1234567890); + $roleDescriptor->setCacheDuration('PT5000S'); + $roleDescriptor->setProtocolSupportEnumeration([ 'protocol1', 'protocol2', - ]; - $roleDescriptor->errorURL = 'https://example.org/error'; + ]); + $roleDescriptor->setErrorURL('https://example.org/error'); + $roleDescriptor->setKeyDescriptor([ + Utils::createKeyDescriptor("testCert") + ]); $document = DOMDocumentFactory::fromString(''); $roleDescriptorElement = $roleDescriptor->toXML($document->firstChild); diff --git a/tests/SAML2/XML/mdattr/EntityAttributesTest.php b/tests/SAML2/XML/mdattr/EntityAttributesTest.php index 1c81d756e..dab2eafa8 100644 --- a/tests/SAML2/XML/mdattr/EntityAttributesTest.php +++ b/tests/SAML2/XML/mdattr/EntityAttributesTest.php @@ -15,22 +15,21 @@ class EntityAttributesTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $attribute1 = new Attribute(); - $attribute1->Name = 'urn:simplesamlphp:v1:simplesamlphp'; - $attribute1->NameFormat = 'urn:oasis:names:tc:SAML:2.0:attrname-format:uri'; - $attribute1->AttributeValue = [ + $attribute1->setName('urn:simplesamlphp:v1:simplesamlphp'); + $attribute1->setNameFormat('urn:oasis:names:tc:SAML:2.0:attrname-format:uri'); + $attribute1->setAttributeValue([ new AttributeValue('FirstValue'), new AttributeValue('SecondValue'), - ]; + ]); $attribute2 = new Attribute(); - $attribute2->Name = 'foo'; - $attribute2->NameFormat = 'urn:simplesamlphp:v1'; - $attribute2->AttributeValue = [ + $attribute2->setName('foo'); + $attribute2->setNameFormat('urn:simplesamlphp:v1'); + $attribute2->setAttributeValue([ new AttributeValue('bar'), - ]; + ]); $entityAttributes = new EntityAttributes(); - $entityAttributes->children[] = $attribute1; - $entityAttributes->children[] = $attribute2; + $entityAttributes->setChildren([$attribute1, $attribute2]); $document = DOMDocumentFactory::fromString(''); $xml = $entityAttributes->toXML($document->firstChild); @@ -63,17 +62,17 @@ public function testUnmarshalling() ); $entityAttributes = new EntityAttributes($document->firstChild); - $this->assertCount(5, $entityAttributes->children); + $this->assertCount(5, $entityAttributes->getChildren()); - $this->assertInstanceOf('SAML2\XML\Chunk', $entityAttributes->children[0]); - $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->children[1]); - $this->assertInstanceOf('SAML2\XML\Chunk', $entityAttributes->children[2]); - $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->children[3]); - $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->children[4]); + $this->assertInstanceOf('SAML2\XML\Chunk', $entityAttributes->getChildren()[0]); + $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->getChildren()[1]); + $this->assertInstanceOf('SAML2\XML\Chunk', $entityAttributes->getChildren()[2]); + $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->getChildren()[3]); + $this->assertInstanceOf('SAML2\XML\saml\Attribute', $entityAttributes->getChildren()[4]); - $this->assertEquals('Assertion', $entityAttributes->children[0]->localName); - $this->assertEquals('1984-08-26T10:01:30.000Z', $entityAttributes->children[0]->xml->getAttribute('IssueInstant')); - $this->assertEquals('attrib2', $entityAttributes->children[3]->Name); + $this->assertEquals('Assertion', $entityAttributes->getChildren()[0]->getLocalName()); + $this->assertEquals('1984-08-26T10:01:30.000Z', $entityAttributes->getChildren()[0]->xml->getAttribute('IssueInstant')); + $this->assertEquals('attrib2', $entityAttributes->getChildren()[3]->getName()); } public function testUnmarshallingAttributes() @@ -93,13 +92,13 @@ public function testUnmarshallingAttributes() ); $entityAttributes = new EntityAttributes($document->firstChild); - $this->assertCount(2, $entityAttributes->children); + $this->assertCount(2, $entityAttributes->getChildren()); - $this->assertEquals('urn:simplesamlphp:v1:simplesamlphp', $entityAttributes->children[0]->Name); - $this->assertEquals('urn:oasis:names:tc:SAML:2.0:attrname-format:uri', $entityAttributes->children[0]->NameFormat); - $this->assertCount(3, $entityAttributes->children[0]->AttributeValue); - $this->assertEquals('foo', $entityAttributes->children[1]->Name); - $this->assertEquals('urn:simplesamlphp:v1', $entityAttributes->children[1]->NameFormat); - $this->assertCount(1, $entityAttributes->children[1]->AttributeValue); + $this->assertEquals('urn:simplesamlphp:v1:simplesamlphp', $entityAttributes->getChildren()[0]->getName()); + $this->assertEquals('urn:oasis:names:tc:SAML:2.0:attrname-format:uri', $entityAttributes->getChildren()[0]->getNameFormat()); + $this->assertCount(3, $entityAttributes->getChildren()[0]->getAttributeValue()); + $this->assertEquals('foo', $entityAttributes->getChildren()[1]->getName()); + $this->assertEquals('urn:simplesamlphp:v1', $entityAttributes->getChildren()[1]->getNameFormat()); + $this->assertCount(1, $entityAttributes->getChildren()[1]->getAttributeValue()); } } diff --git a/tests/SAML2/XML/mdrpi/PublicationInfoTest.php b/tests/SAML2/XML/mdrpi/PublicationInfoTest.php index 8027ecf71..b851b7545 100644 --- a/tests/SAML2/XML/mdrpi/PublicationInfoTest.php +++ b/tests/SAML2/XML/mdrpi/PublicationInfoTest.php @@ -13,13 +13,13 @@ class PublicationInfoTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $publicationInfo = new PublicationInfo(); - $publicationInfo->publisher = 'TestPublisher'; - $publicationInfo->creationInstant = 1234567890; - $publicationInfo->publicationId = 'PublicationIdValue'; - $publicationInfo->UsagePolicy = [ + $publicationInfo->setPublisher('TestPublisher'); + $publicationInfo->setCreationInstant(1234567890); + $publicationInfo->setPublicationId('PublicationIdValue'); + $publicationInfo->setUsagePolicy([ 'en' => 'http://EnglishUsagePolicy', 'no' => 'http://NorwegianUsagePolicy', - ]; + ]); $document = DOMDocumentFactory::fromString(''); $xml = $publicationInfo->toXML($document->firstChild); @@ -62,12 +62,14 @@ public function testUnmarshalling() $publicationInfo = new PublicationInfo($document->firstChild); - $this->assertEquals('SomePublisher', $publicationInfo->publisher); - $this->assertEquals(1293840000, $publicationInfo->creationInstant); - $this->assertEquals('SomePublicationId', $publicationInfo->publicationId); - $this->assertCount(2, $publicationInfo->UsagePolicy); - $this->assertEquals('http://TheEnglishUsagePolicy', $publicationInfo->UsagePolicy["en"]); - $this->assertEquals('http://TheNorwegianUsagePolicy', $publicationInfo->UsagePolicy["no"]); + $this->assertEquals('SomePublisher', $publicationInfo->getPublisher()); + $this->assertEquals(1293840000, $publicationInfo->getCreationInstant()); + $this->assertEquals('SomePublicationId', $publicationInfo->getPublicationId()); + + $usagePolicy = $publicationInfo->getUsagePolicy(); + $this->assertCount(2, $usagePolicy); + $this->assertEquals('http://TheEnglishUsagePolicy', $usagePolicy["en"]); + $this->assertEquals('http://TheNorwegianUsagePolicy', $usagePolicy["no"]); } public function testMissingPublisherThrowsException() diff --git a/tests/SAML2/XML/mdrpi/RegistrationInfoTest.php b/tests/SAML2/XML/mdrpi/RegistrationInfoTest.php index f7bca9e06..b8899b636 100644 --- a/tests/SAML2/XML/mdrpi/RegistrationInfoTest.php +++ b/tests/SAML2/XML/mdrpi/RegistrationInfoTest.php @@ -13,12 +13,12 @@ class RegistrationInfoTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $registrationInfo = new RegistrationInfo(); - $registrationInfo->registrationAuthority = 'https://ExampleAuthority'; - $registrationInfo->registrationInstant = 1234567890; - $registrationInfo->RegistrationPolicy = [ + $registrationInfo->setRegistrationAuthority('https://ExampleAuthority'); + $registrationInfo->setRegistrationInstant(1234567890); + $registrationInfo->setRegistrationPolicy([ 'en' => 'http://EnglishRegistrationPolicy', 'nl' => 'https://DutchRegistratiebeleid', - ]; + ]); $document = DOMDocumentFactory::fromString(''); $xml = $registrationInfo->toXML($document->firstChild); @@ -63,11 +63,13 @@ public function testUnmarshalling() $registrationInfo = new RegistrationInfo($document->firstChild); - $this->assertEquals('urn:example:example.org', $registrationInfo->registrationAuthority); - $this->assertEquals(1148902467, $registrationInfo->registrationInstant); - $this->assertCount(2, $registrationInfo->RegistrationPolicy); - $this->assertEquals('http://www.example.org/aai/metadata/en_registration.html', $registrationInfo->RegistrationPolicy["en"]); - $this->assertEquals('http://www.example.org/aai/metadata/de_registration.html', $registrationInfo->RegistrationPolicy["de"]); + $this->assertEquals('urn:example:example.org', $registrationInfo->getRegistrationAuthority()); + $this->assertEquals(1148902467, $registrationInfo->getRegistrationInstant()); + + $registrationPolicy = $registrationInfo->getRegistrationPolicy(); + $this->assertCount(2, $registrationPolicy); + $this->assertEquals('http://www.example.org/aai/metadata/en_registration.html', $registrationPolicy["en"]); + $this->assertEquals('http://www.example.org/aai/metadata/de_registration.html', $registrationPolicy["de"]); } public function testMissingPublisherThrowsException() @@ -86,7 +88,7 @@ public function testMissingPublisherThrowsException() public function testEmptyRegistrationAuthorityOutboundThrowsException() { $registrationInfo = new RegistrationInfo(); - $registrationInfo->registrationAuthority = ''; + $registrationInfo->setRegistrationAuthority(''); $document = DOMDocumentFactory::fromString(''); diff --git a/tests/SAML2/XML/mdui/DiscoHintsTest.php b/tests/SAML2/XML/mdui/DiscoHintsTest.php index c3c83a8f1..1f32d18b4 100644 --- a/tests/SAML2/XML/mdui/DiscoHintsTest.php +++ b/tests/SAML2/XML/mdui/DiscoHintsTest.php @@ -16,9 +16,9 @@ class DiscoHintsTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $discoHints = new DiscoHints(); - $discoHints->IPHint = ["192.168.6.0/24", "fd00:0123:aa:1001::/64"]; - $discoHints->DomainHint = ["example.org", "student.example.org"]; - $discoHints->GeolocationHint = ["geo:47.37328,8.531126", "geo:19.34343,12.342514"]; + $discoHints->setIPHint(["192.168.6.0/24", "fd00:0123:aa:1001::/64"]); + $discoHints->setDomainHint(["example.org", "student.example.org"]); + $discoHints->setGeolocationHint(["geo:47.37328,8.531126", "geo:19.34343,12.342514"]); $document = DOMDocumentFactory::fromString(''); $xml = $discoHints->toXML($document->firstChild); @@ -87,15 +87,15 @@ public function testUnmarshalling() $disco = new DiscoHints($document->firstChild); - $this->assertCount(2, $disco->IPHint); - $this->assertEquals('130.59.0.0/16', $disco->IPHint[0]); - $this->assertEquals('2001:620::0/96', $disco->IPHint[1]); - $this->assertCount(2, $disco->DomainHint); - $this->assertEquals('example.com', $disco->DomainHint[0]); - $this->assertEquals('www.example.com', $disco->DomainHint[1]); - $this->assertCount(2, $disco->GeolocationHint); - $this->assertEquals('geo:47.37328,8.531126', $disco->GeolocationHint[0]); - $this->assertEquals('geo:19.34343,12.342514', $disco->GeolocationHint[1]); + $this->assertCount(2, $disco->getIPHint()); + $this->assertEquals('130.59.0.0/16', $disco->getIPHint()[0]); + $this->assertEquals('2001:620::0/96', $disco->getIPHint()[1]); + $this->assertCount(2, $disco->getDomainHint()); + $this->assertEquals('example.com', $disco->getDomainHint()[0]); + $this->assertEquals('www.example.com', $disco->getDomainHint()[1]); + $this->assertCount(2, $disco->getGeolocationHint()); + $this->assertEquals('geo:47.37328,8.531126', $disco->getGeolocationHint()[0]); + $this->assertEquals('geo:19.34343,12.342514', $disco->getGeolocationHint()[1]); } /** @@ -105,9 +105,9 @@ public function testMarshallingChildren() { $discoHints = new DiscoHints(); $keywords = new Keywords(); - $keywords->lang = "nl"; - $keywords->Keywords = ["voorbeeld", "specimen"]; - $discoHints->children = [$keywords]; + $keywords->setLanguage("nl"); + $keywords->setKeywords(["voorbeeld", "specimen"]); + $discoHints->setChildren([$keywords]); $document = DOMDocumentFactory::fromString(''); $xml = $discoHints->toXML($document->firstChild); @@ -137,9 +137,9 @@ public function testUnmarshallingChildren() $disco = new DiscoHints($document->firstChild); - $this->assertCount(1, $disco->GeolocationHint); - $this->assertEquals('geo:47.37328,8.531126', $disco->GeolocationHint[0]); - $this->assertCount(1, $disco->children); - $this->assertEquals('content of tag', $disco->children[0]->xml->textContent); + $this->assertCount(1, $disco->getGeolocationHint()); + $this->assertEquals('geo:47.37328,8.531126', $disco->getGeolocationHint()[0]); + $this->assertCount(1, $disco->getChildren()); + $this->assertEquals('content of tag', $disco->getChildren()[0]->xml->textContent); } } diff --git a/tests/SAML2/XML/mdui/KeywordsTest.php b/tests/SAML2/XML/mdui/KeywordsTest.php index 4b057efc7..c5ec3a959 100644 --- a/tests/SAML2/XML/mdui/KeywordsTest.php +++ b/tests/SAML2/XML/mdui/KeywordsTest.php @@ -16,8 +16,8 @@ class KeywordsTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $keywords = new Keywords(); - $keywords->lang = "en"; - $keywords->Keywords = ["KLM", "royal", "Dutch", "air lines"]; + $keywords->setLanguage("en"); + $keywords->setKeywords(["KLM", "royal", "Dutch", "air lines"]); $document = DOMDocumentFactory::fromString(''); $xml = $keywords->toXML($document->firstChild); @@ -38,8 +38,8 @@ public function testMarshalling() public function testKeywordWithPlusSignThrowsException() { $keywords = new Keywords(); - $keywords->lang = "en"; - $keywords->Keywords = ["csharp", "pascal", "c++"]; + $keywords->setLanguage("en"); + $keywords->setKeywords(["csharp", "pascal", "c++"]); $document = DOMDocumentFactory::fromString(''); @@ -58,11 +58,11 @@ public function testUnmarshalling() ); $keywords = new Keywords($document->firstChild); - $this->assertEquals("nl", $keywords->lang); - $this->assertCount(3, $keywords->Keywords); - $this->assertEquals("KLM", $keywords->Keywords[0]); - $this->assertEquals("koninklijke", $keywords->Keywords[1]); - $this->assertEquals("luchtvaart maatschappij", $keywords->Keywords[2]); + $this->assertEquals("nl", $keywords->getLanguage()); + $this->assertCount(3, $keywords->getKeywords()); + $this->assertEquals("KLM", $keywords->getKeywords()[0]); + $this->assertEquals("koninklijke", $keywords->getKeywords()[1]); + $this->assertEquals("luchtvaart maatschappij", $keywords->getKeywords()[2]); } /** diff --git a/tests/SAML2/XML/mdui/LogoTest.php b/tests/SAML2/XML/mdui/LogoTest.php index 4ea883331..6d771bca5 100644 --- a/tests/SAML2/XML/mdui/LogoTest.php +++ b/tests/SAML2/XML/mdui/LogoTest.php @@ -16,10 +16,10 @@ class LogoTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $logo = new Logo(); - $logo->lang = "nl"; - $logo->width = 300; - $logo->height = 200; - $logo->url = "https://static.example.org/images/logos/logo300x200.png"; + $logo->setLanguage("nl"); + $logo->setWidth(300); + $logo->setHeight(200); + $logo->setUrl("https://static.example.org/images/logos/logo300x200.png"); $document = DOMDocumentFactory::fromString(''); $xml = $logo->toXML($document->firstChild); @@ -47,10 +47,10 @@ public function testUnmarshalling() ); $logo = new Logo($document->firstChild); - $this->assertEquals("nl", $logo->lang); - $this->assertEquals(300, $logo->width); - $this->assertEquals(200, $logo->height); - $this->assertEquals("https://static.example.org/images/logos/logo300x200.png", $logo->url); + $this->assertEquals("nl", $logo->getLanguage()); + $this->assertEquals(300, $logo->getWidth()); + $this->assertEquals(200, $logo->getHeight()); + $this->assertEquals("https://static.example.org/images/logos/logo300x200.png", $logo->getUrl()); } /** diff --git a/tests/SAML2/XML/mdui/UIInfoTest.php b/tests/SAML2/XML/mdui/UIInfoTest.php index 6e2aac9c2..d0dabe8db 100644 --- a/tests/SAML2/XML/mdui/UIInfoTest.php +++ b/tests/SAML2/XML/mdui/UIInfoTest.php @@ -16,17 +16,17 @@ class UIInfoTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $logo = new Logo(); - $logo->lang = "nl"; - $logo->width = 30; - $logo->height = 20; - $logo->url = "https://example.edu/logo.png"; + $logo->setLanguage("nl"); + $logo->setWidth(30); + $logo->setHeight(20); + $logo->setUrl("https://example.edu/logo.png"); $uiinfo = new UIInfo(); - $uiinfo->DisplayName = ["nl" => "Voorbeeld", "en" => "Example"]; - $uiinfo->Description = ["nl" => "Omschrijving", "en" => "Description"]; - $uiinfo->InformationURL = ["nl" => "https://voorbeeld.nl/", "en" => "https://example.org"]; - $uiinfo->PrivacyStatementURL = ["nl" => "https://voorbeeld.nl/privacy", "en" => "https://example.org/privacy"]; - $uiinfo->Logo = [$logo]; + $uiinfo->setDisplayName(["nl" => "Voorbeeld", "en" => "Example"]); + $uiinfo->setDescription(["nl" => "Omschrijving", "en" => "Description"]); + $uiinfo->setInformationURL(["nl" => "https://voorbeeld.nl/", "en" => "https://example.org"]); + $uiinfo->setPrivacyStatementURL(["nl" => "https://voorbeeld.nl/privacy", "en" => "https://example.org/privacy"]); + $uiinfo->setLogo([$logo]); $document = DOMDocumentFactory::fromString(''); $xml = $uiinfo->toXML($document->firstChild); @@ -85,22 +85,22 @@ public function testMarshalling() public function testMarshallingChildren() { $keywords = new Keywords(); - $keywords->lang = "nl"; - $keywords->Keywords = ["voorbeeld", "specimen"]; + $keywords->setLanguage("nl"); + $keywords->setKeywords(["voorbeeld", "specimen"]); $logo = new Logo(); - $logo->lang = "nl"; - $logo->width = 30; - $logo->height = 20; - $logo->url = "https://example.edu/logo.png"; + $logo->setLanguage("nl"); + $logo->setWidth(30); + $logo->setHeight(20); + $logo->setUrl("https://example.edu/logo.png"); $discohints = new DiscoHints(); - $discohints->IPHint = ["192.168.6.0/24", "fd00:0123:aa:1001::/64"]; + $discohints->setIPHint(["192.168.6.0/24", "fd00:0123:aa:1001::/64"]); // keywords appears twice, direcyly under UIinfo and as child of DiscoHints - $discohints->children = [$keywords]; + $discohints->setChildren([$keywords]); $uiinfo = new UIInfo(); - $uiinfo->Logo = [$logo]; - $uiinfo->Keywords = [$keywords]; - $uiinfo->children = [$discohints]; + $uiinfo->setLogo([$logo]); + $uiinfo->setKeywords([$keywords]); + $uiinfo->setChildren([$discohints]); $document = DOMDocumentFactory::fromString(''); $xml = $uiinfo->toXML($document->firstChild); @@ -170,16 +170,16 @@ public function testUnmarshalling() $uiinfo = new UIInfo($document->firstChild); - $this->assertCount(2, $uiinfo->DisplayName); - $this->assertEquals('University of Examples', $uiinfo->DisplayName['en']); - $this->assertEquals('Univërsitä øf Exåmpleß', $uiinfo->DisplayName['el']); - $this->assertCount(2, $uiinfo->InformationURL); - $this->assertEquals('http://www.example.edu/en/', $uiinfo->InformationURL['en']); - $this->assertEquals('http://www.example.edu/', $uiinfo->InformationURL['el']); - $this->assertCount(1, $uiinfo->PrivacyStatementURL); - $this->assertEquals('https://example.org/privacy', $uiinfo->PrivacyStatementURL['en']); - $this->assertCount(1, $uiinfo->Description); - $this->assertEquals('Just an example', $uiinfo->Description['en']); + $this->assertCount(2, $uiinfo->getDisplayName()); + $this->assertEquals('University of Examples', $uiinfo->getDisplayName()['en']); + $this->assertEquals('Univërsitä øf Exåmpleß', $uiinfo->getDisplayName()['el']); + $this->assertCount(2, $uiinfo->getInformationURL()); + $this->assertEquals('http://www.example.edu/en/', $uiinfo->getInformationURL()['en']); + $this->assertEquals('http://www.example.edu/', $uiinfo->getInformationURL()['el']); + $this->assertCount(1, $uiinfo->getPrivacyStatementURL()); + $this->assertEquals('https://example.org/privacy', $uiinfo->getPrivacyStatementURL()['en']); + $this->assertCount(1, $uiinfo->getDescription()); + $this->assertEquals('Just an example', $uiinfo->getDescription()['en']); } /** @@ -201,17 +201,17 @@ public function testUnmarshallingChildren() $uiinfo = new UIInfo($document->firstChild); - $this->assertCount(1, $uiinfo->DisplayName); - $this->assertEquals('University of Examples', $uiinfo->DisplayName['en']); - $this->assertCount(1, $uiinfo->Logo); - $this->assertEquals('https://example.org/idp/images/logo_87x88.png', $uiinfo->Logo[0]->url); - $this->assertEquals(87, $uiinfo->Logo[0]->width); - $this->assertEquals(88, $uiinfo->Logo[0]->height); - $this->assertEquals("fy", $uiinfo->Logo[0]->lang); - $this->assertCount(2, $uiinfo->Keywords); - $this->assertEquals('Fictional', $uiinfo->Keywords[0]->Keywords[1]); - $this->assertEquals('fr', $uiinfo->Keywords[1]->lang); - $this->assertCount(2, $uiinfo->children); - $this->assertEquals('child2', $uiinfo->children[1]->localName); + $this->assertCount(1, $uiinfo->getDisplayName()); + $this->assertEquals('University of Examples', $uiinfo->getDisplayName()['en']); + $this->assertCount(1, $uiinfo->getLogo()); + $this->assertEquals('https://example.org/idp/images/logo_87x88.png', $uiinfo->getLogo()[0]->getUrl()); + $this->assertEquals(87, $uiinfo->getLogo()[0]->getWidth()); + $this->assertEquals(88, $uiinfo->getLogo()[0]->getHeight()); + $this->assertEquals("fy", $uiinfo->getLogo()[0]->getLanguage()); + $this->assertCount(2, $uiinfo->getKeywords()); + $this->assertEquals('Fictional', $uiinfo->getKeywords()[0]->getKeywords()[1]); + $this->assertEquals('fr', $uiinfo->getKeywords()[1]->getLanguage()); + $this->assertCount(2, $uiinfo->getChildren()); + $this->assertEquals('child2', $uiinfo->getChildren()[1]->localName); } } diff --git a/tests/SAML2/XML/saml/IssuerXMLShowAllTest.php b/tests/SAML2/XML/saml/IssuerXMLShowAllTest.php index a16a26691..c51dee2d1 100644 --- a/tests/SAML2/XML/saml/IssuerXMLShowAllTest.php +++ b/tests/SAML2/XML/saml/IssuerXMLShowAllTest.php @@ -16,11 +16,11 @@ class IssuerShowAllTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = 'TheFormat'; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat('TheFormat'); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setValue('TheIssuerValue'); $issuerElement = $issuer->toXML(); $issuerElements = Utils::xpQuery($issuerElement, '/saml_assertion:Issuer'); $this->assertCount(1, $issuerElements); @@ -42,22 +42,22 @@ public function testUnmarshalling() ); $issuer = new Issuer($document->firstChild); - $this->assertEquals('TheNameQualifier', $issuer->NameQualifier); - $this->assertEquals('TheSPNameQualifier', $issuer->SPNameQualifier); - $this->assertEquals('TheFormat', $issuer->Format); - $this->assertEquals('TheSPProvidedID', $issuer->SPProvidedID); - $this->assertEquals('TheIssuerValue', $issuer->value); + $this->assertEquals('TheNameQualifier', $issuer->getNameQualifier()); + $this->assertEquals('TheSPNameQualifier', $issuer->getSPNameQualifier()); + $this->assertEquals('TheFormat', $issuer->getFormat()); + $this->assertEquals('TheSPProvidedID', $issuer->getSPProvidedID()); + $this->assertEquals('TheIssuerValue', $issuer->getValue()); } public function testToStringShowAllTrueFormatNameID() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = Constants::NAMEID_ENTITY; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; - $issuer->Saml2IssuerShowAll=true; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat(Constants::NAMEID_ENTITY); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setvalue('TheIssuerValue'); + $issuer->setSaml2IssuerShowAll(true); $output = ''. 'TheIssuerValue'; @@ -67,12 +67,12 @@ public function testToStringShowAllTrueFormatNameID() public function testToStringShowAllFalseFormatNameID() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = Constants::NAMEID_ENTITY; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; - $issuer->Saml2IssuerShowAll=false; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat(Constants::NAMEID_ENTITY); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setValue('TheIssuerValue'); + $issuer->setSaml2IssuerShowAll(false); $output = 'TheIssuerValue'; @@ -81,12 +81,12 @@ public function testToStringShowAllFalseFormatNameID() public function testToStringShowAllTrueNOTNameIDFormat() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = 'TheFormat'; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; - $issuer->Saml2IssuerShowAll=true; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat('TheFormat'); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setValue('TheIssuerValue'); + $issuer->setSaml2IssuerShowAll(true); $output = ''. @@ -97,12 +97,12 @@ public function testToStringShowAllTrueNOTNameIDFormat() public function testToStringShowAllDefaultNOTNameIDFormat() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = 'TheFormat'; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; - //$issuer->Saml2IssuerShowAll=false; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat('TheFormat'); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setValue('TheIssuerValue'); + //$issuer->setSaml2IssuerShowAll(false); $output = ''. @@ -113,12 +113,12 @@ public function testToStringShowAllDefaultNOTNameIDFormat() public function testToStringShowAllDefaultNameIDFormat() { $issuer = new Issuer(); - $issuer->NameQualifier = 'TheNameQualifier'; - $issuer->SPNameQualifier = 'TheSPNameQualifier'; - $issuer->Format = Constants::NAMEID_ENTITY; - $issuer->SPProvidedID = 'TheSPProvidedID'; - $issuer->value = 'TheIssuerValue'; - //$issuer->Saml2IssuerShowAll=false; + $issuer->setNameQualifier('TheNameQualifier'); + $issuer->setSPNameQualifier('TheSPNameQualifier'); + $issuer->setFormat(Constants::NAMEID_ENTITY); + $issuer->setSPProvidedID('TheSPProvidedID'); + $issuer->setValue('TheIssuerValue'); + //$issuer->setSaml2IssuerShowAll(false); $output = 'TheIssuerValue'; diff --git a/tests/SAML2/XML/saml/NameIDTest.php b/tests/SAML2/XML/saml/NameIDTest.php index 3f508adfd..8e6565db1 100644 --- a/tests/SAML2/XML/saml/NameIDTest.php +++ b/tests/SAML2/XML/saml/NameIDTest.php @@ -15,11 +15,11 @@ class NameIDTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $nameId = new NameID(); - $nameId->NameQualifier = 'TheNameQualifier'; - $nameId->SPNameQualifier = 'TheSPNameQualifier'; - $nameId->Format = 'TheFormat'; - $nameId->SPProvidedID = 'TheSPProvidedID'; - $nameId->value = 'TheNameIDValue'; + $nameId->setNameQualifier('TheNameQualifier'); + $nameId->setSPNameQualifier('TheSPNameQualifier'); + $nameId->setFormat('TheFormat'); + $nameId->setSPProvidedID('TheSPProvidedID'); + $nameId->setValue('TheNameIDValue'); $nameIdElement = $nameId->toXML(); $nameIdElements = Utils::xpQuery($nameIdElement, '/saml_assertion:NameID'); @@ -42,21 +42,21 @@ public function testUnmarshalling() ); $nameId = new NameID($document->firstChild); - $this->assertEquals('TheNameQualifier', $nameId->NameQualifier); - $this->assertEquals('TheSPNameQualifier', $nameId->SPNameQualifier); - $this->assertEquals('TheFormat', $nameId->Format); - $this->assertEquals('TheSPProvidedID', $nameId->SPProvidedID); - $this->assertEquals('TheNameIDValue', $nameId->value); + $this->assertEquals('TheNameQualifier', $nameId->getNameQualifier()); + $this->assertEquals('TheSPNameQualifier', $nameId->getSPNameQualifier()); + $this->assertEquals('TheFormat', $nameId->getFormat()); + $this->assertEquals('TheSPProvidedID', $nameId->getSPProvidedID()); + $this->assertEquals('TheNameIDValue', $nameId->getValue()); } public function testToString() { $nameId = new NameID(); - $nameId->NameQualifier = 'TheNameQualifier'; - $nameId->SPNameQualifier = 'TheSPNameQualifier'; - $nameId->Format = 'TheFormat'; - $nameId->SPProvidedID = 'TheSPProvidedID'; - $nameId->value = 'TheNameIDValue'; + $nameId->setNameQualifier('TheNameQualifier'); + $nameId->setSPNameQualifier('TheSPNameQualifier'); + $nameId->setFormat('TheFormat'); + $nameId->setSPProvidedID('TheSPProvidedID'); + $nameId->setValue('TheNameIDValue'); $output = ''. diff --git a/tests/SAML2/XML/saml/SubjectConfirmationDataTest.php b/tests/SAML2/XML/saml/SubjectConfirmationDataTest.php index 4edc17104..556b25b32 100644 --- a/tests/SAML2/XML/saml/SubjectConfirmationDataTest.php +++ b/tests/SAML2/XML/saml/SubjectConfirmationDataTest.php @@ -14,11 +14,11 @@ class SubjectConfirmationDataTest extends \PHPUnit_Framework_TestCase public function testMarshalling() { $subjectConfirmationData = new SubjectConfirmationData(); - $subjectConfirmationData->NotBefore = 987654321; - $subjectConfirmationData->NotOnOrAfter = 1234567890; - $subjectConfirmationData->Recipient = 'https://sp.example.org/asdf'; - $subjectConfirmationData->InResponseTo = 'SomeRequestID'; - $subjectConfirmationData->Address = '127.0.0.1'; + $subjectConfirmationData->setNotBefore(987654321); + $subjectConfirmationData->setNotOnOrAfter(1234567890); + $subjectConfirmationData->setRecipient('https://sp.example.org/asdf'); + $subjectConfirmationData->setInResponseTo('SomeRequestID'); + $subjectConfirmationData->setAddress('127.0.0.1'); $document = DOMDocumentFactory::fromString(''); $subjectConfirmationDataElement = $subjectConfirmationData->toXML($document->firstChild); @@ -53,10 +53,10 @@ public function testUnmarshalling() ); $subjectConfirmationData = new SubjectConfirmationData($document->firstChild); - $this->assertEquals(987654321, $subjectConfirmationData->NotBefore); - $this->assertEquals(1234567890, $subjectConfirmationData->NotOnOrAfter); - $this->assertEquals('https://sp.example.org/asdf', $subjectConfirmationData->Recipient); - $this->assertEquals('SomeRequestID', $subjectConfirmationData->InResponseTo); - $this->assertEquals('127.0.0.1', $subjectConfirmationData->Address); + $this->assertEquals(987654321, $subjectConfirmationData->getNotBefore()); + $this->assertEquals(1234567890, $subjectConfirmationData->getNotOnOrAfter()); + $this->assertEquals('https://sp.example.org/asdf', $subjectConfirmationData->getRecipient()); + $this->assertEquals('SomeRequestID', $subjectConfirmationData->getInResponseTo()); + $this->assertEquals('127.0.0.1', $subjectConfirmationData->getAddress()); } } diff --git a/tests/SAML2/XML/saml/SubjectConfirmationTest.php b/tests/SAML2/XML/saml/SubjectConfirmationTest.php index 9a54a80bf..13b171a8b 100644 --- a/tests/SAML2/XML/saml/SubjectConfirmationTest.php +++ b/tests/SAML2/XML/saml/SubjectConfirmationTest.php @@ -13,11 +13,13 @@ class SubjectConfirmationTest extends \PHPUnit_Framework_TestCase { public function testMarshalling() { + $nameId = new NameID(); + $nameId->setValue('SomeNameIDValue'); + $subjectConfirmation = new SubjectConfirmation(); - $subjectConfirmation->Method = 'SomeMethod'; - $subjectConfirmation->NameID = new NameID(); - $subjectConfirmation->NameID->value = 'SomeNameIDValue'; - $subjectConfirmation->SubjectConfirmationData = new SubjectConfirmationData(); + $subjectConfirmation->setMethod('SomeMethod'); + $subjectConfirmation->setNameID($nameId); + $subjectConfirmation->setSubjectConfirmationData(new SubjectConfirmationData()); $document = DOMDocumentFactory::fromString(''); $subjectConfirmationElement = $subjectConfirmation->toXML($document->firstChild); @@ -43,10 +45,10 @@ public function testUnmarshalling() ); $subjectConfirmation = new SubjectConfirmation($document->firstChild); - $this->assertEquals('SomeMethod', $subjectConfirmation->Method); - $this->assertTrue($subjectConfirmation->NameID instanceof NameID); - $this->assertEquals('SomeNameIDValue', $subjectConfirmation->NameID->value); - $this->assertTrue($subjectConfirmation->SubjectConfirmationData instanceof SubjectConfirmationData); + $this->assertEquals('SomeMethod', $subjectConfirmation->getMethod()); + $this->assertTrue($subjectConfirmation->getNameID() instanceof NameID); + $this->assertEquals('SomeNameIDValue', $subjectConfirmation->getNameID()->getValue()); + $this->assertTrue($subjectConfirmation->getSubjectConfirmationData() instanceof SubjectConfirmationData); } public function testMethodMissingThrowsException() diff --git a/tests/SAML2/XML/samlp/ExtensionsTest.php b/tests/SAML2/XML/samlp/ExtensionsTest.php index 3e2b77b93..5dfb335ea 100644 --- a/tests/SAML2/XML/samlp/ExtensionsTest.php +++ b/tests/SAML2/XML/samlp/ExtensionsTest.php @@ -80,7 +80,7 @@ public function testExtensionsAddSome() $attribute = new Attribute(); $attribute->Name = 'TheName'; $scope = new Scope(); - $scope->scope = "scope"; + $scope->setScope("scope"); Extensions::addList($this->testElement, [$attribute, $scope]); diff --git a/tests/SAML2/XML/shibmd/ScopeTest.php b/tests/SAML2/XML/shibmd/ScopeTest.php index 92e2d4205..e741bc0a4 100644 --- a/tests/SAML2/XML/shibmd/ScopeTest.php +++ b/tests/SAML2/XML/shibmd/ScopeTest.php @@ -16,8 +16,8 @@ class ScopeTest extends \PHPUnit_Framework_TestCase public function testMarshallingLiteral() { $scope = new Scope(); - $scope->scope = "example.org"; - $scope->regexp = FALSE; + $scope->setScope("example.org"); + $scope->setIsRegexpScope(false); $document = DOMDocumentFactory::fromString(''); $scopeElement = $scope->toXML($document->firstChild); @@ -38,7 +38,7 @@ public function testMarshallingLiteral() public function testMarshallingImplicitRegexpValue() { $scope = new Scope(); - $scope->scope = "example.org"; + $scope->setScope("example.org"); $document = DOMDocumentFactory::fromString(''); $scopeElement = $scope->toXML($document->firstChild); @@ -58,8 +58,8 @@ public function testMarshallingImplicitRegexpValue() public function testMarshallingRegexp() { $scope = new Scope(); - $scope->scope = "^(.*\.)?example\.edu$"; - $scope->regexp = TRUE; + $scope->setScope("^(.*\.)?example\.edu$"); + $scope->setIsRegexpScope(true); $document = DOMDocumentFactory::fromString(''); $scopeElement = $scope->toXML($document->firstChild); @@ -85,8 +85,8 @@ public function testUnmarshallingLiteral() ); $scope = new Scope($document->firstChild); - $this->assertEquals('example.org', $scope->scope); - $this->assertFalse($scope->regexp); + $this->assertEquals('example.org', $scope->getScope()); + $this->assertFalse($scope->isRegexpScope()); } /** @@ -102,8 +102,8 @@ public function testUnmarshallingWithoutRegexpValue() ); $scope = new Scope($document->firstChild); - $this->assertEquals('example.org', $scope->scope); - $this->assertFalse($scope->regexp); + $this->assertEquals('example.org', $scope->getScope()); + $this->assertFalse($scope->isRegexpScope()); } /** @@ -118,7 +118,7 @@ public function testUnmarshallingRegexp() ); $scope = new Scope($document->firstChild); - $this->assertEquals('^(.*|)example.edu$', $scope->scope); - $this->assertTrue($scope->regexp); + $this->assertEquals('^(.*|)example.edu$', $scope->getScope()); + $this->assertTrue($scope->isRegexpScope()); } }