Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
15 / 15
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractPrimaryAuthenticationProvider
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
15 / 15
18
100.00% covered (success)
100.00%
1 / 1
 continuePrimaryAuthentication
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 postAuthentication
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 testUserCanAuthenticate
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 providerNormalizeUsername
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
2
 providerRevokeAccessForUser
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
2
 providerAllowsPropertyChange
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 testForAccountCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 continuePrimaryAccountCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 finishAccountCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 postAccountCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 testUserForCreation
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 autoCreatedAccount
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 beginPrimaryAccountLink
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 continuePrimaryAccountLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 postAccountLink
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
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
22namespace MediaWiki\Auth;
23
24/**
25 * A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider
26 *
27 * @stable to extend
28 * @ingroup Auth
29 * @since 1.27
30 */
31abstract class AbstractPrimaryAuthenticationProvider extends AbstractAuthenticationProvider
32    implements PrimaryAuthenticationProvider
33{
34
35    /**
36     * @stable to override
37     *
38     * @param array $reqs
39     *
40     * @return AuthenticationResponse|void
41     */
42    public function continuePrimaryAuthentication( array $reqs ) {
43        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
44        throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
45    }
46
47    /**
48     * @inheritDoc
49     * @stable to override
50     */
51    public function postAuthentication( $user, AuthenticationResponse $response ) {
52    }
53
54    /**
55     * @inheritDoc
56     * @stable to override
57     */
58    public function testUserCanAuthenticate( $username ) {
59        // Assume it can authenticate if it exists
60        return $this->testUserExists( $username );
61    }
62
63    /**
64     * @inheritDoc
65     * @stable to override
66     * @note Reimplement this if you do anything other than
67     *  UserNameUtils->getCanonical( $req->username ) to determine the user being
68     *  authenticated.
69     */
70    public function providerNormalizeUsername( $username ) {
71        $name = $this->userNameUtils->getCanonical( $username );
72        return $name === false ? null : $name;
73    }
74
75    /**
76     * @inheritDoc
77     * @stable to override
78     * @note Reimplement this if self::getAuthenticationRequests( AuthManager::ACTION_REMOVE )
79     *  doesn't return requests that will revoke all access for the user.
80     */
81    public function providerRevokeAccessForUser( $username ) {
82        $reqs = $this->getAuthenticationRequests(
83            AuthManager::ACTION_REMOVE, [ 'username' => $username ]
84        );
85        foreach ( $reqs as $req ) {
86            $req->username = $username;
87            $req->action = AuthManager::ACTION_REMOVE;
88            $this->providerChangeAuthenticationData( $req );
89        }
90    }
91
92    /**
93     * @inheritDoc
94     * @stable to override
95     */
96    public function providerAllowsPropertyChange( $property ) {
97        return true;
98    }
99
100    /**
101     * @inheritDoc
102     * @stable to override
103     */
104    public function testForAccountCreation( $user, $creator, array $reqs ) {
105        return \StatusValue::newGood();
106    }
107
108    /**
109     * @inheritDoc
110     * @stable to override
111     */
112    public function continuePrimaryAccountCreation( $user, $creator, array $reqs ) {
113        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
114        throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
115    }
116
117    /**
118     * @inheritDoc
119     * @stable to override
120     */
121    public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) {
122        return null;
123    }
124
125    /**
126     * @inheritDoc
127     * @stable to override
128     */
129    public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
130    }
131
132    /**
133     * @inheritDoc
134     * @stable to override
135     */
136    public function testUserForCreation( $user, $autocreate, array $options = [] ) {
137        return \StatusValue::newGood();
138    }
139
140    /**
141     * @inheritDoc
142     * @stable to override
143     */
144    public function autoCreatedAccount( $user, $source ) {
145    }
146
147    /**
148     * @inheritDoc
149     * @stable to override
150     */
151    public function beginPrimaryAccountLink( $user, array $reqs ) {
152        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
153        if ( $this->accountCreationType() === self::TYPE_LINK ) {
154            throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
155        } else {
156            throw new \BadMethodCallException(
157                __METHOD__ . ' should not be called on a non-link provider.'
158            );
159        }
160    }
161
162    /**
163     * @inheritDoc
164     * @stable to override
165     */
166    public function continuePrimaryAccountLink( $user, array $reqs ) {
167        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
168        throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
169    }
170
171    /**
172     * @inheritDoc
173     * @stable to override
174     */
175    public function postAccountLink( $user, AuthenticationResponse $response ) {
176    }
177
178}