/** * @param Request $request * @param TokenInterface $token * @return RedirectResponse */ public function onAuthenticationSuccess(Request $request, TokenInterface $token) { // Get current user $currentUser = $this->security->getToken()->getUser(); $currentUsername = $currentUser->getUsername(); if ($currentUsername != 'sys' && $currentUsername != 'admin') { // Get Ldap User $ldapUser = $this->ldap->findUserByUsername($currentUser->getUsername()); // Get DB Stored User $dbUser = $this->em->getRepository('SpiritDevDBoxUserBundle:User')->find($currentUser->getId()); // Merge DB User with Ldap User $dbUser->setDn($ldapUser->getDn()); $dbUser->setLastName($ldapUser->getLastName()); $dbUser->setFirstName($ldapUser->getFirstName()); $dbUser->setEmail($ldapUser->getEmail()); $dbUser->setEmailCanonical($ldapUser->getEmail()); $dbUser->setUsername($ldapUser->getUsername()); $dbUser->setUsernameCanonical($ldapUser->getUsername()); $dbUser->setLanguage($ldapUser->getLanguage()); // Save in db $this->em->flush(); // Update session user $this->security->getToken()->setUser($dbUser); } // Redirect $referer_url = $this->router->generate('spirit_dev_dbox_portal_bundle_introduction'); return new RedirectResponse($referer_url); }
/** * @covers FR3D\LdapBundle\Ldap\LdapManager::findUserByUsername */ public function testFindUserByUsername() { $username = '******'; $ldapResponse = $this->ldapResponse($username); $this->driver->expects($this->once())->method('search')->with($this->equalTo('ou=Groups,dc=example,dc=com'), $this->equalTo('(&(attr0=value0)(uid=test_username))'), $this->equalTo(array('uid')))->will($this->returnValue($ldapResponse)); $resultUser = $this->ldapManager->findUserByUsername($username); $this->assertEquals($username, $resultUser->getUsername()); }
/** * @covers FR3D\LdapBundle\Ldap\LdapManager::findUserByUsername */ public function testFindUserByUsername() { $username = '******'; $entries = array('count' => 1, array('dn' => 'ou=group, dc=host, dc=foo', 'uid' => array('count' => 1, 0 => $username))); $this->connection->expects($this->once())->method('search')->with($this->equalTo('ou=Groups,dc=example,dc=com'), $this->equalTo('(&(attr0=value0)(uid=test_username))'), $this->equalTo(array('uid')))->will($this->returnValue($entries)); $resultUser = $this->ldapManager->findUserByUsername($username); $this->assertEquals($username, $resultUser->getUsername()); }