/**
  * Get the LdapObjectSchema for a specific schema name and object type.
  *
  * @param string $schemaName
  * @param string $objectType
  * @return LdapObjectSchema
  */
 public function get($schemaName, $objectType)
 {
     $cacheItem = $schemaName . '.' . $objectType;
     if ($this->shouldBuildCacheItem($schemaName, $cacheItem)) {
         $ldapObjectSchema = $this->parser->parse($schemaName, $objectType);
         $this->dispatcher->dispatch(new LdapObjectSchemaEvent(Event::LDAP_SCHEMA_LOAD, $ldapObjectSchema));
         $this->cache->set($ldapObjectSchema);
     } else {
         $ldapObjectSchema = $this->cache->get(LdapObjectSchema::getCacheType(), $cacheItem);
     }
     return $ldapObjectSchema;
 }
Пример #2
0
 /**
  * Trigger a LDAP object after creation event.
  *
  * @param AddOperation $operation
  */
 protected function triggerAfterCreationEvent(AddOperation $operation)
 {
     $event = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE);
     $event->setData((new ParameterResolver($this->attributes, $this->hydrator->getParameters()))->resolve());
     $event->setContainer($operation->getLocation());
     $event->setDn($operation->getDn());
     $this->dispatcher->dispatch($event);
 }
Пример #3
0
 /**
  * Restore a deleted LDAP object. Optionally pass the new location container/OU for the object. If a new location
  * is not provided it will use the lastKnownParent value to determine where it should go.
  * 
  * This may require a strategy design at some point, as this is AD specific currently. Unsure as to how other
  * directory services handle deleted object restores. The basic logic for AD to do this is...
  * 
  * 1. Reset the 'isDeleted' attribute.
  * 2. Set the DN so the object ends up in a location other than the "Deleted Objects" container.
  *
  * @param LdapObject $ldapObject
  * @param null|string $location The DN of a container/OU where the restored object should go.
  */
 public function restore(LdapObject $ldapObject, $location = null)
 {
     $event = new LdapObjectRestoreEvent(Event::LDAP_OBJECT_BEFORE_RESTORE, $ldapObject, $location);
     $this->dispatcher->dispatch($event);
     $location = $event->getContainer();
     $this->validateObject($ldapObject);
     $originalDn = $ldapObject->get('dn');
     $ldapObject->reset('isDeleted');
     // Some additional logic may be needed to get the actual restore location...
     $newLocation = $this->getObjectRestoreLocation($ldapObject, $location);
     // The DN contains the full RDN (including the preceding attribute name). The original RDN is before the \0A.
     $rdn = explode('\\0A', $ldapObject->get('dn'), 2)[0];
     $ldapObject->set('dn', "{$rdn},{$newLocation}");
     $this->executeBatchOperation($ldapObject, $originalDn);
     $this->dispatcher->dispatch(new LdapObjectRestoreEvent(Event::LDAP_OBJECT_AFTER_RESTORE, $ldapObject, $location));
 }
Пример #4
0
 function it_should_call_creation_events_when_creating_a_ldap_object(EventDispatcherInterface $dispatcher, $connection)
 {
     $this->addOperation->setLocation('dc=foo,dc=bar');
     $connection->execute($this->addOperation)->willReturn(true);
     $beforeEvent = new LdapObjectCreationEvent(Event::LDAP_OBJECT_BEFORE_CREATE);
     $beforeEvent->setContainer('dc=foo,dc=bar');
     $beforeEvent->setData(['username' => '%foo%', 'password' => '%bar%']);
     $beforeEvent->setDn('');
     $afterEvent = new LdapObjectCreationEvent(Event::LDAP_OBJECT_AFTER_CREATE);
     $afterEvent->setContainer('dc=foo,dc=bar');
     $afterEvent->setData(['username' => 'somedude', 'password' => '12345']);
     $afterEvent->setDn('cn=somedude,dc=foo,dc=bar');
     $dispatcher->dispatch($beforeEvent)->shouldBeCalled();
     $dispatcher->dispatch($afterEvent)->shouldBeCalled();
     $this->config->setSchemaName('ad');
     $this->beConstructedWith($connection, $this->schemaFactory, $dispatcher);
     $this->createUser()->with(['username' => '%foo%', 'password' => '%bar%'])->in('dc=foo,dc=bar')->setParameter('foo', 'somedude')->setParameter('bar', '12345');
     $this->execute();
 }
 function it_should_call_a_login_success_event()
 {
     $this->dispatcher->dispatch('ldap_tools_bundle.login.success', Argument::type('LdapTools\\Bundle\\LdapToolsBundle\\Event\\LdapLoginEvent'))->shouldBeCalled();
     $this->authenticate($this->token);
 }
Пример #6
0
 function it_should_call_the_event_dispatcher_restore_events_when_restoring_an_object(EventDispatcherInterface $dispatcher, $connection)
 {
     $dn = 'cn=foo\\0ADEL:0101011,cn=Deleted Objects,dc=example,dc=local';
     $ldapObject = new LdapObject(['dn' => $dn, 'lastKnownLocation' => 'cn=Users,dc=example,dc=local'], 'deleted');
     $beforeEvent = new LdapObjectRestoreEvent(Event::LDAP_OBJECT_BEFORE_RESTORE, $ldapObject, 'ou=employees,dc=foo,dc=bar');
     $afterEvent = new LdapObjectRestoreEvent(Event::LDAP_OBJECT_AFTER_RESTORE, $ldapObject, 'ou=employees,dc=foo,dc=bar');
     $connection->execute(Argument::type('\\LdapTools\\Operation\\BatchModifyOperation'))->willReturn(true);
     $dispatcher->dispatch($beforeEvent)->shouldBeCalled();
     $dispatcher->dispatch($afterEvent)->shouldBeCalled();
     $this->beConstructedWith($connection, $this->objectSchemaFactory, $dispatcher);
     $this->restore($ldapObject, 'ou=employees,dc=foo,dc=bar');
 }