Skip to content

Commit 25c20fa

Browse files
author
EC2 Default User
committed
Request now returns an exception instead of a string
1 parent 297065c commit 25c20fa

3 files changed

Lines changed: 25 additions & 14 deletions

File tree

lib/Saml2/Auth.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ class OneLogin_Saml2_Auth
109109
private $_errors = array();
110110

111111
/**
112-
* Reason of the last error.
112+
* Last error exception object.
113113
*
114-
* @var string|null
114+
* @var Exception|null
115115
*/
116-
private $_errorReason;
116+
private $_lastError;
117117

118118
/**
119119
* Last AuthNRequest ID or LogoutRequest ID generated by this Service Provider
@@ -188,7 +188,7 @@ public function setStrict($value)
188188
public function processResponse($requestId = null)
189189
{
190190
$this->_errors = array();
191-
$this->_errorReason = null;
191+
$this->_lastError = null;
192192
if (isset($_POST) && isset($_POST['SAMLResponse'])) {
193193
// AuthnResponse -- HTTP_POST Binding
194194
$response = new OneLogin_Saml2_Response($this->_settings, $_POST['SAMLResponse']);
@@ -207,7 +207,7 @@ public function processResponse($requestId = null)
207207
$this->_lastAssertionNotOnOrAfter = $response->getAssertionNotOnOrAfter();
208208
} else {
209209
$this->_errors[] = 'invalid_response';
210-
$this->_errorReason = $response->getError();
210+
$this->_lastError = $response->getError();
211211
}
212212
} else {
213213
$this->_errors[] = 'invalid_binding';
@@ -234,13 +234,13 @@ public function processResponse($requestId = null)
234234
public function processSLO($keepLocalSession = false, $requestId = null, $retrieveParametersFromServer = false, $cbDeleteSession = null, $stay = false)
235235
{
236236
$this->_errors = array();
237-
$this->_errorReason = null;
237+
$this->_lastError = null;
238238
if (isset($_GET) && isset($_GET['SAMLResponse'])) {
239239
$logoutResponse = new OneLogin_Saml2_LogoutResponse($this->_settings, $_GET['SAMLResponse']);
240240
$this->_lastResponse = $logoutResponse->getXML();
241241
if (!$logoutResponse->isValid($requestId, $retrieveParametersFromServer)) {
242242
$this->_errors[] = 'invalid_logout_response';
243-
$this->_errorReason = $logoutResponse->getError();
243+
$this->_lastError = $logoutResponse->getError();
244244
} else if ($logoutResponse->getStatus() !== OneLogin_Saml2_Constants::STATUS_SUCCESS) {
245245
$this->_errors[] = 'logout_not_success';
246246
} else {
@@ -258,7 +258,7 @@ public function processSLO($keepLocalSession = false, $requestId = null, $retrie
258258
$this->_lastRequest = $logoutRequest->getXML();
259259
if (!$logoutRequest->isValid($retrieveParametersFromServer)) {
260260
$this->_errors[] = 'invalid_logout_request';
261-
$this->_errorReason = $logoutRequest->getError();
261+
$this->_lastError = $logoutRequest->getError();
262262
} else {
263263
if (!$keepLocalSession) {
264264
if ($cbDeleteSession === null) {
@@ -406,6 +406,17 @@ public function getErrors()
406406
* @return string|null Error reason
407407
*/
408408
public function getLastErrorReason()
409+
{
410+
return htmlentities($this->_lastError->getMessage());
411+
}
412+
413+
414+
/**
415+
* Returns the last error
416+
*
417+
* @return Exception Error
418+
*/
419+
public function getLastError()
409420
{
410421
return $this->_errorReason;
411422
}

lib/Saml2/LogoutRequest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class OneLogin_Saml2_LogoutRequest
4444
/**
4545
* After execute a validation process, this var contains the cause
4646
*
47-
* @var string
47+
* @var Exception
4848
*/
4949
private $_error;
5050

@@ -397,10 +397,10 @@ public function isValid($retrieveParametersFromServer = false)
397397

398398
return true;
399399
} catch (Exception $e) {
400-
$this->_error = $e->getMessage();
400+
$this->_error = $e;
401401
$debug = $this->_settings->isDebugActive();
402402
if ($debug) {
403-
echo htmlentities($this->_error);
403+
echo htmlentities($this->_error->getMessage());
404404
}
405405
return false;
406406
}

lib/Saml2/Response.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class OneLogin_Saml2_Response
6060
/**
6161
* After validation, if it fail this var has the cause of the problem
6262
*
63-
* @var string
63+
* @var Exception
6464
*/
6565
private $_error;
6666

@@ -419,10 +419,10 @@ public function isValid($requestId = null)
419419
}
420420
return true;
421421
} catch (Exception $e) {
422-
$this->_error = $e->getMessage();
422+
$this->_error = $e;
423423
$debug = $this->_settings->isDebugActive();
424424
if ($debug) {
425-
echo htmlentities($this->_error);
425+
echo htmlentities($e->getMessage());
426426
}
427427
return false;
428428
}

0 commit comments

Comments
 (0)