Author: Chad Sikorra (Chad.Sikorra@gmail.com)
 /**
  * {@inheritdoc}
  */
 public function toLdap($value)
 {
     /**
      * @todo There's a lot more potential logic that needs to happen for this to be accurate...
      */
     if ($this->getOperationType() == AttributeConverterInterface::TYPE_SEARCH_TO && !$value) {
         $fb = new FilterBuilder();
         $value = $fb->bNot($fb->eq('pwdLastSet', '0'));
     } else {
         $value = (bool) $value ? '0' : '-1';
     }
     return $value;
 }
 /**
  * Adds a base 'bOr' operator for the convenience 'orWhere' method only if it does not already exist.
  *
  * @throws \LdapTools\Exception\LdapQueryException
  */
 protected function addBaseOrIfNotExists()
 {
     if (!$this->baseOr) {
         $this->baseOr = $this->filterBuilder->bOr();
         $this->operation->getFilter()->add($this->baseOr);
     }
 }
 function let(LdapConnectionInterface $connection)
 {
     $config = new Configuration();
     $domain = new DomainConfiguration('example.com');
     $domain->setServers(['example'])->setBaseDn('dc=example,dc=com')->setLazyBind(true)->setPageSize(500);
     $connection->getConfig()->willReturn($domain);
     $config->setCacheType('none');
     $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder());
     $cache = CacheFactory::get($config->getCacheType(), []);
     $dispatcher = new SymfonyEventDispatcher();
     $schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $dispatcher);
     $this->fb = new FilterBuilder();
     $this->schema = $schemaFactory;
     $this->objectSchema = $schema = new LdapObjectSchema('ad', 'user');
     $this->objectSchema->setFilter($this->fb->bAnd($this->fb->eq('objectCategory', 'person'), $this->fb->eq('objectClass', 'user')));
     $this->beConstructedWith($connection, $schemaFactory);
 }
 /**
  * @param LdapConnectionInterface $connection
  * @param LdapObjectSchemaFactory $schemaFactory
  */
 public function __construct(LdapConnectionInterface $connection = null, LdapObjectSchemaFactory $schemaFactory = null)
 {
     $this->connection = $connection;
     $this->schemaFactory = $schemaFactory;
     $this->operation = new QueryOperation(new OperatorCollection());
     $this->hydrator = new OperationHydrator($this->connection);
     $this->filterBuilder = FilterBuilder::getInstance($connection);
 }
 /**
  * @param array $filter
  * @param BaseOperator|null $operator
  * @return BaseOperator
  */
 protected function getOperatorForArray(array $filter, BaseOperator $operator = null)
 {
     $filter = !empty($filter) ? $this->filterBuilder->bAnd(...$this->parseFilterToOperators($filter)) : null;
     if (!$filter && !$operator) {
         throw new InvalidArgumentException(sprintf('Type "%s" for schema "%s" needs to have one of the following defined: objectClass, objectCategory, or filter.', $this->schema->getObjectType(), $this->schema->getSchemaName()));
     } elseif ($filter && $operator) {
         $operator = $this->filterBuilder->bAnd($operator, $filter);
     } else {
         $operator = $operator ?: $filter;
     }
     return $operator;
 }
 /**
  * @param bool $value
  * @return \LdapTools\Query\Operator\BaseOperator
  */
 protected function getQueryOperator($value)
 {
     $fb = new FilterBuilder();
     if ($value) {
         $operator = $fb->bAnd($fb->gte('accountExpires', '1'), $fb->lte('accountExpires', '9223372036854775806'));
     } else {
         $operator = $fb->bOr($fb->eq('accountExpires', '0'), $fb->eq('accountExpires', self::NEVER_EXPIRES));
     }
     return $operator;
 }
 /**
  * Transform a bool value into the bitwise operator needed for the LDAP filter.
  * 
  * @param bool $value
  * @return \LdapTools\Query\Operator\BaseOperator
  */
 protected function getQueryOperator($value)
 {
     $fb = new FilterBuilder();
     $mappedValue = $this->getArrayValue($this->getOptions()['uacMap'], $this->getAttribute());
     $operator = $fb->bitwiseAnd('userAccountControl', $mappedValue);
     $value = $this->shouldInvertValue() ? !$value : $value;
     return $value ? $operator : $fb->bNot($operator);
 }
 /**
  * @param bool $value
  * @return \LdapTools\Query\Operator\bOr|\LdapTools\Query\Operator\Comparison
  */
 protected function getQueryValue($value)
 {
     $fb = new FilterBuilder();
     return $value ? $fb->gte('lockoutTime', '1') : $fb->bOr($fb->notPresent('lockoutTime'), $fb->eq('lockoutTime', '0'));
 }
 /**
  * Transform a bool value into the bitwise operator needed for the LDAP filter.
  *
  * @param bool $value
  * @return \LdapTools\Query\Operator\BaseOperator
  */
 protected function getQueryOperator($value)
 {
     $fb = new FilterBuilder();
     $bit = abs($this->getBitForAttribute($this->getAttribute()));
     $operator = $fb->bitwiseAnd('groupType', (string) $bit);
     $value = $this->shouldInvertValue() ? !$value : $value;
     return $value ? $operator : $fb->bNot($operator);
 }
 function it_should_properly_convert_values_when_using_a_multivalued_converter()
 {
     $this->collection->add($this->filter->contains('user.logonWorkstations', ['foo', 'bar']));
     $this->toLdap()->toLdapFilter()->shouldEqual('(|(&(&(objectCategory=person)(objectClass=user))(userWorkstations=*foo,bar*))(&(objectClass=organizationalUnit)))');
 }
 function it_should_hydrate_a_query_operation_to_ldap_with_a_schema($connection)
 {
     $this->schema->setBaseDn('dc=foo,dc=bar');
     $this->setLdapObjectSchema($this->schema);
     $this->setOperationType(AttributeConverterInterface::TYPE_SEARCH_TO);
     $this->setLdapConnection($connection);
     $filter = new FilterBuilder();
     $collection = new OperatorCollection();
     $collection->add($filter->eq('firstName', 'foo'));
     $collection->add($filter->eq('lastName', 'bar'));
     $collection->add($filter->eq('exchangeHideFromGAL', false));
     $collection->addLdapObjectSchema($this->schema);
     $operation = new QueryOperation($collection, ['foo']);
     $this->hydrateToLdap($operation)->getFilter()->shouldBeEqualTo('(&(&(objectCategory=person)(objectClass=user))(givenName=foo)(sn=bar)(msExchHideFromAddressLists=FALSE))');
     $this->hydrateToLdap($operation)->getBaseDn()->shouldBeEqualTo('dc=foo,dc=bar');
 }
Beispiel #12
0
 function it_should_query_results_from_multiple_schema_types($connection)
 {
     $foo = new LdapObjectSchema('foo', 'foo');
     $bar = new LdapObjectSchema('foo', 'bar');
     $foo->setFilter(new Comparison('foo', '=', 'bar'));
     $bar->setFilter(new Comparison('bar', '=', 'foo'));
     $map = ['firstName' => 'givenname', 'lastName' => 'sn', 'created' => 'whencreated', 'name' => 'cn'];
     $bar->setAttributeMap($map);
     $bar->setAttributesToSelect(['name', 'created']);
     $bar->setConverterMap(['generalized_time' => ['created']]);
     $foo->setAttributeMap($map);
     $foo->setAttributesToSelect(['firstName', 'lastName']);
     $fb = new FilterBuilder();
     $filter = new OperatorCollection();
     $filter->addLdapObjectSchema($foo);
     $filter->addLdapObjectSchema($bar);
     $filter->add($fb->bAnd($fb->startsWith('foo.firstName', 'J'), $fb->startsWith('bar.name', 'Smith'), $fb->present('lastName')));
     $this->operation->setFilter($filter);
     $this->operation->setAttributes([]);
     $connection->execute(Argument::that(function ($op) {
         return $op->getFilter() == '(&(foo=bar)(&(givenname=J*)(sn=*)))' && $op->getAttributes() == ['givenname', 'sn'];
     }))->shouldBeCalled()->willReturn($this->ldapEntries);
     $connection->execute(Argument::that(function ($op) {
         return $op->getFilter() == '(&(bar=foo)(&(cn=Smith*)(sn=*)))' && $op->getAttributes() == ['cn', 'whencreated'];
     }))->shouldBeCalled()->willReturn($this->sortEntries);
     $this->getResult()->count()->shouldBeEqualTo(4);
     $this->getArrayResult()->shouldHaveCount(4);
 }