Author: Chad Sikorra (Chad.Sikorra@gmail.com)
Inheritance: implements LdapTools\Operation\LdapOperationInterface, use trait LdapOperationTrait
 /**
  * @param BatchModifyOperation $operation
  * @return BatchModifyOperation
  */
 protected function hydrateModifyOperation(BatchModifyOperation $operation)
 {
     $batches = $this->convertValuesToLdap($operation->getBatchCollection(), $operation->getDn());
     foreach ($batches as $batch) {
         /** @var \LdapTools\BatchModify\Batch $batch */
         $batch->setAttribute($this->schema->getAttributeToLdap($batch->getAttribute()));
     }
     return $operation;
 }
Example #2
0
 /**
  * Workaround AD special cases with the unicodePwd attribute...
  *
  * @link https://support.microsoft.com/en-us/kb/263991
  * @param BatchModifyOperation $operation
  */
 protected function unicodePwdHack(BatchModifyOperation $operation)
 {
     if (!$this->isUnicodePwdHackNeeded()) {
         return;
     }
     foreach ($operation->getBatchCollection() as $batch) {
         if (strtolower($batch->getAttribute()) !== 'unicodepwd') {
             continue;
         }
         $values = $batch->getValues();
         $batch->setValues(base64_encode(reset($values)));
     }
 }
 /**
  * This is quite the mess. Not sure how to better spec this.
  */
 function it_should_generate_add_and_remove_operations_on_a_modify_operation($connection, BatchModifyOperation $operation)
 {
     $sid = 'S-1-5-21-1004336348-1177238915-682003330-512';
     $sidHex = '\\01\\05\\00\\00\\00\\00\\00\\05\\15\\00\\00\\00\\dc\\f4\\dc\\3b\\83\\3d\\2b\\46\\82\\8b\\a6\\28\\00\\02\\00\\00';
     $guid = 'a1131cd3-902b-44c6-b49a-1f6a567cda25';
     $guidHex = '\\d3\\1c\\13\\a1\\2b\\90\\c6\\44\\b4\\9a\\1f\\6a\\56\\7c\\da\\25';
     $dn = 'cn=foo,dc=example,dc=local';
     $objectDn = 'CN=SomeGroup,OU=Employees,DC=example,DC=com';
     $ldapObject = new LdapObject(['dn' => $objectDn], ['group'], 'group', 'group');
     $connection->execute(Argument::that(function ($operation) {
         return $operation->getFilter() == '(&(&(objectClass=bar))(cn=Foo))';
     }))->willReturn($this->entry);
     $connection->execute(Argument::that(function ($operation) use($guid, $guidHex) {
         return $operation->getFilter() == '(&(&(objectClass=bar))(|(objectGuid=' . $guidHex . ')(cn=' . $guid . ')))';
     }))->willReturn($this->entryGuid);
     $connection->execute(Argument::that(function ($operation) use($sid, $sidHex) {
         return $operation->getFilter() == '(&(&(objectClass=bar))(|(objectSid=' . $sidHex . ')(cn=' . $sid . ')))';
     }))->willReturn($this->entrySid);
     $this->setOptions(['foo' => ['to_attribute' => 'member', 'attribute' => 'cn', 'filter' => ['objectClass' => 'bar']]]);
     $this->setOperation($operation);
     $this->setLdapConnection($connection);
     $this->setAttribute('foo');
     $this->setOperationType(AttributeConverterInterface::TYPE_MODIFY);
     $this->setDn($dn);
     $nameDn = $this->entry[0]['distinguishedname'][0];
     $guidDn = $this->entryGuid[0]['distinguishedname'][0];
     $sidDn = $this->entrySid[0]['distinguishedname'][0];
     $batchAdd1 = new Batch(Batch::TYPE['ADD'], 'member', 'Foo');
     $batchAdd2 = new Batch(Batch::TYPE['REMOVE'], 'member', $sid);
     $batchRemove = new Batch(Batch::TYPE['ADD'], 'member', [$guid, $ldapObject]);
     // Expected actions for the add batch...
     $this->setBatch($batchAdd1);
     $operation->addPostOperation(Argument::that(function ($op) use($batchAdd1, $nameDn, $dn) {
         $batches = [new Batch(Batch::TYPE['ADD'], 'member', [$dn])];
         return $op instanceof BatchModifyOperation && $op->getBatchCollection()->toArray() == $batches && $op->getBatchCollection()->getDn() == $nameDn;
     }))->shouldBeCalled();
     $this->toLdap(['Foo'])->shouldBeArray();
     // Expected actions for the remove batch...
     $this->setBatch($batchRemove);
     $operation->addPostOperation(Argument::that(function ($op) use($batchRemove, $sidDn, $dn) {
         $batches = [new Batch($batchRemove->getModType(), 'member', [$dn])];
         return $op instanceof BatchModifyOperation && $op->getBatchCollection()->toArray() == $batches && $op->getBatchCollection()->getDn() == $sidDn;
     }))->shouldBeCalled();
     $this->toLdap([$sid])->shouldBeArray();
     // Expected actions for the multi-add batch...
     $this->setBatch($batchAdd2);
     foreach ([$guidDn, $objectDn] as $value) {
         $operation->addPostOperation(Argument::that(function ($op) use($batchAdd2, $value, $dn) {
             $batches = [new Batch($batchAdd2->getModType(), 'member', [$dn])];
             return $op instanceof BatchModifyOperation && $op->getBatchCollection()->toArray() == $batches && $op->getBatchCollection()->getDn() == $value;
         }))->shouldBeCalled();
     }
     $this->toLdap([$guid, $ldapObject])->shouldBeArray();
 }