diff --git a/src/ZfcUser/Authentication/Adapter/Db.php b/src/ZfcUser/Authentication/Adapter/Db.php index c9bae4f8..dba61000 100644 --- a/src/ZfcUser/Authentication/Adapter/Db.php +++ b/src/ZfcUser/Authentication/Adapter/Db.php @@ -62,7 +62,6 @@ public function authenticate(AuthenticationEvent $event) $identity = $event->getRequest()->getPost()->get('identity'); $credential = $event->getRequest()->getPost()->get('credential'); - $credential = $this->preProcessCredential($credential); $userObject = null; // Cycle through the configured identity sources and test each @@ -96,6 +95,8 @@ public function authenticate(AuthenticationEvent $event) } } + $credential = $this->preProcessCredential($credential, $userObject); + $cryptoService = $this->getHydrator()->getCryptoService(); if (!$cryptoService->verify($credential, $userObject->getPassword())) { // Password does not match @@ -132,10 +133,10 @@ protected function updateUserPasswordHash(UserEntity $user, $password, Bcrypt $b $this->getMapper()->update($user); } - public function preprocessCredential($credential) + public function preprocessCredential($credential, UserEntity $user) { if (is_callable($this->credentialPreprocessor)) { - return call_user_func($this->credentialPreprocessor, $credential); + return call_user_func($this->credentialPreprocessor, $credential, $user); } return $credential; } diff --git a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php index 5d8b3e69..82cc7241 100644 --- a/tests/ZfcUserTest/Authentication/Adapter/DbTest.php +++ b/tests/ZfcUserTest/Authentication/Adapter/DbTest.php @@ -425,7 +425,24 @@ public function testPreprocessCredentialWithCallable() $this->db->setCredentialPreprocessor(function ($credential) use ($expected) { return $expected; }); - $this->assertSame($expected, $this->db->preprocessCredential('ZfcUser')); + $this->assertSame($expected, $this->db->preprocessCredential('ZfcUser', $this->user)); + } + + /** + * @covers ZfcUser\Authentication\Adapter\Db::preprocessCredential + * @covers ZfcUser\Authentication\Adapter\Db::setCredentialPreprocessor + */ + public function testPreprocessCredentialWithCallableAndAdditionalUserParam() + { + $expected = 3; + $this->user->expects($this->once()) + ->method('getId') + ->will($this->returnValue($expected)); + + $this->db->setCredentialPreprocessor(function ($credential, $user) { + return $user->getId(); + }); + $this->assertSame($expected, $this->db->preprocessCredential('ZfcUser', $this->user)); } /** @@ -433,7 +450,7 @@ public function testPreprocessCredentialWithCallable() */ public function testPreprocessCredentialWithoutCallable() { - $this->assertSame('zfcUser', $this->db->preprocessCredential('zfcUser')); + $this->assertSame('zfcUser', $this->db->preprocessCredential('zfcUser', $this->user)); } /**