Skip to content
This repository has been archived by the owner on Feb 15, 2020. It is now read-only.

Commit

Permalink
- Fixing nette 2.3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Dec 1, 2016
1 parent 1932ea5 commit b49884c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
29 changes: 23 additions & 6 deletions src/IPub/Permissions/Access/AnnotationChecker.php
Expand Up @@ -56,7 +56,7 @@ public function isAllowed($element) : bool
{
// Check annotations only if element have to be secured
if (
($element instanceof UI\ComponentReflection || $element instanceof UI\MethodReflection)
$element instanceof \Reflector
&& $element->hasAnnotation('Secured')
) {
return $this->checkUser($element)
Expand Down Expand Up @@ -117,13 +117,13 @@ private function checkResources($element) : bool
{
// Check if element has @Security\Resource annotation & @Secured\Privilege annotation
if ($element->hasAnnotation('Secured\Resource')) {
$resources = UI\ComponentReflection::parseAnnotation($element, 'Secured\Resource');
$resources = $this->getElementAttribute($element, 'Secured\Resource');

if (count($resources) != 1) {
throw new Exceptions\InvalidStateException('Invalid resources count in @Security\Resource annotation!');
}

$privileges = UI\ComponentReflection::parseAnnotation($element, 'Secured\Privilege');
$privileges = $this->getElementAttribute($element, 'Secured\Privilege');

foreach ($resources as $resource) {
if ($privileges !== FALSE) {
Expand Down Expand Up @@ -157,7 +157,7 @@ private function checkPrivileges($element) : bool
{
// Check if element has @Secured\Privilege annotation & hasn't @Secured\Resource annotation
if (!$element->hasAnnotation('Secured\Resource') && $element->hasAnnotation('Secured\Privilege')) {
$privileges = UI\ComponentReflection::parseAnnotation($element, 'Secured\Privilege');
$privileges = $this->getElementAttribute($element, 'Secured\Privilege');

if (count($privileges) != 1) {
throw new Exceptions\InvalidStateException('Invalid privileges count in @Security\Privilege annotation!');
Expand Down Expand Up @@ -189,7 +189,7 @@ private function checkPermission($element) : bool
{
// Check if element has @Secured\Permission annotation
if ($element->hasAnnotation('Secured\Permission')) {
$permissions = UI\ComponentReflection::parseAnnotation($element, 'Secured\Permission');
$permissions = $this->getElementAttribute($element, 'Secured\Permission');

foreach ($permissions as $permission) {
// Check if parameters are defined
Expand Down Expand Up @@ -224,7 +224,7 @@ private function checkRoles($element) : bool
{
// Check if element has @Secured\Role annotation
if ($element->hasAnnotation('Secured\Role')) {
$roles = UI\ComponentReflection::parseAnnotation($element, 'Secured\Role');
$roles = $this->getElementAttribute($element, 'Secured\Role');

foreach ($roles as $role) {
// Check if role name is defined
Expand All @@ -242,4 +242,21 @@ private function checkRoles($element) : bool

return TRUE;
}

/**
* @param \Reflector|UI\ComponentReflection|UI\MethodReflection $element
* @param string $attribute
*
* @return array|FALSE
*/
private function getElementAttribute($element, string $attribute)
{
if (class_exists(UI\ComponentReflection::class)) {
return UI\ComponentReflection::parseAnnotation($element, $attribute);
}

$values = (array) $element->getAnnotation($attribute);

return is_array($values) ? $values : ($values ? [$values] : FALSE);
}
}
4 changes: 0 additions & 4 deletions src/IPub/Permissions/TPermission.php
Expand Up @@ -71,16 +71,12 @@ public function checkRequirements($element)
}

} catch (Application\ForbiddenRequestException $ex) {
/*
if ($redirectUrl) {
$this->getPresenter()->redirectUrl($redirectUrl);

} else {
*/
throw $ex;
/*
}
*/
}
}
}

0 comments on commit b49884c

Please sign in to comment.