Skip to content

Commit 7644eb4

Browse files
committed
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
1 parent 4f096ed commit 7644eb4

4 files changed

Lines changed: 73 additions & 6 deletions

File tree

dictionaries/errors.definition.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,11 @@
211211
},
212212
"descr_METADATANOTFOUND": {
213213
"en": "Unable to locate metadata for %ENTITYID%"
214+
},
215+
"title_AUTHSOURCEERROR": {
216+
"en": "Authentication source error"
217+
},
218+
"descr_AUTHSOURCEERROR": {
219+
"en": "Authentication error in source %AUTHSOURCE%. The reason was: %REASON%"
214220
}
215221
}

dictionaries/errors.translation.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1498,5 +1498,11 @@
14981498
"hr": "Metapodaci za %ENTITYID% nisu prona\u0111eni",
14991499
"it": "Impossibile individuare i metatadi per %ENTITYID%",
15001500
"sv": "Kan inte hitta metadata f\u00f6r %ENTITYID%"
1501+
},
1502+
"title_AUTHSOURCEERROR": {
1503+
"hr": "Pogreška u autentikacijskom modulu"
1504+
},
1505+
"descr_AUTHSOURCEERROR": {
1506+
"hr": "Pogreška u %AUTHSOURCE% autentikacijskom modulu. Razlog: %REASON%"
15011507
}
15021508
}

lib/SimpleSAML/Auth/LDAP.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ private function makeException($description, $type = NULL) {
136136
case ERR_WRONG_PW:// 3 - ExInvalidCredential
137137
return new SimpleSAML_Error_InvalidCredential($description, $errNo);
138138
case ERR_AS_DATA_INCONSIST:// 4 - ExAsDataInconsist
139-
return new SimpleSAML_Error_AuthSource($description, $errNo);
139+
return new SimpleSAML_Error_AuthSource('ldap', $description);
140140
case ERR_AS_INTERNAL:// 5 - ExAsInternal
141-
return new SimpleSAML_Error_AuthSource($description, $errNo);
141+
return new SimpleSAML_Error_AuthSource('ldap', $description);
142142
}
143143
}else{
144144
switch ($errNo){
@@ -150,10 +150,10 @@ private function makeException($description, $type = NULL) {
150150
return new SimpleSAML_Error_InvalidCredential($description, $errNo);
151151
case -1://NO_SERVER_CONNECTION
152152
SimpleSAML_Logger::error($description . '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')');
153-
return new SimpleSAML_Error_AuthSource($description, $errNo);
153+
return new SimpleSAML_Error_AuthSource('ldap', $description);
154154
default:
155155
SimpleSAML_Logger::error($description . '; cause: \'' . ldap_error($this->ldap) . '\' (0x' . dechex($errNo) . ')');
156-
return new SimpleSAML_Error_AuthSource($description, $errNo);
156+
return new SimpleSAML_Error_AuthSource('ldap', $description);
157157
}
158158
}
159159
}

lib/SimpleSAML/Error/AuthSource.php

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,67 @@
22
/**
33
* Baseclass for auth source exceptions.
44
*
5-
* @author Thomas Graff <thomas.graff@uninett.no>
65
* @package simpleSAMLphp_base
76
* @version $Id$
87
*
98
*/
10-
class SimpleSAML_Error_AuthSource extends SimpleSAML_Error_Exception{
9+
class SimpleSAML_Error_AuthSource extends SimpleSAML_Error_Error {
10+
11+
12+
/**
13+
* Authsource module name.
14+
*/
15+
private $authsource;
16+
17+
18+
/**
19+
* Reason why this request was invalid.
20+
*/
21+
private $reason;
22+
23+
24+
/**
25+
* Create a new AuthSource error.
26+
*
27+
* @param string $authsource Authsource module name from where this error was thrown.
28+
* @param string $reason Description of the error.
29+
*/
30+
public function __construct($authsource, $reason, $cause = NULL) {
31+
assert('is_string($authsource)');
32+
assert('is_string($reason)');
33+
34+
$this->authsource = $authsource;
35+
$this->reason = $reason;
36+
parent::__construct(
37+
array(
38+
'AUTHSOURCEERROR',
39+
'%AUTHSOURCE%' => htmlspecialchars(var_export($this->authsource, TRUE)),
40+
'%REASON%' => htmlspecialchars(var_export($this->reason, TRUE))
41+
),
42+
$cause
43+
);
44+
}
45+
46+
47+
/**
48+
* Retrieve the authsource module name from where this error was thrown.
49+
*
50+
* @return string Authsource module name.
51+
*/
52+
public function getAuthSource() {
53+
return $this->authsource;
54+
}
55+
56+
57+
/**
58+
* Retrieve the reason why the request was invalid.
59+
*
60+
* @return string The reason why the request was invalid.
61+
*/
62+
public function getReason() {
63+
return $this->reason;
64+
}
65+
1166

1267
}
1368

0 commit comments

Comments
 (0)