From 7644eb4e1b811d1a3e65ac5e1b0e2399e7debe2c Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 12 Apr 2011 13:44:19 +0000 Subject: [PATCH] Update Error_AuthSource to become a standard base class for authsource errors. Thanks to Andjelko Horvat for adding this. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2812 44740490-163a-0410-bde0-09ae8108e29a --- dictionaries/errors.definition.json | 6 +++ dictionaries/errors.translation.json | 6 +++ lib/SimpleSAML/Auth/LDAP.php | 8 ++-- lib/SimpleSAML/Error/AuthSource.php | 59 +++++++++++++++++++++++++++- 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/dictionaries/errors.definition.json b/dictionaries/errors.definition.json index b2d6cfb4b..c1b1866f7 100644 --- a/dictionaries/errors.definition.json +++ b/dictionaries/errors.definition.json @@ -211,5 +211,11 @@ }, "descr_METADATANOTFOUND": { "en": "Unable to locate metadata for %ENTITYID%" + }, + "title_AUTHSOURCEERROR": { + "en": "Authentication source error" + }, + "descr_AUTHSOURCEERROR": { + "en": "Authentication error in source %AUTHSOURCE%. The reason was: %REASON%" } } diff --git a/dictionaries/errors.translation.json b/dictionaries/errors.translation.json index 23a5fe5ef..eae8c4609 100644 --- a/dictionaries/errors.translation.json +++ b/dictionaries/errors.translation.json @@ -1498,5 +1498,11 @@ "hr": "Metapodaci za %ENTITYID% nisu prona\u0111eni", "it": "Impossibile individuare i metatadi per %ENTITYID%", "sv": "Kan inte hitta metadata f\u00f6r %ENTITYID%" + }, + "title_AUTHSOURCEERROR": { + "hr": "Pogreška u autentikacijskom modulu" + }, + "descr_AUTHSOURCEERROR": { + "hr": "Pogreška u %AUTHSOURCE% autentikacijskom modulu. Razlog: %REASON%" } } diff --git a/lib/SimpleSAML/Auth/LDAP.php b/lib/SimpleSAML/Auth/LDAP.php index 503fefc0f..dc2aaa309 100644 --- a/lib/SimpleSAML/Auth/LDAP.php +++ b/lib/SimpleSAML/Auth/LDAP.php @@ -136,9 +136,9 @@ class SimpleSAML_Auth_LDAP { case ERR_WRONG_PW:// 3 - ExInvalidCredential return new SimpleSAML_Error_InvalidCredential($description, $errNo); case ERR_AS_DATA_INCONSIST:// 4 - ExAsDataInconsist - return new SimpleSAML_Error_AuthSource($description, $errNo); + return new SimpleSAML_Error_AuthSource('ldap', $description); case ERR_AS_INTERNAL:// 5 - ExAsInternal - return new SimpleSAML_Error_AuthSource($description, $errNo); + return new SimpleSAML_Error_AuthSource('ldap', $description); } }else{ switch ($errNo){ @@ -150,10 +150,10 @@ class SimpleSAML_Auth_LDAP { return new SimpleSAML_Error_InvalidCredential($description, $errNo); case -1://NO_SERVER_CONNECTION SimpleSAML_Logger::error($description . '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')'); - return new SimpleSAML_Error_AuthSource($description, $errNo); + return new SimpleSAML_Error_AuthSource('ldap', $description); default: SimpleSAML_Logger::error($description . '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')'); - return new SimpleSAML_Error_AuthSource($description, $errNo); + return new SimpleSAML_Error_AuthSource('ldap', $description); } } } diff --git a/lib/SimpleSAML/Error/AuthSource.php b/lib/SimpleSAML/Error/AuthSource.php index 6e353d53e..7df5cadb6 100644 --- a/lib/SimpleSAML/Error/AuthSource.php +++ b/lib/SimpleSAML/Error/AuthSource.php @@ -2,12 +2,67 @@ /** * Baseclass for auth source exceptions. * - * @author Thomas Graff <thomas.graff@uninett.no> * @package simpleSAMLphp_base * @version $Id$ * */ -class SimpleSAML_Error_AuthSource extends SimpleSAML_Error_Exception{ +class SimpleSAML_Error_AuthSource extends SimpleSAML_Error_Error { + + + /** + * Authsource module name. + */ + private $authsource; + + + /** + * Reason why this request was invalid. + */ + private $reason; + + + /** + * Create a new AuthSource error. + * + * @param string $authsource Authsource module name from where this error was thrown. + * @param string $reason Description of the error. + */ + public function __construct($authsource, $reason, $cause = NULL) { + assert('is_string($authsource)'); + assert('is_string($reason)'); + + $this->authsource = $authsource; + $this->reason = $reason; + parent::__construct( + array( + 'AUTHSOURCEERROR', + '%AUTHSOURCE%' => htmlspecialchars(var_export($this->authsource, TRUE)), + '%REASON%' => htmlspecialchars(var_export($this->reason, TRUE)) + ), + $cause + ); + } + + + /** + * Retrieve the authsource module name from where this error was thrown. + * + * @return string Authsource module name. + */ + public function getAuthSource() { + return $this->authsource; + } + + + /** + * Retrieve the reason why the request was invalid. + * + * @return string The reason why the request was invalid. + */ + public function getReason() { + return $this->reason; + } + } -- GitLab