저자: Chad Sikorra (Chad.Sikorra@gmail.com)
 function let(LdapManager $ldap, LdapQueryBuilder $qb, LdapQuery $query, LdapConnectionInterface $connection)
 {
     $groups = new LdapObjectCollection();
     $groups->add(new LdapObject(['name' => 'Foo', 'dn' => 'cn=Foo,dc=example,dc=local']));
     $groups->add(new LdapObject(['guid' => '291d8444-9d5b-4b0a-a6d7-853408f704d5', 'dn' => 'cn=Bar,dc=example,dc=local']));
     $groups->add(new LdapObject(['sid' => 'S-1-5-18', 'dn' => 'cn=LocalSys,dc=example,dc=local']));
     $groups->add(new LdapObject(['name' => 'Just a DN', 'dn' => 'cn=Stuff,dc=example,dc=local']));
     $roleMap = ['ROLE_AWESOME' => ['foo'], 'ROLE_ADMIN' => ['291d8444-9d5b-4b0a-a6d7-853408f704d5'], 'ROLE_DN' => ['cn=Stuff,dc=example,dc=local'], 'ROLE_SID' => ['S-1-5-18']];
     $attrMap = ['username' => 'username', 'accountNonLocked' => 'locked', 'accountNonExpired' => 'accountExpirationDate', 'enabled' => 'disabled', 'credentialsNonExpired' => 'passwordMustChange', 'guid' => 'guid', 'groups' => 'groups', 'stringRepresentation' => 'username'];
     $config = new DomainConfiguration('foo.bar');
     $filter = new ADFilterBuilder();
     $ldapObject = new LdapObject($this->attr, ['user'], ['user'], 'user');
     $query->getSingleResult()->willReturn($ldapObject);
     $query->getResult()->willReturn($groups);
     $query->getArrayResult()->willReturn([['name' => 'foo'], ['name' => 'bar']]);
     $qb->from(LdapObjectType::USER)->willReturn($qb);
     $qb->from('group')->willReturn($qb);
     $qb->select(["username", "locked", "accountExpirationDate", "disabled", "passwordMustChange", "guid", "groups", "username"])->willReturn($qb);
     $qb->select(["name", "sid", "guid"])->willReturn($qb);
     $qb->select('name')->willReturn($qb);
     $qb->where(['username' => 'foo'])->willReturn($qb);
     $qb->getLdapQuery()->willReturn($query);
     $qb->filter()->willReturn($filter);
     $qb->where($filter->hasMemberRecursively($this->attr['guid'], 'members'))->willReturn($qb);
     $ldap->buildLdapQuery()->willReturn($qb);
     $connection->getConfig()->willReturn($config);
     $ldap->getConnection()->willReturn($connection);
     $this->beConstructedWith($ldap, $attrMap, $roleMap, true);
 }
 function let(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $options = ['addressType' => ['exchangeSmtpAddress' => 'smtp', 'exchangeDefaultSmtpAddress' => 'smtp'], 'default' => ['exchangeDefaultSmtpAddress']];
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $this->setOptions($options);
     $this->setLdapConnection($connection);
     $this->setDn('cn=foo,dc=foo,dc=bar');
 }
예제 #3
0
 /**
  * Get a FilterBuilder instance based on the connection.
  * 
  * @param LdapConnectionInterface|null $connection
  * @return ADFilterBuilder|FilterBuilder
  */
 public static function getInstance(LdapConnectionInterface $connection = null)
 {
     if ($connection && $connection->getConfig()->getLdapType() == LdapConnection::TYPE_AD) {
         $filterBuilder = new ADFilterBuilder();
     } else {
         $filterBuilder = new self();
     }
     return $filterBuilder;
 }
예제 #4
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(LdapConnectionInterface $connection, AddOperation $operation)
 {
     $schema = new LdapObjectSchema('ad', 'user');
     $schema->setAttributeMap(['username' => 'sAMAccountName', 'emailAddress' => 'mail', 'disabled' => 'userAccountControl', 'passwordMustChange' => 'pwdLastSet', 'passwordNeverExpires' => 'userAccountControl', 'trustedForAllDelegation' => 'userAccountControl', 'groups' => 'memberOf']);
     $schema->setConverterMap(['disabled' => 'user_account_control', 'passwordMustChange' => 'password_must_change', 'trustedForAllDelegation' => 'user_account_control', 'passwordNeverExpires' => 'user_account_control', 'groups' => 'group_membership']);
     $schema->setConverterOptions(['user_account_control' => ['uacMap' => ['disabled' => '2', 'passwordNeverExpires' => '65536', 'smartCardRequired' => '262144', 'trustedForAllDelegation' => '524288', 'passwordIsReversible' => '128'], 'defaultValue' => '512'], 'group_membership' => ['groups' => ['to_attribute' => 'member', 'from_attribute' => 'memberOf', 'attribute' => 'sAMAccountName', 'filter' => ['objectClass' => 'group']]]]);
     $this->schema = $schema;
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $this->beConstructedThrough('getInstance', [$schema, $this->entryTo, AttributeConverterInterface::TYPE_CREATE]);
 }
 function let(LdapManager $ldap, LdapConnectionInterface $connection, RouterInterface $router, EventDispatcherInterface $dispatcher)
 {
     $this->userChecker = new LdapUserChecker();
     $this->request = new Request();
     $this->request->setSession(new Session());
     $router->generate('login')->willReturn('/login');
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $ldap->getConnection()->willReturn($connection);
     $ldap->getDomainContext()->willReturn('foo.bar');
     $this->beConstructedWith(true, $this->userChecker, $ldap, $router, $dispatcher);
 }
 function let(LdapConnectionInterface $connection)
 {
     $schema = new LdapObjectSchema('ad', 'user');
     $schema->setAttributeMap(['username' => 'sAMAccountName', 'emailAddress' => 'mail', 'disabled' => 'userAccountControl', 'passwordMustChange' => 'pwdLastSet', 'passwordNeverExpires' => 'userAccountControl', 'trustedForAllDelegation' => 'userAccountControl', 'groups' => 'memberOf']);
     $schema->setConverterMap(['disabled' => 'user_account_control', 'passwordMustChange' => 'password_must_change', 'trustedForAllDelegation' => 'user_account_control', 'passwordNeverExpires' => 'user_account_control', 'groups' => 'group_membership']);
     $schema->setConverterOptions(['user_account_control' => ['uacMap' => ['disabled' => '2', 'passwordNeverExpires' => '65536', 'smartCardRequired' => '262144', 'trustedForAllDelegation' => '524288', 'passwordIsReversible' => '128'], 'defaultValue' => '512'], 'group_membership' => ['groups' => ['to_attribute' => 'member', 'from_attribute' => 'memberOf', 'attribute' => 'sAMAccountName', 'filter' => ['objectClass' => 'group']]]]);
     $this->expectedSearch = new QueryOperation('(&(distinguishedName=cn=foo,dc=foo,dc=bar))', ['userAccountControl']);
     $this->schema = $schema;
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $connection->getRootDse()->willReturn(new LdapObject(['foo' => 'bar']));
 }
예제 #8
0
 function let(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $connection->getConfig()->willReturn(new DomainConfiguration('foo.bar'));
     $options = ['defaultValue' => '-2147483646', 'distribution' => 'typeDistribution', 'types' => ['scope' => ['scopeDomainLocal', 'scopeGlobal', 'scopeUniversal'], 'type' => ['typeBuiltin', 'typeSecurity', 'typeDistribution']], 'typeMap' => ['typeBuiltin' => '1', 'typeSecurity' => '2147483648', 'typeDistribution' => '2147483648', 'scopeDomainLocal' => '4', 'scopeGlobal' => '2', 'scopeUniversal' => '8']];
     $this->expectedSearch = new QueryOperation('(&(distinguishedName=cn=foo,dc=foo,dc=bar))', ['groupType']);
     $this->setOptions($options);
     $this->setLdapConnection($connection);
     $this->setDn('cn=foo,dc=foo,dc=bar');
     $this->expectedOp = function ($operation) {
         return $operation->getFilter() == '(&(objectClass=*))' && $operation->getBaseDn() == 'cn=foo,dc=foo,dc=bar';
     };
 }
 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);
 }
 function let(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $config = new DomainConfiguration('foo.bar');
     $config->setBaseDn('dc=foo,dc=bar');
     $connection->getConfig()->willReturn($config);
     $options = ['uacMap' => ['disabled' => '2', 'enabled' => '2', 'passwordNeverExpires' => '65536', 'smartCardRequired' => '262144', 'trustedForAllDelegation' => '262144', 'trustedForAnyAuthDelegation' => '16777216', 'passwordIsReversible' => '128'], 'defaultValue' => '512', 'invert' => ['enabled']];
     $this->setOptions($options);
     $this->setLdapConnection($connection);
     $this->setDn('cn=foo,dc=foo,dc=bar');
     $this->expectedOp = function ($operation) {
         return $operation->getFilter() == '(&(objectClass=*))' && $operation->getAttributes() == ['userAccountControl'] && $operation->getBaseDn() == 'cn=foo,dc=foo,dc=bar';
     };
 }
 function it_should_throw_an_exception_if_ssl_or_tls_is_not_enabled(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException');
     $config = new DomainConfiguration('example.local');
     $config->setUseTls(true);
     $connection->getConfig()->willReturn($config);
     $this->setLdapConnection($connection);
     $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException');
     $config->setUseTls(false);
     $this->shouldThrow('\\LdapTools\\Exception\\LdapConnectionException')->duringToLdap('test');
     $config->setUseSsl(true);
     $this->toLdap('test')->shouldNotThrow('\\LdapTools\\Exception\\LdapConnectionException');
 }
예제 #12
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);
 }
예제 #13
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);
 }
예제 #14
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);
 }
예제 #15
0
 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);
 }
예제 #16
0
 /**
  * Resets the paging control so that read operations work after a paging operation is used.
  *
  * @throws LdapConnectionException
  */
 public function resetPagingControl()
 {
     // Per RFC 2696, to abandon a paged search you should send a size of 0 along with the cookie used in the search.
     // However, testing this it doesn't seem to completely work. Perhaps a PHP bug?
     if (!@ldap_control_paged_result($this->connection->getConnection(), 0, false, $this->cookie)) {
         throw new LdapConnectionException(sprintf('Unable to reset paged results control for read operation: %s', $this->connection->getLastError()));
     }
 }
예제 #17
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();
 }
예제 #18
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);
 }
예제 #19
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);
 }
 function let(\LdapTools\Connection\LdapConnectionInterface $connection)
 {
     $connection->getConfig()->willReturn(new DomainConfiguration('example.local'));
     $this->setLdapConnection($connection);
     $this->setDn('cn=foo,dc=foo,dc=bar');
     $dn = $this->dn;
     $groupSidHex = $this->groupSidHex;
     $connection->execute(Argument::that(function ($operation) use($dn) {
         return $operation->getFilter() == '(&(objectClass=*))' && $operation->getAttributes() == ['objectSid'] && $operation->getBaseDn() == $dn;
     }))->willReturn(['count' => 1, ["objectsid" => ["count" => 1, 0 => pack('H*', str_replace('\\', '', $this->userSidHex))], 0 => "objectsid", 'count' => 1, 'dn' => $this->dn]]);
     $connection->execute(Argument::that(function ($operation) use($groupSidHex) {
         return $operation->getFilter() == '(&(objectSid=' . $groupSidHex . '))' && $operation->getAttributes() == ['cn'];
     }))->willReturn(['count' => 1, ["cn" => ["count" => 1, 0 => 'Domain Users'], 0 => "cn", "count" => 1, "dn" => "CN=Domain Users,CN=Users,dc=example,dc=local"]]);
     $connection->execute(Argument::that(function ($operation) use($dn) {
         return $operation->getFilter() == '(&(objectClass=group)(cn=Domain Users)(member=' . $dn . ')(groupType:1.2.840.113556.1.4.803:=2147483648))' && $operation->getAttributes() == ['objectSid'];
     }))->willReturn(['count' => 1, ["objectSid" => ["count" => 1, 0 => pack('H*', str_replace('\\', '', $this->groupSidHex))], 0 => "objectSid", "count" => 1, "dn" => "CN=Domain Users,CN=Users,dc=example,dc=local"]]);
     $connection->execute(Argument::that(function ($operation) use($dn) {
         return $operation->getFilter() == '(&(objectClass=group)(cn=Domain Users)(member=foo)(groupType:1.2.840.113556.1.4.803:=2147483648))' && $operation->getAttributes() == ['objectSid'];
     }))->willReturn(['count' => 0]);
 }
 function let(Reader $reader, LdapManager $ldap, LifecycleEventArgs $eventArgs, ObjectManager $om, ClassMetadata $metadata, LdapObjectSchemaFactory $schemaFactory, LdapConnectionInterface $connection, LdapObjectSchema $schema, LdapQueryBuilder $qb, LdapQuery $query, $entity)
 {
     $rc = new \ReflectionClass('Doctrine\\Common\\Persistence\\Event\\LifecycleEventArgs');
     if ($rc->hasMethod('getObjectManager')) {
         $eventArgs->getObjectManager()->willReturn($om);
         $eventArgs->getObject()->willReturn($entity);
     } else {
         $eventArgs->getEntityManager()->willReturn($om);
         $eventArgs->getEntity()->willReturn($entity);
     }
     $om->getClassMetadata(Argument::any())->willReturn($metadata);
     $this->config = new DomainConfiguration('foo.bar');
     $connection->getConfig()->willReturn($this->config);
     $ldap->getDomainContext()->willReturn('foo.bar');
     $ldap->getSchemaFactory()->willReturn($schemaFactory);
     $ldap->getConnection()->willReturn($connection);
     $ldap->buildLdapQuery()->willReturn($qb);
     $qb->getLdapQuery()->willReturn($query);
     $this->beConstructedWith($reader, $ldap);
 }
예제 #22
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);
     }
 }
 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();
 }
 function let(LdapConnectionInterface $connection, EventDispatcherInterface $dispatcher, LdapLoggerInterface $logger)
 {
     $connection->getConfig()->willReturn(new DomainConfiguration('example.local'));
     $connection->getConnection()->willReturn(null);
     $connection->isBound()->willReturn(true);
     $connection->getServer()->willReturn('foo');
     $connection->getIdleTime()->willReturn(1);
     $this->setConnection($connection);
     $this->setEventDispatcher($dispatcher);
     $this->setLogger($logger);
 }
 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);
 }
예제 #26
0
 /**
  * Encodes any values with the needed type for LDAP.
  *
  * @param array|string $values
  * @return array
  */
 protected function encodeValues($values)
 {
     if (is_null($this->connection) || $this->type == AttributeConverterInterface::TYPE_SEARCH_FROM) {
         return $values;
     }
     $encoded = is_array($values) ? $values : [$values];
     foreach ($encoded as $index => $value) {
         if (is_string($value)) {
             $encoded[$index] = LdapUtilities::encode($value, $this->connection->getConfig()->getEncoding());
         }
     }
     // This is to pass it back the same way it was received. ldap_modify_batch is picky about values being an array.
     return is_array($values) ? $encoded : reset($encoded);
 }
예제 #27
0
 /**
  * @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));
 }
예제 #28
0
 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);
 }
예제 #29
0
 /**
  * @param bool $isRoot
  * @return SID
  */
 protected function getDomainSid($isRoot)
 {
     if (!$isRoot && $this->domainSid) {
         return $this->domainSid;
     } elseif ($isRoot && $this->rootDomainSid) {
         return $this->rootDomainSid;
     }
     $baseDn = $isRoot ? 'rootDomainNamingContext' : 'defaultNamingContext';
     $domainSid = (new LdapQueryBuilder($this->connection))->setBaseDn($this->connection->getRootDse()->get($baseDn))->select('objectSid')->where(['objectClass' => 'domain'])->andWhere(['objectClass' => 'domainDns'])->setSizeLimit(1)->getLdapQuery()->getSingleScalarResult();
     $sid = new SID($domainSid);
     if ($isRoot) {
         $this->rootDomainSid = $sid;
     } else {
         $this->domainSid = $sid;
     }
     return $sid;
 }
예제 #30
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);
 }