Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/users.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@
'RbacPolicy' => [],
'PasswordRehash' => [
'authenticators' => [
'Form' => 'Authentication.Password',
// name of the identifier inside the collection of the authenticator ('Authentication.Password' is loaded as 'Password')
'Form' => 'Password',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Component/LoginComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ protected function handlePasswordRehash($service, $user, \Cake\Http\ServerReques
}

$authenticationProvider = $service->getAuthenticationProvider();
if (!$authenticationProvider || !method_exists($authenticationProvider, 'getIdentifier')) {
// is_callable: CakeDC\Auth\Authenticator\FormAuthenticator proxies getIdentifier() via __call
if (!$authenticationProvider || !is_callable([$authenticationProvider, 'getIdentifier'])) {
return;
}

Expand Down
20 changes: 9 additions & 11 deletions tests/TestCase/Controller/Traits/LoginTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ public function testLoginRehash()

public function testLoginRehashWithAuthenticatorStructure()
{
// default configuration of the plugin (config/users.php)
\Cake\Core\Configure::write('Auth.PasswordRehash', [
'authenticators' => [
'Form' => 'Authentication.Password',
'Form' => 'Password',
],
]);

Expand All @@ -309,16 +310,13 @@ public function testLoginRehashWithAuthenticatorStructure()
->method('needsPasswordRehash')
->willReturn(true);

$identifierCollection = new IdentifierCollection([]);
$identifierCollection->set('Authentication.Password', $passwordIdentifier);
// 'Authentication.Password' configured as identifier of the Form authenticator is loaded as 'Password'
$identifierCollection = new IdentifierCollection(['Authentication.Password' => []]);
$this->assertTrue($identifierCollection->has('Password'));
$identifierCollection->set('Password', $passwordIdentifier);

$formAuthenticator = $this->getMockBuilder(FormAuthenticator::class)
->disableOriginalConstructor()
->addMethods(['getIdentifier'])
->getMock();
$formAuthenticator->expects($this->any())
->method('getIdentifier')
->willReturn($identifierCollection);
// the real authenticator, it proxies getIdentifier() to the base authenticator via __call
$formAuthenticator = new FormAuthenticator($identifierCollection);

$authenticatorCollection = $this->getMockBuilder(AuthenticatorCollection::class)
->disableOriginalConstructor()
Expand Down Expand Up @@ -392,7 +390,7 @@ public function testLoginRehashWithAuthenticatorStructure()
'component' => 'CakeDC/Users.Login',
'targetAuthenticator' => FormAuthenticator::class,
'PasswordRehash' => [
'authenticators' => ['Form' => 'Authentication.Password'],
'authenticators' => ['Form' => 'Password'],
],
];

Expand Down