-
Notifications
You must be signed in to change notification settings - Fork 701
Expand file tree
/
Copy pathErrorCodes.php
More file actions
542 lines (458 loc) · 21.6 KB
/
ErrorCodes.php
File metadata and controls
542 lines (458 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
<?php
declare(strict_types=1);
namespace SimpleSAML\Error;
use SimpleSAML\Locale\Translate;
use SimpleSAML\Module\core\Controller\Login;
use function array_merge;
/**
* Class that maps SimpleSAMLphp error codes to translateable strings.
*
* @package SimpleSAMLphp
*/
class ErrorCodes
{
final public const string ACSPARAMS = 'ACSPARAMS';
final public const string ADMINNOTHASHED = 'ADMINNOTHASHED';
final public const string ARSPARAMS = 'ARSPARAMS';
final public const string AUTHSOURCEERROR = 'AUTHSOURCEERROR';
final public const string BADREQUEST = 'BADREQUEST';
final public const string CASERROR = 'CASERROR';
final public const string CONFIG = 'CONFIG';
final public const string CREATEREQUEST = 'CREATEREQUEST';
final public const string DISCOPARAMS = 'DISCOPARAMS';
final public const string GENERATEAUTHNRESPONSE = 'GENERATEAUTHNRESPONSE';
final public const string INVALIDCERT = 'INVALIDCERT';
final public const string LDAPERROR = 'LDAPERROR';
final public const string LOGOUTINFOLOST = 'LOGOUTINFOLOST';
final public const string LOGOUTREQUEST = 'LOGOUTREQUEST';
final public const string MEMCACHEDOWN = 'MEMCACHEDOWN';
final public const string METADATA = 'METADATA';
final public const string METADATANOTFOUND = 'METADATANOTFOUND';
final public const string METHODNOTALLOWED = 'METHODNOTALLOWED';
final public const string NOACCESS = 'NOACCESS';
final public const string NOCERT = 'NOCERT';
final public const string NORELAYSTATE = 'NORELAYSTATE';
final public const string NOSTATE = 'NOSTATE';
final public const string NOTFOUND = 'NOTFOUND';
final public const string NOTFOUNDREASON = 'NOTFOUNDREASON';
final public const string NOTSET = 'NOTSET';
final public const string NOTVALIDCERT = 'NOTVALIDCERT';
final public const string NOTVALIDCERTSIGNATURE = 'NOTVALIDCERTSIGNATURE';
final public const string PROCESSASSERTION = 'PROCESSASSERTION';
final public const string PROCESSAUTHNREQUEST = 'PROCESSAUTHNREQUEST';
final public const string RESPONSESTATUSNOSUCCESS = 'RESPONSESTATUSNOSUCCESS';
final public const string SLOSERVICEPARAMS = 'SLOSERVICEPARAMS';
final public const string SSOPARAMS = 'SSOPARAMS';
final public const string UNHANDLEDEXCEPTION = 'UNHANDLEDEXCEPTION';
final public const string UNKNOWNCERT = 'UNKNOWNCERT';
final public const string USERABORTED = 'USERABORTED';
final public const string WRONGUSERPASS = 'WRONGUSERPASS';
final public const string KEY_TITLE = 'title';
final public const string KEY_DESCRIPTION = 'descr';
/**
*/
public function __construct()
{
// Automatically register instances of subclasses with Login to allow
// custom ErrorCodes to work in a redirect environment
Login::registerErrorCodeClass($this);
}
/**
* Fetch all default translation strings for error code titles.
*
* @return array A map from error code to error code title
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getDefaultTitles()
* TODO NextMajorRelease Move content to substitute method and remove.
*/
final public static function defaultGetAllErrorCodeTitles(): array
{
return [
self::ACSPARAMS => Translate::noop('No SAML response provided'),
self::ADMINNOTHASHED => Translate::noop('Admin password not set to a hashed value'),
self::ARSPARAMS => Translate::noop('No SAML message provided'),
self::AUTHSOURCEERROR => Translate::noop('Authentication source error'),
self::BADREQUEST => Translate::noop('Bad request received'),
self::CASERROR => Translate::noop('CAS Error'),
self::CONFIG => Translate::noop('Configuration error'),
self::CREATEREQUEST => Translate::noop('Error creating request'),
self::DISCOPARAMS => Translate::noop('Bad request to discovery service'),
self::GENERATEAUTHNRESPONSE => Translate::noop('Could not create authentication response'),
self::INVALIDCERT => Translate::noop('Invalid certificate'),
self::LDAPERROR => Translate::noop('LDAP Error'),
self::LOGOUTINFOLOST => Translate::noop('Logout information lost'),
self::LOGOUTREQUEST => Translate::noop('Error processing the Logout Request'),
self::MEMCACHEDOWN => Translate::noop('Cannot retrieve session data'),
self::METADATA => Translate::noop('Error loading metadata'),
self::METADATANOTFOUND => Translate::noop('Metadata not found'),
self::METHODNOTALLOWED => Translate::noop('Method not allowed'),
self::NOACCESS => Translate::noop('No access'),
self::NOCERT => Translate::noop('No certificate'),
self::NORELAYSTATE => Translate::noop('No RelayState'),
self::NOSTATE => Translate::noop('State information lost'),
self::NOTFOUND => Translate::noop('Page not found'),
self::NOTFOUNDREASON => Translate::noop('Page not found'),
self::NOTSET => Translate::noop('Password not set'),
self::NOTVALIDCERT => Translate::noop('Invalid certificate'),
self::NOTVALIDCERTSIGNATURE => Translate::noop('Invalid certificate signature'),
self::PROCESSASSERTION => Translate::noop('Error processing response from Identity Provider'),
self::PROCESSAUTHNREQUEST => Translate::noop('Error processing request from Service Provider'),
self::RESPONSESTATUSNOSUCCESS => Translate::noop('Error received from Identity Provider'),
self::SLOSERVICEPARAMS => Translate::noop('No SAML message provided'),
self::SSOPARAMS => Translate::noop('No SAML request provided'),
self::UNHANDLEDEXCEPTION => Translate::noop('Unhandled exception'),
self::UNKNOWNCERT => Translate::noop('Unknown certificate'),
self::USERABORTED => Translate::noop('Authentication aborted'),
self::WRONGUSERPASS => Translate::noop('Incorrect username or password'),
];
}
/**
* Fetch all default translation strings for error code titles.
*
* @return array A map from error code to error code title
*/
final public function getDefaultTitles(): array
{
// TODO NextMajorRelease Move content from self::defaultGetAllErrorCodeTitles() to this method.
return self::defaultGetAllErrorCodeTitles();
}
/**
* Fetch all title translation strings for custom error codes.
*
* Extend this to define custom error codes and their title translations.
*
* @return array A map from custom error code to error code title
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getCustomTitles()
* TODO NextMajorRelease Remove this method.
*/
public static function getCustomErrorCodeTitles(): array
{
return [];
}
/**
* Fetch all title translation strings for custom error codes.
*
* Extend this to define custom error codes and their title translations.
*
* @return array A map from custom error code to error code title
*/
public function getCustomTitles(): array
{
return [];
}
/**
* Fetch all translation strings for error code titles.
*
* @return array A map from error code to error code title
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getAllTitles()
* TODO NextMajorRelease Remove this method.
*/
public static function getAllErrorCodeTitles(): array
{
return array_merge(self::defaultGetAllErrorCodeTitles(), static::getCustomErrorCodeTitles());
}
/**
* Fetch all translation strings for error code titles.
*
* @return array A map from error code to error code title
*/
public function getAllTitles(): array
{
return array_merge($this->getDefaultTitles(), $this->getCustomTitles());
}
/**
* Fetch all default translation strings for error code descriptions.
*
* @return array A map from error code to error code description
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getDefaultDescriptions()
* TODO NextMajorRelease Move content to substitute method and remove.
*/
final public static function defaultGetAllErrorCodeDescriptions(): array
{
return [
self::ACSPARAMS => Translate::noop("" .
"You accessed the Assertion Consumer Service interface, but did not " .
"provide a SAML Authentication Response. Please note that this endpoint is" .
" not intended to be accessed directly."),
self::ARSPARAMS => Translate::noop("" .
"You accessed the Artifact Resolution Service interface, but did not " .
"provide a SAML ArtifactResolve message. Please note that this endpoint is" .
" not intended to be accessed directly."),
self::AUTHSOURCEERROR => Translate::noop("" .
'Authentication error in source %AUTHSOURCE%. The reason was: %REASON%'),
self::BADREQUEST =>
Translate::noop('There is an error in the request to this page. The reason was: %REASON%'),
self::CASERROR => Translate::noop('Error when communicating with the CAS server.'),
self::CONFIG => Translate::noop('SimpleSAMLphp appears to be misconfigured.'),
self::CREATEREQUEST => Translate::noop("An error occurred when trying to create the SAML request."),
self::DISCOPARAMS => Translate::noop("" .
"The parameters sent to the discovery service were not according to " .
"specifications."),
self::GENERATEAUTHNRESPONSE => Translate::noop("" .
"When this identity provider tried to create an authentication response, " .
"an error occurred."),
self::INVALIDCERT => Translate::noop("" .
"Authentication failed: the certificate your browser sent is invalid or " .
"cannot be read"),
self::LDAPERROR => Translate::noop("" .
"LDAP is the user database, and when you try to login, we need to contact " .
"an LDAP database. An error occurred when we tried it this time."),
self::LOGOUTINFOLOST => Translate::noop("" .
"The information about the current logout operation has been lost. You " .
"should return to the service you were trying to log out from and try to " .
"log out again. This error can be caused by the logout information " .
"expiring. The logout information is stored for a limited amount of time - " .
"usually a number of hours. This is longer than any normal logout " .
"operation should take, so this error may indicate some other error with " .
"the configuration. If the problem persists, contact your service " .
"provider."),
self::LOGOUTREQUEST => Translate::noop('An error occurred when trying to process the Logout Request.'),
self::MEMCACHEDOWN => Translate::noop("" .
"Your session data cannot be retrieved right now due to technical " .
"difficulties. Please try again in a few minutes."),
self::METADATA => Translate::noop("" .
"There is some misconfiguration of your SimpleSAMLphp installation. If you" .
" are the administrator of this service, you should make sure your " .
"metadata configuration is correctly setup."),
self::METADATANOTFOUND => Translate::noop('Unable to locate metadata for %ENTITYID%'),
self::METHODNOTALLOWED => Translate::noop('%MESSAGE%'),
self::NOACCESS => Translate::noop("" .
"This endpoint is not enabled. Check the enable options in your " .
"configuration of SimpleSAMLphp."),
self::NOCERT => Translate::noop('Authentication failed: your browser did not send any certificate'),
self::NORELAYSTATE => Translate::noop("" .
"The initiator of this request did not provide a RelayState parameter " .
"indicating where to go next."),
self::NOSTATE => Translate::noop('State information lost, and no way to restart the request'),
self::NOTFOUND => Translate::noop('The given page was not found. The URL was: %URL%'),
self::NOTFOUNDREASON => Translate::noop("" .
"The given page was not found. The reason was: %REASON% The URL was: %URL%"),
self::NOTSET => Translate::noop("" .
"The password in the configuration (auth.adminpassword) is not changed " .
"from the default value. Please edit the configuration file."),
self::ADMINNOTHASHED => Translate::noop("" .
"The password in the configuration (auth.adminpassword) is not a hashed value. " .
"Full details on how to fix this are supplied at " .
"https://github.com/simplesamlphp/simplesamlphp/wiki/" .
"Frequently-Asked-Questions-(FAQ)#failed-to-login-to-the-" .
"admin-page-with-and-error-message-admin-password-" .
"not-set-to-a-hashed-value"),
self::NOTVALIDCERT => Translate::noop('You did not present a valid certificate.'),
self::NOTVALIDCERTSIGNATURE => Translate::noop('Unable to validate certificate signature.'),
self::PROCESSASSERTION =>
Translate::noop('We did not accept the response sent from the Identity Provider.'),
self::PROCESSAUTHNREQUEST => Translate::noop("" .
"This Identity Provider received an Authentication Request from a Service " .
"Provider, but an error occurred when trying to process the request."),
self::RESPONSESTATUSNOSUCCESS => Translate::noop("" .
"The Identity Provider responded with an error. (The status code in the " .
"SAML Response was not success)"),
self::SLOSERVICEPARAMS => Translate::noop("" .
"You accessed the SingleLogoutService interface, but did not provide a " .
"SAML LogoutRequest or LogoutResponse. Please note that this endpoint is " .
"not intended to be accessed directly."),
self::SSOPARAMS => Translate::noop("" .
"You accessed the Single Sign On Service interface, but did not provide a " .
"SAML Authentication Request. Please note that this endpoint is not " .
"intended to be accessed directly."),
self::UNHANDLEDEXCEPTION => Translate::noop('An unhandled exception was thrown.'),
self::UNKNOWNCERT => Translate::noop('Authentication failed: the certificate your browser sent is unknown'),
self::USERABORTED => Translate::noop('The authentication was aborted by the user'),
self::WRONGUSERPASS => Translate::noop("" .
"Either no user with the given username could be found, or the password " .
"you gave was wrong. Please check the username and try again."),
];
}
/**
* Fetch all default translation strings for error code descriptions.
*
* @return array A map from error code to error code description
*/
final public function getDefaultDescriptions(): array
{
// TODO NextMajorRelease Move content from self::defaultGetAllErrorCodeDescriptions() to this method.
return self::defaultGetAllErrorCodeDescriptions();
}
/**
* Fetch all description translation strings for custom error codes.
*
* Extend this to define custom error codes and their description translations.
*
* @return array A map from error code to error code description
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getCustomDescriptions()
* TODO NextMajorRelease Remove this method.
*/
public static function getCustomErrorCodeDescriptions(): array
{
return [];
}
/**
* Fetch all description translation strings for custom error codes.
*
* Extend this to define custom error codes and their description translations.
*
* @return array A map from error code to error code description
*/
public function getCustomDescriptions(): array
{
return [];
}
/**
* Fetch all translation strings for error code descriptions.
*
* @return array A map from error code to error code description
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getAllDescriptions()
* TODO NextMajorRelease Remove this method.
*/
public static function getAllErrorCodeDescriptions(): array
{
return array_merge(self::defaultGetAllErrorCodeDescriptions(), static::getCustomErrorCodeDescriptions());
}
/**
* @return array
*/
public function getAllDescriptions(): array
{
return array_merge($this->getDefaultDescriptions(), $this->getCustomDescriptions());
}
/**
* Get a map of both errorcode titles and descriptions
*
* Convenience-method for template-callers
*
* @return array An array containing both errorcode maps.
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getAllMessages()
* TODO NextMajorRelease Remove this method.
*/
public static function getAllErrorCodeMessages(): array
{
return [
self::KEY_TITLE => self::getAllErrorCodeTitles(),
self::KEY_DESCRIPTION => self::getAllErrorCodeDescriptions(),
];
}
/**
* Get a map of both errorcode titles and descriptions
*
* Convenience-method for template-callers
*
* @return array An array containing both errorcode maps.
*/
public function getAllMessages(): array
{
return [
self::KEY_TITLE => $this->getAllTitles(),
self::KEY_DESCRIPTION => $this->getAllDescriptions(),
];
}
/**
* Fetch a translation string for a title for a given error code.
*
* @param string $errorCode The error code to look up
*
* @return string A string to translate
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getTitle()
* TODO NextMajorRelease Remove this method.
*/
public static function getErrorCodeTitle(string $errorCode): string
{
if (array_key_exists($errorCode, self::getAllErrorCodeTitles())) {
$errorCodeTitles = self::getAllErrorCodeTitles();
return $errorCodeTitles[$errorCode];
} else {
return Translate::addTagPrefix($errorCode, 'title_');
}
}
/**
* Fetch a translation string for a title for a given error code.
*
* @param string $errorCode The error code to look up
*
* @return string A string to translate
*/
public function getTitle(string $errorCode): string
{
return (string)($this->getAllTitles()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'title_'));
}
/**
* Fetch a translation string for a description for a given error code.
*
* @param string $errorCode The error code to look up
*
* @return string A string to translate
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getDescription()
* TODO NextMajorRelease Remove this method.
*/
public static function getErrorCodeDescription(string $errorCode): string
{
if (array_key_exists($errorCode, self::getAllErrorCodeDescriptions())) {
$errorCodeDescriptions = self::getAllErrorCodeDescriptions();
return $errorCodeDescriptions[$errorCode];
} else {
return Translate::addTagPrefix($errorCode, 'descr_');
}
}
/**
* Fetch a translation string for a description for a given error code.
*
* @param string $errorCode The error code to look up
*
* @return string A string to translate
*/
public function getDescription(string $errorCode): string
{
return (string)($this->getAllDescriptions()[$errorCode] ?? Translate::addTagPrefix($errorCode, 'descr_'));
}
/**
* Get both title and description for a specific error code
*
* Convenience-method for template-callers
*
* @param string $errorCode The error code to look up
*
* @return array An array containing both errorcode strings.
*
* @deprecated Static method access is deprecated. Move to instance method.
* @see self::getMessage()
* TODO NextMajorRelease Remove this method.
*/
public static function getErrorCodeMessage(string $errorCode): array
{
return [
self::KEY_TITLE => self::getErrorCodeTitle($errorCode),
self::KEY_DESCRIPTION => self::getErrorCodeDescription($errorCode),
];
}
/**
* Get both title and description for a specific error code
*
* Convenience-method for template-callers
*
* @param string $errorCode The error code to look up
*
* @return array An array containing both errorcode strings.
*/
public function getMessage(string $errorCode): array
{
return [
self::KEY_TITLE => $this->getTitle($errorCode),
self::KEY_DESCRIPTION => $this->getDescription($errorCode),
];
}
}