2015-11-22 20:17:00 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
* @ingroup Auth
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Auth;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A base class that implements some of the boilerplate for a PrimaryAuthenticationProvider
|
|
|
|
|
*
|
2020-07-13 09:00:30 +00:00
|
|
|
* @stable to extend
|
2015-11-22 20:17:00 +00:00
|
|
|
* @ingroup Auth
|
|
|
|
|
* @since 1.27
|
|
|
|
|
*/
|
|
|
|
|
abstract class AbstractPrimaryAuthenticationProvider extends AbstractAuthenticationProvider
|
|
|
|
|
implements PrimaryAuthenticationProvider
|
|
|
|
|
{
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*
|
|
|
|
|
* @param array $reqs
|
|
|
|
|
*
|
|
|
|
|
* @return AuthenticationResponse|void
|
|
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function continuePrimaryAuthentication( array $reqs ) {
|
2021-09-04 01:42:33 +00:00
|
|
|
// @phan-suppress-previous-line PhanPluginNeverReturnMethod
|
2015-11-22 20:17:00 +00:00
|
|
|
throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function postAuthentication( $user, AuthenticationResponse $response ) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function testUserCanAuthenticate( $username ) {
|
|
|
|
|
// Assume it can authenticate if it exists
|
|
|
|
|
return $this->testUserExists( $username );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-11 14:49:52 +00:00
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2015-11-22 20:17:00 +00:00
|
|
|
* @note Reimplement this if you do anything other than
|
2021-05-28 13:38:53 +00:00
|
|
|
* UserNameUtils->getCanonical( $req->username ) to determine the user being
|
2015-11-22 20:17:00 +00:00
|
|
|
* authenticated.
|
|
|
|
|
*/
|
|
|
|
|
public function providerNormalizeUsername( $username ) {
|
2021-05-28 13:38:53 +00:00
|
|
|
$name = $this->userNameUtils->getCanonical( $username );
|
2015-11-22 20:17:00 +00:00
|
|
|
return $name === false ? null : $name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-08-11 14:49:52 +00:00
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2015-11-22 20:17:00 +00:00
|
|
|
* @note Reimplement this if self::getAuthenticationRequests( AuthManager::ACTION_REMOVE )
|
|
|
|
|
* doesn't return requests that will revoke all access for the user.
|
|
|
|
|
*/
|
|
|
|
|
public function providerRevokeAccessForUser( $username ) {
|
|
|
|
|
$reqs = $this->getAuthenticationRequests(
|
|
|
|
|
AuthManager::ACTION_REMOVE, [ 'username' => $username ]
|
|
|
|
|
);
|
|
|
|
|
foreach ( $reqs as $req ) {
|
|
|
|
|
$req->username = $username;
|
|
|
|
|
$req->action = AuthManager::ACTION_REMOVE;
|
|
|
|
|
$this->providerChangeAuthenticationData( $req );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function providerAllowsPropertyChange( $property ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function testForAccountCreation( $user, $creator, array $reqs ) {
|
|
|
|
|
return \StatusValue::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function continuePrimaryAccountCreation( $user, $creator, array $reqs ) {
|
2021-09-04 01:42:33 +00:00
|
|
|
// @phan-suppress-previous-line PhanPluginNeverReturnMethod
|
2015-11-22 20:17:00 +00:00
|
|
|
throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function finishAccountCreation( $user, $creator, AuthenticationResponse $response ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function postAccountCreation( $user, $creator, AuthenticationResponse $response ) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2016-06-16 21:43:12 +00:00
|
|
|
public function testUserForCreation( $user, $autocreate, array $options = [] ) {
|
2015-11-22 20:17:00 +00:00
|
|
|
return \StatusValue::newGood();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function autoCreatedAccount( $user, $source ) {
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function beginPrimaryAccountLink( $user, array $reqs ) {
|
2021-09-04 01:42:33 +00:00
|
|
|
// @phan-suppress-previous-line PhanPluginNeverReturnMethod
|
2015-11-22 20:17:00 +00:00
|
|
|
if ( $this->accountCreationType() === self::TYPE_LINK ) {
|
|
|
|
|
throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
|
|
|
|
|
} else {
|
|
|
|
|
throw new \BadMethodCallException(
|
|
|
|
|
__METHOD__ . ' should not be called on a non-link provider.'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function continuePrimaryAccountLink( $user, array $reqs ) {
|
2021-09-04 01:42:33 +00:00
|
|
|
// @phan-suppress-previous-line PhanPluginNeverReturnMethod
|
2015-11-22 20:17:00 +00:00
|
|
|
throw new \BadMethodCallException( __METHOD__ . ' is not implemented.' );
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-01 18:47:23 +00:00
|
|
|
/**
|
|
|
|
|
* @inheritDoc
|
2020-07-13 08:57:12 +00:00
|
|
|
* @stable to override
|
2020-07-01 18:47:23 +00:00
|
|
|
*/
|
2015-11-22 20:17:00 +00:00
|
|
|
public function postAccountLink( $user, AuthenticationResponse $response ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|