저자: Chad Sikorra (Chad.Sikorra@gmail.com)
상속: use trait ConfigurationParseTrait
예제 #1
0
 function let(LdapConnectionInterface $connection, LdapObject $rootdse)
 {
     $domain = new DomainConfiguration('example.local');
     $domain->setUseTls(true);
     $connection->getConfig()->willReturn($domain);
     $connection->getRootDse()->willReturn($rootdse);
     $config = new Configuration();
     $this->parser = new SchemaYamlParser($config->getSchemaFolder());
     $this->schema = $this->parser->parse('ad', 'user');
 }
 function let()
 {
     $this->filter = new FilterBuilder();
     $config = new Configuration();
     $parser = new SchemaYamlParser($config->getSchemaFolder());
     $this->schema = $parser->parse('ad', 'user');
     $this->collection = new OperatorCollection();
     $this->collection->addLdapObjectSchema($this->schema);
     $this->collection->addLdapObjectSchema($parser->parse('ad', 'ou'));
     $this->beConstructedThrough('getInstance', [$this->schema, $this->collection, AttributeConverterInterface::TYPE_SEARCH_TO]);
 }
 /**
  * {@inheritdoc}
  */
 public function warmUp($cacheDir)
 {
     $domain = $this->ldap->getDomainContext();
     foreach ($this->config->getDomainConfiguration() as $domainConfig) {
         $this->ldap->switchDomain($domainConfig->getDomainName());
         $schemaFactory = $this->ldap->getSchemaFactory();
         $parser = $this->ldap->getSchemaParser();
         $schema = empty($domainConfig->getSchemaName()) ? $domainConfig->getLdapType() : $domainConfig->getSchemaName();
         $ldapObjects = $parser->parseAll($schema);
         $this->cacheAllLdapSchemaObjects($schemaFactory, ...$ldapObjects);
     }
     $this->ldap->switchDomain($domain);
 }
예제 #4
0
 function let(LdapConnectionInterface $connection)
 {
     $config = (new DomainConfiguration('example.com'))->setSchemaName('example');
     $connection->getConfig()->willReturn($config);
     $config = new Configuration();
     $parserTest = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../resources/schema');
     $parser = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../../resources/schema');
     $cache = CacheFactory::get('none', []);
     $this->dispatcherTest = new SymfonyEventDispatcher();
     $this->dispatcher = new SymfonyEventDispatcher();
     $this->objectSchemaFactoryTest = new LdapObjectSchemaFactory($cache, $parserTest, $this->dispatcherTest);
     $this->objectSchemaFactory = new LdapObjectSchemaFactory($cache, $parser, $this->dispatcher);
     $this->beConstructedWith($connection, $this->objectSchemaFactory, $this->dispatcher);
 }
예제 #5
0
 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);
 }
예제 #6
0
 public function let(LdapConnectionInterface $connection)
 {
     $this->config = (new DomainConfiguration('example.com'))->setSchemaName('example');
     $this->config->setUseTls(true);
     $ldapObject = new LdapObject(['defaultNamingContext' => 'dc=example,dc=com'], ['*'], '', 'ad');
     $connection->getConfig()->willReturn($this->config);
     $connection->getRootDse()->willReturn($ldapObject);
     $config = new Configuration();
     $parser = SchemaParserFactory::get($config->getSchemaFormat(), $config->getSchemaFolder());
     $parserTest = SchemaParserFactory::get($config->getSchemaFormat(), __DIR__ . '/../../resources/schema');
     $cache = CacheFactory::get('none', []);
     $this->dispatcher = new SymfonyEventDispatcher();
     $this->schemaFactoryTest = new LdapObjectSchemaFactory($cache, $parserTest, $this->dispatcher);
     $this->schemaFactory = new LdapObjectSchemaFactory($cache, $parser, $this->dispatcher);
     $this->attributes['unicodePwd'] = (new EncodeWindowsPassword())->toLdap('12345');
     $this->addOperation = (new AddOperation('foo'))->setDn("cn=somedude,dc=foo,dc=bar")->setAttributes($this->attributes);
     $this->beConstructedWith($connection, $this->schemaFactoryTest, $this->dispatcher);
 }
예제 #7
0
 /**
  * @param Configuration $config
  * @param Connection\LdapConnectionInterface[] $connections
  */
 public function __construct(Configuration $config, LdapConnectionInterface ...$connections)
 {
     $this->config = $config;
     $this->domains = $config->getDomainConfiguration();
     if (empty($this->domains) && empty($connections)) {
         throw new \RuntimeException("Your configuration must have at least one domain.");
     }
     $this->registerAttributeConverters($config->getAttributeConverters());
     // Pre-populate the connections array. They will be instantiated as needed.
     foreach (array_keys($this->domains) as $domain) {
         $this->connections[$domain] = null;
     }
     $this->addConnection(...$connections);
     $this->context = array_keys($this->domains)[0];
     if (!empty($this->config->getDefaultDomain())) {
         $this->validateDomainName($this->config->getDefaultDomain());
         $this->context = $this->config->getDefaultDomain();
     }
 }
 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);
 }
예제 #9
0
 function it_should_get_the_ldif_string_representation_in_the_context_of_a_type_and_a_schema(LdapConnectionInterface $connection, LdapObject $rootdse)
 {
     $domain = new DomainConfiguration('example.local');
     $domain->setUseTls(true);
     $connection->getConfig()->willReturn($domain);
     $connection->getRootDse()->willReturn($rootdse);
     $config = new Configuration();
     $parser = new SchemaYamlParser($config->getSchemaFolder());
     $schema = $parser->parse('ad', 'user');
     $dn = 'cn=foo,dc=foo,dc=bar';
     $this->beConstructedWith($dn);
     $this->setLdapObjectSchema($schema);
     $this->setLdapConnection($connection);
     $this->add('phoneNumber', '555-5555');
     $this->reset('lastName');
     $this->replace('firstName', 'bar');
     $this->delete('password', 'foo');
     $this->add('password', 'bar');
     $ldif = "dn: {$dn}\r\n" . "changetype: modify\r\n" . "add: telephoneNumber\r\n" . "telephoneNumber: 555-5555\r\n" . "-\r\n" . "delete: sn\r\n" . "-\r\n" . "replace: givenName\r\n" . "givenName: bar\r\n" . "-\r\n" . "delete: unicodePwd\r\n" . "unicodePwd: IgBmAG8AbwAiAA==\r\n" . "-\r\n" . "add: unicodePwd\r\n" . "unicodePwd: IgBiAGEAcgAiAA==\r\n" . "-\r\n";
     $this->toString()->shouldBeEqualTo($ldif);
 }
예제 #10
0
 function it_should_register_converters_listed_in_the_config()
 {
     $config = new Configuration();
     $config->setSchemaFolder(__DIR__ . '/../resources/schema');
     $config->setAttributeConverters(['my_bool' => '\\LdapTools\\AttributeConverter\\ConvertBoolean']);
     $domain = new DomainConfiguration('example.com');
     $domain->setServers(['example'])->setLazyBind(true)->setBaseDn('dc=example,dc=com')->setSchemaName('example');
     $config->addDomain($domain);
     $this->beConstructedWith($config);
     $this->buildLdapQuery()->from('custom_converter')->where(['foo' => true])->toLdapFilter()->shouldBeEqualTo('(&(objectClass=foo)(&(bar=TRUE)))');
 }
 function it_should_call_the_load_schema_event($dispatcher)
 {
     $config = new Configuration();
     $parser = SchemaParserFactory::get('yml', $config->getSchemaFolder());
     $cache = CacheFactory::get('none', []);
     new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, new LdapObjectSchema('ad', 'user'));
     $dispatcher->dispatch(Argument::type('\\LdapTools\\Event\\LdapObjectSchemaEvent'))->shouldBeCalled();
     $this->beConstructedWith($cache, $parser, $dispatcher);
     $this->get('ad', LdapObjectType::USER);
 }
예제 #12
0
 function it_should_get_the_ldif_representation_in_the_context_of_a_type_and_schema(LdapConnectionInterface $connection, LdapObject $rootdse)
 {
     $domain = new DomainConfiguration('example.local');
     $domain->setUseTls(true);
     $connection->getConfig()->willReturn($domain);
     $connection->getRootDse()->willReturn($rootdse);
     $config = new Configuration();
     $parser = new SchemaYamlParser($config->getSchemaFolder());
     $schema = $parser->parse('ad', 'user');
     $this->beConstructedWith(null);
     $this->setLdapObjectSchema($schema);
     $this->setLdapConnection($connection);
     $this->setAttributes(['username' => 'John', 'password' => '12345']);
     $this->setLocation('ou=employees,dc=example,dc=local');
     $ldif = "dn: cn=John,ou=employees,dc=example,dc=local\r\n" . "changetype: add\r\n" . "cn: John\r\n" . "displayname: John\r\n" . "givenName: John\r\n" . "userPrincipalName: John@example.local\r\n" . "objectclass: top\r\n" . "objectclass: person\r\n" . "objectclass: organizationalPerson\r\n" . "objectclass: user\r\n" . "sAMAccountName: John\r\n" . "unicodePwd: IgAxADIAMwA0ADUAIgA=\r\n" . "userAccountControl: 512\r\n";
     $this->toString()->shouldBeEqualTo($ldif);
 }
예제 #13
0
 function let()
 {
     $config = new Configuration();
     $this->beConstructedWith($config->getSchemaFolder());
 }
예제 #14
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');
 }