-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create AuthenticationFailure exception
Refactors the AuthenticationPlugin::showFailure() to receive the new exception and move the showFailure calls to the Authentication middleware. Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
- Loading branch information
1 parent
2a58575
commit cfdaedb
Showing
14 changed files
with
237 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PhpMyAdmin\Exceptions; | ||
|
||
use RuntimeException; | ||
use Throwable; | ||
|
||
use function __; | ||
|
||
final class AuthenticationFailure extends RuntimeException | ||
{ | ||
public const SERVER_DENIED = 'server-denied'; | ||
public const ALLOW_DENIED = 'allow-denied'; | ||
public const ROOT_DENIED = 'root-denied'; | ||
public const EMPTY_DENIED = 'empty-denied'; | ||
public const NO_ACTIVITY = 'no-activity'; | ||
|
||
/** @psalm-param self::* $failureType */ | ||
public function __construct( | ||
public readonly string $failureType, | ||
string $message = '', | ||
int $code = 0, | ||
Throwable|null $previous = null, | ||
) { | ||
parent::__construct($message, $code, $previous); | ||
} | ||
|
||
/** | ||
* Database server denied user login | ||
*/ | ||
public static function serverDenied(): self | ||
{ | ||
return new self(self::SERVER_DENIED, __('Cannot log in to the database server.')); | ||
} | ||
|
||
/** | ||
* User denied by allow/deny rules | ||
*/ | ||
public static function allowDenied(): self | ||
{ | ||
return new self(self::ALLOW_DENIED, __('Access denied!')); | ||
} | ||
|
||
/** | ||
* User 'root' is denied in configuration | ||
*/ | ||
public static function rootDenied(): self | ||
{ | ||
return new self(self::ROOT_DENIED, __('Access denied!')); | ||
} | ||
|
||
/** | ||
* Empty password is denied | ||
*/ | ||
public static function emptyDenied(): self | ||
{ | ||
return new self( | ||
self::EMPTY_DENIED, | ||
__('Login without a password is forbidden by configuration (see AllowNoPassword).'), | ||
); | ||
} | ||
|
||
/** | ||
* Automatically logged out due to inactivity | ||
*/ | ||
public static function noActivity(): self | ||
{ | ||
return new self( | ||
self::NO_ACTIVITY, | ||
__( | ||
'You have been automatically logged out due to inactivity of %s seconds.' | ||
. ' Once you log in again, you should be able to resume the work where you left off.', | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.