Skip to content

Commit

Permalink
updated for latest security changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kriswallsmith committed Mar 10, 2011
1 parent 29eb994 commit a28f276
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
phpunit.xml
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions Security/User/LdapUser.php
Expand Up @@ -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 <jmikola@gmail.com>
*/
class LdapUser implements AccountInterface
class LdapUser implements UserInterface
{
protected $username;
protected $roles;
Expand All @@ -31,57 +31,57 @@ 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()
{
return $this->username;
}

/**
* @see Symfony\Component\Security\Core\User\AccountInterface::getRoles()
* @see Symfony\Component\Security\Core\User\UserInterface::getRoles()
*/
public function getRoles()
{
return $this->roles;
}

/**
* @see Symfony\Component\Security\Core\User\AccountInterface::getPassword()
* @see Symfony\Component\Security\Core\User\UserInterface::getPassword()
*/
public function getPassword()
{
return null;
}

/**
* @see Symfony\Component\Security\Core\User\AccountInterface::getSalt()
* @see Symfony\Component\Security\Core\User\UserInterface::getSalt()
*/
public function getSalt()
{
return null;
}

/**
* @see Symfony\Component\Security\Core\User\AccountInterface::getUsername()
* @see Symfony\Component\Security\Core\User\UserInterface::getUsername()
*/
public function getUsername()
{
return $this->username;
}

/**
* @see Symfony\Component\Security\Core\User\AccountInterface::eraseCredentials()
* @see Symfony\Component\Security\Core\User\UserInterface::eraseCredentials()
* @codeCoverageIgnore
*/
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;
Expand Down
10 changes: 5 additions & 5 deletions Security/User/LdapUserProvider.php
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions Tests/Security/User/LdapUserProviderTest.php
Expand Up @@ -98,7 +98,7 @@ public function testLoadUserByUsernameNotFound()
$this->provider->loadUserByUsername('jmikola');
}

public function testLoadUserByAccount()
public function testLoadUser()
{
$username = 'jmikola';
$account = new LdapUser($username);
Expand All @@ -112,19 +112,19 @@ 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());
$this->assertEquals(array('ROLE_LDAP'), $user->getRoles());
}

/**
* @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()
Expand Down
2 changes: 1 addition & 1 deletion Tests/Security/User/LdapUserTest.php
Expand Up @@ -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')));
}
}
17 changes: 17 additions & 0 deletions Tests/bootstrap.php
@@ -0,0 +1,17 @@
<?php

require_once $_SERVER['SYMFONY_SRC'].'/Symfony/Component/ClassLoader/UniversalClassLoader.php';

$loader = new Symfony\Component\ClassLoader\UniversalClassLoader();
$loader->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;
}
});
7 changes: 6 additions & 1 deletion phpunit.xml.dist
Expand Up @@ -9,14 +9,19 @@
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="../../../autoload.php"
bootstrap="./Tests/bootstrap.php"
>
<testsuites>
<testsuite name="OpenSkyLdapBundle Test Suite">
<directory>./Tests/</directory>
</testsuite>
</testsuites>

<php>
<!-- <server name="SYMFONY_SRC" value="/path/to/symfony/src" /> -->
<!-- <server name="ZEND_LIB" value="/path/to/zend/library" /> -->
</php>

<filter>
<whitelist>
<directory>./</directory>
Expand Down

0 comments on commit a28f276

Please sign in to comment.