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 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @ingroup Auth |
20 | */ |
21 | |
22 | namespace MediaWiki\Auth; |
23 | |
24 | use MediaWiki\MainConfigNames; |
25 | |
26 | /** |
27 | * Check if the user is blocked, and prevent authentication if so. |
28 | * |
29 | * Not all scenarios are covered by this class, AuthManager does some block checks itself |
30 | * via AuthManager::authorizeCreateAccount(). |
31 | * |
32 | * @ingroup Auth |
33 | * @since 1.27 |
34 | */ |
35 | class CheckBlocksSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider { |
36 | |
37 | /** @var bool */ |
38 | protected $blockDisablesLogin = null; |
39 | |
40 | /** |
41 | * @param array $params |
42 | * - blockDisablesLogin: (bool) Whether blocked accounts can log in, |
43 | * defaults to $wgBlockDisablesLogin |
44 | */ |
45 | public function __construct( $params = [] ) { |
46 | if ( isset( $params['blockDisablesLogin'] ) ) { |
47 | $this->blockDisablesLogin = (bool)$params['blockDisablesLogin']; |
48 | } |
49 | } |
50 | |
51 | /** @inheritDoc */ |
52 | protected function postInitSetup() { |
53 | $this->blockDisablesLogin ??= $this->config->get( MainConfigNames::BlockDisablesLogin ); |
54 | } |
55 | |
56 | /** @inheritDoc */ |
57 | public function getAuthenticationRequests( $action, array $options ) { |
58 | return []; |
59 | } |
60 | |
61 | /** @inheritDoc */ |
62 | public function beginSecondaryAuthentication( $user, array $reqs ) { |
63 | if ( !$this->blockDisablesLogin ) { |
64 | return AuthenticationResponse::newAbstain(); |
65 | } |
66 | $block = $user->getBlock(); |
67 | // Ignore IP blocks and partial blocks, $wgBlockDisablesLogin was meant for |
68 | // blocks banning specific users. |
69 | if ( $block && $block->isSitewide() && $block->isBlocking( $user ) ) { |
70 | return AuthenticationResponse::newFail( |
71 | new \Message( 'login-userblocked', [ $user->getName() ] ) |
72 | ); |
73 | } else { |
74 | return AuthenticationResponse::newPass(); |
75 | } |
76 | } |
77 | |
78 | /** @inheritDoc */ |
79 | public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) { |
80 | return AuthenticationResponse::newAbstain(); |
81 | } |
82 | |
83 | } |