This repository has been archived by the owner on Feb 24, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changing how IsGranted works so that it can use all controller args as
subject
- Loading branch information
1 parent
74f1f17
commit 0a2d6b3
Showing
8 changed files
with
239 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
Tests/Fixtures/FooBundle/Controller/IsGrantedController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\Fixtures\FooBundle\Controller; | ||
|
||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class IsGrantedController | ||
{ | ||
/** | ||
* @Route("/is_granted/anonymous") | ||
* @IsGranted("IS_AUTHENTICATED_ANONYMOUSLY") | ||
*/ | ||
public function someAction() | ||
{ | ||
return new Response('yay1'); | ||
} | ||
|
||
/** | ||
* @Route("/is_granted/request/attribute/args/{a}") | ||
* @IsGranted("ISGRANTED_VOTER", subject="a") | ||
*/ | ||
public function some2Action($a) | ||
{ | ||
return new Response('yay2'); | ||
} | ||
|
||
/** | ||
* @Route("/is_granted/resolved/args") | ||
* @IsGranted("ISGRANTED_VOTER", subject="foo") | ||
*/ | ||
public function some3Action(Request $foo) | ||
{ | ||
return new Response('yay3'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Tests\Fixtures\FooBundle\Security; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Authorization\Voter\Voter; | ||
|
||
/** | ||
* Used in the function test IsGrantedTest. | ||
*/ | ||
class IsGrantedVoter extends Voter | ||
{ | ||
protected function supports($attribute, $subject) | ||
{ | ||
return 'ISGRANTED_VOTER' === $attribute; | ||
} | ||
|
||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token) | ||
{ | ||
// we use these specific conditions in the test | ||
if ('allow_access' === $subject) { | ||
return true; | ||
} | ||
|
||
if ($subject instanceof Request) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.