- Removed method isEntitled from PermissionLib

- Renamed method checkPermissions to isEntitled
- isEntitled: if the controller is called from the command line, then is always trusted
- Adapted controllers application/core/APIv1_Controller.php and application/core/FHC_Controller.php
This commit is contained in:
Paolo
2018-03-29 12:23:05 +02:00
parent 042f187818
commit dda27c7d6e
3 changed files with 7 additions and 31 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ class APIv1_Controller extends REST_Controller
*/
private function _isAllowed($requiredPermissions)
{
if (!$this->permissionlib->checkPermissions($requiredPermissions, $this->router->method))
if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method))
{
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
}
+1 -1
View File
@@ -28,7 +28,7 @@ class FHC_Controller extends CI_Controller
*/
private function _isAllowed($requiredPermissions)
{
if (!$this->permissionlib->checkPermissions($requiredPermissions, $this->router->method))
if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method))
{
header('HTTP/1.0 401 Unauthorized');
echo 'You are not allowed to access to this content';
+5 -29
View File
@@ -67,34 +67,6 @@ class PermissionLib
}
}
/**
* Check if the user is entitled to get access to a source with the given access type
*
* @return bool <b>true</b> if a user has the right to access to the specified
* resource with a specified permission type, <b>false</b> otherwise
*/
public function isEntitled($sourceName, $permissionType)
{
$isEntitled = false;
// If it's called from command line than it's trusted
if (!is_cli())
{
// If the resource exists
if (isset($this->acl[$sourceName]))
{
// Checks permission
$isEntitled = $this->isBerechtigt($this->acl[$sourceName], $permissionType);
}
}
else
{
$isEntitled = true;
}
return $isEntitled;
}
/**
* Get a permission by a given source
*/
@@ -130,6 +102,7 @@ class PermissionLib
/**
* Checks if the caller is allowed to access to this content with the given permissions
* - if it's called from command line than it's trusted
* - checks if the parameter $requiredPermissions is set, is an array and contains at least one element
* - checks if the given $requiredPermissions parameter contains the called method of the controller
* - checks if the HTTP method used to call is GET or POST
@@ -145,11 +118,14 @@ class PermissionLib
* NOTE: the displayed error messages are used to warn the developer about any issues that could occur,
* they are not intended for the final user!
*/
public function checkPermissions($requiredPermissions, $calledMethod)
public function isEntitled($requiredPermissions, $calledMethod)
{
$checkPermissions = false;
$requestMethod = $_SERVER['REQUEST_METHOD'];
// If it's called from command line than it's trusted
if (is_cli()) return true;
// Checks if the parameter $requiredPermissions is set, is an array and contains at least one element
if (isset($requiredPermissions) && is_array($requiredPermissions) && count($requiredPermissions) > 0)
{