ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
HTTPPost.php
Go to the documentation of this file.
1<?php
2
3
12
19
21{
22
26 private $configuration = null;
27
31 private $metadata = null;
32
33
40 public function __construct(
43 ) {
44 $this->configuration = $configuration;
45 $this->metadata = $metadatastore;
46 }
47
48
58 public function sendResponse(
63 $shire
64 ) {
66
67 $privatekey = Crypto::loadPrivateKey($idpmd, true);
68 $publickey = Crypto::loadPublicKey($idpmd, true);
69
70 $responsedom = DOMDocumentFactory::fromString(str_replace("\r", "", $response));
71
72 $responseroot = $responsedom->getElementsByTagName('Response')->item(0);
73 $firstassertionroot = $responsedom->getElementsByTagName('Assertion')->item(0);
74
75 /* Determine what we should sign - either the Response element or the Assertion. The default is to sign the
76 * Assertion, but that can be overridden by the 'signresponse' option in the SP metadata or
77 * 'saml20.signresponse' in the global configuration.
78 *
79 * TODO: neither 'signresponse' nor 'shib13.signresponse' are valid options any longer. Remove!
80 */
81 if ($spmd->hasValue('signresponse')) {
82 $signResponse = $spmd->getBoolean('signresponse');
83 } else {
84 $signResponse = $this->configuration->getBoolean('shib13.signresponse', true);
85 }
86
87 // check if we have an assertion to sign. Force to sign the response if not
88 if ($firstassertionroot === null) {
89 $signResponse = true;
90 }
91
92 $signer = new Signer(array(
93 'privatekey_array' => $privatekey,
94 'publickey_array' => $publickey,
95 'id' => ($signResponse ? 'ResponseID' : 'AssertionID'),
96 ));
97
98 if ($idpmd->hasValue('certificatechain')) {
99 $signer->addCertificate($idpmd->getString('certificatechain'));
100 }
101
102 if ($signResponse) {
103 // sign the response - this must be done after encrypting the assertion
104 // we insert the signature before the saml2p:Status element
105 $statusElements = XML::getDOMChildren($responseroot, 'Status', '@saml1p');
106 assert('count($statusElements) === 1');
107 $signer->sign($responseroot, $responseroot, $statusElements[0]);
108 } else {
109 // Sign the assertion
110 $signer->sign($firstassertionroot, $firstassertionroot);
111 }
112
113 $response = $responsedom->saveXML();
114
116
117 HTTP::submitPOSTData($shire, array(
118 'TARGET' => $relayState,
119 'SAMLResponse' => base64_encode($response),
120 ));
121 }
122
123
131 public function decodeResponse($post)
132 {
133 assert('is_array($post)');
134
135 if (!array_key_exists('SAMLResponse', $post)) {
136 throw new \Exception('Missing required SAMLResponse parameter.');
137 }
138 $rawResponse = $post['SAMLResponse'];
139 $samlResponseXML = base64_decode($rawResponse);
140
141 XML::debugSAMLMessage($samlResponseXML, 'in');
142
143 XML::checkSAMLMessage($samlResponseXML, 'saml11');
144
145 $samlResponse = new AuthnResponse();
146 $samlResponse->setXML($samlResponseXML);
147
148 if (array_key_exists('TARGET', $post)) {
149 $samlResponse->setRelayState($post['TARGET']);
150 }
151
152 return $samlResponse;
153 }
154}
An exception for terminatinating execution or to throw for unit testing.
__construct(\SimpleSAML_Configuration $configuration, \SimpleSAML_Metadata_MetaDataStorageHandler $metadatastore)
Constructor for the \SimpleSAML\Bindings\Shib13\HTTPPost class.
Definition: HTTPPost.php:40
decodeResponse($post)
Decode a received response.
Definition: HTTPPost.php:131
sendResponse( $response, \SimpleSAML_Configuration $idpmd, \SimpleSAML_Configuration $spmd, $relayState, $shire)
Send an authenticationResponse using HTTP-POST.
Definition: HTTPPost.php:58
static loadPublicKey(\SimpleSAML_Configuration $metadata, $required=false, $prefix='')
Get public key or certificate from metadata.
Definition: Crypto.php:265
static loadPrivateKey(\SimpleSAML_Configuration $metadata, $required=false, $prefix='', $full_path=false)
Load a private key from metadata.
Definition: Crypto.php:195
static submitPOSTData($destination, $data)
Submit a POST form to a specific destination.
Definition: HTTP.php:1205
static checkSAMLMessage($message, $type)
This function performs some sanity checks on XML documents, and optionally validates them against the...
Definition: XML.php:35
static debugSAMLMessage($message, $type)
Helper function to log SAML messages that we send or receive.
Definition: XML.php:94
$relayState
$post
Definition: post.php:34
$response