Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Ldap] added Ldap entry rename for ExtLdap adapter #20390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 UPGRADE-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,8 @@ Yaml
the `!php/object` tag.

* Duplicate mapping keys lead to a `ParseException`.

Ldap
--------------

* The `RenameEntryInterface` has been deprecated, and merged with `EntryManagerInterface`
15 changes: 14 additions & 1 deletion 15 src/Symfony/Component/Ldap/Adapter/ExtLdap/EntryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Ldap\Adapter\ExtLdap;

use Symfony\Component\Ldap\Adapter\EntryManagerInterface;
use Symfony\Component\Ldap\Adapter\RenameEntryInterface;
use Symfony\Component\Ldap\Entry;
use Symfony\Component\Ldap\Exception\LdapException;
use Symfony\Component\Ldap\Exception\NotBoundException;
Expand All @@ -20,7 +21,7 @@
* @author Charles Sarrazin <charles@sarraz.in>
* @author Bob van de Vijver <bobvandevijver@hotmail.com>
*/
class EntryManager implements EntryManagerInterface
class EntryManager implements EntryManagerInterface, RenameEntryInterface
{
private $connection;

Expand Down Expand Up @@ -67,6 +68,18 @@ public function remove(Entry $entry)
}
}

/**
* {@inheritdoc}
*/
public function rename(Entry $entry, $newRdn, $removeOldRdn = true)
{
$con = $this->getConnectionResource();

if (!@ldap_rename($con, $entry->getDn(), $newRdn, null, $removeOldRdn)) {
throw new LdapException(sprintf('Could not rename entry "%s" to "%s": %s', $entry->getDn(), $newRdn, ldap_error($con)));
}
}

/**
* Get the connection resource, but first check if the connection is bound.
*/
Expand Down
22 changes: 22 additions & 0 deletions 22 src/Symfony/Component/Ldap/Adapter/RenameEntryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Symfony\Component\Ldap\Adapter;

use Symfony\Component\Ldap\Entry;

/**
* @deprecated This interface will be deprecated in 4.0, and merged with `EntryManagerInterface`
*
* @author Kevin Schuurmans <kevin.schuurmans@freshheads.com>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just add a mention that this interface will be deprecated for 4.0, and merged with EntryManagerInterface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done that.

*/
interface RenameEntryInterface
{
/**
* Renames an entry on the Ldap server.
*
* @param Entry $entry
* @param string $newRdn
* @param bool $removeOldRdn
*/
public function rename(Entry $entry, $newRdn, $removeOldRdn = true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,49 @@ private function executeSearchQuery($expectedResults = 1)

return $results;
}

/**
* @group functional
*/
public function testLdapRename()
{
$result = $this->executeSearchQuery(1);

$entry = $result[0];

$entryManager = $this->adapter->getEntryManager();
$entryManager->rename($entry, 'cn=Kevin');

$result = $this->executeSearchQuery(1);
$renamedEntry = $result[0];
$this->assertEquals($renamedEntry->getAttribute('cn')[0], 'Kevin');

$oldRdn = $entry->getAttribute('cn')[0];
$entryManager->rename($renamedEntry, 'cn='.$oldRdn);
$this->executeSearchQuery(1);
}

/**
* @group functional
*/
public function testLdapRenameWithoutRemovingOldRdn()
{
$result = $this->executeSearchQuery(1);

$entry = $result[0];

$entryManager = $this->adapter->getEntryManager();
$entryManager->rename($entry, 'cn=Kevin', false);

$result = $this->executeSearchQuery(1);

$newEntry = $result[0];
$originalCN = $entry->getAttribute('cn')[0];

$this->assertContains($originalCN, $newEntry->getAttribute('cn'));

$entryManager->rename($newEntry, 'cn='.$originalCN);

$this->executeSearchQuery(1);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.