/** * @param \Symfony\Component\Security\Core\User\UserProviderInterface $userProvider * @param \LdapTools\Bundle\LdapToolsBundle\Security\User\LdapUserChecker $userChecker * @param \LdapTools\LdapManager $ldap * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token * @param \LdapTools\Bundle\LdapToolsBundle\Security\User\LdapUser $user * @param \LdapTools\Connection\LdapConnectionInterface $connection * @param \LdapTools\Operation\AuthenticationResponse $response * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */ function let($userProvider, $userChecker, $ldap, $token, $user, $connection, $response, $dispatcher) { $this->userProvider = $userProvider; $this->userChecker = $userChecker; $this->ldap = $ldap; $this->token = $token; $this->user = $user; $this->connection = $connection; $this->operation = (new AuthenticationOperation())->setUsername('foo')->setPassword('bar'); $this->response = $response; $this->dispatcher = $dispatcher; $token->getUsername()->willReturn('foo'); $token->getCredentials()->willReturn('bar'); $token->hasAttribute('ldap_domain')->willReturn(false); $token->getAttributes()->willReturn([]); $this->userProvider->loadUserByUsername('foo')->willReturn($user); $this->connection->getConfig()->willReturn(new DomainConfiguration('foo.bar')); $this->connection->execute($this->operation)->willReturn($this->response); $this->response->isAuthenticated()->willReturn(true); $this->ldap->getConnection()->willReturn($this->connection); $this->ldap->getDomainContext()->willReturn('foo.bar'); $this->user->getUsername()->willReturn('foo'); $this->user->getRoles()->willReturn(['ROLE_USER']); $this->user->isAccountNonLocked()->willReturn(true); $this->user->isEnabled()->willReturn(true); $this->user->isAccountNonExpired()->willReturn(true); $this->user->isCredentialsNonExpired()->willReturn(true); $this->beConstructedWith('restricted', true, $this->userProvider, new LdapUserChecker(), $this->ldap, $this->dispatcher); }
function it_should_refresh_roles_but_not_attributes_if_specified($query, LdapUser $user) { $this->setRefreshAttributes(false); $query->getResult()->shouldBeCalled(); $user->toArray()->shouldBeCalled()->willReturn(['foo' => 'bar', 'guid' => $this->attr['guid']]); $user->getType()->shouldBeCalled()->willReturn('user'); $user->getRoles()->shouldNotBeCalled(); $query->getSingleResult()->shouldNotBeCalled(); $this->refreshUser($user)->toArray()->shouldEqual(['foo' => 'bar', 'guid' => $this->attr['guid']]); }
function it_should_call_a_login_success_event() { $credentials = $this->credentials; $credentials['ldap_domain'] = ''; $user = new LdapUser(new LdapObject(['username' => 'foo'])); $token = new UsernamePasswordToken($user, $credentials['password'], 'ldap-tools', $user->getRoles()); $token->setAttribute('ldap_domain', ''); $this->connection->execute(new AuthenticationOperation('foo', 'bar'))->shouldBeCalled()->willReturn(new AuthenticationResponse(true)); $this->checkCredentials($credentials, $user)->shouldReturn(true); $this->dispatcher->dispatch('ldap_tools_bundle.login.success', new LdapLoginEvent($user, $token))->shouldBeCalled(); }