diff --git a/src/SAML11/Constants.php b/src/SAML11/Constants.php index 9b492ac..87bb37e 100644 --- a/src/SAML11/Constants.php +++ b/src/SAML11/Constants.php @@ -81,7 +81,6 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants */ public const NAMEID_UNSPECIFIED = 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified'; - /** * Windows Domain Qualifier Name NameID format. */ @@ -102,4 +101,80 @@ class Constants extends \SimpleSAML\XMLSecurity\Constants * The namespace for the SAML 1.1 protocol. */ public const NS_SAMLP = 'urn:oasis:names:tc:SAML:1.0:protocol'; + + /** + * The SAML responder or SAML authority is able to process the request but has chosen not to respond. + * This status code MAY be used when there is concern about the security context of the request message or + * the sequence of request messages received from a particular requester. + * + * Second-level status code. + */ + public const STATUS_REQUEST_DENIED = 'samlp:RequestDenied'; + + /** + * The SAML responder cannot process any requests with the protocol version specified in the request. + * + * Second-level status code. + */ + public const STATUS_REQUEST_VERSION_DEPRECATED = 'samlp:RequestVersionDeprecated'; + + /** + * The SAML responder cannot process the request because the protocol version specified in the request message + * is a major upgrade from the highest protocol version supported by the responder. + * + * Second-level status code. + */ + public const STATUS_REQUEST_VERSION_TOO_HIGH = 'samlp:RequestVersionTooHigh'; + + /** + * The SAML responder cannot process the request because the protocol version specified in the request message + * is too low. + * + * Second-level status code. + */ + public const STATUS_REQUEST_VERSION_TOO_LOW = 'samlp:RequestVersionTooLow'; + + /** + * The request could not be performed due to an error on the part of the requester. + * + * Top-level status code. + */ + public const STATUS_REQUESTER = 'samlp:Requester'; + + /** + * The resource value provided in the request message is invalid or unrecognized. + * + * Second-level status code. + */ + public const STATUS_RESOURCE_NOT_RECOGNIZED = 'samlp:ResourceNotRecognized'; + + /** + * The request could not be performed due to an error on the part of the SAML responder or SAML authority. + * + * Top-level status code. + */ + public const STATUS_RESPONDER = 'samlp:Responder'; + + /** + * Top-level status code indicating successful processing of the request. + * The request succeeded. Additional information MAY be returned in the + * and/or elements. + * + * Top-level status code. + */ + public const STATUS_SUCCESS = 'samlp:Success'; + + /** + * The response message would contain more elements than the SAML responder is able to return. + * + * Second-level status code. + */ + public const STATUS_TOO_MANY_RESPONSES = 'samlp:TooManyResponses'; + + /** + * The SAML responder could not process the request because the version of the request message was incorrect. + * + * Top-level status code. + */ + public const STATUS_VERSION_MISMATCH = 'samlp:VersionMismatch'; } diff --git a/src/SAML11/XML/samlp/AbstractStatusCodeType.php b/src/SAML11/XML/samlp/AbstractStatusCodeType.php new file mode 100644 index 0000000..d3e0bb2 --- /dev/null +++ b/src/SAML11/XML/samlp/AbstractStatusCodeType.php @@ -0,0 +1,100 @@ +Value; + } + + + /** + * Collect the subcodes + * + * @return \SimpleSAML\SAML11\XML\samlp\StatusCode[] + */ + public function getSubCodes(): array + { + return $this->subCodes; + } + + + /** + * Convert XML into a StatusCode + * + * @param \DOMElement $xml The XML element we should load + * @return static + * + * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException + * if the qualified name of the supplied element is wrong + * @throws \SimpleSAML\XML\Exception\MissingAttributeException + * if the supplied element is missing one of the mandatory attributes + */ + public static function fromXML(DOMElement $xml): static + { + Assert::same($xml->localName, 'StatusCode', InvalidDOMElementException::class); + Assert::same($xml->namespaceURI, StatusCode::NS, InvalidDOMElementException::class); + + $Value = self::getAttribute($xml, 'Value'); + $subCodes = StatusCode::getChildrenOfClass($xml); + + return new static( + $Value, + $subCodes, + ); + } + + + /** + * Convert this StatusCode to XML. + * + * @param \DOMElement|null $parent The element we should append this StatusCode to. + * @return \DOMElement + */ + public function toXML(DOMElement $parent = null): DOMElement + { + $e = $this->instantiateParentElement($parent); + $e->setAttribute('Value', $this->getValue()); + + foreach ($this->getSubCodes() as $subCode) { + $subCode->toXML($e); + } + + return $e; + } +} diff --git a/src/SAML11/XML/samlp/StatusCode.php b/src/SAML11/XML/samlp/StatusCode.php new file mode 100644 index 0000000..9f41257 --- /dev/null +++ b/src/SAML11/XML/samlp/StatusCode.php @@ -0,0 +1,14 @@ + + + diff --git a/tests/src/SAML11/XML/samlp/StatusCodeTest.php b/tests/src/SAML11/XML/samlp/StatusCodeTest.php new file mode 100644 index 0000000..617e34a --- /dev/null +++ b/tests/src/SAML11/XML/samlp/StatusCodeTest.php @@ -0,0 +1,65 @@ +assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($statusCode), + ); + } +}