diff options
-rw-r--r-- | Acl/Dbal/AclProvider.php | 6 | ||||
-rw-r--r-- | Core/Authentication/Provider/AuthenticationProviderInterface.php | 2 | ||||
-rw-r--r-- | Http/HttpUtils.php | 14 | ||||
-rw-r--r-- | Http/RememberMe/PersistentTokenBasedRememberMeServices.php | 7 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | Tests/Acl/Dbal/AclProviderTest.php | 17 | ||||
-rw-r--r-- | Tests/Http/HttpUtilsTest.php | 16 |
7 files changed, 54 insertions, 10 deletions
diff --git a/Acl/Dbal/AclProvider.php b/Acl/Dbal/AclProvider.php index 6f47231..822a160 100644 --- a/Acl/Dbal/AclProvider.php +++ b/Acl/Dbal/AclProvider.php @@ -263,7 +263,11 @@ SELECTCLAUSE; for ($i = 0; $i < $count; $i++) { if (!isset($types[$batch[$i]->getType()])) { $types[$batch[$i]->getType()] = true; - if ($count > 1) { + + // if there is more than one type we can safely break out of the + // loop, because it is the differentiator factor on whether to + // query for only one or more class types + if (count($types) > 1) { break; } } diff --git a/Core/Authentication/Provider/AuthenticationProviderInterface.php b/Core/Authentication/Provider/AuthenticationProviderInterface.php index 956adf1..f63a924 100644 --- a/Core/Authentication/Provider/AuthenticationProviderInterface.php +++ b/Core/Authentication/Provider/AuthenticationProviderInterface.php @@ -31,5 +31,5 @@ interface AuthenticationProviderInterface extends AuthenticationManagerInterface * * @return Boolean true if the implementation supports the Token, false otherwise */ - function supports(TokenInterface $token); + public function supports(TokenInterface $token); } diff --git a/Http/HttpUtils.php b/Http/HttpUtils.php index eb7894c..0453520 100644 --- a/Http/HttpUtils.php +++ b/Http/HttpUtils.php @@ -70,7 +70,7 @@ class HttpUtils */ public function createRequest(Request $request, $path) { - $newRequest = Request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all()); + $newRequest = $request::create($this->generateUri($request, $path), 'get', array(), $request->cookies->all(), array(), $request->server->all()); if ($request->hasSession()) { $newRequest->setSession($request->getSession()); } @@ -140,6 +140,16 @@ class HttpUtils throw new \LogicException('You must provide a UrlGeneratorInterface instance to be able to use routes.'); } - return $this->urlGenerator->generate($path, array(), UrlGeneratorInterface::ABSOLUTE_URL); + $url = $this->urlGenerator->generate($path, $request->attributes->all(), UrlGeneratorInterface::ABSOLUTE_URL); + + // unnecessary query string parameters must be removed from url + // (ie. query parameters that are presents in $attributes) + // fortunately, they all are, so we have to remove entire query string + $position = strpos($url, '?'); + if (false !== $position) { + $url = substr($url, 0, $position); + } + + return $url; } } diff --git a/Http/RememberMe/PersistentTokenBasedRememberMeServices.php b/Http/RememberMe/PersistentTokenBasedRememberMeServices.php index 9f4013d..6500bfd 100644 --- a/Http/RememberMe/PersistentTokenBasedRememberMeServices.php +++ b/Http/RememberMe/PersistentTokenBasedRememberMeServices.php @@ -20,6 +20,7 @@ use Symfony\Component\Security\Core\Exception\CookieTheftException; use Symfony\Component\Security\Core\Authentication\RememberMe\PersistentToken; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Util\SecureRandomInterface; +use Psr\Log\LoggerInterface; /** * Concrete implementation of the RememberMeServicesInterface which needs @@ -98,7 +99,7 @@ class PersistentTokenBasedRememberMeServices extends AbstractRememberMeServices } $series = $persistentToken->getSeries(); - $tokenValue = $this->secureRandom->nextBytes(64); + $tokenValue = base64_encode($this->secureRandom->nextBytes(64)); $this->tokenProvider->updateToken($series, $tokenValue, new \DateTime()); $request->attributes->set(self::COOKIE_ATTR_NAME, new Cookie( @@ -120,8 +121,8 @@ class PersistentTokenBasedRememberMeServices extends AbstractRememberMeServices */ protected function onLoginSuccess(Request $request, Response $response, TokenInterface $token) { - $series = $this->secureRandom->nextBytes(64); - $tokenValue = $this->secureRandom->nextBytes(64); + $series = base64_encode($this->secureRandom->nextBytes(64)); + $tokenValue = base64_encode($this->secureRandom->nextBytes(64)); $this->tokenProvider->createNewToken( new PersistentToken( @@ -11,7 +11,7 @@ Resources Documentation: -http://symfony.com/doc/2.0/book/security.html +http://symfony.com/doc/2.2/book/security.html Resources --------- diff --git a/Tests/Acl/Dbal/AclProviderTest.php b/Tests/Acl/Dbal/AclProviderTest.php index 83771ee..ad58d72 100644 --- a/Tests/Acl/Dbal/AclProviderTest.php +++ b/Tests/Acl/Dbal/AclProviderTest.php @@ -72,6 +72,23 @@ class AclProviderTest extends \PHPUnit_Framework_TestCase $this->assertTrue($oids[1]->equals($acl1->getObjectIdentity())); } + public function testFindAclsWithDifferentTypes() + { + $oids = array(); + $oids[] = new ObjectIdentity('123', 'Bundle\SomeVendor\MyBundle\Entity\SomeEntity'); + $oids[] = new ObjectIdentity('123', 'Bundle\MyBundle\Entity\AnotherEntity'); + + $provider = $this->getProvider(); + + $acls = $provider->findAcls($oids); + $this->assertInstanceOf('SplObjectStorage', $acls); + $this->assertCount(2, $acls); + $this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\Acl', $acl0 = $acls->offsetGet($oids[0])); + $this->assertInstanceOf('Symfony\Component\Security\Acl\Domain\Acl', $acl1 = $acls->offsetGet($oids[1])); + $this->assertTrue($oids[0]->equals($acl0->getObjectIdentity())); + $this->assertTrue($oids[1]->equals($acl1->getObjectIdentity())); + } + public function testFindAclCachesAclInMemory() { $oid = new ObjectIdentity('1', 'foo'); diff --git a/Tests/Http/HttpUtilsTest.php b/Tests/Http/HttpUtilsTest.php index fc1b754..bf078da 100644 --- a/Tests/Http/HttpUtilsTest.php +++ b/Tests/Http/HttpUtilsTest.php @@ -137,13 +137,25 @@ class HttpUtilsTest extends \PHPUnit_Framework_TestCase $utils->checkRequestPath($this->getRequest(), 'foobar'); } - private function getUrlGenerator() + public function testGenerateUriRemovesQueryString() + { + $method = new \ReflectionMethod('Symfony\Component\Security\Http\HttpUtils', 'generateUri'); + $method->setAccessible(true); + + $utils = new HttpUtils($this->getUrlGenerator()); + $this->assertEquals('/foo/bar', $method->invoke($utils, new Request(), 'route_name')); + + $utils = new HttpUtils($this->getUrlGenerator('/foo/bar?param=value')); + $this->assertEquals('/foo/bar', $method->invoke($utils, new Request(), 'route_name')); + } + + private function getUrlGenerator($generatedUrl = '/foo/bar') { $urlGenerator = $this->getMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface'); $urlGenerator ->expects($this->any()) ->method('generate') - ->will($this->returnValue('/foo/bar')) + ->will($this->returnValue($generatedUrl)) ; return $urlGenerator; |