OATHUser: Use UserIdentity where applicable

Depends-on: I562d6347f34691f1717d92b476618108af3de956
Change-Id: If0147e03ab7b7f43e6a261b673350317193389c1
This commit is contained in:
Taavi Väänänen 2024-11-05 20:35:57 +02:00
parent 1893b37c3e
commit d52c9514bd
No known key found for this signature in database
GPG key ID: EF242F709F912FBE
4 changed files with 11 additions and 13 deletions

View file

@ -41,7 +41,7 @@ class TOTPDisableForm extends OATHAuthOOUIHTMLForm {
*/
public function onSubmit( array $formData ) {
// Don't increase pingLimiter, instead check for the limit being exceeded.
if ( $this->oathUser->getUser()->pingLimiter( 'badoath', 0 ) ) {
if ( $this->getUser()->pingLimiter( 'badoath', 0 ) ) {
// Arbitrary duration given here
LoggerFactory::getInstance( 'authentication' )->info(
'OATHAuth {user} rate limited while disabling 2FA from {clientip}', [

View file

@ -23,6 +23,7 @@ use Base32\Base32;
use DomainException;
use Exception;
use jakobo\HOTP\HOTP;
use MediaWiki\Context\RequestContext;
use MediaWiki\Extension\OATHAuth\IAuthKey;
use MediaWiki\Extension\OATHAuth\Notifications\Manager;
use MediaWiki\Extension\OATHAuth\OATHAuthServices;
@ -168,7 +169,7 @@ class TOTPKey implements IAuthKey {
// Remove any whitespace from the received token, which can be an intended group separator
$token = preg_replace( '/\s+/', '', $token );
$clientIP = $user->getUser()->getRequest()->getIP();
$clientIP = RequestContext::getMain()->getRequest()->getIP();
$logger = $this->getLogger();

View file

@ -19,7 +19,7 @@
namespace MediaWiki\Extension\OATHAuth;
use InvalidArgumentException;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentity;
use ReflectionClass;
/**
@ -28,7 +28,7 @@ use ReflectionClass;
* @ingroup Extensions
*/
class OATHUser {
private User $user;
private UserIdentity $user;
private int $centralId;
/** @var IAuthKey[] */
@ -37,18 +37,15 @@ class OATHUser {
/**
* Constructor. Can't be called directly. Use OATHUserRepository::findByUser instead.
* @param User $user
* @param UserIdentity $user
* @param int $centralId
*/
public function __construct( User $user, int $centralId ) {
public function __construct( UserIdentity $user, int $centralId ) {
$this->user = $user;
$this->centralId = $centralId;
}
/**
* @return User
*/
public function getUser(): User {
public function getUser(): UserIdentity {
return $this->user;
}

View file

@ -24,7 +24,7 @@ use MediaWiki\Context\RequestContext;
use MediaWiki\Extension\OATHAuth\Notifications\Manager;
use MediaWiki\Json\FormatJson;
use MediaWiki\User\CentralId\CentralIdLookupFactory;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentity;
use MWException;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
@ -65,12 +65,12 @@ class OATHUserRepository implements LoggerAwareInterface {
}
/**
* @param User $user
* @param UserIdentity $user
* @return OATHUser
* @throws ConfigException
* @throws MWException
*/
public function findByUser( User $user ) {
public function findByUser( UserIdentity $user ) {
$oathUser = $this->cache->get( $user->getName() );
if ( !$oathUser ) {
$uid = $this->centralIdLookupFactory->getLookup()