From a28f27671fc0d9592e0ef8652f04781475d40d0b Mon Sep 17 00:00:00 2001 From: Kris Wallsmith Date: Thu, 10 Mar 2011 15:29:26 -0800 Subject: [PATCH] updated for latest security changes --- .gitignore | 1 + README.md | 2 +- Security/User/LdapUser.php | 20 ++++++++++---------- Security/User/LdapUserProvider.php | 10 +++++----- Tests/Security/User/LdapUserProviderTest.php | 10 +++++----- Tests/Security/User/LdapUserTest.php | 2 +- Tests/bootstrap.php | 17 +++++++++++++++++ phpunit.xml.dist | 7 ++++++- 8 files changed, 46 insertions(+), 23 deletions(-) create mode 100644 .gitignore create mode 100644 Tests/bootstrap.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57be4e3 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +phpunit.xml \ No newline at end of file diff --git a/README.md b/README.md index bee1bd5..ff57eea 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ See also: ## The LdapUser Object ## Users provided by the LDAP UserProvider will be instances of LdapUser, which is -a lightweight implementation of Symfony2's AccountInterface. This user object +a lightweight implementation of Symfony2's UserInterface. This user object stores only a username and array of roles. ## Deriving Symfony2 Roles from LDAP Groups diff --git a/Security/User/LdapUser.php b/Security/User/LdapUser.php index 8f2aa92..9b2df81 100644 --- a/Security/User/LdapUser.php +++ b/Security/User/LdapUser.php @@ -2,14 +2,14 @@ namespace OpenSky\Bundle\LdapBundle\Security\User; -use Symfony\Component\Security\Core\User\AccountInterface; +use Symfony\Component\Security\Core\User\UserInterface; /** * LdapUser is the user implementation used by the LDAP user provider. * * @author Jeremy Mikola */ -class LdapUser implements AccountInterface +class LdapUser implements UserInterface { protected $username; protected $roles; @@ -31,7 +31,7 @@ public function __construct($username, array $roles = array()) } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::__toString() + * @see Symfony\Component\Security\Core\User\UserInterface::__toString() */ public function __toString() { @@ -39,7 +39,7 @@ public function __toString() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::getRoles() + * @see Symfony\Component\Security\Core\User\UserInterface::getRoles() */ public function getRoles() { @@ -47,7 +47,7 @@ public function getRoles() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::getPassword() + * @see Symfony\Component\Security\Core\User\UserInterface::getPassword() */ public function getPassword() { @@ -55,7 +55,7 @@ public function getPassword() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::getSalt() + * @see Symfony\Component\Security\Core\User\UserInterface::getSalt() */ public function getSalt() { @@ -63,7 +63,7 @@ public function getSalt() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::getUsername() + * @see Symfony\Component\Security\Core\User\UserInterface::getUsername() */ public function getUsername() { @@ -71,7 +71,7 @@ public function getUsername() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::eraseCredentials() + * @see Symfony\Component\Security\Core\User\UserInterface::eraseCredentials() * @codeCoverageIgnore */ public function eraseCredentials() @@ -79,9 +79,9 @@ public function eraseCredentials() } /** - * @see Symfony\Component\Security\Core\User\AccountInterface::equals() + * @see Symfony\Component\Security\Core\User\UserInterface::equals() */ - public function equals(AccountInterface $account) + public function equals(UserInterface $account) { if (!$account instanceof LdapUser) { return false; diff --git a/Security/User/LdapUserProvider.php b/Security/User/LdapUserProvider.php index 67ef961..58b2fc8 100644 --- a/Security/User/LdapUserProvider.php +++ b/Security/User/LdapUserProvider.php @@ -3,8 +3,8 @@ namespace OpenSky\Bundle\LdapBundle\Security\User; use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; -use Symfony\Component\Security\Core\Exception\UnsupportedAccountException; -use Symfony\Component\Security\Core\User\AccountInterface; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; +use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; use Zend\Ldap\Ldap; @@ -62,12 +62,12 @@ public function loadUserByUsername($username) } /** - * @see Symfony\Component\Security\Core\User\UserProviderInterface::loadUserByAccount() + * @see Symfony\Component\Security\Core\User\UserProviderInterface::loadUser() */ - public function loadUserByAccount(AccountInterface $account) + public function loadUser(UserInterface $account) { if (!$account instanceof LdapUser) { - throw new UnsupportedAccountException(sprintf('Instances of "%s" are not supported.', get_class($account))); + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($account))); } return $this->loadUserByUsername((string) $account); diff --git a/Tests/Security/User/LdapUserProviderTest.php b/Tests/Security/User/LdapUserProviderTest.php index 3e6a844..5286dff 100644 --- a/Tests/Security/User/LdapUserProviderTest.php +++ b/Tests/Security/User/LdapUserProviderTest.php @@ -98,7 +98,7 @@ public function testLoadUserByUsernameNotFound() $this->provider->loadUserByUsername('jmikola'); } - public function testLoadUserByAccount() + public function testLoadUser() { $username = 'jmikola'; $account = new LdapUser($username); @@ -112,7 +112,7 @@ public function testLoadUserByAccount() ->method('searchEntries') ->will($this->returnValue(array())); - $user = $this->provider->loadUserByAccount($account); + $user = $this->provider->loadUser($account); $this->assertTrue($user->equals($account)); $this->assertEquals($username, $user->getUsername()); @@ -120,11 +120,11 @@ public function testLoadUserByAccount() } /** - * @expectedException Symfony\Component\Security\Core\Exception\UnsupportedAccountException + * @expectedException Symfony\Component\Security\Core\Exception\UnsupportedUserException */ - public function testLoadUserByAccountNotSupported() + public function testLoadUserNotSupported() { - $this->provider->loadUserByAccount($this->getMock('Symfony\Component\Security\Core\User\AccountInterface')); + $this->provider->loadUser($this->getMock('Symfony\Component\Security\Core\User\UserInterface')); } private function createRoleEntries() diff --git a/Tests/Security/User/LdapUserTest.php b/Tests/Security/User/LdapUserTest.php index ab6d8f2..b761571 100644 --- a/Tests/Security/User/LdapUserTest.php +++ b/Tests/Security/User/LdapUserTest.php @@ -53,6 +53,6 @@ public function testEquals() $this->assertTrue($user->equals(new LdapUser('jmikola'))); $this->assertFalse($user->equals(new LdapUser('foobar'))); - $this->assertFalse($user->equals($this->getMock('Symfony\Component\Security\Core\User\AccountInterface'))); + $this->assertFalse($user->equals($this->getMock('Symfony\Component\Security\Core\User\UserInterface'))); } } diff --git a/Tests/bootstrap.php b/Tests/bootstrap.php new file mode 100644 index 0000000..b56a4de --- /dev/null +++ b/Tests/bootstrap.php @@ -0,0 +1,17 @@ +registerNamespace('Symfony', $_SERVER['SYMFONY_SRC']); +$loader->registerNamespace('Zend', $_SERVER['ZEND_LIB']); +$loader->register(); + +spl_autoload_register(function($class) +{ + if (0 === strpos($class, 'OpenSky\\Bundle\\LdapBundle\\')) { + $path = implode('/', array_slice(explode('\\', $class), 3)).'.php'; + require_once __DIR__.'/../'.$path; + return true; + } +}); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0946c00..1f26975 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="../../../autoload.php" + bootstrap="./Tests/bootstrap.php" > @@ -17,6 +17,11 @@ + + + + + ./