Skip to content

Commit

Permalink
bug #37177 [Ldap] fix refreshUser() ignoring extra_fields (arkste)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.4 branch (closes #37177).

Discussion
----------

[Ldap] fix refreshUser() ignoring extra_fields

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? |no
| Tickets       | -
| License       | MIT
| Doc PR        | -

While #31532 introduced `extra_fields` in general, #32824 later added `LdapUser` & `LdapUserProvider` and ignored `extra_fields` on `refreshUser()`.

This PR fixes `refreshUser()` and adds a test which makes sure, that the refreshed ldap user doesn't lose its default values.

Commits
-------

cb8f129 [Ldap] fix refreshUser() ignoring extra_fields
  • Loading branch information
chalasr committed Jun 10, 2020
2 parents 5edbf0b + cb8f129 commit c70241e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Ldap/Security/LdapUserProvider.php
Expand Up @@ -108,7 +108,7 @@ public function refreshUser(UserInterface $user)
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
}

return new LdapUser($user->getEntry(), $user->getUsername(), $user->getPassword(), $user->getRoles());
return new LdapUser($user->getEntry(), $user->getUsername(), $user->getPassword(), $user->getRoles(), $user->getExtraFields());
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Ldap/Tests/Security/LdapUserProviderTest.php
Expand Up @@ -330,4 +330,14 @@ public function testLoadUserByUsernameIsSuccessfulWithPasswordAttribute()
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})', 'userpassword', ['email']);
$this->assertInstanceOf(LdapUser::class, $provider->loadUserByUsername('foo'));
}

public function testRefreshUserShouldReturnUserWithSameProperties()
{
$ldap = $this->createMock(LdapInterface::class);
$provider = new LdapUserProvider($ldap, 'ou=MyBusiness,dc=symfony,dc=com', null, null, [], 'sAMAccountName', '({uid_key}={username})', 'userpassword', ['email']);

$user = new LdapUser(new Entry('foo'), 'foo', 'bar', ['ROLE_DUMMY'], ['email' => 'foo@symfony.com']);

$this->assertEquals($user, $provider->refreshUser($user));
}
}

0 comments on commit c70241e

Please sign in to comment.