I've modified the Fr3d\LDAPBundle to suit my current needs, this solves my problem and hopefully help someone:
Edit:
vendor\fr3d\ldap-bundle\FR3D\LdapBundle\Ldap\LdapManager.php
Add this function:
<?php
public function setOptions($options) {
$this->driver->setOptions($options);
}
Edit:
vendor\fr3d\ldap-bundle\FR3D\LdapBundle\Driver\ZendLdapDriver.php
Add this function:
<?php
public function setOptions($options)
{
$this->driver->setOptions(array_merge($this->driver->getOptions(), $options));
}
Edit:
vendor\fr3d\ldap-bundle\FR3D\LdapBundle\Security\Authentication\LdapAuthenticationProvider.php
Modify the function retrieveUser( ... ):
<?php
protected function retrieveUser($username, UsernamePasswordToken $token)
{
$user = $token->getUser();
if ($user instanceof UserInterface) {
return $user;
}
$this->ldapManager->setOptions(array( 'username' => $token->getUser(), 'password' => $token->getCredentials()));
try {
$user = $this->userProvider->loadUserByUsername($username);
return $user;
} catch (UsernameNotFoundException $notFound) {
throw $notFound;
} catch (\Exception $repositoryProblem) {
if (Kernel::MINOR_VERSION <= 1) {
throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, (int)$repositoryProblem->getCode(), $repositoryProblem);
} else {
$e = new AuthenticationServiceException($repositoryProblem->getMessage(), (int)$repositoryProblem->getCode(), $repositoryProblem);
$e->setToken($token);
throw $e;
}
}
}
That's all!, now the FOSUser login credentials are used for Bind()ing to the server.
Maybe a config parameter would be nicer, but for now this solves my problem.
Thanks Qoop!
fr3d_ldapconfig are for the LDAP server rather than the actual individual user. Note: for security in the repo I have these all in myparameters.ymlas things likeldap.driver.usernameand reference them in the config using%ldap.driver.username%. - qooplmao