Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
fix(acl): filter access to api using external entry point (#8021)
Browse files Browse the repository at this point in the history
  • Loading branch information
kduret authored Oct 28, 2019
1 parent 42da02f commit 0a02bd2
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 25 deletions.
7 changes: 5 additions & 2 deletions www/api/class/centreon_administration_widget.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,13 @@ public function postRemove()
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}
}
7 changes: 5 additions & 2 deletions www/api/class/centreon_clapi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,14 @@ public function postAction()
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions www/api/class/centreon_configuration_objects.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,13 @@ protected function retrieveRelatedValues($relationObject, $id)
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}
}
9 changes: 8 additions & 1 deletion www/api/class/centreon_home_customview.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ public function getPreferences()
*/
public function authorize($action, $user, $isInternal = false)
{
return true;
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return false;
}
}
2 changes: 1 addition & 1 deletion www/api/class/centreon_keepalive.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public function getKeepAlive()
*/
public function authorize($action, $user, $isInternal = false)
{
return true;
return $isInternal;
}
}
9 changes: 8 additions & 1 deletion www/api/class/centreon_metric.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,13 @@ protected function executeQueryPeriods($query, $start, $end, $queryValues)
*/
public function authorize($action, $user, $isInternal = false)
{
return true;
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiRealtime())
) {
return true;
}

return false;
}
}
2 changes: 1 addition & 1 deletion www/api/class/centreon_proxy.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function postCheckConfiguration()
*/
public function authorize($action, $user, $isInternal = false)
{
return true;
return $isInternal;
}
}
7 changes: 5 additions & 2 deletions www/api/class/centreon_realtime_base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,13 @@ protected function retrieveRelatedValues($relationObject, $id)
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiRealtime())
) {
return true;
}

return $user->hasAccessRestApiRealtime();
return false;
}
}
7 changes: 5 additions & 2 deletions www/api/class/centreon_results_acceptor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,13 @@ public function postSubmit()
*/
public function authorize($action, $user, $isInternal)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}
}
7 changes: 5 additions & 2 deletions www/api/class/centreon_submit_results.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,13 @@ public function postSubmit()
*/
public function authorize($action, $user, $isInternal)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiRealtime())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}
}
8 changes: 6 additions & 2 deletions www/api/class/centreon_topcounter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,9 +856,13 @@ protected function checkChangeState($pollerId, $lastRestart)
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiRealtime())
) {
return true;
}
return $user->hasAccessRestApiConfiguration();

return false;
}
}
7 changes: 5 additions & 2 deletions www/api/class/centreon_wiki.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ public function postDeletePage()
*/
public function authorize($action, $user, $isInternal = false)
{
if (parent::authorize($action, $user, $isInternal)) {
if (
parent::authorize($action, $user, $isInternal)
|| ($user && $user->hasAccessRestApiConfiguration())
) {
return true;
}

return $user->hasAccessRestApiConfiguration();
return false;
}
}
27 changes: 22 additions & 5 deletions www/api/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,27 @@
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_STRICT);
ini_set('display_errors', 'Off');

require_once dirname(__FILE__) . '/../../bootstrap.php';
require_once _CENTREON_PATH_ . '/www/class/centreonDB.class.php';
require_once dirname(__FILE__) . '/class/webService.class.php';
require_once __DIR__ . '/../../bootstrap.php';
require_once __DIR__ . '/../class/centreon.class.php';
require_once __DIR__ . '/class/webService.class.php';

$pearDB = new CentreonDB;
$pearDB = $dependencyInjector['configuration_db'];

CentreonWebService::router($dependencyInjector, null, false);
$user = null;
// get user information if a token is provided
if (isset($_SERVER['HTTP_CENTREON_AUTH_TOKEN'])) {
try {
$res = $pearDB->prepare(
"SELECT c.* FROM ws_token w, contact c WHERE c.contact_id = w.contact_id AND token = ?"
);
$res->execute(array($_SERVER['HTTP_CENTREON_AUTH_TOKEN']));
if ($userInfos = $res->fetch()) {
$centreon = new Centreon($userInfos);
$user = $centreon->user;
}
} catch (\PDOException $e) {
CentreonWebService::sendResult("Database error", 500);
}
}

CentreonWebService::router($dependencyInjector, $user, false);

0 comments on commit 0a02bd2

Please sign in to comment.