public function execute(LdapOperationInterface $operation)
{
/** @var AuthenticationOperation $operation */
$this->dispatcher->dispatch(new LdapAuthenticationEvent(Event::LDAP_AUTHENTICATION_BEFORE, $operation));
$wasBound = $this->connection->isBound();
$response = $this->getAuthenticationResponse($operation);
if ($response->isAuthenticated() && $operation->getSwitchToCredentials()) {
$this->switchCredentials($operation);
} elseif ($wasBound) {
$this->connection->close()->connect();
} else {
$this->connection->close();
}
$this->dispatcher->dispatch(new LdapAuthenticationEvent(Event::LDAP_AUTHENTICATION_AFTER, $operation, $response));
return $response;
}