Author: Chad Sikorra (Chad.Sikorra@gmail.com)
 /**
  * @param LdapObjectSchemaFactory $schemaFactory
  * @param LdapObjectSchema ...$schemaObjects
  */
 protected function cacheAllLdapSchemaObjects(LdapObjectSchemaFactory $schemaFactory, LdapObjectSchema ...$schemaObjects)
 {
     /** @var LdapObjectSchema $ldapSchemaObject */
     foreach ($schemaObjects as $ldapSchemaObject) {
         $schemaFactory->get($ldapSchemaObject->getSchemaName(), $ldapSchemaObject->getObjectType());
     }
 }
 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);
 }
Exemplo n.º 3
0
 /**
  * @param string $type
  * @return \LdapTools\Schema\LdapObjectSchema
  */
 protected function getSchemaForType($type)
 {
     if (!$this->schemaFactory || !$this->connection) {
         throw new InvalidArgumentException('If you set a schema type for a LDIF entry you must use a SchemaFactory and LdapConnection in the LDIF constructor.');
     }
     return $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type);
 }
Exemplo n.º 4
0
 /**
  * Do the LDAP query to get the LDAP object.
  *
  * @param bool $anonymous
  * @return \LdapTools\Object\LdapObject
  */
 protected function doLdapQuery($anonymous)
 {
     if ($anonymous) {
         $this->connection->connect('', '', true);
     }
     $schema = $this->schemaFactory->get(self::SCHEMA_ROOTDSE_NAME, $this->connection->getConfig()->getLdapType());
     return (new LdapQueryBuilder($this->connection))->from($schema)->select('*')->getLdapQuery()->getSingleResult();
 }
Exemplo n.º 5
0
 /**
  * Get the batch modification array that ldap_modify_batch expects.
  *
  * @param BatchModifyOperation $operation
  * @param string $type
  */
 protected function hydrateOperation(BatchModifyOperation $operation, $type)
 {
     $this->hydrator->setOperationType(AttributeConverterInterface::TYPE_MODIFY);
     if ($type) {
         $this->hydrator->setLdapObjectSchema($this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type));
     }
     $this->hydrator->hydrateToLdap($operation);
     if ($type) {
         $this->hydrator->setLdapObjectSchema(null);
     }
 }
Exemplo n.º 6
0
 /**
  * @param string|LdapObjectSchema $type
  * @return LdapObjectSchema
  */
 protected function getSchemaFromType($type)
 {
     if (is_string($type) && !$this->schemaFactory) {
         throw new LogicException('To build a filter with schema types you must pass a SchemaFactory to the constructor');
     } elseif (is_string($type)) {
         $type = $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type);
     } elseif (!$type instanceof LdapObjectSchema) {
         throw new InvalidArgumentException('You must either pass the schema object type as a string to this method, or pass the schema types ' . 'LdapObjectSchema to this method.');
     }
     return $type;
 }
Exemplo n.º 7
0
 /**
  * Specify the object type to create. Either by its string name type from the schema of the LdapObjectSchema.
  *
  * @param string|LdapObjectSchema $type
  * @return $this
  */
 public function create($type)
 {
     if (!is_string($type) && !$type instanceof LdapObjectSchema) {
         throw new InvalidArgumentException('You must either pass the schema object type as a string to this method, or pass the schema types ' . 'LdapObjectSchema to this method.');
     }
     if (!$type instanceof LdapObjectSchema) {
         $type = $this->schemaFactory->get($this->connection->getConfig()->getSchemaName(), $type);
     }
     $this->schema = $type;
     $this->container = $type->getDefaultContainer();
     return $this;
 }
Exemplo n.º 8
0
 function it_should_sort_results_for_multiple_aliases($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);
     $ou = $schemaFactory->get('ad', 'ou');
     $container = $schemaFactory->get('ad', 'container');
     $filter = new OperatorCollection();
     $filter->addLdapObjectSchema($ou);
     $filter->addLdapObjectSchema($container);
     $this->operation->setFilter($filter);
     $this->operation->setAttributes([]);
     $connection->execute(Argument::that(function ($op) {
         return $op->getFilter() == '(objectClass=organizationalUnit)';
     }))->shouldBeCalled()->willReturn($this->ous);
     $connection->execute(Argument::that(function ($op) {
         return $op->getFilter() == '(&(objectCategory=container))';
     }))->shouldBeCalled()->willReturn($this->containers);
     $this->setOrderBy(['Name' => LdapQuery::ORDER['ASC'], 'ou.Description' => LdapQuery::ORDER['DESC']]);
     $this->getResult()->shouldHavePlaceKeyAndValue(0, 'name', 'Computers');
     $this->getResult()->shouldHavePlaceKeyAndValue(1, 'name', 'Employees');
     $this->getResult()->shouldHavePlaceKeyAndValue(2, 'name', 'Users');
     $this->getResult()->shouldHavePlaceKeyAndValue(3, 'name', 'West');
 }