execute() public method

Execute an operation against LDAP (Add, Modify, Delete, Move, Query, etc).
public execute ( LdapTools\Operation\LdapOperationInterface $operation ) : mixed
$operation LdapTools\Operation\LdapOperationInterface
return mixed
コード例 #1
0
 /**
  * Add the object with the selected attributes into LDAP.
  */
 public function execute()
 {
     $this->triggerBeforeCreationEvent();
     $operation = $this->getAddOperation()->setServer($this->server);
     $this->connection->execute($operation);
     $this->triggerAfterCreationEvent($operation);
 }
コード例 #2
0
 /**
  * @param LdapObject $ldapObject
  * @param string|null $dn The DN to use for the batch operation to LDAP.
  */
 protected function executeBatchOperation(LdapObject $ldapObject, $dn = null)
 {
     $dn = $dn ?: $ldapObject->get('dn');
     $operation = new BatchModifyOperation($dn, $ldapObject->getBatchCollection());
     $this->hydrateOperation($operation, $ldapObject->getType());
     $this->connection->execute($operation);
     $ldapObject->setBatchCollection(new BatchCollection($ldapObject->get('dn')));
 }
コード例 #3
0
ファイル: RootDseSpec.php プロジェクト: ldaptools/ldaptools
 function let(LdapConnectionInterface $connection, EventDispatcherInterface $dispatcher)
 {
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == "(&(objectClass=*))" && $operation->getBaseDn() == "";
     }))->willReturn($this->entry);
     $connection->getConfig()->willReturn(new DomainConfiguration('example.local'));
     $connection->isBound()->willReturn(false);
     $connection->connect('', '', true)->willReturn(null);
     $this->beConstructedWith($connection, $dispatcher);
 }
コード例 #4
0
 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();
 }
コード例 #5
0
 public function let(LdapConnectionInterface $connection)
 {
     $config = new Configuration();
     $config->setCacheType('none');
     $connection->execute(Argument::any())->willReturn($this->ldapEntries);
     $connection->getConfig()->willReturn(new DomainConfiguration('example.local'));
     $cache = CacheFactory::get($config->getCacheType(), $config->getCacheOptions());
     $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder());
     $dispatcher = new SymfonyEventDispatcher();
     $schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $dispatcher);
     $this->beConstructedWith($schemaFactory->get('ad', 'user'), $connection);
 }
コード例 #6
0
ファイル: LdapQuery.php プロジェクト: ldaptools/ldaptools
 /**
  * @param QueryOperation $operation
  * @param string $hydratorType
  * @param null|LdapObjectSchema $schema
  * @param null|string $alias
  * @return mixed
  */
 protected function getResultsFromLdap(QueryOperation $operation, $hydratorType, $schema = null, $alias = null)
 {
     $hydrator = $this->hydratorFactory->get($hydratorType);
     $hydrator->setLdapConnection($this->ldap);
     $hydrator->setOperationType(AttributeConverterInterface::TYPE_SEARCH_FROM);
     $hydrator->setLdapObjectSchema($schema);
     $hydrator->setSelectedAttributes($this->getAttributesToLdap($operation->getAttributes(), false, $schema, $alias));
     $opHydrator = new OperationHydrator($this->ldap);
     $opHydrator->setAlias($alias);
     $opHydrator->setOrderBy($this->orderBy);
     $opHydrator->setLdapObjectSchema($schema);
     $opHydrator->hydrateToLdap($operation);
     return $hydrator->hydrateAllFromLdap($this->ldap->execute($operation));
 }
コード例 #7
0
 function let(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $this->expectedCurrentValueResult[0]['gplink'][0] = implode('', $this->gPLinks);
     $this->expectedDisplayResult[0]['objectguid'][0] = (new GUID('8E1F85EB-4882-4920-88A5-CF52F31D8D31'))->toBinary();
     $this->expectedDisplayResult[1]['objectguid'][0] = (new GUID('B261DB28-5EA3-4D69-B79D-5C22E8018183'))->toBinary();
     $this->expectedSingleDisplayResult[0]['objectguid'][0] = (new GUID('8E1F85EB-4882-4920-88A5-CF52F31D8D31'))->toBinary();
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(|(distinguishedName=cn={B261DB28-5EA3-4D69-B79D-5C22E8018183},cn=policies,cn=system,DC=example,DC=local)(distinguishedName=cn={8E1F85EB-4882-4920-88A5-CF52F31D8D31},cn=policies,cn=system,DC=example,DC=local)))';
     }))->willReturn($this->expectedDisplayResult);
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(|(distinguishedName=cn={8E1F85EB-4882-4920-88A5-CF52F31D8D31},cn=policies,cn=system,DC=example,DC=local)))';
     }))->willReturn($this->expectedSingleDisplayResult);
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(|(displayName=Foo)(displayName=Bar)))';
     }))->willReturn($this->expectedDNResult);
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(objectClass=*))' && $operation->getBaseDn() == 'ou=foo,dc=foo,dc=bar';
     }))->willReturn($this->expectedCurrentValueResult);
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $this->setLdapConnection($connection);
     $this->setDn('ou=foo,dc=foo,dc=bar');
     $this->expectedGPOLinks = [new GPOLink(new LdapObject(['dn' => 'cn={B261DB28-5EA3-4D69-B79D-5C22E8018183},cn=policies,cn=system,DC=example,DC=local', 'guid' => 'b261db28-5ea3-4d69-b79d-5c22e8018183', 'name' => 'Bar']), 2), new GPOLink(new LdapObject(['dn' => 'cn={8E1F85EB-4882-4920-88A5-CF52F31D8D31},cn=policies,cn=system,DC=example,DC=local', 'guid' => '8e1f85eb-4882-4920-88a5-cf52f31d8d31', 'name' => 'Foo']), 0)];
 }
コード例 #8
0
ファイル: LdapQuerySpec.php プロジェクト: ldaptools/ldaptools
 function let(LdapConnectionInterface $connection)
 {
     $attribbutes = ['defaultNamingContext' => 'dc=example,dc=local', 'configurationNamingContext' => 'cn=Configuration,dc=example,dc=local'];
     $rootDse = new LdapObject($attribbutes);
     $this->filter = new OperatorCollection();
     $this->filter->add(new Comparison('foo', '=', 'bar'));
     $this->operation = new QueryOperation($this->filter);
     $this->operation->setFilter($this->filter);
     $this->operation->setAttributes(["cn", "givenName", "foo"]);
     $op = clone $this->operation;
     $op->setFilter($this->filter->toLdapFilter());
     $connection->execute($op)->willReturn($this->ldapEntries);
     $connection->getRootDse()->willReturn($rootDse);
     $connection->getConfig()->willReturn(new DomainConfiguration('example.local'));
     $this->beConstructedWith($connection);
     $this->setQueryOperation($this->operation);
 }
コード例 #9
0
 function let(UserProviderInterface $userProvider, LdapUserChecker $userChecker, LdapManager $ldap, TokenInterface $token, LdapUser $user, LdapConnectionInterface $connection, AuthenticationResponse $response, \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher)
 {
     $this->operation = (new AuthenticationOperation())->setUsername('foo')->setPassword('bar');
     $token->getUsername()->willReturn('foo');
     $token->getCredentials()->willReturn('bar');
     $token->hasAttribute('ldap_domain')->willReturn(false);
     $token->getAttributes()->willReturn([]);
     $token->getUser()->willReturn($user);
     $userProvider->loadUserByUsername('foo')->willReturn($user);
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $connection->execute($this->operation)->willReturn($response);
     $response->isAuthenticated()->willReturn(true);
     $ldap->getConnection()->willReturn($connection);
     $ldap->getDomainContext()->willReturn('foo.bar');
     $user->getUsername()->willReturn('foo');
     $user->getRoles()->willReturn(['ROLE_USER']);
     $user->isAccountNonLocked()->willReturn(true);
     $user->isEnabled()->willReturn(true);
     $user->isAccountNonExpired()->willReturn(true);
     $user->isCredentialsNonExpired()->willReturn(true);
     $this->beConstructedWith('restricted', true, $userProvider, new LdapUserChecker(), $ldap, $dispatcher);
 }
コード例 #10
0
 function it_should_throw_a_bad_credentials_exception_if_a_connection_issue_occurs_during_authentication()
 {
     $this->connection->execute($this->operation)->willThrow(new LdapConnectionException('fail'));
     $this->shouldThrow('\\Symfony\\Component\\Security\\Core\\Exception\\BadCredentialsException')->duringAuthenticate($this->token);
 }
コード例 #11
0
 function it_should_attempt_to_authenticate_a_username_and_password(LdapConnectionInterface $connection)
 {
     $operation = new AuthenticationOperation();
     $operation->setUsername('foo')->setPassword('bar');
     $response = new AuthenticationResponse(true);
     $domainConfig = new DomainConfiguration('example.local');
     $connection->getConfig()->willReturn($domainConfig);
     $connection->execute($operation)->willReturn($response);
     $this->beConstructedWith(new Configuration(), $connection);
     $this->authenticate('foo', 'bar')->shouldBeEqualTo(true);
 }