Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Maks3w committed Apr 29, 2015
2 parents 1385094 + 59d002d commit bf7d40e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Config:
- [BC Break] Removed `version` key in config.yml
- [BC Break] `bindRequiredDn` it's false by default, in v1.5.0 works as true

Security:
- [BC Break] You may need set `erase_credentials` setting to `false` if you encounter problems when the user
reauthenticate. See [issue#76](https://github.com/Maks3w/FR3DLdapBundle/issues/76) for more details.

### v1.5.2, v1.6.1 (2012-02-18)

* Add support for Composer package manager now you can find this bundle in http://www.packagist.org
Expand Down
4 changes: 4 additions & 0 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public function registerBundles()
# app/config/security.yml

security:
# Preserve plain text password in token for refresh the user.
# Analyze the security considerations before turn off this setting.
erase_credentials: false

firewalls:
main:
pattern: ^/
Expand Down
11 changes: 9 additions & 2 deletions Security/Authentication/LdapAuthenticationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,19 @@ protected function retrieveUser($username, UsernamePasswordToken $token)
protected function checkAuthentication(UserInterface $user, UsernamePasswordToken $token)
{
$currentUser = $token->getUser();
$presentedPassword = $token->getCredentials();
if ($currentUser instanceof UserInterface) {
if (!$this->ldapManager->bind($currentUser, $currentUser->getPassword())) {
if ('' === $presentedPassword) {
throw new BadCredentialsException(
'The password in the token is empty. You may forgive turn off `erase_credentials` in your `security.yml`'
);
}

if (!$this->ldapManager->bind($currentUser, $presentedPassword)) {
throw new BadCredentialsException('The credentials were changed from another session.');
}
} else {
if ('' === ($presentedPassword = $token->getCredentials())) {
if ('' === $presentedPassword) {
throw new BadCredentialsException('The presented password cannot be empty.');
}

Expand Down
26 changes: 24 additions & 2 deletions Tests/Security/Authentication/LdapAuthenticationProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function testCheckAuthenticationKnownUser()
$password = 'password';
$user = new TestUser();
$user->setUsername($username);
$user->setPassword($password);

$token = new UsernamePasswordToken($username, $password, 'provider_key', array());
$token->setUser($user);

Expand All @@ -131,6 +131,28 @@ public function testCheckAuthenticationKnownUser()
$this->assertTrue(true);
}

public function testCheckAuthenticationWhenTokenNeedsReauthenticationWorksWithoutOriginalCredentials()
{
$method = $this->setMethodAccessible('checkAuthentication');
$username = 'username';
$password = 'password';
$user = new TestUser();
$user->setUsername($username);

$token = new UsernamePasswordToken($user, $password, 'provider_key', array());

$this->ldapManager->expects($this->once())
->method('bind')
->with($this->equalTo($user), $this->equalTo($password))
->will($this->returnValue(true));

$method->invoke(
$this->ldapAuthenticationProvider,
$this->getMock('Symfony\\Component\\Security\\Core\\User\\UserInterface'),
$token
);
}

/**
* @expectedException \Symfony\Component\Security\Core\Exception\BadCredentialsException
* @expectedExceptionMessage The credentials were changed from another session.
Expand All @@ -142,7 +164,7 @@ public function testCheckAuthenticationKnownUserCredentialsChanged()
$password = 'other_password';
$user = new TestUser();
$user->setUsername($username);
$user->setPassword($password);

$token = new UsernamePasswordToken($username, $password, 'provider_key', array());
$token->setUser($user);

Expand Down
8 changes: 8 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ UPGRADE FROM 1.5 to 2.0
<argument>%fr3d_ldap.ldap_manager.parameters%</argument>
</service>
```

* `checkAuthentication()` now reauthenticate current user using token `getCrendetials()` instead `getPassword()`

Turn off `erase_credentials` in application `security.yml`:
```yml
# app/config/security.yml
erase_credentials: false
```

0 comments on commit bf7d40e

Please sign in to comment.