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
This commit is contained in:
csteipp 2016-04-01 13:45:40 -07:00 committed by Darian Anthony Patrick
parent 079877734c
commit 65543e1f6c
3 changed files with 12 additions and 8 deletions

View file

@ -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 {

View file

@ -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;

View file

@ -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__
);
}