|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SAML2; |
|
4
|
|
|
|
|
5
|
|
|
use DOMDocument; |
|
6
|
|
|
|
|
7
|
|
|
use SAML2\XML\ecp\Response as ECPResponse; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class which implements the SOAP binding. |
|
11
|
|
|
* |
|
12
|
|
|
* @package SimpleSAMLphp |
|
13
|
|
|
*/ |
|
14
|
|
|
class SOAP extends Binding |
|
15
|
|
|
{ |
|
16
|
|
|
public function getOutputToSend(Message $message) |
|
17
|
|
|
{ |
|
18
|
|
|
$envelope = <<<SOAP |
|
19
|
|
|
<?xml version="1.0" encoding="utf-8"?> |
|
20
|
|
|
<SOAP-ENV:Envelope xmlns:SOAP-ENV="%s"> |
|
21
|
|
|
<SOAP-ENV:Header /> |
|
22
|
|
|
<SOAP-ENV:Body /> |
|
23
|
|
|
</SOAP-ENV:Envelope> |
|
24
|
|
|
SOAP; |
|
25
|
|
|
$envelope = sprintf($envelope, Constants::NS_SOAP); |
|
26
|
|
|
|
|
27
|
|
|
$doc = new DOMDocument; |
|
28
|
|
|
$doc->loadXML($envelope); |
|
29
|
|
|
|
|
30
|
|
|
// In the Artifact Resolution profile, this will be an ArtifactResolve |
|
31
|
|
|
// containing another message (e.g. a Response), however in the ECP |
|
32
|
|
|
// profile, this is the Response itself. |
|
33
|
|
|
if ($message instanceof Response) { |
|
34
|
|
|
$header = $doc->getElementsByTagNameNS(Constants::NS_SOAP, 'Header')->item(0); |
|
35
|
|
|
|
|
36
|
|
|
$response = new ECPResponse; |
|
37
|
|
|
$response->AssertionConsumerServiceURL = $this->getDestination() ?: $message->getDestination(); |
|
38
|
|
|
|
|
39
|
|
|
$response->toXML($header); |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
// TODO We SHOULD add ecp:RequestAuthenticated SOAP header if we |
|
42
|
|
|
// authenticated the AuthnRequest. It may make sense to have a |
|
43
|
|
|
// standardized way for Message objects to contain (optional) SOAP |
|
44
|
|
|
// headers for use with the SOAP binding. |
|
45
|
|
|
// |
|
46
|
|
|
// https://docs.oasis-open.org/security/saml/Post2.0/saml-ecp/v2.0/cs01/saml-ecp-v2.0-cs01.html#_Toc366664733 |
|
47
|
|
|
// See Section 2.3.6.1 |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$body = $doc->getElementsByTagNameNs(Constants::NS_SOAP, 'Body')->item(0); |
|
51
|
|
|
|
|
52
|
|
|
$body->appendChild($doc->importNode($message->toSignedXML(), true)); |
|
53
|
|
|
|
|
54
|
|
|
return $doc->saveXML(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Send a SAML 2 message using the SOAP binding. |
|
59
|
|
|
* |
|
60
|
|
|
* Note: This function never returns. |
|
61
|
|
|
* |
|
62
|
|
|
* @param \SAML2\Message $message The message we should send. |
|
63
|
|
|
* |
|
64
|
|
|
* @SuppressWarnings(PHPMD.ExitExpression) |
|
65
|
|
|
*/ |
|
66
|
|
|
public function send(Message $message) |
|
67
|
|
|
{ |
|
68
|
|
|
header('Content-Type: text/xml', true); |
|
69
|
|
|
|
|
70
|
|
|
$xml = $this->getOutputToSend($message); |
|
71
|
|
|
SAML2_Utils::getContainer()->debugMessage($xml, 'out'); |
|
72
|
|
|
echo $xml; |
|
73
|
|
|
|
|
74
|
|
|
exit(0); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Receive a SAML 2 message sent using the HTTP-POST binding. |
|
79
|
|
|
* |
|
80
|
|
|
* Throws an exception if it is unable receive the message. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \SAML2\Message The received message. |
|
83
|
|
|
* @throws \Exception |
|
84
|
|
|
*/ |
|
85
|
|
|
public function receive() |
|
86
|
|
|
{ |
|
87
|
|
|
$postText = $this->getInputStream(); |
|
88
|
|
|
|
|
89
|
|
|
if (empty($postText)) { |
|
90
|
|
|
throw new \Exception('Invalid message received to AssertionConsumerService endpoint.'); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
$document = DOMDocumentFactory::fromString($postText); |
|
94
|
|
|
$xml = $document->firstChild; |
|
95
|
|
|
Utils::getContainer()->debugMessage($xml, 'in'); |
|
|
|
|
|
|
96
|
|
|
$results = Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]'); |
|
97
|
|
|
|
|
98
|
|
|
return Message::fromXML($results[0]); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
protected function getInputStream() |
|
102
|
|
|
{ |
|
103
|
|
|
return file_get_contents('php://input'); |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.