Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| CheckBlocksSecondaryAuthenticationProvider | |
100.00% |
13 / 13 |
|
100.00% |
5 / 5 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| postInitSetup | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getAuthenticationRequests | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| beginSecondaryAuthentication | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
5 | |||
| beginSecondaryAccountCreation | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | */ |
| 6 | |
| 7 | namespace MediaWiki\Auth; |
| 8 | |
| 9 | use MediaWiki\MainConfigNames; |
| 10 | use MediaWiki\Message\Message; |
| 11 | |
| 12 | /** |
| 13 | * Check if the user is blocked, and prevent authentication if so. |
| 14 | * |
| 15 | * Not all scenarios are covered by this class, AuthManager does some block checks itself |
| 16 | * via AuthManager::authorizeCreateAccount(). |
| 17 | * |
| 18 | * @ingroup Auth |
| 19 | * @since 1.27 |
| 20 | */ |
| 21 | class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider { |
| 22 | |
| 23 | /** @var bool */ |
| 24 | protected $blockDisablesLogin = null; |
| 25 | |
| 26 | /** |
| 27 | * @param array $params |
| 28 | * - blockDisablesLogin: (bool) Whether blocked accounts can log in, |
| 29 | * defaults to $wgBlockDisablesLogin |
| 30 | */ |
| 31 | public function __construct( $params = [] ) { |
| 32 | if ( isset( $params['blockDisablesLogin'] ) ) { |
| 33 | $this->blockDisablesLogin = (bool)$params['blockDisablesLogin']; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** @inheritDoc */ |
| 38 | protected function postInitSetup() { |
| 39 | $this->blockDisablesLogin ??= $this->config->get( MainConfigNames::BlockDisablesLogin ); |
| 40 | } |
| 41 | |
| 42 | /** @inheritDoc */ |
| 43 | public function getAuthenticationRequests( $action, array $options ) { |
| 44 | return []; |
| 45 | } |
| 46 | |
| 47 | /** @inheritDoc */ |
| 48 | public function beginSecondaryAuthentication( $user, array $reqs ) { |
| 49 | if ( !$this->blockDisablesLogin ) { |
| 50 | return AuthenticationResponse::newAbstain(); |
| 51 | } |
| 52 | $block = $user->getBlock(); |
| 53 | // Ignore IP blocks and partial blocks, $wgBlockDisablesLogin was meant for |
| 54 | // blocks banning specific users. |
| 55 | if ( $block && $block->isSitewide() && $block->isBlocking( $user ) ) { |
| 56 | return AuthenticationResponse::newFail( |
| 57 | new Message( 'login-userblocked', [ $user->getName() ] ) |
| 58 | ); |
| 59 | } else { |
| 60 | return AuthenticationResponse::newPass(); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** @inheritDoc */ |
| 65 | public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { |
| 66 | return AuthenticationResponse::newAbstain(); |
| 67 | } |
| 68 | |
| 69 | } |