Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
CentralAuthSecondaryAuthenticationProvider
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 4
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getAuthenticationRequests
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 beginSecondaryAuthentication
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
42
 beginSecondaryAccountCreation
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
22namespace MediaWiki\Extension\CentralAuth;
23
24use MediaWiki\Auth\AbstractSecondaryAuthenticationProvider;
25use MediaWiki\Auth\AuthenticationResponse;
26use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
27use MediaWiki\WikiMap\WikiMap;
28
29/**
30 * This implements CentralAuth checks that should be done on all logins, e.g.
31 * being renamed or centrally locked.
32 */
33class CentralAuthSecondaryAuthenticationProvider extends AbstractSecondaryAuthenticationProvider {
34
35    /**
36     * @param array $params
37     */
38    public function __construct( $params = [] ) {
39    }
40
41    /** @inheritDoc */
42    public function getAuthenticationRequests( $action, array $options ) {
43        return [];
44    }
45
46    /** @inheritDoc */
47    public function beginSecondaryAuthentication( $user, array $reqs ) {
48        $centralUser = CentralAuthUser::getInstance( $user );
49
50        // Since logins are rare, check the actual DB
51        $rename = $centralUser->renameInProgressOn( WikiMap::getCurrentWikiId() );
52        if ( $rename ) {
53            // This wiki specifically has a rename in progress, so always abort
54            return AuthenticationResponse::newFail(
55                wfMessage( 'centralauth-rename-abortlogin', $user->getName() )
56            );
57        }
58
59        // Now check if the user is the target of a rename anywhere
60        $rename = $centralUser->renameInProgress();
61        if ( $rename ) {
62            // It's possible a user is being renamed but someone else with
63            // an unattached account is trying to login. Since we've already
64            // moved everything over to the new account name, we only need
65            // to check one username.
66            $newCAUser = $rename[1] === $user->getName()
67                ? $centralUser
68                : CentralAuthUser::getInstanceByName( $rename[0] );
69
70            if ( $newCAUser->isAttached() ) {
71                // If there is an account using that name that exists on this wiki
72                // reject the login.
73                return AuthenticationResponse::newFail(
74                    wfMessage( 'centralauth-rename-abortlogin', $user->getName() )
75                );
76            }
77        }
78
79        if ( $centralUser->canAuthenticate() === CentralAuthUser::AUTHENTICATE_LOCKED ) {
80            return AuthenticationResponse::newFail(
81                wfMessage( 'centralauth-login-error-locked' )
82                    ->params( wfEscapeWikiText( $centralUser->getName() ) ),
83                [ CentralAuthUser::AUTHENTICATE_LOCKED ]
84            );
85        }
86
87        return AuthenticationResponse::newAbstain();
88    }
89
90    /** @inheritDoc */
91    public function beginSecondaryAccountCreation( $user, $creator, array $reqs ) {
92        return AuthenticationResponse::newAbstain();
93    }
94}