Merge remote-tracking branch 'origin/master'

This commit is contained in:
Manfred Kindl
2019-04-26 17:21:15 +02:00
3 changed files with 25 additions and 12 deletions
+23 -10
View File
@@ -5,6 +5,8 @@
*/
class APIv1_Controller extends REST_Controller
{
private $_requiredPermissions;
/**
* Standard constructor for all the RESTful resources
*/
@@ -12,24 +14,35 @@ class APIv1_Controller extends REST_Controller
{
parent::__construct();
// Loads permission lib
$this->load->library('PermissionLib');
$this->_requiredPermissions = $requiredPermissions;
log_message('debug', 'Called API: '.$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
$this->_isAllowed($requiredPermissions);
}
/**
* Checks if the caller is allowed to access to this content with the given permissions
* If it is not allowed will set the HTTP header with code 401
* Wrapper for permissionlib->isEntitled
* This method is automatically called by CodeIgniter after the execution of the constructor is completed
* - Cheks if the AuthLib was loaded, if not it means that the authentication failed
* - Loads the permsission lib and calls permissionlib->isEntitled
* - Checks if the caller is allowed to access to this content with the given permissions
* if it is not allowed will set the HTTP header with code 401
* - Calls the parent (REST_Controller) _remap method to performs other checks
*/
private function _isAllowed($requiredPermissions)
public function _remap($object_called, $arguments)
{
if (!$this->permissionlib->isEntitled($requiredPermissions, $this->router->method))
if (isset($this->authlib)) // if set then the authentication is ok
{
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
// Loads permission lib
$this->load->library('PermissionLib');
// Cheks if the user has the permission to call a method
if (!$this->permissionlib->isEntitled($this->_requiredPermissions, $this->router->method))
{
// If not...
$this->response(error('You are not allowed to access to this content'), REST_Controller::HTTP_UNAUTHORIZED);
}
}
// Finally calls the parent _remap to perform other checks
parent::_remap($object_called, $arguments);
}
}
+1 -1
View File
@@ -627,7 +627,7 @@ abstract class REST_Controller extends CI_Controller {
{
$this->_log_request();
}
//echo 'RestKey: '.$this->rest->key;
$this->response([
$this->config->item('rest_status_field_name') => FALSE,
$this->config->item('rest_message_field_name') => sprintf($this->lang->line('text_rest_invalid_api_key'), $this->rest->key)
+1 -1
View File
@@ -237,7 +237,7 @@ class AuthLib
*/
public function basicAuthentication($username, $password)
{
return isSuccess($this->_checkLDAPAuthentication($username, $password));
return isSuccess($this->loginLDAP($username, $password));
}
/**