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

Commit

Permalink
fix(api): restrain access to provider configurations with menu access (
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyjaouen authored Oct 5, 2022
1 parent 2e03601 commit 26d7d9c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/Centreon/Domain/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Contact implements UserInterface, ContactInterface
public const ROLE_CONFIGURATION_CONTACTS_READ = 'ROLE_CONFIGURATION_USERS_CONTACTS__USERS_R';
public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ_WRITE = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_RW';
public const ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_READ = 'ROLE_CONFIGURATION_USERS_CONTACT_GROUPS_R';
public const ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE = 'ROLE_ADMINISTRATION_AUTHENTICATION_RW';

/**
* @var string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\Local\Api\FindConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Core\Security\Application\ProviderConfiguration\Local\UseCase\FindConfiguration\FindConfiguration;
use Core\Security\Application\ProviderConfiguration\Local\UseCase\FindConfiguration\FindConfigurationPresenterInterface;
Expand All @@ -38,6 +40,13 @@ public function __invoke(
FindConfigurationPresenterInterface $presenter,
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}

$useCase($presenter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\Local\Api\UpdateConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Core\Security\Application\ProviderConfiguration\Local\UseCase\UpdateConfiguration\UpdateConfiguration;
use Core\Security\Application\ProviderConfiguration\Local\UseCase\UpdateConfiguration\UpdateConfigurationRequest;
Expand All @@ -45,6 +47,13 @@ public function __invoke(
UpdateConfigurationPresenterInterface $presenter,
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$this->validateDataSent($request, __DIR__ . '/UpdateConfigurationSchema.json');
$updateConfigurationRequest = $this->createUpdateConfigurationRequest($request);
$useCase($presenter, $updateConfigurationRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\OpenId\Api\FindOpenIdConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Core\Security\Application\ProviderConfiguration\OpenId\UseCase\FindOpenIdConfiguration\{
FindOpenIdConfiguration,
Expand All @@ -41,6 +43,13 @@ public function __invoke(
FindOpenIdConfigurationPresenterInterface $presenter
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$useCase($presenter);

return $presenter->show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\OpenId\Api\UpdateOpenIdConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Core\Security\Application\ProviderConfiguration\OpenId\UseCase\UpdateOpenIdConfiguration\{
UpdateOpenIdConfiguration,
Expand All @@ -45,6 +47,13 @@ public function __invoke(
UpdateOpenIdConfigurationPresenterInterface $presenter
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$this->validateDataSent($request, __DIR__ . '/UpdateOpenIdConfigurationSchema.json');
$updateOpenIdConfigurationRequest = $this->createUpdateOpenIdConfigurationRequest($request);
$useCase($presenter, $updateOpenIdConfigurationRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\WebSSO\Api\FindWebSSOConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Core\Security\Application\ProviderConfiguration\WebSSO\UseCase\FindWebSSOConfiguration\{
FindWebSSOConfiguration,
Expand All @@ -41,6 +43,13 @@ public function __invoke(
FindWebSSOConfigurationPresenterInterface $presenter
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$useCase($presenter);

return $presenter->show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@

namespace Core\Security\Infrastructure\ProviderConfiguration\WebSSO\Api\UpdateWebSSOConfiguration;

use Centreon\Domain\Contact\Contact;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Application\ProviderConfiguration\WebSSO\UseCase\UpdateWebSSOConfiguration\{
Expand All @@ -48,6 +50,13 @@ public function __invoke(
UpdateWebSSOConfigurationPresenterInterface $presenter
): object {
$this->denyAccessUnlessGrantedForApiConfiguration();
/**
* @var Contact $contact
*/
$contact = $this->getUser();
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$this->info('Validating request body...');
$this->validateDataSent($request, __DIR__ . '/UpdateWebSSOConfigurationSchema.json');
$updateWebSSOConfigurationRequest = $this->createUpdateWebSSOConfigurationRequest($request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ public function setUp(): void

$timezone = new \DateTimeZone('Europe/Paris');
$adminContact = (new Contact())
->setId(1)
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
->setId(1)
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
Expand All @@ -83,10 +84,12 @@ public function setUp(): void
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function setUp(): void
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
Expand All @@ -92,10 +93,12 @@ public function setUp(): void
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@

$timezone = new \DateTimeZone('Europe/Paris');
$adminContact = (new Contact())
->setId(1)
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
->setId(1)
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
Expand All @@ -68,10 +69,12 @@
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
Expand All @@ -70,10 +71,12 @@
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
->method('isGranted')
Expand All @@ -67,10 +69,12 @@
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
->setName('admin')
->setAdmin(true)
->setTimezone($timezone);
$adminContact->addTopologyRule(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE);

$authorizationChecker = $this->createMock(AuthorizationCheckerInterface::class);
$authorizationChecker->expects($this->once())
->method('isGranted')
Expand All @@ -67,10 +69,12 @@
->method('get')
->withConsecutive(
[$this->equalTo('security.authorization_checker')],
[$this->equalTo('security.token_storage')],
[$this->equalTo('parameter_bag')]
)
->willReturnOnConsecutiveCalls(
$authorizationChecker,
$tokenStorage,
new class () {
public function get(): string
{
Expand Down

0 comments on commit 26d7d9c

Please sign in to comment.