Skip to content

[Security] Add constants for access decision strategies #10390

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
Mar 13, 2014
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
*/
class AccessDecisionManager implements AccessDecisionManagerInterface
{
const STRATEGY_AFFIRMATIVE = 'affirmative';
const STRATEGY_CONSENSUS = 'consensus';
const STRATEGY_UNANIMOUS = 'unanimous';

private $voters;
private $strategy;
private $allowIfAllAbstainDecisions;
Expand All @@ -37,7 +41,7 @@ class AccessDecisionManager implements AccessDecisionManagerInterface
*
* @throws \InvalidArgumentException
*/
public function __construct(array $voters, $strategy = 'affirmative', $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
public function __construct(array $voters, $strategy = self::STRATEGY_AFFIRMATIVE, $allowIfAllAbstainDecisions = false, $allowIfEqualGrantedDeniedDecisions = true)
{
if (!$voters) {
throw new \InvalidArgumentException('You must at least add one voter.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,34 +77,34 @@ public function getStrategyTests()
{
return array(
// affirmative
array('affirmative', $this->getVoters(1, 0, 0), false, true, true),
array('affirmative', $this->getVoters(1, 2, 0), false, true, true),
array('affirmative', $this->getVoters(0, 1, 0), false, true, false),
array('affirmative', $this->getVoters(0, 0, 1), false, true, false),
array('affirmative', $this->getVoters(0, 0, 1), true, true, true),
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 0, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(1, 2, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 1, 0), false, true, false),
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), false, true, false),
array(AccessDecisionManager::STRATEGY_AFFIRMATIVE, $this->getVoters(0, 0, 1), true, true, true),

// consensus
array('consensus', $this->getVoters(1, 0, 0), false, true, true),
array('consensus', $this->getVoters(1, 2, 0), false, true, false),
array('consensus', $this->getVoters(2, 1, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 0, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(1, 2, 0), false, true, false),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 1, 0), false, true, true),

array('consensus', $this->getVoters(0, 0, 1), false, true, false),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), false, true, false),

array('consensus', $this->getVoters(0, 0, 1), true, true, true),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(0, 0, 1), true, true, true),

array('consensus', $this->getVoters(2, 2, 0), false, true, true),
array('consensus', $this->getVoters(2, 2, 1), false, true, true),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, true, true),

array('consensus', $this->getVoters(2, 2, 0), false, false, false),
array('consensus', $this->getVoters(2, 2, 1), false, false, false),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 0), false, false, false),
array(AccessDecisionManager::STRATEGY_CONSENSUS, $this->getVoters(2, 2, 1), false, false, false),

// unanimous
array('unanimous', $this->getVoters(1, 0, 0), false, true, true),
array('unanimous', $this->getVoters(1, 0, 1), false, true, true),
array('unanimous', $this->getVoters(1, 1, 0), false, true, false),
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 0), false, true, true),
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 0, 1), false, true, true),
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(1, 1, 0), false, true, false),

array('unanimous', $this->getVoters(0, 0, 2), false, true, false),
array('unanimous', $this->getVoters(0, 0, 2), true, true, true),
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), false, true, false),
array(AccessDecisionManager::STRATEGY_UNANIMOUS, $this->getVoters(0, 0, 2), true, true, true),
);
}

Expand Down