From 65543e1f6c01dc30bf8bff4151dd378d65f4c5c9 Mon Sep 17 00:00:00 2001 From: csteipp Date: Fri, 1 Apr 2016 13:45:40 -0700 Subject: [PATCH] Fixup DB/uid handling for SUL wikis We need to pass the db name to getConnection, in addition to wfGetLB. Also, use core's CentralIdLookup for mapping local user to CentralId when using a central DB for OATH secret storage. Change-Id: I12a457633956a9a34dc5302ddcff468e31dd9cef --- OATHAuth.hooks.php | 5 +++-- OATHAuthKey.php | 3 ++- OATHUserRepository.php | 12 +++++++----- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/OATHAuth.hooks.php b/OATHAuth.hooks.php index 0fd551cb..7425b608 100644 --- a/OATHAuth.hooks.php +++ b/OATHAuth.hooks.php @@ -79,14 +79,15 @@ class OATHAuthHooks { $oathrepo = self::getOATHUserRepository(); $oathuser = $oathrepo->findByUser( $user ); + $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user ); if ( $oathuser->getKey() !== null && !$request->getCheck( 'token' ) ) { $encData = OATHAuthUtils::encryptSessionData( $request->getValues(), - $user->getId() + $uid ); $request->setSessionData( 'oath_login', $encData ); - $request->setSessionData( 'oath_uid', $user->getId() ); + $request->setSessionData( 'oath_uid', $uid ); $output->redirect( SpecialPage::getTitleFor( 'OATH' )->getFullURL( '', false, PROTO_CURRENT ) ); return false; } else { diff --git a/OATHAuthKey.php b/OATHAuthKey.php index c5ce2393..fb67283e 100644 --- a/OATHAuthKey.php +++ b/OATHAuthKey.php @@ -89,7 +89,8 @@ class OATHAuthKey { // Prevent replay attacks $memc = ObjectCache::newAnything( array() ); - $memcKey = wfMemcKey( 'oauthauth', 'usedtokens', $user->getUser()->getId() ); + $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ); + $memcKey = wfMemcKey( 'oauthauth', 'usedtokens', $uid ); $lastWindow = (int)$memc->get( $memcKey ); $retval = false; diff --git a/OATHUserRepository.php b/OATHUserRepository.php index 946578d1..5699c7e9 100644 --- a/OATHUserRepository.php +++ b/OATHUserRepository.php @@ -6,14 +6,16 @@ class OATHUserRepository { private $dbw; public function __construct( LoadBalancer $lb ) { - $this->dbr = $lb->getConnection( DB_SLAVE ); - $this->dbw = $lb->getConnection( DB_MASTER ); + global $wgOATHAuthDatabase; + $this->dbr = $lb->getConnection( DB_SLAVE, array(), $wgOATHAuthDatabase ); + $this->dbw = $lb->getConnection( DB_MASTER, array(), $wgOATHAuthDatabase ); } public function findByUser( User $user ) { $oathUser = new OATHUser( $user, null ); - $res = $this->dbr->selectRow( 'oathauth_users', '*', array( 'id' => $user->getId() ), __METHOD__ ); + $uid = CentralIdLookup::factory()->centralIdFromLocalUser( $user ); + $res = $this->dbr->selectRow( 'oathauth_users', '*', array( 'id' => $uid ), __METHOD__ ); if ($res) { $key = new OATHAuthKey( $res->secret, explode( ',', $res->scratch_tokens ) ); $oathUser->setKey( $key ); @@ -27,7 +29,7 @@ class OATHUserRepository { 'oathauth_users', array( 'id' ), array( - 'id' => $user->getUser()->getId(), + 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ), 'secret' => $user->getKey()->getSecret(), 'scratch_tokens' => implode( ',', $user->getKey()->getScratchTokens() ), ), @@ -38,7 +40,7 @@ class OATHUserRepository { public function remove( OATHUser $user ) { $this->dbw->delete( 'oathauth_users', - array( 'id' => $user->getUser()->getId() ), + array( 'id' => CentralIdLookup::factory()->centralIdFromLocalUser( $user->getUser() ) ), __METHOD__ ); }