From 29b8414711a5532d17b686bf58307fac49342171 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Mon, 24 Sep 2018 18:42:29 +0200 Subject: [PATCH] Added SourceVoter draft --- application/src/Security/SourceVoter.php | 62 ++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 application/src/Security/SourceVoter.php diff --git a/application/src/Security/SourceVoter.php b/application/src/Security/SourceVoter.php new file mode 100644 index 0000000..ee035fd --- /dev/null +++ b/application/src/Security/SourceVoter.php @@ -0,0 +1,62 @@ +checkInstance($subject) && $this->checkRight($attribute); + } + + //private function checkLayer(string $layer):bool{ + // return (in_array($right, array_keys(LayerType::getChoices()))); + //} + + private function checkRight(string $right):bool{ + return (in_array($right, array_keys(RightType::getChoices()))); + } + + private function checkInstance($subject):bool{ + return ($subject instanceof SourceInterface); + } + + /** + * @todo add if father, that it should have all rights! + * @param string[] $attribute + * @param SourceInterface $subject + * @param TokenInterface $token + * {@inheritdoc} + * @see \Symfony\Component\Security\Core\Authorization\Voter\Voter::voteOnAttribute() + */ + protected function voteOnAttribute($attribute, $subject, TokenInterface $token) + { + /** + * @var UserInterface $user + */ + $user = $token->getUser(); + return $subject->getNode() + ->getLaw() + ->isGranted($user->getSource()->getNode(), LayerType::SOURCE, $attribute); + } +} +