getDomainContext() публичный Метод

Get the domain name currently being used.
public getDomainContext ( ) : string
Результат string
 /**
  * {@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);
 }
 function it_should_switch_the_domain_if_the_token_has_the_ldap_domain_set()
 {
     // It first grabs a copy of the domain context, then checks against it, then checks it at the end...
     $this->ldap->getDomainContext()->willReturn('foo.bar', 'foo.bar', 'example.local');
     $this->token->hasAttribute('ldap_domain')->willReturn(true);
     $this->token->getAttribute('ldap_domain')->willReturn('example.local');
     $this->ldap->switchDomain('example.local')->shouldBeCalledTimes(1);
     $this->ldap->switchDomain('foo.bar')->shouldBeCalledTimes(1);
     $this->authenticate($this->token)->shouldReturnAnInstanceOf('\\Symfony\\Component\\Security\\Core\\Authentication\\Token\\UsernamePasswordToken');
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function configureOptions(OptionsResolver $resolver)
 {
     $ldap = $this->ldap;
     $resolver->setDefaults(['ldap_domain' => $this->ldap->getDomainContext(), 'ldap_attributes' => null, 'ldap_query_builder' => null, 'choice_name' => 'name', 'choice_value' => 'guid', 'choices' => [], 'choice_loader' => function (Options $options) use($ldap) {
         if (!interface_exists('\\Symfony\\Component\\Form\\ChoiceList\\Loader\\ChoiceLoaderInterface')) {
             return null;
         }
         return new LdapObjectChoiceLoader($ldap, $options['ldap_type'], $options['choice_name'], $options['choice_value'], $options['ldap_query_builder']);
     }, 'choice_list' => function (Options $options) use($ldap) {
         // Always prefer the ChoiceLoader if it exists. Fall back to the ObjectChoiceList...
         if (interface_exists('\\Symfony\\Component\\Form\\ChoiceList\\Loader\\ChoiceLoaderInterface')) {
             return null;
         }
         $legacyChoiceLoader = new LegacyLdapChoiceLoader($ldap, $options['ldap_type'], $options['choice_name'], $options['choice_value'], $options['ldap_query_builder']);
         $preferred = isset($options['preferred_choices']) ? $options['preferred_choices'] : [];
         return new LdapObjectChoiceList($legacyChoiceLoader->load(), $options['choice_name'], $preferred, null, $options['choice_value']);
     }]);
     $resolver->setRequired(['ldap_type']);
     $this->setAllowedTypes($resolver);
 }
 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);
 }
 /**
  * @param \LdapTools\LdapManager $ldap
  * @param \LdapTools\Connection\LdapConnectionInterface $connection
  * @param \Symfony\Component\Routing\RouterInterface $router
  * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
  */
 function let($ldap, $connection, $router, $dispatcher)
 {
     $this->ldap = $ldap;
     $this->router = $router;
     $this->userChecker = new LdapUserChecker();
     $this->connection = $connection;
     $this->config = new DomainConfiguration('foo.bar');
     $this->request = new Request();
     $this->request->setSession(new Session());
     $this->dispatcher = $dispatcher;
     $this->router->generate('login')->willReturn('/login');
     $this->connection->getConfig()->willReturn($this->config);
     $this->ldap->getConnection()->willReturn($this->connection);
     $this->ldap->getDomainContext()->willReturn('foo.bar');
     $this->beConstructedWith(true, $this->userChecker, $ldap, $router, $dispatcher);
 }
 /**
  * Based on an array of IDs for LDAP objects, set the property to either a LdapObject for LdapObjectCollection.
  *
  * @param \ReflectionProperty $property
  * @param LdapObjectAnnotation $annotation
  * @param $entity
  */
 protected function setLdapObjectForProperty(\ReflectionProperty $property, LdapObjectAnnotation $annotation, $entity)
 {
     if (empty($property->getValue($entity))) {
         return;
     }
     $domain = $this->ldap->getDomainContext();
     $switchDomain = $annotation->domain ?: null;
     if ($switchDomain) {
         $this->ldap->switchDomain($annotation->domain);
     }
     $results = $this->queryLdapForObjects($property, $annotation, $entity);
     $property->setValue($entity, $results);
     if ($switchDomain) {
         $this->ldap->switchDomain($domain);
     }
 }
 public function let(LdapManager $ldap, LdapQueryBuilder $qb, LdapQuery $query, LdapObjectCollection $collection)
 {
     $ldap->getDomainContext()->willReturn('foo.bar');
     $ldap->buildLdapQuery()->willReturn($qb);
     $qb->select(Argument::any())->willReturn($qb);
     $qb->from(Argument::any())->willReturn($qb);
     $qb->getLdapQuery()->willReturn($query);
     $query->getResult()->WillReturn($collection);
     $collection->toArray()->willReturn([]);
     $this->resolver = new OptionsResolver();
     if (Kernel::VERSION >= 2.6) {
         $this->resolver->setDefault('ldap_type', 'user');
     } else {
         $this->resolver->setDefaults(['ldap_type' => 'user']);
     }
     $this->beConstructedWith($ldap);
 }
 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);
 }
 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);
 }
 /**
  * If the passed domain is not the current context, then switch back to it.
  *
  * @param string $domain
  */
 protected function switchDomainBackIfNeeded($domain)
 {
     if ($domain !== $this->ldap->getDomainContext()) {
         $this->ldap->switchDomain($domain);
     }
 }