Skip to content

Commit dd64f65

Browse files
bug #60626 [Ldap] Fix LdapUser::isEqualTo (MatTheCat)
This PR was merged into the 7.3 branch. Discussion ---------- [Ldap] Fix `LdapUser::isEqualTo` | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60454 | License | MIT Since #59682 `LdapUser`s’ password no longer is serialized in the session, which means that `isEqualTo` will crash when trying to access it. This PR makes `getPassword` returns `null` by default to fix this, and update `isEqualTo` to apply #59539’s logic. Commits ------- ad74742 [Ldap] Fix `LdapUser::isEqualTo`
2 parents 37f5341 + ad74742 commit dd64f65

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/Symfony/Component/Ldap/Security/LdapUser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function getRoles(): array
4747

4848
public function getPassword(): ?string
4949
{
50-
return $this->password;
50+
return $this->password ?? null;
5151
}
5252

5353
public function getSalt(): ?string
@@ -89,7 +89,7 @@ public function isEqualTo(UserInterface $user): bool
8989
return false;
9090
}
9191

92-
if ($this->getPassword() !== $user->getPassword()) {
92+
if (($this->getPassword() ?? $user->getPassword()) !== $user->getPassword()) {
9393
return false;
9494
}
9595

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Ldap\Tests\Security;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Ldap\Entry;
16+
use Symfony\Component\Ldap\Security\LdapUser;
17+
18+
class LdapUserTest extends TestCase
19+
{
20+
public function testIsEqualToWorksOnUnserializedUser()
21+
{
22+
$user = new LdapUser(new Entry('uid=jonhdoe,ou=MyBusiness,dc=symfony,dc=com', []), 'jonhdoe', 'p455w0rd');
23+
$unserializedUser = unserialize(serialize($user));
24+
25+
$this->assertTrue($unserializedUser->isEqualTo($user));
26+
}
27+
}

0 commit comments

Comments
 (0)