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.
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.
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
22 namespace MediaWiki\Auth
;
25 * A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider
31 abstract class AbstractPrimaryAuthenticationProvider
extends AbstractAuthenticationProvider
32 implements PrimaryAuthenticationProvider
40 * @return AuthenticationResponse|void
42 public function continuePrimaryAuthentication( array $reqs ) {
43 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
44 throw new \
BadMethodCallException( __METHOD__
. ' is not implemented.' );
51 public function postAuthentication( $user, AuthenticationResponse
$response ) {
58 public function testUserCanAuthenticate( $username ) {
59 // Assume it can authenticate if it exists
60 return $this->testUserExists( $username );
66 * @note Reimplement this if you do anything other than
67 * UserNameUtils->getCanonical( $req->username ) to determine the user being
70 public function providerNormalizeUsername( $username ) {
71 $name = $this->userNameUtils
->getCanonical( $username );
72 return $name === false ?
null : $name;
78 * @note Reimplement this if self::getAuthenticationRequests( AuthManager::ACTION_REMOVE )
79 * doesn't return requests that will revoke all access for the user.
81 public function providerRevokeAccessForUser( $username ) {
82 $reqs = $this->getAuthenticationRequests(
83 AuthManager
::ACTION_REMOVE
, [ 'username' => $username ]
85 foreach ( $reqs as $req ) {
86 $req->username
= $username;
87 $req->action
= AuthManager
::ACTION_REMOVE
;
88 $this->providerChangeAuthenticationData( $req );
96 public function providerAllowsPropertyChange( $property ) {
102 * @stable to override
104 public function testForAccountCreation( $user, $creator, array $reqs ) {
105 return \StatusValue
::newGood();
110 * @stable to override
112 public function continuePrimaryAccountCreation( $user, $creator, array $reqs ) {
113 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
114 throw new \
BadMethodCallException( __METHOD__
. ' is not implemented.' );
119 * @stable to override
121 public function finishAccountCreation( $user, $creator, AuthenticationResponse
$response ) {
127 * @stable to override
129 public function postAccountCreation( $user, $creator, AuthenticationResponse
$response ) {
134 * @stable to override
136 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
137 return \StatusValue
::newGood();
142 * @stable to override
144 public function autoCreatedAccount( $user, $source ) {
149 * @stable to override
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.' );
156 throw new \
BadMethodCallException(
157 __METHOD__
. ' should not be called on a non-link provider.'
164 * @stable to override
166 public function continuePrimaryAccountLink( $user, array $reqs ) {
167 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
168 throw new \
BadMethodCallException( __METHOD__
. ' is not implemented.' );
173 * @stable to override
175 public function postAccountLink( $user, AuthenticationResponse
$response ) {