Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / auth / AbstractPrimaryAuthenticationProvider.php
blobb026f86e5395d35ee8116ce2622ae57d4850d349
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.
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
18 * @file
19 * @ingroup Auth
22 namespace MediaWiki\Auth;
24 /**
25 * A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider
27 * @stable to extend
28 * @ingroup Auth
29 * @since 1.27
31 abstract class AbstractPrimaryAuthenticationProvider extends AbstractAuthenticationProvider
32 implements PrimaryAuthenticationProvider
35 /**
36 * @stable to override
38 * @param array $reqs
40 * @return AuthenticationResponse|void
42 public function continuePrimaryAuthentication( array $reqs ) {
43 // @phan-suppress-previous-line PhanPluginNeverReturnMethod
44 throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
47 /**
48 * @inheritDoc
49 * @stable to override
51 public function postAuthentication( $user, AuthenticationResponse $response ) {
54 /**
55 * @inheritDoc
56 * @stable to override
58 public function testUserCanAuthenticate( $username ) {
59 // Assume it can authenticate if it exists
60 return $this->testUserExists( $username );
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.
70 public function providerNormalizeUsername( $username ) {
71 $name = $this->userNameUtils->getCanonical( $username );
72 return $name === false ? null : $name;
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.
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 );
92 /**
93 * @inheritDoc
94 * @stable to override
96 public function providerAllowsPropertyChange( $property ) {
97 return true;
101 * @inheritDoc
102 * @stable to override
104 public function testForAccountCreation( $user, $creator, array $reqs ) {
105 return \StatusValue::newGood();
109 * @inheritDoc
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.' );
118 * @inheritDoc
119 * @stable to override
121 public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) {
122 return null;
126 * @inheritDoc
127 * @stable to override
129 public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
133 * @inheritDoc
134 * @stable to override
136 public function testUserForCreation( $user, $autocreate, array $options = [] ) {
137 return \StatusValue::newGood();
141 * @inheritDoc
142 * @stable to override
144 public function autoCreatedAccount( $user, $source ) {
148 * @inheritDoc
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.' );
155 } else {
156 throw new \BadMethodCallException(
157 __METHOD__ . ' should not be called on a non-link provider.'
163 * @inheritDoc
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.' );
172 * @inheritDoc
173 * @stable to override
175 public function postAccountLink( $user, AuthenticationResponse $response ) {