repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/FindConfiguration/FindConfigurationErrorResponse.php | centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/FindConfiguration/FindConfigurationErrorResponse.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Local\UseCase\FindConfiguration;
use Core\Application\Common\UseCase\ErrorResponse;
final class FindConfigurationErrorResponse extends ErrorResponse
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfigurationRequest.php | centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfigurationRequest.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration;
final class UpdateConfigurationRequest
{
/** @var int */
public int $passwordMinimumLength;
/** @var bool */
public bool $hasUppercase;
/** @var bool */
public bool $hasLowercase;
/** @var bool */
public bool $hasNumber;
/** @var bool */
public bool $hasSpecialCharacter;
/** @var bool */
public bool $canReusePasswords;
/** @var int|null */
public ?int $attempts = null;
/** @var int|null */
public ?int $blockingDuration = null;
/** @var int|null */
public ?int $passwordExpirationDelay = null;
/** @var string[] */
public array $passwordExpirationExcludedUserAliases;
/** @var int|null */
public ?int $delayBeforeNewPassword = null;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfigurationPresenterInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfigurationPresenterInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration;
use Core\Application\Common\UseCase\PresenterInterface;
interface UpdateConfigurationPresenterInterface extends PresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/UpdateConfiguration/UpdateConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration;
use Centreon\Domain\Common\Assertion\AssertionException;
use Centreon\Domain\Log\LoggerTrait;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\NoContentResponse;
use Core\Application\Configuration\User\Repository\ReadUserRepositoryInterface;
use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface;
use Core\Security\ProviderConfiguration\Application\Local\Repository\WriteConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Local\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Local\Model\CustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\Local\Model\SecurityPolicy;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
class UpdateConfiguration
{
use LoggerTrait;
/**
* @param WriteConfigurationRepositoryInterface $writeConfigurationRepository
* @param ReadUserRepositoryInterface $readUserRepository
* @param ProviderAuthenticationFactoryInterface $providerFactory
*/
public function __construct(
private WriteConfigurationRepositoryInterface $writeConfigurationRepository,
private ReadUserRepositoryInterface $readUserRepository,
private ProviderAuthenticationFactoryInterface $providerFactory,
) {
}
/**
* @param UpdateConfigurationPresenterInterface $presenter
* @param UpdateConfigurationRequest $request
*/
public function __invoke(
UpdateConfigurationPresenterInterface $presenter,
UpdateConfigurationRequest $request,
): void {
$this->info('Updating Security Policy');
try {
$provider = $this->providerFactory->create(Provider::LOCAL);
/** @var Configuration $configuration */
$configuration = $provider->getConfiguration();
$securityPolicy = new SecurityPolicy(
$request->passwordMinimumLength,
$request->hasUppercase,
$request->hasLowercase,
$request->hasNumber,
$request->hasSpecialCharacter,
$request->canReusePasswords,
$request->attempts,
$request->blockingDuration,
$request->passwordExpirationDelay,
$request->passwordExpirationExcludedUserAliases,
$request->delayBeforeNewPassword
);
$excludedUserIds = $this->readUserRepository->findUserIdsByAliases(
$request->passwordExpirationExcludedUserAliases
);
$configuration->setCustomConfiguration(new CustomConfiguration($securityPolicy));
$this->writeConfigurationRepository->updateConfiguration($configuration, $excludedUserIds);
$presenter->setResponseStatus(new NoContentResponse());
} catch (AssertionException $ex) {
$this->error('Unable to create Security Policy because one or several parameters are invalid');
$presenter->setResponseStatus(new ErrorResponse($ex->getMessage()));
return;
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Local/Repository/WriteConfigurationRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/Local/Repository/WriteConfigurationRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Local\Repository;
use Core\Security\ProviderConfiguration\Domain\Local\Model\Configuration;
interface WriteConfigurationRepositoryInterface
{
/**
* Update the provider configuration.
*
* @param Configuration $configuration
* @param int[] $excludedUserIds
*/
public function updateConfiguration(Configuration $configuration, array $excludedUserIds): void;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfigurationPresenterInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfigurationPresenterInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\FindSAMLConfiguration;
use Core\Application\Common\UseCase\ResponseStatusInterface;
interface FindSAMLConfigurationPresenterInterface
{
public function presentResponse(FindSAMLConfigurationResponse|ResponseStatusInterface $response): void;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfigurationResponse.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfigurationResponse.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\FindSAMLConfiguration;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\RequestedAuthnContextComparisonEnum;
/**
* @phpstan-type _authorizationRules array{
* claim_value: string,
* access_group: array{
* id: int,
* name: string
* }
* }
* @phpstan-type _aclConditions array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* relations: array<_authorizationRules>,
* }
*/
final class FindSAMLConfigurationResponse
{
public bool $isActive = false;
public bool $isForced = false;
public bool $isAutoImportEnabled = false;
/** @var array<string,int|string>|null */
public ?array $contactTemplate = null;
public ?string $emailBindAttribute = null;
public ?string $userNameBindAttribute = null;
public string $remoteLoginUrl = '';
public string $entityIdUrl = '';
public ?string $publicCertificate = '';
public string $userIdAttribute = '';
public bool $requestAuthnContext = false;
public RequestedAuthnContextComparisonEnum $requestedAuthnContextComparison;
public bool $logoutFrom = true;
public ?string $logoutFromUrl = null;
/** @var _aclConditions|array{} */
public array $aclConditions = [];
/** @var array<string,bool|string|string[]> */
public array $authenticationConditions = [];
/**
* @var array{}|array{
* "is_enabled": bool,
* "attribute_path": string,
* "endpoint"?: array{
* "type": string,
* "custom_endpoint": string|null
* },
* "relations": array<array{
* "group_value": string,
* "contact_group": array{
* "id": int,
* "name": string
* }
* }>
* }
*/
public array $groupsMapping = [];
/**
* @param ContactTemplate $contactTemplate
*
* @return array<string,int|string>
*/
public static function contactTemplateToArray(ContactTemplate $contactTemplate): array
{
return [
'id' => $contactTemplate->getId(),
'name' => $contactTemplate->getName(),
];
}
/**
* @param AuthorizationRule[] $authorizationRules
*
* @return array<_authorizationRules>
*/
public static function authorizationRulesToArray(array $authorizationRules): array
{
return array_map(fn (AuthorizationRule $authorizationRule) => [
'claim_value' => $authorizationRule->getClaimValue(),
'access_group' => [
'id' => $authorizationRule->getAccessGroup()->getId(),
'name' => $authorizationRule->getAccessGroup()->getName(),
],
'priority' => $authorizationRule->getPriority(),
], $authorizationRules);
}
/**
* @param AuthenticationConditions $authenticationConditions
*
* @return array{
* "is_enabled": bool,
* "attribute_path": string,
* "authorized_values": string[],
* }
*/
public static function authenticationConditionsToArray(AuthenticationConditions $authenticationConditions): array
{
return [
'is_enabled' => $authenticationConditions->isEnabled(),
'attribute_path' => $authenticationConditions->getAttributePath(),
'authorized_values' => $authenticationConditions->getAuthorizedValues(),
];
}
/**
* @param GroupsMapping $groupsMapping
*
* @return array{
* "is_enabled": bool,
* "attribute_path": string,
* "relations": array<array{
* "group_value": string,
* "contact_group": array{
* "id": int,
* "name": string
* }
* }>
* }
*/
public static function groupsMappingToArray(GroupsMapping $groupsMapping): array
{
$relations = self::contactGroupRelationsToArray($groupsMapping->getContactGroupRelations());
return [
'is_enabled' => $groupsMapping->isEnabled(),
'attribute_path' => $groupsMapping->getAttributePath(),
'relations' => $relations,
];
}
/**
* @param ContactGroupRelation[] $contactGroupRelations
*
* @return array<array{
* "group_value": string,
* "contact_group": array{
* "id": int,
* "name": string
* }
* }>
*/
public static function contactGroupRelationsToArray(array $contactGroupRelations): array
{
return array_map(
fn (ContactGroupRelation $contactGroupRelation) => [
'group_value' => $contactGroupRelation->getClaimValue(),
'contact_group' => [
'id' => $contactGroupRelation->getContactGroup()->getId(),
'name' => $contactGroupRelation->getContactGroup()->getName(),
],
],
$contactGroupRelations
);
}
/**
* @param ACLConditions $aclConditions
*
* @return _aclConditions
*/
public static function aclConditionsToArray(ACLConditions $aclConditions): array
{
$relations = self::authorizationRulesToArray($aclConditions->getRelations());
return [
'is_enabled' => $aclConditions->isEnabled(),
'apply_only_first_role' => $aclConditions->onlyFirstRoleIsApplied(),
'attribute_path' => $aclConditions->getAttributePath(),
'relations' => $relations,
];
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/FindSAMLConfiguration/FindSAMLConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\FindSAMLConfiguration;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration;
final readonly class FindSAMLConfiguration
{
/**
* @param ProviderAuthenticationFactoryInterface $providerFactory
*/
public function __construct(private ProviderAuthenticationFactoryInterface $providerFactory)
{
}
/**
* @param FindSAMLConfigurationPresenterInterface $presenter
*/
public function __invoke(FindSAMLConfigurationPresenterInterface $presenter): void
{
try {
$provider = $this->providerFactory->create(Provider::SAML);
$configuration = $provider->getConfiguration();
} catch (\Throwable $e) {
$presenter->presentResponse(new ErrorResponse(
message: $e->getMessage(),
context: ['provider' => Provider::SAML],
exception: $e
));
return;
}
$presenter->presentResponse($this->createResponse($configuration));
}
/**
* @param Configuration $provider
*
* @return FindSAMLConfigurationResponse
*/
private function createResponse(Configuration $provider): FindSAMLConfigurationResponse
{
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $provider->getCustomConfiguration();
$response = new FindSAMLConfigurationResponse();
$response->isActive = $provider->isActive();
$response->isForced = $provider->isForced();
$response->entityIdUrl = $customConfiguration->getEntityIDUrl();
$response->remoteLoginUrl = $customConfiguration->getRemoteLoginUrl();
$response->publicCertificate = $customConfiguration->getPublicCertificate();
$response->userIdAttribute = $customConfiguration->getUserIdAttribute();
$response->requestAuthnContext = $customConfiguration->hasRequestedAuthnContext();
$response->requestedAuthnContextComparison = $customConfiguration->getRequestedAuthnContextComparison();
$response->logoutFrom = $customConfiguration->getLogoutFrom();
$response->logoutFromUrl = $customConfiguration->getLogoutFromUrl();
$response->isAutoImportEnabled = $customConfiguration->isAutoImportEnabled();
$response->emailBindAttribute = $customConfiguration->getEmailBindAttribute();
$response->userNameBindAttribute = $customConfiguration->getUserNameBindAttribute();
$response->contactTemplate = $customConfiguration->getContactTemplate() === null
? null
: $response::contactTemplateToArray($customConfiguration->getContactTemplate());
$response->aclConditions = FindSAMLConfigurationResponse::aclConditionsToArray(
$customConfiguration->getACLConditions()
);
$response->authenticationConditions
= $response::authenticationConditionsToArray(
$customConfiguration->getAuthenticationConditions()
);
$response->groupsMapping = $response::groupsMappingToArray(
$customConfiguration->getGroupsMapping()
);
return $response;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfigurationRequest.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfigurationRequest.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\UpdateSAMLConfiguration;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\RequestedAuthnContextComparisonEnum;
final class UpdateSAMLConfigurationRequest
{
public RequestedAuthnContextComparisonEnum $requestedAuthnContextComparison;
/**
* @param array{id: int, name: string}|null $contactTemplate
* @param array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* relations: array<array{claim_value: string, access_group_id: int, priority: int}>
* } $rolesMapping
* @param array{
* is_enabled: bool,
* attribute_path: string,
* authorized_values: string[],
* trusted_client_addresses: string[],
* blacklist_client_addresses: string[]
* } $authenticationConditions
* @param array{
* is_enabled: bool,
* attribute_path: string,
* relations: array<array{group_value: string, contact_group_id: int}>
* } $groupsMapping
*
* @throws \InvalidArgumentException
*/
public function __construct(
public bool $isActive = false,
public bool $isForced = false,
public string $remoteLoginUrl = '',
public string $entityIdUrl = '',
public ?string $publicCertificate = null,
public string $userIdAttribute = '',
public bool $requestedAuthnContext = false,
string $requestedAuthnContextComparison = RequestedAuthnContextComparisonEnum::EXACT->value,
public bool $logoutFrom = true,
public ?string $logoutFromUrl = null,
public bool $isAutoImportEnabled = false,
public ?array $contactTemplate = null,
public ?string $emailBindAttribute = null,
public ?string $userNameBindAttribute = null,
public array $rolesMapping = [
'is_enabled' => false,
'apply_only_first_role' => false,
'attribute_path' => '',
'relations' => [],
],
public array $authenticationConditions = [
'is_enabled' => false,
'attribute_path' => '',
'authorized_values' => [],
'trusted_client_addresses' => [],
'blacklist_client_addresses' => [],
],
public array $groupsMapping = [
'is_enabled' => false,
'attribute_path' => '',
'relations' => [],
],
) {
$this->validateRequest($requestedAuthnContextComparison);
$this->requestedAuthnContextComparison = RequestedAuthnContextComparisonEnum::tryFrom(
$requestedAuthnContextComparison
) ?? throw new \InvalidArgumentException('Invalid requested authentication context comparison value');
}
/**
* @throws \InvalidArgumentException
*/
public function validateRequest(string $requestedAuthnContextComparison): void
{
if ($this->isActive) {
if ($this->publicCertificate === null || $this->publicCertificate === '') {
throw new \InvalidArgumentException('Public certificate must be provided');
}
if ($this->entityIdUrl === '') {
throw new \InvalidArgumentException('Entity ID URL must be provided');
}
if ($this->remoteLoginUrl === '') {
throw new \InvalidArgumentException('Remote login URL must be provided');
}
if ($this->userIdAttribute === '') {
throw new \InvalidArgumentException('User ID attribute must be provided');
}
if (
$this->requestedAuthnContext
&& RequestedAuthnContextComparisonEnum::tryFrom($requestedAuthnContextComparison) === null
) {
throw new \InvalidArgumentException(
'Invalid requested authentication context comparison value, must be one of: ' . implode(
', ',
array_map(fn ($e) => $e->value, RequestedAuthnContextComparisonEnum::cases())
)
);
}
if ($this->logoutFrom && ($this->logoutFromUrl === null || $this->logoutFromUrl === '')) {
throw new \InvalidArgumentException('Logout from URL must be provided when logout from is enabled');
}
if ($this->isAutoImportEnabled) {
if ($this->emailBindAttribute === null || $this->emailBindAttribute === '') {
throw new \InvalidArgumentException(
'Email bind attribute must be provided when auto import is enabled'
);
}
if ($this->userNameBindAttribute === null || $this->userNameBindAttribute === '') {
throw new \InvalidArgumentException(
'Fullname bind attribute must be provided when auto import is enabled'
);
}
if (empty($this->contactTemplate)) {
throw new \InvalidArgumentException(
'Contact template must be provided when auto import is enabled'
);
}
}
}
}
/**
* @return array<string,mixed>
*/
public function toArray(): array
{
return [
'entity_id_url' => $this->entityIdUrl,
'remote_login_url' => $this->remoteLoginUrl,
'user_id_attribute' => $this->userIdAttribute,
'requested_authn_context' => $this->requestedAuthnContext,
'requested_authn_context_comparison' => $this->requestedAuthnContextComparison->value,
'certificate' => $this->publicCertificate,
'logout_from' => $this->logoutFrom,
'logout_from_url' => $this->logoutFromUrl,
'contact_template' => $this->contactTemplate,
'auto_import' => $this->isAutoImportEnabled,
'email_bind_attribute' => $this->emailBindAttribute,
'fullname_bind_attribute' => $this->userNameBindAttribute,
'authentication_conditions' => $this->authenticationConditions,
'groups_mapping' => $this->groupsMapping,
'roles_mapping' => $this->rolesMapping,
];
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfigurationPresenterInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfigurationPresenterInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\UpdateSAMLConfiguration;
use Core\Application\Common\UseCase\ResponseStatusInterface;
interface UpdateSAMLConfigurationPresenterInterface
{
public function presentResponse(ResponseStatusInterface $response): void;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/UseCase/UpdateSAMLConfiguration/UpdateSAMLConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\UseCase\UpdateSAMLConfiguration;
use Centreon\Domain\Log\Logger;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\NoContentResponse;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Common\Infrastructure\Repository\DatabaseRepositoryManager;
use Core\Contact\Application\Repository\ReadContactGroupRepositoryInterface;
use Core\Contact\Application\Repository\ReadContactTemplateRepositoryInterface;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface;
use Core\Security\ProviderConfiguration\Application\SAML\Repository\WriteSAMLConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\ACLConditionsException;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration;
final readonly class UpdateSAMLConfiguration
{
public function __construct(
private WriteSAMLConfigurationRepositoryInterface $writeSAMLConfigurationRepository,
private ReadContactTemplateRepositoryInterface $contactTemplateRepository,
private ReadContactGroupRepositoryInterface $contactGroupRepository,
private ReadAccessGroupRepositoryInterface $accessGroupRepository,
private DatabaseRepositoryManager $databaseRepositoryManager,
private ProviderAuthenticationFactoryInterface $providerAuthenticationFactory,
) {
}
public function __invoke(
UpdateSAMLConfigurationPresenterInterface $presenter,
UpdateSAMLConfigurationRequest $request,
): void {
try {
$provider = $this->providerAuthenticationFactory->create(Provider::SAML);
$configuration = $provider->getConfiguration();
$configuration->update($request->isActive, $request->isForced);
$requestArray = $request->toArray();
$requestArray['contact_template'] = $request->contactTemplate
&& array_key_exists('id', $request->contactTemplate) !== null
? $this->getContactTemplateOrFail($request->contactTemplate)
: null;
$requestArray['roles_mapping'] = $this->createAclConditions($request->rolesMapping);
$requestArray['authentication_conditions'] = $this->createAuthenticationConditions(
$request->authenticationConditions
);
$requestArray['groups_mapping'] = $this->createGroupsMapping($request->groupsMapping);
$configuration->setCustomConfiguration(CustomConfiguration::createFromValues($requestArray));
$this->updateConfiguration($configuration);
$presenter->presentResponse(new NoContentResponse());
} catch (\Throwable $e) {
$presenter->presentResponse(new ErrorResponse(
message: $e->getMessage(),
context: ['provider' => Provider::SAML],
exception: $e
));
return;
}
$presenter->presentResponse(new NoContentResponse());
}
/**
* Get Contact template or throw an Exception.
*
* @param array{id: int, name: string}|null $contactTemplateFromRequest
*
* @throws \Throwable|ConfigurationException
*/
private function getContactTemplateOrFail(?array $contactTemplateFromRequest): ?ContactTemplate
{
if ($contactTemplateFromRequest === null) {
return null;
}
if (($contactTemplate = $this->contactTemplateRepository->find($contactTemplateFromRequest['id'])) === null) {
throw ConfigurationException::contactTemplateNotFound(
$contactTemplateFromRequest['name']
);
}
return $contactTemplate;
}
/**
* Create Authorization Rules.
*
* @param array<array{claim_value: string, access_group_id: int, priority: int}> $authorizationRulesFromRequest
*
* @throws RepositoryException
*
* @return AuthorizationRule[]
*/
private function createAuthorizationRules(array $authorizationRulesFromRequest): array
{
$accessGroupIds = $this->getAccessGroupIds($authorizationRulesFromRequest);
if ($accessGroupIds === []) {
return [];
}
$foundAccessGroups = $this->accessGroupRepository->findByIds($accessGroupIds);
$this->logNonExistentAccessGroupsIds($accessGroupIds, $foundAccessGroups);
$authorizationRules = [];
foreach ($authorizationRulesFromRequest as $authorizationRule) {
$accessGroup = $this->findAccessGroupFromFoundAccessGroups(
$authorizationRule['access_group_id'],
$foundAccessGroups
);
if ($accessGroup !== null) {
$authorizationRules[] = new AuthorizationRule(
$authorizationRule['claim_value'],
$accessGroup,
$authorizationRule['priority']
);
}
}
return $authorizationRules;
}
/**
* @param array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* relations: array<array{claim_value: string, access_group_id: int, priority: int}>
* } $rolesMapping
*
* @throws RepositoryException
* @throws ACLConditionsException
*/
private function createAclConditions(array $rolesMapping): ACLConditions
{
$rules = $this->createAuthorizationRules($rolesMapping['relations']);
return new ACLConditions(
$rolesMapping['is_enabled'],
$rolesMapping['apply_only_first_role'],
$rolesMapping['attribute_path'],
null,
$rules
);
}
/**
* Add log for all the non existent access groups.
*
* @param int[] $accessGroupIdsFromRequest
* @param AccessGroup[] $foundAccessGroups
*/
private function logNonExistentAccessGroupsIds(array $accessGroupIdsFromRequest, array $foundAccessGroups): void
{
$foundAccessGroupsId = [];
foreach ($foundAccessGroups as $foundAccessGroup) {
$foundAccessGroupsId[] = $foundAccessGroup->getId();
}
$nonExistentAccessGroupsIds = array_diff($accessGroupIdsFromRequest, $foundAccessGroupsId);
if ($nonExistentAccessGroupsIds !== []) {
Logger::create()->error('Access Groups not found', [
'access_group_ids' => implode(', ', $nonExistentAccessGroupsIds),
]);
}
}
/**
* Compare the access group id sent in request with Access groups from database
* Return the access group that have the same id than the access group id from the request.
*
* @param AccessGroup[] $foundAccessGroups Access groups found in data storage
*/
private function findAccessGroupFromFoundAccessGroups(
int $accessGroupIdFromRequest,
array $foundAccessGroups,
): ?AccessGroup {
foreach ($foundAccessGroups as $foundAccessGroup) {
if ($accessGroupIdFromRequest === $foundAccessGroup->getId()) {
return $foundAccessGroup;
}
}
return null;
}
/**
* Return all unique access group id from request.
*
* @param array<array{claim_value: string, access_group_id: int}> $authorizationRulesFromRequest
*
* @return int[]
*/
private function getAccessGroupIds(array $authorizationRulesFromRequest): array
{
$accessGroupIds = [];
foreach ($authorizationRulesFromRequest as $authorizationRules) {
$accessGroupIds[] = $authorizationRules['access_group_id'];
}
return array_unique($accessGroupIds);
}
/**
* Update SAML Provider.
*
* @throws RepositoryException
*/
private function updateConfiguration(Configuration $configuration): void
{
$isAlreadyInTransaction = $this->databaseRepositoryManager->isTransactionActive();
try {
if (! $isAlreadyInTransaction) {
$this->databaseRepositoryManager->startTransaction();
}
$this->writeSAMLConfigurationRepository->updateConfiguration($configuration);
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
$authorizationRules = $customConfiguration->getACLConditions()->getRelations();
$this->writeSAMLConfigurationRepository->deleteAuthorizationRules();
if ($authorizationRules !== []) {
$this->writeSAMLConfigurationRepository->insertAuthorizationRules($authorizationRules);
}
$contactGroupRelations = $customConfiguration->getGroupsMapping()->getContactGroupRelations();
$this->writeSAMLConfigurationRepository->deleteContactGroupRelations();
if ($contactGroupRelations !== []) {
$this->writeSAMLConfigurationRepository->insertContactGroupRelations($contactGroupRelations);
}
if (! $isAlreadyInTransaction) {
$this->databaseRepositoryManager->commitTransaction();
}
} catch (RepositoryException $ex) {
if (! $isAlreadyInTransaction) {
$this->databaseRepositoryManager->rollbackTransaction();
throw $ex;
}
}
}
/**
* Create Authentication Condition from request data.
*
* @param array{
* "is_enabled": bool,
* "attribute_path": string,
* "authorized_values": string[],
* "trusted_client_addresses": string[],
* "blacklist_client_addresses": string[],
* } $authenticationConditionsParameters
*
* @throws ConfigurationException
*/
private function createAuthenticationConditions(array $authenticationConditionsParameters): AuthenticationConditions
{
return new AuthenticationConditions(
$authenticationConditionsParameters['is_enabled'],
$authenticationConditionsParameters['attribute_path'],
null,
$authenticationConditionsParameters['authorized_values'],
);
}
/**
* Create Groups Mapping from data send to the request.
*
* @param array{
* "is_enabled": bool,
* "attribute_path": string,
* "relations":array<array{
* "group_value": string,
* "contact_group_id": int
* }>
* } $groupsMappingParameters
*
* @throws \Throwable
*/
private function createGroupsMapping(array $groupsMappingParameters): GroupsMapping
{
$contactGroupIds = $this->getContactGroupIds($groupsMappingParameters['relations']);
$foundContactGroups = $this->contactGroupRepository->findByIds($contactGroupIds);
$this->logNonExistentContactGroupsIds($contactGroupIds, $foundContactGroups);
$contactGroupRelations = [];
foreach ($groupsMappingParameters['relations'] as $contactGroupRelation) {
$contactGroup = $this->findContactGroupFromFoundContactGroups(
$contactGroupRelation['contact_group_id'],
$foundContactGroups
);
if ($contactGroup !== null) {
$contactGroupRelations[] = new ContactGroupRelation(
$contactGroupRelation['group_value'],
$contactGroup
);
}
}
return new GroupsMapping(
$groupsMappingParameters['is_enabled'],
$groupsMappingParameters['attribute_path'],
null,
$contactGroupRelations
);
}
/**
* @param array<array{"group_value": string, "contact_group_id": int}> $contactGroupParameters
*
* @return int[]
*/
private function getContactGroupIds(array $contactGroupParameters): array
{
$contactGroupIds = [];
foreach ($contactGroupParameters as $groupsMapping) {
$contactGroupIds[] = $groupsMapping['contact_group_id'];
}
return array_unique($contactGroupIds);
}
/**
* Add log for all the non existent contact groups.
*
* @param int[] $contactGroupIds
* @param ContactGroup[] $foundContactGroups
*/
private function logNonExistentContactGroupsIds(array $contactGroupIds, array $foundContactGroups): void
{
$foundContactGroupsId = [];
foreach ($foundContactGroups as $foundAccessGroup) {
$foundContactGroupsId[] = $foundAccessGroup->getId();
}
$nonExistentContactGroupsIds = array_diff($contactGroupIds, $foundContactGroupsId);
if ($nonExistentContactGroupsIds !== []) {
Logger::create()->error('Contact groups not found', [
'contact_group_ids' => implode(', ', $nonExistentContactGroupsIds),
]);
}
}
/**
* Compare the contact group id sent in request with contact groups from database
* Return the contact group that have the same id than the contact group id from the request.
*
* @param ContactGroup[] $foundContactGroups contact groups found in data storage
*/
private function findContactGroupFromFoundContactGroups(
int $contactGroupIdFromRequest,
array $foundContactGroups,
): ?ContactGroup {
foreach ($foundContactGroups as $foundContactGroup) {
if ($contactGroupIdFromRequest === $foundContactGroup->getId()) {
return $foundContactGroup;
}
}
return null;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/Repository/WriteSAMLConfigurationRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/Repository/WriteSAMLConfigurationRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\Repository;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
interface WriteSAMLConfigurationRepositoryInterface
{
/**
* @throws RepositoryException
*/
public function updateConfiguration(Configuration $configuration): void;
/**
* @throws RepositoryException
*/
public function deleteAuthorizationRules(): void;
/**
* @param AuthorizationRule[] $authorizationRules
*
* @throws RepositoryException
*/
public function insertAuthorizationRules(array $authorizationRules): void;
/**
* @throws RepositoryException
*/
public function deleteContactGroupRelations(): void;
/**
* @param ContactGroupRelation[] $contactGroupRelations
*
* @throws RepositoryException
*/
public function insertContactGroupRelations(array $contactGroupRelations): void;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/SAML/Repository/ReadSAMLConfigurationRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/SAML/Repository/ReadSAMLConfigurationRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\SAML\Repository;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
interface ReadSAMLConfigurationRepositoryInterface
{
/**
* @throws RepositoryException
* @return array<AuthorizationRule>
*/
public function findAuthorizationRulesByConfigurationId(int $providerConfigurationId): array;
/**
* @throws RepositoryException
*/
public function findOneContactTemplate(int $contactTemplateId): ?ContactTemplate;
/**
* @throws RepositoryException
*/
public function findOneContactGroup(int $contactGroupId): ?ContactGroup;
/**
* @throws RepositoryException
* @return ContactGroupRelation[]
*/
public function findContactGroupRelationsByConfigurationId(int $providerConfigurationId): array;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Repository/ReadConfigurationRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/Repository/ReadConfigurationRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Repository;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
interface ReadConfigurationRepositoryInterface
{
/**
* @throws RepositoryException
*/
public function getConfigurationByType(string $providerType): Configuration;
/**
* @throws RepositoryException
*/
public function getConfigurationById(int $id): Configuration;
/**
* @throws RepositoryException
* @return Configuration[]
*/
public function findConfigurations(): array;
/**
* @throws RepositoryException
* @return array<string,mixed>
*/
public function findExcludedUsers(): array;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Application/Repository/ReadProviderConfigurationsRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Application/Repository/ReadProviderConfigurationsRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Application\Repository;
interface ReadProviderConfigurationsRepositoryInterface
{
/**
* Find provider configurations.
*
* @return mixed[]
*/
public function findConfigurations(): array;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/CustomConfigurationInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/CustomConfigurationInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain;
interface CustomConfigurationInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/LoginLoggerInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/LoginLoggerInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain;
use Exception;
/**
* This interface is used on authentication only.
*/
interface LoginLoggerInterface
{
/**
* @param string $scope
* @param string $message
* @param array<mixed> $content
*/
public function info(string $scope, string $message, array $content = []): void;
/**
* @param string $scope
* @param string $message
* @param array<mixed> $content
*/
public function debug(string $scope, string $message, array $content = []): void;
/**
* @param string $scope
* @param string $message
* @param array<mixed> $content
*/
public function error(string $scope, string $message, array $content = []): void;
/**
* @param string $scope
* @param string $message
* @param Exception $exception
*/
public function exception(string $scope, string $message, Exception $exception): void;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/GroupsMapping.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/GroupsMapping.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
/**
* This class is designed to represent The mapping between OpenID Claims and Centreon Contact Groups.
* Claims are gathered from the Response (attribute path) of an endpoint defined by the user.
* e.g : "http://myprovider.com/my_authorizations" will return a response:.
*
* {
* "infos": {
* "groups": [
* "groupA",
* "groupB"
* ]
* }
* }
*
* If we want to map contact group with groupA, we should set attributePath to "infos.groups",
* and ContactGroupRelation->claimValue to "groupA"
* with ["groupA"]
*/
class GroupsMapping
{
/**
* @param bool $isEnabled
* @param string $attributePath
* @param Endpoint|null $endpoint
* @param ContactGroupRelation[] $contactGroupRelations
*
* @throws ConfigurationException
*/
public function __construct(
private bool $isEnabled,
private string $attributePath,
private ?Endpoint $endpoint,
private array $contactGroupRelations,
) {
$this->validateMandatoryParametersForEnabledGroupsMapping($isEnabled, $attributePath);
}
/**
* @param ContactGroupRelation[] $contactGroupRelations
*
* @return self
*/
public function setContactGroupRelations(array $contactGroupRelations): self
{
$this->contactGroupRelations = $contactGroupRelations;
return $this;
}
/**
* @return ContactGroupRelation[]
*/
public function getContactGroupRelations(): array
{
return $this->contactGroupRelations;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->isEnabled;
}
/**
* @return string
*/
public function getAttributePath(): string
{
return $this->attributePath;
}
/**
* @return Endpoint|null
*/
public function getEndpoint(): ?Endpoint
{
return $this->endpoint;
}
/**
* Validate that all mandatory parameters are correctly set when groups mapping are enabled.
*
* @param bool $isEnabled
* @param string $attributePath
*
* @throws ConfigurationException
*/
private function validateMandatoryParametersForEnabledGroupsMapping(
bool $isEnabled,
string $attributePath,
): void {
if ($isEnabled) {
$mandatoryParameters = [];
if (empty($attributePath)) {
$mandatoryParameters[] = 'attribute_path';
}
if ($mandatoryParameters !== []) {
throw ConfigurationException::missingMandatoryParameters($mandatoryParameters);
}
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Endpoint.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Endpoint.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\InvalidEndpointException;
/**
* @phpstan-type _EndpointArray array{
* type: string,
* custom_endpoint:string|null
* }
*/
class Endpoint
{
public const INTROSPECTION = 'introspection_endpoint';
public const USER_INFORMATION = 'user_information_endpoint';
public const CUSTOM = 'custom_endpoint';
/**
* @var string[]
*/
private const ALLOWED_TYPES = [
self::INTROSPECTION,
self::USER_INFORMATION,
self::CUSTOM,
];
/**
* @param string $type
* @param string|null $url
*
* @throws InvalidEndpointException
*/
public function __construct(
private string $type = self::INTROSPECTION,
private ?string $url = null,
) {
$this->guardType();
$this->guardUrl();
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string|null
*/
public function getUrl(): ?string
{
if ($this->type !== self::CUSTOM) {
return null;
}
return $this->url;
}
/**
* @return _EndpointArray
*/
public function toArray(): array
{
return [
'type' => $this->type,
'custom_endpoint' => $this->url,
];
}
/**
* @throws InvalidEndpointException
*/
private function guardType(): void
{
if (! in_array($this->type, self::ALLOWED_TYPES, true)) {
throw InvalidEndpointException::invalidType();
}
}
/**
* @throws InvalidEndpointException
*/
private function guardUrl(): void
{
if ($this->type === self::CUSTOM) {
$this->url = $this->sanitizeEndpointValue($this->url);
if (
$this->url === null
|| (
! str_starts_with($this->url, '/')
&& filter_var($this->url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED) === false
)
) {
throw InvalidEndpointException::invalidUrl();
}
}
}
/**
* Trim unnecessary spaces and slashes in endpoint and return a valid endpoint value.
*
* @param ?string $value
*
* @return ?string
*/
private function sanitizeEndpointValue(?string $value): ?string
{
if ($value === null || mb_strlen(trim($value, ' /')) === 0) {
return null;
}
if (str_contains($value, 'http://') || str_contains($value, 'https://')) {
return ltrim(rtrim($value, ' /'));
}
return '/' . trim($value, ' /');
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/ContactGroupRelation.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/ContactGroupRelation.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Contact\Domain\Model\ContactGroup;
/**
* This class is designed to represent the relation between a Provider Claim and a contact Group.
*/
class ContactGroupRelation
{
/**
* @param string $claimValue
* @param ContactGroup $contactGroup
*/
public function __construct(private string $claimValue, private ContactGroup $contactGroup)
{
}
/**
* @return string
*/
public function getClaimValue(): string
{
return $this->claimValue;
}
/**
* @return ContactGroup
*/
public function getContactGroup(): ContactGroup
{
return $this->contactGroup;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/ACLConditions.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/ACLConditions.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\ACLConditionsException;
/**
* ACL condition block regarding OpenID.
*
* @phpstan-import-type _EndpointArray from Endpoint
*/
class ACLConditions
{
/**
* @param bool $isEnabled
* @param bool $applyOnlyFirstRole
* @param string $attributePath
* @param ?Endpoint $endpoint
* @param AuthorizationRule[] $relations
*
* @throws ACLConditionsException
*/
public function __construct(
private bool $isEnabled,
private bool $applyOnlyFirstRole,
private string $attributePath,
private ?Endpoint $endpoint,
private array $relations = [],
) {
$this->guard();
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->isEnabled;
}
/**
* @return bool
*/
public function onlyFirstRoleIsApplied(): bool
{
return $this->applyOnlyFirstRole;
}
/**
* @return string
*/
public function getAttributePath(): string
{
return $this->attributePath;
}
/**
* @return Endpoint|null
*/
public function getEndpoint(): ?Endpoint
{
return $this->endpoint;
}
/**
* @return AuthorizationRule[]
*/
public function getRelations(): array
{
return $this->relations;
}
/**
* @return array<string>
*/
public function getClaimValues(): array
{
return array_map(static fn ($relation) => $relation->getClaimValue(), $this->relations);
}
/**
* @return array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* endpoint: _EndpointArray|null,
* }
*/
public function toArray(): array
{
return [
'is_enabled' => $this->isEnabled,
'apply_only_first_role' => $this->applyOnlyFirstRole,
'attribute_path' => $this->attributePath,
'endpoint' => $this->endpoint?->toArray(),
];
}
/**
* Check mandatory parameters.
*
* @throws ACLConditionsException
*/
private function guard(): void
{
if ($this->isEnabled) {
$missing = [];
if (! mb_strlen($this->attributePath)) {
$missing[] = 'attribute_path';
}
if ($this->applyOnlyFirstRole && $this->relations === []) {
$missing[] = 'relations';
}
if ($missing !== []) {
throw ACLConditionsException::missingFields($missing);
}
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Provider.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Provider.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
final class Provider
{
public const LOCAL = 'local';
public const OPENID = 'openid';
public const WEB_SSO = 'web-sso';
public const SAML = 'saml';
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/AuthenticationConditions.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/AuthenticationConditions.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Centreon\Domain\Common\Assertion\Assertion;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
/**
* This class is designed to represent the Authentication Conditions to be able to connect with OpenID Provider
* Conditions are gathered from the Response (attribute path) of an endpoint defined by the user.
* e.g : "http://myprovider.com/my_authorizations" will return a response:.
*
* {
* "infos": {
* "groups": [
* "groupA",
* "groupB"
* ]
* }
* }
*
* If we want to allow access for user with groupA, we should set attributePath to "infos.groups", and authorizedValues
* with ["groupA"]
*/
class AuthenticationConditions
{
/** @var string[] */
private array $trustedClientAddresses = [];
/** @var string[] */
private array $blacklistClientAddresses = [];
/**
* @param bool $isEnabled
* @param string $attributePath
* @param Endpoint|null $endpoint
* @param string[] $authorizedValues
*
* @throws ConfigurationException
*/
public function __construct(
private bool $isEnabled,
private string $attributePath,
private ?Endpoint $endpoint,
private array $authorizedValues,
) {
$this->validateMandatoryParametersForEnabledCondition(
$isEnabled,
$attributePath,
$authorizedValues
);
}
/**
* @return bool
*/
public function isEnabled(): bool
{
return $this->isEnabled;
}
/**
* @return string
*/
public function getAttributePath(): string
{
return $this->attributePath;
}
/**
* @return Endpoint|null
*/
public function getEndpoint(): ?Endpoint
{
return $this->endpoint;
}
/**
* @return string[]
*/
public function getAuthorizedValues(): array
{
return $this->authorizedValues;
}
/**
* @return string[]
*/
public function getTrustedClientAddresses(): array
{
return $this->trustedClientAddresses;
}
/**
* @return string[]
*/
public function getBlacklistClientAddresses(): array
{
return $this->blacklistClientAddresses;
}
/**
* @param string[] $trustedClientAddresses
*
* @throws \Assert\AssertionFailedException
*
* @return self
*/
public function setTrustedClientAddresses(array $trustedClientAddresses): self
{
$this->trustedClientAddresses = [];
foreach ($trustedClientAddresses as $trustedClientAddress) {
$this->addTrustedClientAddress($trustedClientAddress);
}
return $this;
}
/**
* @param string $trustedClientAddress
*
* @throws \Assert\AssertionFailedException
*
* @return self
*/
public function addTrustedClientAddress(string $trustedClientAddress): self
{
$this->validateClientAddressOrFail($trustedClientAddress, 'trustedClientAddresses');
$this->trustedClientAddresses[] = $trustedClientAddress;
return $this;
}
/**
* @param string[] $blacklistClientAddresses
*
* @throws \Assert\AssertionFailedException
*
* @return self
*/
public function setBlacklistClientAddresses(array $blacklistClientAddresses): self
{
$this->blacklistClientAddresses = [];
foreach ($blacklistClientAddresses as $blacklistClientAddress) {
$this->addBlacklistClientAddress($blacklistClientAddress);
}
return $this;
}
/**
* @param string $blacklistClientAddress
*
* @throws \Assert\AssertionFailedException
*
* @return self
*/
public function addBlacklistClientAddress(string $blacklistClientAddress): self
{
$this->validateClientAddressOrFail($blacklistClientAddress, 'blacklistClientAddresses');
$this->blacklistClientAddresses[] = $blacklistClientAddress;
return $this;
}
/**
* @param string $clientAddress
* @param string $fieldName
*
* @throws \Assert\AssertionFailedException
*/
private function validateClientAddressOrFail(string $clientAddress, string $fieldName): void
{
Assertion::ipOrDomain($clientAddress, 'AuthenticationConditions::' . $fieldName);
}
/**
* Validate that all mandatory parameters are correctly set when conditions are enabled.
*
* @param bool $isEnabled
* @param string $attributePath
* @param string[] $authorizedValues
*
* @throws ConfigurationException
*/
private function validateMandatoryParametersForEnabledCondition(
bool $isEnabled,
string $attributePath,
array $authorizedValues,
): void {
if ($isEnabled) {
$mandatoryParameters = [];
if (empty($attributePath)) {
$mandatoryParameters[] = 'attribute_path';
}
if ($authorizedValues === []) {
$mandatoryParameters[] = 'authorized_values';
}
if ($mandatoryParameters !== []) {
throw ConfigurationException::missingMandatoryParameters($mandatoryParameters);
}
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/AuthorizationRule.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/AuthorizationRule.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
class AuthorizationRule
{
/**
* @param string $claimValue
* @param AccessGroup $accessGroup
* @param int $priority
*/
public function __construct(private string $claimValue, private AccessGroup $accessGroup, private int $priority)
{
}
/**
* @return string
*/
public function getClaimValue(): string
{
return $this->claimValue;
}
/**
* @return AccessGroup
*/
public function getAccessGroup(): AccessGroup
{
return $this->accessGroup;
}
/**
* @return int
*/
public function getPriority(): int
{
return $this->priority;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Configuration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Model/Configuration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Model;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
class Configuration
{
protected CustomConfigurationInterface $customConfiguration;
/**
* @param int $id
* @param string $type
* @param string $name
* @param string $jsonCustomConfiguration
* @param bool $isActive
* @param bool $isForced
*/
public function __construct(
private int $id,
private string $type,
private string $name,
private string $jsonCustomConfiguration,
private bool $isActive,
private bool $isForced,
) {
}
/**
* @param bool|null $isActive
* @param bool|null $isForced
*/
public function update(?bool $isActive = null, ?bool $isForced = null): void
{
if ($isActive !== null) {
$this->isActive = $isActive;
}
if ($isForced !== null) {
$this->isForced = $isForced;
}
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id): void
{
$this->id = $id;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @return bool
*/
public function isForced(): bool
{
return $this->isForced;
}
/**
* @return string
*/
public function getJsonCustomConfiguration(): string
{
return $this->jsonCustomConfiguration;
}
/**
* @param CustomConfigurationInterface $customConfiguration
*/
public function setCustomConfiguration(CustomConfigurationInterface $customConfiguration): void
{
$this->customConfiguration = $customConfiguration;
}
/**
* @return CustomConfigurationInterface
*/
public function getCustomConfiguration(): CustomConfigurationInterface
{
return $this->customConfiguration;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/CustomConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/CustomConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\WebSSO\Model;
use Centreon\Domain\Common\Assertion\Assertion;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
final class CustomConfiguration implements CustomConfigurationInterface, ProviderConfigurationInterface
{
/**
* @param array<string> $trustedClientAddresses
* @param array<string> $blacklistClientAddresses
* @param string|null $loginHeaderAttribute
* @param string|null $patternMatchingLogin
* @param string|null $patternReplaceLogin
*/
public function __construct(
private array $trustedClientAddresses = [],
private array $blacklistClientAddresses = [],
private ?string $loginHeaderAttribute = null,
private ?string $patternMatchingLogin = null,
private ?string $patternReplaceLogin = null,
) {
$this->guard();
}
/**
* @return array<string>
*/
public function getTrustedClientAddresses(): array
{
return $this->trustedClientAddresses;
}
/**
* @return array<string>
*/
public function getBlackListClientAddresses(): array
{
return $this->blacklistClientAddresses;
}
/**
* @return string|null
*/
public function getLoginHeaderAttribute(): ?string
{
return $this->loginHeaderAttribute;
}
/**
* @return string|null
*/
public function getPatternMatchingLogin(): ?string
{
return $this->patternMatchingLogin;
}
/**
* @return string|null
*/
public function getPatternReplaceLogin(): ?string
{
return $this->patternReplaceLogin;
}
/**
* Validate ips.
*/
private function guard(): void
{
foreach ($this->getTrustedClientAddresses() as $trustedClientAddress) {
Assertion::ipAddress($trustedClientAddress, 'WebSSOConfiguration::trustedClientAddresses');
}
foreach ($this->getBlackListClientAddresses() as $blacklistClientAddress) {
Assertion::ipAddress($blacklistClientAddress, 'WebSSOConfiguration::blacklistClientAddresses');
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/WebSSOConfigurationFactory.php | centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/WebSSOConfigurationFactory.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\WebSSO\Model;
use Core\Security\ProviderConfiguration\Application\WebSSO\UseCase\UpdateWebSSOConfiguration\{
UpdateWebSSOConfigurationRequest
};
class WebSSOConfigurationFactory
{
/**
* @param UpdateWebSSOConfigurationRequest $request
*
* @return WebSSOConfiguration
*/
public static function createFromRequest(UpdateWebSSOConfigurationRequest $request): WebSSOConfiguration
{
return new WebSSOConfiguration(
$request->isActive,
$request->isForced,
$request->trustedClientAddresses,
$request->blacklistClientAddresses,
$request->loginHeaderAttribute,
$request->patternMatchingLogin,
$request->patternReplaceLogin
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/Configuration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/Configuration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\WebSSO\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
final class Configuration extends \Core\Security\ProviderConfiguration\Domain\Model\Configuration implements ProviderConfigurationInterface
{
/**
* @return CustomConfiguration
*/
public function getCustomConfiguration(): CustomConfiguration
{
return $this->customConfiguration instanceof CustomConfiguration
? $this->customConfiguration
: throw ConfigurationException::unexpectedCustomConfiguration(($this->customConfiguration)::class);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/WebSSOConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/WebSSO/Model/WebSSOConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\WebSSO\Model;
use Centreon\Domain\Common\Assertion\Assertion;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
class WebSSOConfiguration implements ProviderConfigurationInterface
{
public const NAME = 'web-sso';
/** @var int|null */
private ?int $id = null;
/**
* @param bool $isActive
* @param bool $isForced
* @param array<string> $trustedClientAddresses
* @param array<string> $blacklistClientAddresses
* @param string|null $loginHeaderAttribute
* @param string|null $patternMatchingLogin
* @param string|null $patternReplaceLogin
*/
public function __construct(
private bool $isActive,
private bool $isForced,
private array $trustedClientAddresses,
private array $blacklistClientAddresses,
private ?string $loginHeaderAttribute,
private ?string $patternMatchingLogin,
private ?string $patternReplaceLogin,
) {
foreach ($trustedClientAddresses as $trustedClientAddress) {
Assertion::ipAddress($trustedClientAddress, 'WebSSOConfiguration::trustedClientAddresses');
}
foreach ($blacklistClientAddresses as $blacklistClientAddress) {
Assertion::ipAddress($blacklistClientAddress, 'WebSSOConfiguration::blacklistClientAddresses');
}
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @param int|null $id
*
* @return static
*/
public function setId(?int $id): static
{
$this->id = $id;
return $this;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @return bool
*/
public function isForced(): bool
{
return $this->isForced;
}
/**
* @return array<string>
*/
public function getTrustedClientAddresses(): array
{
return $this->trustedClientAddresses;
}
/**
* @return array<string>
*/
public function getBlackListClientAddresses(): array
{
return $this->blacklistClientAddresses;
}
/**
* @return string|null
*/
public function getLoginHeaderAttribute(): ?string
{
return $this->loginHeaderAttribute;
}
/**
* @return string|null
*/
public function getPatternMatchingLogin(): ?string
{
return $this->patternMatchingLogin;
}
/**
* @return string|null
*/
public function getPatternReplaceLogin(): ?string
{
return $this->patternReplaceLogin;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/ConfigurationException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/ConfigurationException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception;
class ConfigurationException extends \Exception
{
/**
* Exception thrown when token endpoint is needed but missing.
*
* @return self
*/
public static function missingTokenEndpoint(): self
{
return new self(_('Missing token endpoint in your configuration'));
}
/**
* Exception thrown when a CustomConfiguration class was unexpected.
*
* @param class-string $class
*
* @return self
*/
public static function unexpectedCustomConfiguration(string $class): self
{
return new self(sprintf(_('Must not Happen, got unexpected CustomConfiguration type %s'), $class));
}
/**
* Exception thrown when both user information endpoints are missing.
*
* @return self
*/
public static function missingInformationEndpoint(): self
{
return new self(_('Missing userinfo and introspection token endpoint'));
}
/**
* Exception thrown when auto import is enabled but mandatory parameters are missing.
*
* @param string[] $missingAutoImportParameters
*
* @return self
*/
public static function missingAutoImportMandatoryParameters(array $missingAutoImportParameters): self
{
return new self(_(sprintf(
'Missing auto import mandatory parameters: %s',
implode(', ', $missingAutoImportParameters)
)));
}
/**
* Exception thrown when contact template link to configuration doesn't exist.
*
* @param string $contactTemplateName
*
* @return self
*/
public static function contactTemplateNotFound(string $contactTemplateName): self
{
return new self(_(sprintf(
"The contact template '%s' doesn't exist",
$contactTemplateName
)));
}
/**
* Exception thrown when contact group link to configuration doesn't exist.
*
* @param int $contactGroupId
*
* @return self
*/
public static function contactGroupNotFound(int $contactGroupId): self
{
return new self(_(sprintf(
"The contact group ID #%d doesn't exist",
$contactGroupId
)));
}
/**
* Exception thrown when mandatory parameters are missing.
*
* @param array<string> $missingParameters
*
* @return self
*/
public static function missingMandatoryParameters(array $missingParameters): self
{
return new self(_(sprintf(
'Missing mandatory parameters: %s',
implode(', ', $missingParameters)
)));
}
/**
* Exception thrown when the Authentication Endpoints is not valid.
*
* @param string $endpoint
*
* @return self
*/
public static function invalidAuthenticationConditionsEndpoint(string $endpoint): self
{
return new self(_(sprintf(
'The authentication conditions endpoint should match your introspection or user information endpoints:'
. ' %s given',
$endpoint
)));
}
/**
* Exception thrown when the requested_authn_context_comparison is not valid.
* Needs to be one of 'exact', 'minimum', 'maximum', 'better'.
*
* @param mixed $requested_authn_context_comparison
*
* @return self
*/
public static function invalidRequestedAuthnContextComparison(mixed $requested_authn_context_comparison): self
{
return new self(_(sprintf(
"The requested_authn_context_comparison value is not valid: %s given. Needs to be one of 'exact', 'minimum', 'maximum', 'better'",
$requested_authn_context_comparison
)));
}
public static function missingRequestedAuthnContextComparison(): self
{
return new self(_('The requested_authn_context_comparison value is missing but is required when requested_authn_context is set to true'));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/InvalidEndpointException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/InvalidEndpointException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception;
class InvalidEndpointException extends \DomainException
{
/**
* @return self
*/
public static function invalidType(): self
{
return new self('Invalid endpoint type specified');
}
/**
* @return self
*/
public static function invalidUrl(): self
{
return new self('Invalid endpoint URL specified');
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/AttributePathFetcherNotFoundException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/AttributePathFetcherNotFoundException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception;
class AttributePathFetcherNotFoundException extends \DomainException
{
/**
* @param string $type
*
* @return self
*/
public static function create(string $type): self
{
return new self(sprintf('attribute path fetch %s not found', $type));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidStatusCodeException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidStatusCodeException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception\Http;
class InvalidStatusCodeException extends \DomainException
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidResponseException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidResponseException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception\Http;
class InvalidResponseException extends \DomainException
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidContentException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Exception/Http/InvalidContentException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Exception\Http;
class InvalidContentException extends \DomainException
{
/** @var array<mixed> */
private array $content = [];
/**
* @param array<mixed> $content
*
* @return self
*/
public static function createWithContent(array $content): self
{
$self = new self();
$self->setContent($content);
return $self;
}
/**
* @param array<mixed> $value
*/
public function setContent(array $value): void
{
$this->content = $value;
}
/**
* @return array<mixed>
*/
public function getContent(): array
{
return $this->content;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/GroupsMapping.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/GroupsMapping.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess;
use Centreon\Domain\Log\LoggerTrait;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration as OpenIdCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration as SamlCustomConfiguration;
/**
* Configured conditions must be satisfied to be authorized and map IDP's groups and Centreon's groups.
*
* @see GroupsMapping::validate()
*/
class GroupsMapping implements SecurityAccessInterface
{
use LoggerTrait;
/** @var string */
private string $scope = 'undefined';
/** @var ContactGroup[] */
private array $userContactGroups = [];
/**
* @param LoginLoggerInterface $loginLogger
*/
public function __construct(
private readonly LoginLoggerInterface $loginLogger,
) {
}
/**
* @param Configuration $configuration
* @param array<string,mixed> $identityProviderData
*
* @throws AuthenticationConditionsException
* @throws ConfigurationException
*/
public function validate(Configuration $configuration, array $identityProviderData): void
{
$this->scope = $configuration->getType();
$customConfiguration = $configuration->getCustomConfiguration();
if (
! $customConfiguration instanceof OpenIdCustomConfiguration
&& ! $customConfiguration instanceof SamlCustomConfiguration
) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$groupsMapping = $customConfiguration->getGroupsMapping();
if (! $groupsMapping->isEnabled()) {
$this->loginLogger->info($this->scope, 'Groups Mapping disabled');
$this->info('Groups Mapping disabled');
return;
}
$this->loginLogger->info($this->scope, 'Groups Mapping Enabled');
$this->info('Groups Mapping Enabled');
$groupsAttributePath[] = $groupsMapping->getAttributePath();
if ($configuration->getType() === Provider::OPENID) {
$groupsAttributePath = explode('.', $groupsMapping->getAttributePath());
}
$this->loginLogger->info($this->scope, 'Configured groups mapping attribute path found', $groupsAttributePath);
$this->info('Configured groups mapping attribute path found', ['groupAttributePath' => $groupsAttributePath]);
$groupRelationContextDebug = array_map(
fn (ContactGroupRelation $contactGroupRelation) => [
'group claim' => $contactGroupRelation->getClaimValue(),
'contact group' => $contactGroupRelation->getContactGroup()->getName(),
],
$groupsMapping->getContactGroupRelations()
);
$this->loginLogger->info($this->scope, 'Groups relations', $groupRelationContextDebug);
$this->info('Groups relations', $groupRelationContextDebug);
foreach ($groupsAttributePath as $attribute) {
$providerGroups = [];
if (array_key_exists($attribute, $identityProviderData)) {
$providerGroups = $identityProviderData[$attribute];
$identityProviderData = $identityProviderData[$attribute];
} else {
break;
}
}
if (is_string($providerGroups)) {
$providerGroups = explode(',', $providerGroups);
}
$this->validateGroupsMappingAttributeOrFail($providerGroups, $groupsMapping->getContactGroupRelations());
}
/**
* @return ContactGroup[]
*/
public function getUserContactGroups(): array
{
return $this->userContactGroups;
}
/**
* @inheritDoc
*/
public function getConditionMatches(): array
{
return [];
}
/**
* @param array<mixed> $providerGroupsMapping
* @param array<mixed> $contactGroupRelations
*
* @throws AuthenticationConditionsException
*/
private function validateGroupsMappingAttributeOrFail(
array $providerGroupsMapping,
array $contactGroupRelations,
): void {
if (array_is_list($providerGroupsMapping) === false) {
$errorMessage = 'Invalid authentication conditions format, array of strings expected';
$this->error(
$errorMessage,
[
'authentication_condition_from_provider' => $providerGroupsMapping,
]
);
$this->loginLogger->exception(
$this->scope,
$errorMessage,
AuthenticationConditionsException::invalidAuthenticationConditions()
);
throw AuthenticationConditionsException::invalidAuthenticationConditions();
}
$claimsFromProvider = [];
foreach ($contactGroupRelations as $contactGroupRelation) {
$claimsFromProvider[] = $contactGroupRelation->getClaimValue();
}
$groupsMatches = array_intersect($providerGroupsMapping, $claimsFromProvider);
$this->userContactGroups = [];
foreach ($groupsMatches as $groupsMatch) {
foreach ($contactGroupRelations as $contactGroupRelation) {
if ($contactGroupRelation->getClaimValue() === $groupsMatch) {
$this->userContactGroups[] = $contactGroupRelation->getContactGroup();
}
}
}
if ($groupsMatches === []) {
$this->error(
'Configured attribute value not found in groups mapping endpoint',
[
'provider_groups_mapping' => $providerGroupsMapping,
'configured_groups_mapping' => $claimsFromProvider,
]
);
$this->loginLogger->exception(
$this->scope,
'Configured attribute value not found in groups mapping endpoint: %s, message: %s',
AuthenticationConditionsException::conditionsNotFound()
);
}
$this->info('Groups found', ['group' => $groupsMatches]);
$this->loginLogger->info($this->scope, 'Groups found', $groupsMatches);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/Conditions.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/Conditions.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration as OpenIdCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration as SamlCustomConfiguration;
/**
* Configured conditions must be satisfied to be authorized.
*
* @see Conditions::validate()
*/
class Conditions implements SecurityAccessInterface
{
use LoggerTrait;
public function __construct(
private readonly LoginLoggerInterface $loginLogger,
) {
}
/**
* @param Configuration $configuration
* @param array<string,mixed> $identityProviderData
*
* @throws AuthenticationConditionsException
*/
public function validate(Configuration $configuration, array $identityProviderData): void
{
$scope = $configuration->getType();
$customConfiguration = $configuration->getCustomConfiguration();
if (
! $customConfiguration instanceof OpenIdCustomConfiguration
&& ! $customConfiguration instanceof SamlCustomConfiguration
) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$authenticationConditions = $customConfiguration->getAuthenticationConditions();
if (! $authenticationConditions->isEnabled()) {
$this->loginLogger->info($scope, 'Authentication conditions disabled');
$this->info('Authentication conditions disabled');
return;
}
$this->loginLogger->info($scope, 'Authentication conditions is enabled');
$this->info('Authentication conditions is enabled');
$localConditions = $authenticationConditions->getAuthorizedValues();
$authenticationAttributePath[] = $authenticationConditions->getAttributePath();
if ($configuration->getType() === Provider::OPENID) {
$authenticationAttributePath = explode('.', $authenticationConditions->getAttributePath());
}
$this->loginLogger->info($scope, 'Configured attribute path found', $authenticationAttributePath);
$this->loginLogger->info($scope, 'Configured authorized values', $localConditions);
foreach ($authenticationAttributePath as $attribute) {
$providerAuthenticationConditions = [];
if (array_key_exists($attribute, $identityProviderData)) {
$providerAuthenticationConditions = $identityProviderData[$attribute];
$identityProviderData = $identityProviderData[$attribute];
} else {
break;
}
}
if (is_string($providerAuthenticationConditions)) {
$providerAuthenticationConditions = explode(',', $providerAuthenticationConditions);
}
if (array_is_list($providerAuthenticationConditions) === false) {
$errorMessage = 'Invalid authentication conditions format, array of strings expected';
$this->error(
$errorMessage,
[
'authentication_condition_from_provider' => $providerAuthenticationConditions,
]
);
$this->loginLogger->exception(
$scope,
$errorMessage,
AuthenticationConditionsException::invalidAuthenticationConditions()
);
throw AuthenticationConditionsException::invalidAuthenticationConditions();
}
$conditionMatches = array_intersect($providerAuthenticationConditions, $localConditions);
if (count($conditionMatches) !== count($localConditions)) {
$this->error(
'Configured attribute value not found in conditions endpoint',
[
'configured_authorized_values' => $authenticationConditions->getAuthorizedValues(),
]
);
$this->loginLogger->exception(
$scope,
'Configured attribute value not found in conditions endpoint: %s, message: %s',
AuthenticationConditionsException::conditionsNotFound()
);
throw AuthenticationConditionsException::conditionsNotFound();
}
$this->info('Conditions found', ['conditions' => $conditionMatches]);
$this->loginLogger->info($scope, 'Conditions found', $conditionMatches);
}
/**
* @inheritDoc
*/
public function getConditionMatches(): array
{
return [];
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/RolesMapping.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/RolesMapping.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Authentication\Domain\Exception\AclConditionsException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration as OpenIdCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration as SamlCustomConfiguration;
/**
* Configured conditions must be satisfied to be authorized and map IDP's roles and Centreon's ACLs.
*
* @see RolesMapping::validate()
*/
class RolesMapping implements SecurityAccessInterface
{
use LoggerTrait;
/** @var string */
private string $scope = 'undefined';
/** @var string[] */
private array $conditionMatches = [];
/**
* @param LoginLoggerInterface $loginLogger
*/
public function __construct(
private readonly LoginLoggerInterface $loginLogger,
) {
}
/**
* @param Configuration $configuration
* @param array<string,mixed> $identityProviderData
*
* @throws AclConditionsException
*/
public function validate(Configuration $configuration, array $identityProviderData): void
{
$this->scope = $configuration->getType();
$customConfiguration = $configuration->getCustomConfiguration();
if (
! $customConfiguration instanceof OpenIdCustomConfiguration
&& ! $customConfiguration instanceof SamlCustomConfiguration
) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$aclConditions = $customConfiguration->getACLConditions();
if (! $aclConditions->isEnabled()) {
$this->loginLogger->info($this->scope, 'Roles mapping is disabled');
$this->info('Roles mapping is disabled');
return;
}
$this->loginLogger->info($this->scope, 'Roles mapping is enabled');
$this->info('Roles mapping is enabled');
$attributePath[] = $aclConditions->getAttributePath();
if ($configuration->getType() === Provider::OPENID) {
$attributePath = explode('.', $aclConditions->getAttributePath());
}
foreach ($attributePath as $attribute) {
$providerConditions = [];
if (array_key_exists($attribute, $identityProviderData)) {
$providerConditions = $identityProviderData[$attribute];
$identityProviderData = $identityProviderData[$attribute];
} else {
break;
}
}
if (is_string($providerConditions)) {
$providerConditions = explode(',', $providerConditions);
}
$this->validateAclAttributeOrFail($providerConditions, $aclConditions);
}
/**
* @inheritDoc
*/
public function getConditionMatches(): array
{
return $this->conditionMatches;
}
/**
* Validate roles mapping conditions.
*
* @param array<mixed> $conditions
* @param ACLConditions $aclConditions
*
* @throws AclConditionsException
*/
private function validateAclAttributeOrFail(array $conditions, ACLConditions $aclConditions): void
{
if (! array_is_list($conditions)) {
$errorMessage = 'Invalid roles mapping (ACL) conditions format, array of strings expected';
$this->error($errorMessage, [
'authentication_condition_from_provider' => $conditions,
]);
$this->loginLogger->exception(
$this->scope,
$errorMessage,
AclConditionsException::invalidAclConditions()
);
throw AclConditionsException::invalidAclConditions();
}
$configuredClaimValues = $aclConditions->getClaimValues();
if ($aclConditions->onlyFirstRoleIsApplied() && $configuredClaimValues !== []) {
foreach ($configuredClaimValues as $claimValue) {
if (in_array($claimValue, $conditions, true)) {
$this->conditionMatches = [$claimValue];
break;
}
}
} else {
$this->conditionMatches = array_intersect($conditions, $configuredClaimValues);
}
if ($this->conditionMatches === []) {
$this->error(
'Configured attribute value not found in roles mapping configuration',
[
'configured_authorized_values' => $configuredClaimValues,
'provider_conditions' => $conditions,
]
);
$this->loginLogger->exception(
$this->scope,
'Configured attribute value not found in roles mapping configuration',
AclConditionsException::invalidAclConditions()
);
throw AclConditionsException::conditionsNotFound();
}
$this->info('Role mapping relation found', [
'conditions_matches' => $this->conditionMatches,
'provider' => $conditions,
'configured' => $configuredClaimValues,
]);
$this->loginLogger->info(
$this->scope,
'Role mapping relation found',
[
'conditions_matches' => implode(', ', $this->conditionMatches),
'provider' => $conditions,
'configured' => $configuredClaimValues,
]
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/SecurityAccessInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/SecurityAccessInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess;
use Core\Security\Authentication\Infrastructure\Provider\OpenId;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath\AttributePathFetcherInterface;
/**
* Interface used by each security access controls: Authentication conditions, Roles mapping and Groups mapping
* Security access controls are use in authentication to control access on OIDC and SAML, you probably find theme in
* OIDC provider and SAML provider classes.
*
* <b>Important</b>: If all security access are enabled, they must all be satisfied to authorize the user
*
* @see Conditions (SecurityAccess)
* @see RolesMapping (SecurityAccess)
* @see GroupsMapping (SecurityAccess)
* @see OpenId (Provider)
*/
interface SecurityAccessInterface
{
/**
* Call this method to perform the control access, the process continues normally if you are authorized,
* otherwise an exception will be thrown.
*
* @param Configuration $configuration The authentication configuration
* @param array<string,mixed> $identityProviderData Data fetched from the identity provider
*
* @see AttributePathFetcherInterface
*/
public function validate(Configuration $configuration, array $identityProviderData): void;
/**
* Get the condition that has matched between IdP and OpenID Configuration.
* This allow application to be able to define ACLs for authenticated user.
*
* @return string[]
*/
public function getConditionMatches(): array;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/IntrospectionFetcher.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/IntrospectionFetcher.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidContentException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidResponseException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidStatusCodeException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\OpenIdCustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Repository\ReadAttributePathRepositoryInterface;
class IntrospectionFetcher implements AttributePathFetcherInterface
{
use LoggerTrait;
public function __construct(
private readonly LoginLoggerInterface $loginLogger,
private readonly ReadAttributePathRepositoryInterface $attributePathRepository,
) {
}
/**
* @param string $accessToken
* @param Configuration $configuration
* @param Endpoint $endpoint
*
* @throws SSOAuthenticationException
*
* @return array<string,mixed>
*/
public function fetch(string $accessToken, Configuration $configuration, Endpoint $endpoint): array
{
$scope = $configuration->getType();
$customConfiguration = $configuration->getCustomConfiguration();
if (! $customConfiguration instanceof OpenIdCustomConfigurationInterface) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$url = $customConfiguration->getBaseUrl() . '/'
. ltrim($customConfiguration->getIntrospectionTokenEndpoint() ?? '', '/');
try {
return $this->attributePathRepository->getData($url, $accessToken, $configuration, $endpoint->getType());
} catch (InvalidResponseException $invalidResponseException) {
$this->loginLogger->exception(
$scope,
'Unable to get Introspection Information: %s, message: %s',
$invalidResponseException
);
$this->error(sprintf(
'[Error] Unable to get Introspection Token Information:, message: %s',
$invalidResponseException->getMessage()
));
throw SSOAuthenticationException::requestForIntrospectionTokenFail();
} catch (InvalidContentException $invalidContentException) {
$content = $invalidContentException->getContent();
$this->loginLogger->error($scope, 'Introspection Token Info: ', $content);
$this->error(
'error from external provider :' . (array_key_exists('error', $content)
? $content['error']
: 'No content in response')
);
throw SSOAuthenticationException::errorFromExternalProvider($configuration->getName());
} catch (InvalidStatusCodeException $invalidStatusCodeException) {
$this->loginLogger->exception(
$scope,
'Unable to get Introspection Information: %s, message: %s',
SSOAuthenticationException::requestForIntrospectionTokenFail()
);
$this->error(
sprintf(
'invalid status code return by external provider, [%d] returned, [%d] expected',
$invalidStatusCodeException->getCode(),
200
)
);
throw SSOAuthenticationException::requestForIntrospectionTokenFail();
}
}
/**
* @inheritDoc
*/
public function supports(Endpoint $endpoint): bool
{
return $endpoint->getType() === Endpoint::INTROSPECTION;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/UserInformationFetcher.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/UserInformationFetcher.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidContentException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidResponseException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidStatusCodeException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\OpenIdCustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Repository\ReadAttributePathRepositoryInterface;
class UserInformationFetcher implements AttributePathFetcherInterface
{
use LoggerTrait;
public function __construct(
private readonly LoginLoggerInterface $loginLogger,
private readonly ReadAttributePathRepositoryInterface $attributePathRepository,
) {
}
/**
* @param string $accessToken
* @param Configuration $configuration
* @param Endpoint $endpoint
*
* @throws SSOAuthenticationException
*
* @return array<string,mixed>
*/
public function fetch(string $accessToken, Configuration $configuration, Endpoint $endpoint): array
{
$scope = $configuration->getType();
$customConfiguration = $configuration->getCustomConfiguration();
if (! $customConfiguration instanceof OpenIdCustomConfigurationInterface) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$url = str_starts_with($customConfiguration->getUserInformationEndpoint() ?? '', '/')
? $customConfiguration->getBaseUrl() . $customConfiguration->getUserInformationEndpoint()
: $customConfiguration->getUserInformationEndpoint();
try {
return $this->attributePathRepository->getData($url ?? '', $accessToken, $configuration, $endpoint->getType());
} catch (InvalidResponseException) {
throw SSOAuthenticationException::requestForUserInformationFail();
} catch (InvalidStatusCodeException $invalidStatusCodeException) {
$exception = SSOAuthenticationException::requestForUserInformationFail();
$this->loginLogger->exception(
$scope,
'Unable to get User Information: %s, message: %s',
$exception
);
$this->error(
sprintf(
'invalid status code return by external provider, [%d] returned, [%d] expected',
$invalidStatusCodeException->getCode(),
200
)
);
throw $exception;
} catch (InvalidContentException $invalidContentException) {
$content = $invalidContentException->getContent();
$this->loginLogger->error($scope, 'User Information Info: ', $content);
$this->error(
'error from external provider :' . (array_key_exists('error', $content)
? $content['error']
: 'No content in response')
);
throw SSOAuthenticationException::errorFromExternalProvider($configuration->getName());
}
}
/**
* @inheritDoc
*/
public function supports(Endpoint $endpoint): bool
{
return $endpoint->getType() === Endpoint::USER_INFORMATION;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/HttpUrlFetcher.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/HttpUrlFetcher.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidContentException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidResponseException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidStatusCodeException;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\OpenIdCustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Repository\ReadAttributePathRepositoryInterface;
class HttpUrlFetcher implements AttributePathFetcherInterface
{
use LoggerTrait;
public function __construct(
private readonly ReadAttributePathRepositoryInterface $attributePathRepository,
private readonly LoginLoggerInterface $loginLogger,
) {
}
/**
* @param string $accessToken
* @param Configuration $configuration
* @param Endpoint $endpoint
*
* @throws SSOAuthenticationException
*
* @return array<string,mixed>
*/
public function fetch(string $accessToken, Configuration $configuration, Endpoint $endpoint): array
{
$scope = $configuration->getType();
$customEndpoint = $endpoint->getUrl() ?? '';
$customConfiguration = $configuration->getCustomConfiguration();
if (
str_starts_with($customEndpoint, '/')
&& $customConfiguration instanceof OpenIdCustomConfigurationInterface
) {
$url = $customConfiguration->getBaseUrl() . $customEndpoint;
} else {
$url = $customEndpoint;
}
try {
return $this->attributePathRepository->getData($url, $accessToken, $configuration, $endpoint->getType());
} catch (InvalidResponseException) {
throw SSOAuthenticationException::requestOnCustomEndpointFailed();
} catch (InvalidStatusCodeException $invalidStatusCodeException) {
$this->loginLogger->exception(
$scope,
'Unable to get custom endpoint information: %s, message: %s',
SSOAuthenticationException::requestOnCustomEndpointFailed()
);
$this->error(
sprintf(
'invalid status code return by external provider, [%d] returned, [%d] expected',
$invalidStatusCodeException->getCode(),
200
)
);
throw SSOAuthenticationException::requestOnCustomEndpointFailed();
} catch (InvalidContentException $invalidContentException) {
$content = $invalidContentException->getContent();
$this->loginLogger->error($scope, 'Custom endpoint Info: ', $content);
$this->error(
'error from external provider :' . (array_key_exists('error', $content)
? $content['error']
: 'No content in response')
);
throw SSOAuthenticationException::errorFromExternalProvider($configuration->getName());
}
}
/**
* @inheritDoc
*/
public function supports(Endpoint $endpoint): bool
{
return $endpoint->getType() === Endpoint::CUSTOM;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/AttributePathFetcher.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/AttributePathFetcher.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath;
use Core\Security\ProviderConfiguration\Domain\Exception\AttributePathFetcherNotFoundException;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
class AttributePathFetcher
{
/** @var AttributePathFetcherInterface[] */
private array $fetchers;
/**
* @param IntrospectionFetcher $introspectionFetcher
* @param UserInformationFetcher $userInformationFetcher
* @param HttpUrlFetcher $httpUrlFetcher
*/
public function __construct(
private readonly IntrospectionFetcher $introspectionFetcher,
private readonly UserInformationFetcher $userInformationFetcher,
private readonly HttpUrlFetcher $httpUrlFetcher,
) {
$this->fetchers = [
$this->introspectionFetcher,
$this->userInformationFetcher,
$this->httpUrlFetcher,
];
}
/**
* @param string $accessToken
* @param Configuration $configuration
* @param Endpoint $endpoint
*
* @return array<mixed>
*/
public function fetch(string $accessToken, Configuration $configuration, Endpoint $endpoint): array
{
return $this->findFirstFetcher($endpoint)->fetch($accessToken, $configuration, $endpoint);
}
/**
* @param Endpoint $endpoint
*
* @return AttributePathFetcherInterface
*/
private function findFirstFetcher(Endpoint $endpoint): AttributePathFetcherInterface
{
foreach ($this->fetchers as $fetcher) {
if ($fetcher->supports($endpoint)) {
return $fetcher;
}
}
throw AttributePathFetcherNotFoundException::create($endpoint->getType());
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/AttributePathFetcherInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SecurityAccess/AttributePath/AttributePathFetcherInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
/**
* All fetchers must implement this interface
* A fetcher is associate to one Endpoint type: Introspection, user information or custom url
* Fetchers are use in authentication to control access on OIDC and SAML.
*
* @see Endpoint
*/
interface AttributePathFetcherInterface
{
/**
* @param string $accessToken
* @param Configuration $configuration
* @param Endpoint $endpoint
*
* @return array<string,mixed>
*/
public function fetch(string $accessToken, Configuration $configuration, Endpoint $endpoint): array;
/**
* If the method supports return true the fetch method will be executed.
*
* @param Endpoint $endpoint
*
* @return bool
*/
public function supports(Endpoint $endpoint): bool;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/CustomConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/CustomConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\OpenId\Model;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use TypeError;
class CustomConfiguration implements CustomConfigurationInterface, OpenIdCustomConfigurationInterface
{
public const DEFAULT_LOGIN_CLAIM = 'preferred_username';
public const AUTHENTICATION_POST = 'client_secret_post';
public const AUTHENTICATION_BASIC = 'client_secret_basic';
public const TYPE = 'openid';
public const NAME = 'openid';
/** @var string|null */
private ?string $endSessionEndpoint = null;
/** @var string[] */
private array $connectionScopes = [];
/** @var string|null */
private ?string $loginClaim = null;
/** @var string|null */
private ?string $authenticationType = null;
/** @var bool */
private bool $verifyPeer = false;
/** @var array<AuthorizationRule> */
private array $authorizationRules = [];
/** @var bool */
private bool $isAutoImportEnabled = false;
/** @var string|null */
private ?string $clientId = null;
/** @var string|null */
private ?string $clientSecret = null;
/** @var string|null */
private ?string $baseUrl = null;
/** @var string|null */
private ?string $authorizationEndpoint = null;
/** @var string|null */
private ?string $tokenEndpoint = null;
/** @var string|null */
private ?string $introspectionTokenEndpoint = null;
/** @var string|null */
private ?string $userInformationEndpoint = null;
/** @var ContactTemplate|null */
private ?ContactTemplate $contactTemplate = null;
/** @var string|null */
private ?string $emailBindAttribute = null;
/** @var string|null */
private ?string $userNameBindAttribute = null;
/** @var ContactGroup|null */
private ?ContactGroup $contactGroup = null;
/** @var ACLConditions */
private ACLConditions $aclConditions;
/** @var AuthenticationConditions */
private AuthenticationConditions $authenticationConditions;
/** @var GroupsMapping */
private GroupsMapping $groupsMapping;
private ?string $redirectUrl = null;
/**
* @param array<string,mixed> $json
*
* @throws ConfigurationException
*/
public function __construct(array $json)
{
$this->create($json);
}
/**
* @return string|null
*/
public function getEndSessionEndpoint(): ?string
{
return $this->endSessionEndpoint;
}
/**
* @return string[]
*/
public function getConnectionScopes(): array
{
return $this->connectionScopes;
}
/**
* @return string|null
*/
public function getLoginClaim(): ?string
{
return $this->loginClaim;
}
/**
* @return string|null
*/
public function getAuthenticationType(): ?string
{
return $this->authenticationType;
}
/**
* @return bool
*/
public function verifyPeer(): bool
{
return $this->verifyPeer;
}
/**
* @return AuthorizationRule[]
*/
public function getAuthorizationRules(): array
{
return $this->authorizationRules;
}
/**
* @return bool
*/
public function isAutoImportEnabled(): bool
{
return $this->isAutoImportEnabled;
}
/**
* @return string|null
*/
public function getBaseUrl(): ?string
{
return $this->baseUrl;
}
/**
* @return string|null
*/
public function getAuthorizationEndpoint(): ?string
{
return $this->authorizationEndpoint;
}
/**
* @return string|null
*/
public function getTokenEndpoint(): ?string
{
return $this->tokenEndpoint;
}
/**
* @return string|null
*/
public function getIntrospectionTokenEndpoint(): ?string
{
return $this->introspectionTokenEndpoint;
}
/**
* @return string|null
*/
public function getUserInformationEndpoint(): ?string
{
return $this->userInformationEndpoint;
}
/**
* @return string|null
*/
public function getClientId(): ?string
{
return $this->clientId;
}
/**
* @return string|null
*/
public function getClientSecret(): ?string
{
return $this->clientSecret;
}
/**
* @return ContactTemplate|null
*/
public function getContactTemplate(): ?ContactTemplate
{
return $this->contactTemplate;
}
/**
* @return string|null
*/
public function getEmailBindAttribute(): ?string
{
return $this->emailBindAttribute;
}
/**
* @return string|null
*/
public function getUserNameBindAttribute(): ?string
{
return $this->userNameBindAttribute;
}
/**
* @return ContactGroup|null
*/
public function getContactGroup(): ?ContactGroup
{
return $this->contactGroup;
}
/**
* @return ACLConditions
*/
public function getACLConditions(): ACLConditions
{
return $this->aclConditions;
}
/**
* @param string|null $baseUrl
*
* @return self
*/
public function setBaseUrl(?string $baseUrl): self
{
$this->baseUrl = $baseUrl;
return $this;
}
/**
* @param string|null $authorizationEndpoint
*
* @return self
*/
public function setAuthorizationEndpoint(?string $authorizationEndpoint): self
{
$this->authorizationEndpoint = $authorizationEndpoint;
return $this;
}
/**
* @param string|null $tokenEndpoint
*
* @return self
*/
public function setTokenEndpoint(?string $tokenEndpoint): self
{
$this->tokenEndpoint = $tokenEndpoint;
return $this;
}
/**
* @param string|null $introspectionTokenEndpoint
*
* @return self
*/
public function setIntrospectionTokenEndpoint(?string $introspectionTokenEndpoint): self
{
$this->introspectionTokenEndpoint = $introspectionTokenEndpoint;
return $this;
}
/**
* @param string|null $userInformationEndpoint
*
* @return self
*/
public function setUserInformationEndpoint(?string $userInformationEndpoint): self
{
$this->userInformationEndpoint = $userInformationEndpoint;
return $this;
}
/**
* @param string|null $endSessionEndpoint
*
* @return self
*/
public function setEndSessionEndpoint(?string $endSessionEndpoint): self
{
$this->endSessionEndpoint = $endSessionEndpoint;
return $this;
}
/**
* @param string[] $connectionScopes
*
* @return self
*/
public function setConnectionScopes(array $connectionScopes): self
{
$this->connectionScopes = [];
foreach ($connectionScopes as $connectionScope) {
$this->addConnectionScope($connectionScope);
}
return $this;
}
/**
* @param string $connectionScope
*
* @return self
*/
public function addConnectionScope(string $connectionScope): self
{
$this->connectionScopes[] = $connectionScope;
return $this;
}
/**
* @param string|null $loginClaim
*
* @return self
*/
public function setLoginClaim(?string $loginClaim): self
{
$this->loginClaim = $loginClaim;
return $this;
}
/**
* @param string|null $clientId
*
* @return self
*/
public function setClientId(?string $clientId): self
{
$this->clientId = $clientId;
return $this;
}
/**
* @param string|null $clientSecret
*
* @return self
*/
public function setClientSecret(?string $clientSecret): self
{
$this->clientSecret = $clientSecret;
return $this;
}
/**
* @param string|null $authenticationType
*
* @return self
*/
public function setAuthenticationType(?string $authenticationType): self
{
$this->authenticationType = $authenticationType;
return $this;
}
/**
* @param bool $verifyPeer
*
* @return self
*/
public function setVerifyPeer(bool $verifyPeer): self
{
$this->verifyPeer = $verifyPeer;
return $this;
}
/**
* @param bool $isAutoImportEnabled
*
* @return self
*/
public function setAutoImportEnabled(bool $isAutoImportEnabled): self
{
$this->isAutoImportEnabled = $isAutoImportEnabled;
return $this;
}
/**
* @param ContactTemplate|null $contactTemplate
*
* @return self
*/
public function setContactTemplate(?ContactTemplate $contactTemplate): self
{
$this->contactTemplate = $contactTemplate;
return $this;
}
/**
* @param string|null $emailBindAttribute
*
* @return self
*/
public function setEmailBindAttribute(?string $emailBindAttribute): self
{
$this->emailBindAttribute = $emailBindAttribute;
return $this;
}
/**
* @param string|null $userNameBindAttribute
*
* @return self
*/
public function setUserNameBindAttribute(?string $userNameBindAttribute): self
{
$this->userNameBindAttribute = $userNameBindAttribute;
return $this;
}
/**
* @param AuthorizationRule[] $authorizationRules
*
* @throws TypeError
*
* @return self
*/
public function setAuthorizationRules(array $authorizationRules): self
{
$this->authorizationRules = [];
foreach ($authorizationRules as $authorizationRule) {
$this->addAuthorizationRule($authorizationRule);
}
return $this;
}
/**
* @param AuthorizationRule $authorizationRule
*
* @return self
*/
public function addAuthorizationRule(AuthorizationRule $authorizationRule): self
{
$this->authorizationRules[] = $authorizationRule;
return $this;
}
/**
* @param ContactGroup|null $contactGroup
*
* @return self
*/
public function setContactGroup(?ContactGroup $contactGroup): self
{
$this->contactGroup = $contactGroup;
return $this;
}
/**
* @param AuthenticationConditions $authenticationConditions
*
* @return self
*/
public function setAuthenticationConditions(AuthenticationConditions $authenticationConditions): self
{
$this->authenticationConditions = $authenticationConditions;
return $this;
}
/**
* @inheritDoc
*/
public function getAuthenticationConditions(): AuthenticationConditions
{
return $this->authenticationConditions;
}
/**
* @param GroupsMapping $groupsMapping
*
* @return self
*/
public function setGroupsMapping(GroupsMapping $groupsMapping): self
{
$this->groupsMapping = $groupsMapping;
return $this;
}
/**
* @return GroupsMapping
*/
public function getGroupsMapping(): GroupsMapping
{
return $this->groupsMapping;
}
public function getRedirectUrl(): ?string
{
return $this->redirectUrl;
}
public function setRedirectUrl(?string $redirectUrl): self
{
$this->redirectUrl = $redirectUrl;
return $this;
}
/**
* @param array<string,mixed> $json
*
* @throws ConfigurationException
*/
public function create(array $json): void
{
if (isset($json['is_active']) && $json['is_active']) {
$this->validateMandatoryFields($json);
}
$this->setClientId($json['client_id']);
$this->setAutoImportEnabled($json['auto_import']);
$this->setClientSecret($json['client_secret']);
$this->setBaseUrl($this->sanitizeEndpointValue($json['base_url']));
$this->setAuthorizationEndpoint($this->sanitizeEndpointValue($json['authorization_endpoint']));
$this->setTokenEndpoint($this->sanitizeEndpointValue($json['token_endpoint']));
$this->setIntrospectionTokenEndpoint($this->sanitizeEndpointValue($json['introspection_token_endpoint']));
$this->setUserInformationEndpoint($this->sanitizeEndpointValue($json['userinfo_endpoint']));
$this->setContactTemplate($json['contact_template']);
$this->setEmailBindAttribute($json['email_bind_attribute']);
$this->setUserNameBindAttribute($json['fullname_bind_attribute']);
$this->setEndSessionEndpoint($this->sanitizeEndpointValue($json['endsession_endpoint']));
$this->setConnectionScopes($json['connection_scopes']);
$this->setLoginClaim($json['login_claim']);
$this->setAuthenticationType($json['authentication_type']);
$this->setVerifyPeer($json['verify_peer']);
$this->setAuthenticationConditions($json['authentication_conditions']);
$this->setACLConditions($json['roles_mapping']);
$this->setGroupsMapping($json['groups_mapping']);
$this->setRedirectUrl($json['redirect_url']);
}
/**
* @param ACLConditions $aclConditions
*
* @return CustomConfiguration
*/
public function setACLConditions(ACLConditions $aclConditions): self
{
$this->aclConditions = $aclConditions;
return $this;
}
/**
* @throws ConfigurationException
*
* @return array<string,mixed> $json
*/
public function toArray(): array
{
return [
'client_id' => $this->getClientId(),
'auto_import' => $this->isAutoImportEnabled(),
'client_secret' => $this->getClientSecret(),
'base_url' => $this->getBaseUrl(),
'authorization_endpoint' => $this->getAuthorizationEndpoint(),
'token_endpoint' => $this->getTokenEndpoint(),
'introspection_token_endpoint' => $this->getIntrospectionTokenEndpoint(),
'userinfo_endpoint' => $this->getUserInformationEndpoint(),
'contact_template' => $this->getContactTemplate(),
'email_bind_attribute' => $this->getEmailBindAttribute(),
'fullname_bind_attribute' => $this->getUserNameBindAttribute(),
'endsession_endpoint' => $this->getEndSessionEndpoint(),
'connection_scopes' => $this->getConnectionScopes(),
'login_claim' => $this->getLoginClaim(),
'authentication_type' => $this->getAuthenticationType(),
'verify_peer' => $this->verifyPeer(),
'authentication_conditions' => $this->getAuthenticationConditions(),
'roles_mapping' => $this->getACLConditions(),
'groups_mapping' => $this->getGroupsMapping(),
'redirect_url' => $this->getRedirectUrl(),
];
}
/**
* @param array<string,mixed> $json
*
* @throws ConfigurationException
*/
private function validateMandatoryFields(array $json): void
{
$mandatoryFields = [
'client_id',
'client_secret',
'base_url',
'authorization_endpoint',
'token_endpoint',
];
$emptyParameters = [];
foreach ($mandatoryFields as $key) {
if (empty($json[$key])) {
$emptyParameters[] = $key;
}
}
if ($emptyParameters !== []) {
throw ConfigurationException::missingMandatoryParameters($emptyParameters);
}
if (empty($json['introspection_token_endpoint']) && empty($json['userinfo_endpoint'])) {
throw ConfigurationException::missingInformationEndpoint();
}
if ($json['auto_import'] === true) {
$this->validateParametersForAutoImport(
$json['contact_template'],
$json['email_bind_attribute'],
$json['fullname_bind_attribute']
);
}
}
/**
* Validate mandatory parameters for auto import.
*
* @param ContactTemplate|null $contactTemplate
* @param string|null $emailBindAttribute
* @param string|null $userNameBindAttribute
*
* @throws ConfigurationException
*/
private function validateParametersForAutoImport(
?ContactTemplate $contactTemplate,
?string $emailBindAttribute,
?string $userNameBindAttribute,
): void {
$missingMandatoryParameters = [];
if ($contactTemplate === null) {
$missingMandatoryParameters[] = 'contact_template';
}
if (empty($emailBindAttribute)) {
$missingMandatoryParameters[] = 'email_bind_attribute';
}
if (empty($userNameBindAttribute)) {
$missingMandatoryParameters[] = 'fullname_bind_attribute';
}
if ($missingMandatoryParameters !== []) {
throw ConfigurationException::missingAutoImportMandatoryParameters(
$missingMandatoryParameters
);
}
}
/**
* Trim unnecessary spaces and slashes in endpoint and return a valid endpoint value.
*
* @param ?string $value
*
* @return ?string
*/
private function sanitizeEndpointValue(?string $value): ?string
{
if ($value === null || mb_strlen(trim($value, ' /')) === 0) {
return null;
}
if (str_contains($value, 'http://') || str_contains($value, 'https://')) {
return ltrim(rtrim($value, ' /'));
}
return '/' . trim($value, ' /');
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/OpenIdCustomConfigurationInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/OpenIdCustomConfigurationInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\OpenId\Model;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
interface OpenIdCustomConfigurationInterface
{
/**
* @return string|null
*/
public function getEndSessionEndpoint(): ?string;
/**
* @return string[]
*/
public function getConnectionScopes(): array;
/**
* @return string|null
*/
public function getLoginClaim(): ?string;
/**
* @return string|null
*/
public function getAuthenticationType(): ?string;
/**
* @return bool
*/
public function verifyPeer(): bool;
/**
* @return AuthorizationRule[]
*/
public function getAuthorizationRules(): array;
/**
* @return bool
*/
public function isAutoImportEnabled(): bool;
/**
* @return string|null
*/
public function getBaseUrl(): ?string;
/**
* @return string|null
*/
public function getAuthorizationEndpoint(): ?string;
/**
* @return string|null
*/
public function getTokenEndpoint(): ?string;
/**
* @return string|null
*/
public function getIntrospectionTokenEndpoint(): ?string;
/**
* @return string|null
*/
public function getUserInformationEndpoint(): ?string;
/**
* @return string|null
*/
public function getClientId(): ?string;
/**
* @return string|null
*/
public function getClientSecret(): ?string;
/**
* @return ContactTemplate|null
*/
public function getContactTemplate(): ?ContactTemplate;
/**
* @return string|null
*/
public function getEmailBindAttribute(): ?string;
/**
* @return string|null
*/
public function getUserNameBindAttribute(): ?string;
/**
* @return ContactGroup|null
*/
public function getContactGroup(): ?ContactGroup;
/**
* @return AuthenticationConditions
*/
public function getAuthenticationConditions(): AuthenticationConditions;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/Configuration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Model/Configuration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\OpenId\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
class Configuration extends \Core\Security\ProviderConfiguration\Domain\Model\Configuration implements ProviderConfigurationInterface
{
/**
* @return CustomConfiguration
*/
public function getCustomConfiguration(): CustomConfiguration
{
return $this->customConfiguration instanceof CustomConfiguration
? $this->customConfiguration
: throw ConfigurationException::unexpectedCustomConfiguration(($this->customConfiguration)::class);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Exceptions/OpenIdConfigurationException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Exceptions/OpenIdConfigurationException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions;
class OpenIdConfigurationException extends \Exception
{
/**
* Exception thrown when token endpoint is needed but missing.
*
* @return self
*/
public static function missingTokenEndpoint(): self
{
return new self(_('Missing token endpoint in your configuration'));
}
/**
* Exception thrown when both user information endpoints are missing.
*
* @return self
*/
public static function missingInformationEndpoint(): self
{
return new self(_('Missing userinfo and introspection token endpoint'));
}
/**
* Exception thrown when auto import is enabled but mandatory parameters are missing.
*
* @param string[] $missingAutoImportParameters
*
* @return self
*/
public static function missingAutoImportMandatoryParameters(array $missingAutoImportParameters): self
{
return new self(_(sprintf(
'Missing auto import mandatory parameters: %s',
implode(', ', $missingAutoImportParameters)
)));
}
/**
* Exception thrown when contact template link to configuration doesn't exist.
*
* @param string $contactTemplateName
*
* @return self
*/
public static function contactTemplateNotFound(string $contactTemplateName): self
{
return new self(_(sprintf(
"The contact template '%s' doesn't exist",
$contactTemplateName
)));
}
/**
* Exception thrown when contact group link to configuration doesn't exist.
*
* @param int $contactGroupId
*
* @return self
*/
public static function contactGroupNotFound(int $contactGroupId): self
{
return new self(_(sprintf(
"The contact group id #%d doesn't exist",
$contactGroupId
)));
}
/**
* Exception thrown when mandatory parameters are missing.
*
* @param array<string> $missingParameters
*
* @return self
*/
public static function missingMandatoryParameters(array $missingParameters): self
{
return new self(_(sprintf(
'Missing mandatory parameters: %s',
implode(', ', $missingParameters)
)));
}
/**
* @param string $credential
*
* @return self
*/
public static function unableToRetrieveCredentialFromVault(string $credential): self
{
return new self(_(sprintf("Unable to retrieve credentials ['%s'] from vault", $credential)));
}
public static function unknownProviderType(string $type): self
{
return new self(_(sprintf(
'Unknown provider type: %s',
$type
)));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Exceptions/ACLConditionsException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/OpenId/Exceptions/ACLConditionsException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
class ACLConditionsException extends ConfigurationException
{
/**
* @param array<string> $fields
*
* @return self
*/
public static function missingFields(array $fields): self
{
return new self(_(sprintf(
'Missing mandatory fields: %s',
implode(', ', $fields)
)));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Local/ConfigurationException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Local/ConfigurationException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Local;
class ConfigurationException extends \Exception
{
/**
* @return self
*/
public static function notFound(): self
{
return new self(_('Local provider configuration not found'));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/LocalCustomConfigurationInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/LocalCustomConfigurationInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Local\Model;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
interface LocalCustomConfigurationInterface extends CustomConfigurationInterface
{
/**
* @return SecurityPolicy
*/
public function getSecurityPolicy(): SecurityPolicy;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/CustomConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/CustomConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Local\Model;
final class CustomConfiguration implements LocalCustomConfigurationInterface
{
/**
* @param SecurityPolicy $securityPolicy
*/
public function __construct(private SecurityPolicy $securityPolicy)
{
}
/**
* @return SecurityPolicy
*/
public function getSecurityPolicy(): SecurityPolicy
{
return $this->securityPolicy;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/SecurityPolicy.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/SecurityPolicy.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Local\Model;
use Centreon\Domain\Common\Assertion\Assertion;
use Centreon\Domain\Common\Assertion\AssertionException;
class SecurityPolicy
{
public const SPECIAL_CHARACTERS_LIST = '@$!%*?&';
public const MIN_PASSWORD_LENGTH = 8;
public const MAX_PASSWORD_LENGTH = 128;
public const MIN_ATTEMPTS = 1;
public const MAX_ATTEMPTS = 10;
public const MIN_BLOCKING_DURATION = 1;
public const MAX_BLOCKING_DURATION = 604800;
public const // 7 days in seconds.
MIN_PASSWORD_EXPIRATION_DELAY = 604800;
public const // 7 days in seconds.
MAX_PASSWORD_EXPIRATION_DELAY = 31536000;
public const // 12 months in seconds.
MIN_NEW_PASSWORD_DELAY = 3600;
public const // 1 hour in seconds.
MAX_NEW_PASSWORD_DELAY = 604800; // 7 days in seconds.
/**
* @param int $passwordMinimumLength
* @param bool $hasUppercase
* @param bool $hasLowercase
* @param bool $hasNumber
* @param bool $hasSpecialCharacter
* @param bool $canReusePasswords
* @param int|null $attempts
* @param int|null $blockingDuration
* @param int|null $passwordExpirationDelay
* @param string[] $passwordExpirationExcludedUserAliases
* @param int|null $delayBeforeNewPassword
*
* @throws AssertionException
*/
public function __construct(
private int $passwordMinimumLength,
private bool $hasUppercase,
private bool $hasLowercase,
private bool $hasNumber,
private bool $hasSpecialCharacter,
private bool $canReusePasswords,
private ?int $attempts,
private ?int $blockingDuration,
private ?int $passwordExpirationDelay,
private array $passwordExpirationExcludedUserAliases,
private ?int $delayBeforeNewPassword,
) {
Assertion::min($passwordMinimumLength, self::MIN_PASSWORD_LENGTH, 'SecurityPolicy::passwordMinimumLength');
Assertion::max($passwordMinimumLength, self::MAX_PASSWORD_LENGTH, 'SecurityPolicy::passwordMinimumLength');
if ($attempts !== null) {
Assertion::min($attempts, self::MIN_ATTEMPTS, 'SecurityPolicy::attempts');
Assertion::max($attempts, self::MAX_ATTEMPTS, 'SecurityPolicy::attempts');
}
if ($blockingDuration !== null) {
Assertion::min($blockingDuration, self::MIN_BLOCKING_DURATION, 'SecurityPolicy::blockingDuration');
Assertion::max($blockingDuration, self::MAX_BLOCKING_DURATION, 'SecurityPolicy::blockingDuration');
}
if ($passwordExpirationDelay !== null) {
Assertion::min(
$passwordExpirationDelay,
self::MIN_PASSWORD_EXPIRATION_DELAY,
'SecurityPolicy::passwordExpirationDelay'
);
Assertion::max(
$passwordExpirationDelay,
self::MAX_PASSWORD_EXPIRATION_DELAY,
'SecurityPolicy::passwordExpirationDelay'
);
}
if ($delayBeforeNewPassword !== null) {
Assertion::min(
$delayBeforeNewPassword,
self::MIN_NEW_PASSWORD_DELAY,
'SecurityPolicy::delayBeforeNewPassword'
);
Assertion::max(
$delayBeforeNewPassword,
self::MAX_NEW_PASSWORD_DELAY,
'SecurityPolicy::delayBeforeNewPassword'
);
}
}
/**
* @return int
*/
public function getPasswordMinimumLength(): int
{
return $this->passwordMinimumLength;
}
/**
* @param int $passwordMinimumLength
*
* @return self
*/
public function setPasswordMinimumLength(int $passwordMinimumLength): self
{
$this->passwordMinimumLength = $passwordMinimumLength;
return $this;
}
/**
* @return bool
*/
public function hasUppercase(): bool
{
return $this->hasUppercase;
}
/**
* @param bool $hasUppercase
*
* @return self
*/
public function setUppercase(bool $hasUppercase): self
{
$this->hasUppercase = $hasUppercase;
return $this;
}
/**
* @return bool
*/
public function hasLowercase(): bool
{
return $this->hasLowercase;
}
/**
* @param bool $hasLowercase
*
* @return self
*/
public function setLowercase(bool $hasLowercase): self
{
$this->hasLowercase = $hasLowercase;
return $this;
}
/**
* @return bool
*/
public function hasNumber(): bool
{
return $this->hasNumber;
}
/**
* @param bool $hasNumber
*
* @return self
*/
public function setNumber(bool $hasNumber): self
{
$this->hasNumber = $hasNumber;
return $this;
}
/**
* @return bool
*/
public function hasSpecialCharacter(): bool
{
return $this->hasSpecialCharacter;
}
/**
* @param bool $hasSpecialCharacter
*
* @return self
*/
public function setSpecialCharacter(bool $hasSpecialCharacter): self
{
$this->hasSpecialCharacter = $hasSpecialCharacter;
return $this;
}
/**
* @return bool
*/
public function canReusePasswords(): bool
{
return $this->canReusePasswords;
}
/**
* @param bool $canReusePasswords
*
* @return self
*/
public function setReusePassword(bool $canReusePasswords): self
{
$this->canReusePasswords = $canReusePasswords;
return $this;
}
/**
* @return int|null
*/
public function getAttempts(): ?int
{
return $this->attempts;
}
/**
* @param int|null $attempts
*
* @return self
*/
public function setAttempts(?int $attempts): self
{
$this->attempts = $attempts;
return $this;
}
/**
* @return int|null
*/
public function getBlockingDuration(): ?int
{
return $this->blockingDuration;
}
/**
* @param int|null $blockingDuration
*
* @return self
*/
public function setBlockingDuration(?int $blockingDuration): self
{
$this->blockingDuration = $blockingDuration;
return $this;
}
/**
* @return int|null
*/
public function getPasswordExpirationDelay(): ?int
{
return $this->passwordExpirationDelay;
}
/**
* @param int|null $passwordExpirationDelay
*
* @return self
*/
public function setPasswordExpirationDelay(?int $passwordExpirationDelay): self
{
$this->passwordExpirationDelay = $passwordExpirationDelay;
return $this;
}
/**
* @return string[]
*/
public function getPasswordExpirationExcludedUserAliases(): array
{
return $this->passwordExpirationExcludedUserAliases;
}
/**
* @param string[] $passwordExpirationExcludedUserAliases
*
* @return self
*/
public function setPasswordExpirationExcludedUserAliases(array $passwordExpirationExcludedUserAliases): self
{
$this->passwordExpirationExcludedUserAliases = $passwordExpirationExcludedUserAliases;
return $this;
}
/**
* @return int|null
*/
public function getDelayBeforeNewPassword(): ?int
{
return $this->delayBeforeNewPassword;
}
/**
* @param int|null $delayBeforeNewPassword
*
* @return self
*/
public function setDelayBeforeNewPassword(?int $delayBeforeNewPassword): self
{
$this->delayBeforeNewPassword = $delayBeforeNewPassword;
return $this;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/Configuration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Local/Model/Configuration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Local\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
class Configuration extends \Core\Security\ProviderConfiguration\Domain\Model\Configuration implements ProviderConfigurationInterface
{
/**
* @return CustomConfiguration
*/
public function getCustomConfiguration(): CustomConfiguration
{
return $this->customConfiguration instanceof CustomConfiguration
? $this->customConfiguration
: throw ConfigurationException::unexpectedCustomConfiguration(($this->customConfiguration)::class);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/SAMLCustomConfigurationInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/SAMLCustomConfigurationInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SAML\Model;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
interface SAMLCustomConfigurationInterface
{
/**
* @return AuthorizationRule[]
*/
public function getAuthorizationRules(): array;
public function isAutoImportEnabled(): bool;
public function getContactTemplate(): ?ContactTemplate;
public function getEmailBindAttribute(): ?string;
public function getUserNameBindAttribute(): ?string;
public function getContactGroup(): ?ContactGroup;
public function getAuthenticationConditions(): AuthenticationConditions;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/CustomConfiguration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/CustomConfiguration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SAML\Model;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\SAML\Exception\MissingLogoutUrlException;
final class CustomConfiguration implements CustomConfigurationInterface, SAMLCustomConfigurationInterface
{
public const LOGOUT_FROM_CENTREON = false;
public const LOGOUT_FROM_CENTREON_AND_IDP = true;
/** @var array<AuthorizationRule> */
private array $authorizationRules = [];
private bool $isAutoImportEnabled = false;
private ?ContactTemplate $contactTemplate = null;
private ?string $emailBindAttribute = null;
private ?string $userNameBindAttribute = null;
private ?ContactGroup $contactGroup = null;
private ACLConditions $aclConditions;
private AuthenticationConditions $authenticationConditions;
private GroupsMapping $groupsMapping;
private string $remoteLoginUrl = '';
private string $entityIdUrl = '';
private ?string $publicCertificate = '';
private string $userIdAttribute = '';
private bool $requestedAuthnContext = false;
private RequestedAuthnContextComparisonEnum $requestedAuthnContextComparison;
private bool $logoutFrom = true;
private ?string $logoutFromUrl = null;
private function __construct()
{
}
/**
* @param array<string,mixed> $values
*
* @throws ConfigurationException|MissingLogoutUrlException
*/
public static function createFromValues(array $values): self
{
$customConfiguration = new self();
if (isset($values['is_active']) && $values['is_active']) {
$customConfiguration->validateMandatoryFields($values);
}
$customConfiguration->setEntityIDUrl($values['entity_id_url']);
$customConfiguration->setRemoteLoginUrl($values['remote_login_url']);
$customConfiguration->setPublicCertificate($values['certificate']);
$customConfiguration->setLogoutFrom($values['logout_from']);
if (isset($values['is_forced']) && $values['is_forced'] === true) {
$customConfiguration->setLogoutFrom(self::LOGOUT_FROM_CENTREON_AND_IDP);
}
$customConfiguration->setLogoutFromUrl($values['logout_from_url']);
$customConfiguration->setUserIdAttribute($values['user_id_attribute']);
$customConfiguration->setRequestedAuthnContext($values['requested_authn_context'] ?? false);
$customConfiguration->setRequestedAuthnContextComparison(
RequestedAuthnContextComparisonEnum::tryFrom($values['requested_authn_context_comparison'])
?? throw ConfigurationException::invalidRequestedAuthnContextComparison($values['requested_authn_context_comparison'])
);
$customConfiguration->setAutoImportEnabled($values['auto_import']);
$customConfiguration->setUserNameBindAttribute($values['fullname_bind_attribute']);
$customConfiguration->setEmailBindAttribute($values['email_bind_attribute']);
$customConfiguration->setContactTemplate($values['contact_template']);
$customConfiguration->setAuthenticationConditions($values['authentication_conditions']);
$customConfiguration->setACLConditions($values['roles_mapping']);
$customConfiguration->setGroupsMapping($values['groups_mapping']);
return $customConfiguration;
}
public function getRemoteLoginUrl(): string
{
return $this->remoteLoginUrl;
}
public function setRemoteLoginUrl(string $value): void
{
$this->remoteLoginUrl = $value;
}
public function getEntityIDUrl(): string
{
return $this->entityIdUrl;
}
public function setEntityIDUrl(string $value): void
{
$this->entityIdUrl = $value;
}
public function getPublicCertificate(): ?string
{
return $this->publicCertificate;
}
public function setPublicCertificate(?string $value): void
{
$this->publicCertificate = $value;
}
public function getUserIdAttribute(): string
{
return $this->userIdAttribute;
}
public function setUserIdAttribute(string $value): void
{
$this->userIdAttribute = $value;
}
public function hasRequestedAuthnContext(): bool
{
return $this->requestedAuthnContext;
}
public function setRequestedAuthnContext(bool $requestedAuthnContext): void
{
$this->requestedAuthnContext = $requestedAuthnContext;
}
public function getRequestedAuthnContextComparison(): RequestedAuthnContextComparisonEnum
{
return $this->requestedAuthnContextComparison;
}
public function setRequestedAuthnContextComparison(RequestedAuthnContextComparisonEnum $value): void
{
$this->requestedAuthnContextComparison = $value;
}
public function getLogoutFrom(): bool
{
return $this->logoutFrom;
}
public function setLogoutFrom(bool $value): void
{
$this->logoutFrom = $value;
}
public function getLogoutFromUrl(): ?string
{
return $this->logoutFromUrl;
}
public function setLogoutFromUrl(?string $value): void
{
$this->logoutFromUrl = $value;
}
/**
* @return AuthorizationRule[]
*/
public function getAuthorizationRules(): array
{
return $this->authorizationRules;
}
public function isAutoImportEnabled(): bool
{
return $this->isAutoImportEnabled;
}
public function getContactTemplate(): ?ContactTemplate
{
return $this->contactTemplate;
}
public function getEmailBindAttribute(): ?string
{
return $this->emailBindAttribute;
}
public function setEmailBindAttribute(?string $value): void
{
$this->emailBindAttribute = $value;
}
public function getUserNameBindAttribute(): ?string
{
return $this->userNameBindAttribute;
}
public function setUserNameBindAttribute(?string $value): void
{
$this->userNameBindAttribute = $value;
}
public function getContactGroup(): ?ContactGroup
{
return $this->contactGroup;
}
public function getACLConditions(): ACLConditions
{
return $this->aclConditions;
}
public function setAutoImportEnabled(bool $isAutoImportEnabled): self
{
$this->isAutoImportEnabled = $isAutoImportEnabled;
return $this;
}
public function setContactTemplate(?ContactTemplate $contactTemplate): self
{
$this->contactTemplate = $contactTemplate;
return $this;
}
/**
* @param AuthorizationRule[] $authorizationRules
*/
public function setAuthorizationRules(array $authorizationRules): self
{
$this->authorizationRules = [];
foreach ($authorizationRules as $authorizationRule) {
$this->addAuthorizationRule($authorizationRule);
}
return $this;
}
public function addAuthorizationRule(AuthorizationRule $authorizationRule): self
{
$this->authorizationRules[] = $authorizationRule;
return $this;
}
public function setContactGroup(?ContactGroup $contactGroup): self
{
$this->contactGroup = $contactGroup;
return $this;
}
public function setAuthenticationConditions(AuthenticationConditions $authenticationConditions): self
{
$this->authenticationConditions = $authenticationConditions;
return $this;
}
public function getAuthenticationConditions(): AuthenticationConditions
{
return $this->authenticationConditions;
}
public function setGroupsMapping(GroupsMapping $groupsMapping): self
{
$this->groupsMapping = $groupsMapping;
return $this;
}
public function getGroupsMapping(): GroupsMapping
{
return $this->groupsMapping;
}
private function setACLConditions(ACLConditions $aclConditions): self
{
$this->aclConditions = $aclConditions;
return $this;
}
/**
* @param array<string,mixed> $json
*
* @throws ConfigurationException|MissingLogoutUrlException
*/
private function validateMandatoryFields(array $json): void
{
$mandatoryFields = [
'is_active',
'is_forced',
'remote_login_url',
'certificate',
'user_id_attribute',
'requested_authn_context',
'logout_from',
];
$emptyParameters = [];
foreach ($mandatoryFields as $key) {
if (! array_key_exists($key, $json)) {
$emptyParameters[] = $key;
}
}
if ($emptyParameters !== []) {
throw ConfigurationException::missingMandatoryParameters($emptyParameters);
}
if ($json['auto_import'] === true) {
$this->validateParametersForAutoImport(
$json['contact_template'],
$json['email_bind_attribute'],
$json['fullname_bind_attribute']
);
}
if (
($json['logout_from'] === true || (isset($json['is_forced']) && $json['is_forced'] === true))
&& empty($json['logout_from_url'])
) {
throw MissingLogoutUrlException::create();
}
$this->validateRequestedAuthnContextConfiguration($json);
}
/**
* @throws ConfigurationException
*/
private function validateParametersForAutoImport(
?ContactTemplate $contactTemplate,
?string $emailBindAttribute,
?string $userNameBindAttribute,
): void {
$missingMandatoryParameters = [];
if ($contactTemplate === null) {
$missingMandatoryParameters[] = 'contact_template';
}
if (empty($emailBindAttribute)) {
$missingMandatoryParameters[] = 'email_bind_attribute';
}
if (empty($userNameBindAttribute)) {
$missingMandatoryParameters[] = 'fullname_bind_attribute';
}
if ($missingMandatoryParameters !== []) {
throw ConfigurationException::missingAutoImportMandatoryParameters(
$missingMandatoryParameters
);
}
}
/**
* @param array<string,mixed> $json
*
* @throws ConfigurationException
*/
private function validateRequestedAuthnContextConfiguration(array $json): void
{
if (isset($json['requested_authn_context']) && $json['requested_authn_context'] === true) {
if (! isset($json['requested_authn_context_comparison'])) {
throw ConfigurationException::missingRequestedAuthnContextComparison();
}
if (RequestedAuthnContextComparisonEnum::tryFrom($json['requested_authn_context_comparison']) === null) {
throw ConfigurationException::invalidRequestedAuthnContextComparison(
$json['requested_authn_context_comparison']
);
}
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/Configuration.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/Configuration.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SAML\Model;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Security\Domain\Authentication\Interfaces\ProviderConfigurationInterface;
final class Configuration extends \Core\Security\ProviderConfiguration\Domain\Model\Configuration implements ProviderConfigurationInterface
{
/**
* @throws ConfigurationException
*/
public function getCustomConfiguration(): CustomConfiguration
{
return $this->customConfiguration instanceof CustomConfiguration
? $this->customConfiguration
: throw ConfigurationException::unexpectedCustomConfiguration(($this->customConfiguration)::class);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/RequestedAuthnContextComparisonEnum.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Model/RequestedAuthnContextComparisonEnum.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SAML\Model;
enum RequestedAuthnContextComparisonEnum: string
{
case MINIMUM = 'minimum';
case EXACT = 'exact';
case BETTER = 'better';
case MAXIMUM = 'maximum';
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Exception/MissingLogoutUrlException.php | centreon/src/Core/Security/ProviderConfiguration/Domain/SAML/Exception/MissingLogoutUrlException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\SAML\Exception;
class MissingLogoutUrlException extends \DomainException
{
public static function create(): self
{
return new self('Logout URL parameter is missing', 400);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Domain/Repository/ReadAttributePathRepositoryInterface.php | centreon/src/Core/Security/ProviderConfiguration/Domain/Repository/ReadAttributePathRepositoryInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Domain\Repository;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
/**
* Use this interface to implement the concrete repository class.
* This interface is used on each fetchers to get information returned by the method getdata()
* Data retrieval is, at the moment, processed only through http.
*/
interface ReadAttributePathRepositoryInterface
{
/**
* @param string $url
* @param string $token
* @param Configuration $configuration
* @param string $endpointType
*
* @return array<mixed>
*/
public function getData(string $url, string $token, Configuration $configuration, string $endpointType): array;
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Logger/LoginLogger.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Logger/LoginLogger.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Logger;
use CentreonUserLog;
use Core\Security\ProviderConfiguration\Domain\LoginLoggerInterface;
use Pimple\Container;
class LoginLogger implements LoginLoggerInterface
{
/** @var CentreonUserLog */
private CentreonUserLog $logger;
/**
* @param Container $container
*/
public function __construct(Container $container)
{
$pearDB = $container['configuration_db'];
$this->logger = new CentreonUserLog(-1, $pearDB);
}
/**
* @inheritDoc
*/
public function debug(string $scope, string $message, array $content = []): void
{
$this->logger->insertLog(
CentreonUserLog::TYPE_LOGIN,
"[{$scope}] [DEBUG] {$message} " . json_encode($content)
);
}
/**
* @inheritDoc
*/
public function info(string $scope, string $message, array $content = []): void
{
$this->logger->insertLog(
CentreonUserLog::TYPE_LOGIN,
"[{$scope}] [INFO] {$message} " . json_encode($content)
);
}
/**
* @inheritDoc
*/
public function error(string $scope, string $message, array $content = []): void
{
if (array_key_exists('error', $content)) {
$this->logger->insertLog(
CentreonUserLog::TYPE_LOGIN,
"[{$scope}] [Error] {$message}" . json_encode($content)
);
}
}
/**
* @inheritDoc
*/
public function exception(string $scope, string $message, \Exception $exception): void
{
$this->logger->insertLog(
CentreonUserLog::TYPE_LOGIN,
sprintf(
"[{$scope}] [ERROR] {$message}",
$exception::class,
$exception->getMessage()
)
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Api\UpdateWebSSOConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\WebSSO\UseCase\UpdateWebSSOConfiguration\{
UpdateWebSSOConfigurationPresenterInterface as PresenterInterface
};
class UpdateWebSSOConfigurationPresenter extends AbstractPresenter implements PresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Api\UpdateWebSSOConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Centreon\Domain\Log\LoggerTrait;
use Core\Security\ProviderConfiguration\Application\WebSSO\UseCase\UpdateWebSSOConfiguration\{
UpdateWebSSOConfiguration,
UpdateWebSSOConfigurationPresenterInterface,
UpdateWebSSOConfigurationRequest
};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class UpdateWebSSOConfigurationController extends AbstractController
{
use LoggerTrait;
/**
* @param UpdateWebSSOConfiguration $useCase
* @param Request $request
* @param UpdateWebSSOConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
UpdateWebSSOConfiguration $useCase,
Request $request,
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);
$useCase($presenter, $updateWebSSOConfigurationRequest);
return $presenter->show();
}
/**
* @param Request $request
*
* @return UpdateWebSSOConfigurationRequest
*/
private function createUpdateWebSSOConfigurationRequest(Request $request): UpdateWebSSOConfigurationRequest
{
$requestData = json_decode((string) $request->getContent(), true);
$updateWebSSOConfigurationRequest = new UpdateWebSSOConfigurationRequest();
$updateWebSSOConfigurationRequest->isActive = $requestData['is_active'];
$updateWebSSOConfigurationRequest->isForced = $requestData['is_forced'];
$updateWebSSOConfigurationRequest->trustedClientAddresses = $requestData['trusted_client_addresses'];
$updateWebSSOConfigurationRequest->blacklistClientAddresses = $requestData['blacklist_client_addresses'];
$updateWebSSOConfigurationRequest->loginHeaderAttribute = $requestData['login_header_attribute'];
$updateWebSSOConfigurationRequest->patternMatchingLogin = $requestData['pattern_matching_login'];
$updateWebSSOConfigurationRequest->patternReplaceLogin = $requestData['pattern_replace_login'];
return $updateWebSSOConfigurationRequest;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Api\FindWebSSOConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\WebSSO\UseCase\FindWebSSOConfiguration\{
FindWebSSOConfiguration,
FindWebSSOConfigurationPresenterInterface
};
use Symfony\Component\HttpFoundation\Response;
final class FindWebSSOConfigurationController extends AbstractController
{
/**
* @param FindWebSSOConfiguration $useCase
* @param FindWebSSOConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
FindWebSSOConfiguration $useCase,
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();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Api/FindWebSSOConfiguration/FindWebSSOConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Api\FindWebSSOConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\WebSSO\UseCase\FindWebSSOConfiguration\{
FindWebSSOConfigurationPresenterInterface,
FindWebSSOConfigurationResponse
};
class FindWebSSOConfigurationPresenter extends AbstractPresenter implements FindWebSSOConfigurationPresenterInterface
{
/**
* {@inheritDoc}
*
* @param FindWebSSOConfigurationResponse $data
*/
public function present(mixed $data): void
{
$presenterResponse = [
'is_active' => $data->isActive,
'is_forced' => $data->isForced,
'trusted_client_addresses' => $data->trustedClientAddresses,
'blacklist_client_addresses' => $data->blacklistClientAddresses,
'login_header_attribute' => $data->loginHeaderAttribute,
'pattern_matching_login' => $data->patternMatchingLogin,
'pattern_replace_login' => $data->patternReplaceLogin,
];
parent::present($presenterResponse);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbWriteWebSSOConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbWriteWebSSOConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Repository;
use Centreon\Domain\Log\LoggerTrait;
use Centreon\Infrastructure\DatabaseConnection;
use Centreon\Infrastructure\Repository\AbstractRepositoryDRB;
use Core\Security\ProviderConfiguration\Application\WebSSO\Repository\WriteWebSSOConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration;
class DbWriteWebSSOConfigurationRepository extends AbstractRepositoryDRB implements WriteWebSSOConfigurationRepositoryInterface
{
use LoggerTrait;
/**
* @param DatabaseConnection $db
*/
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}
/**
* @inheritDoc
*/
public function updateConfiguration(WebSSOConfiguration $configuration): void
{
$this->info('Updating WebSSO Provider in DBMS');
$statement = $this->db->prepare(
$this->translateDbName(
"UPDATE `:db`.`provider_configuration` SET
`custom_configuration` = :customConfiguration, `is_active` = :isActive, `is_forced` = :isForced
WHERE `name`='web-sso'"
)
);
$statement->bindValue(
':customConfiguration',
json_encode($this->buildCustomConfigurationFromWebSSOConfiguration($configuration)),
\PDO::PARAM_STR
);
$statement->bindValue(':isActive', $configuration->isActive() ? '1' : '0', \PDO::PARAM_STR);
$statement->bindValue(':isForced', $configuration->isForced() ? '1' : '0', \PDO::PARAM_STR);
$statement->execute();
}
/**
* @param WebSSOConfiguration $configuration
*
* @return array<string,mixed>
*/
private function buildCustomConfigurationFromWebSSOConfiguration(WebSSOConfiguration $configuration): array
{
return [
'trusted_client_addresses' => $configuration->getTrustedClientAddresses(),
'blacklist_client_addresses' => $configuration->getBlacklistClientAddresses(),
'login_header_attribute' => $configuration->getLoginHeaderAttribute(),
'pattern_matching_login' => $configuration->getPatternMatchingLogin(),
'pattern_replace_login' => $configuration->getPatternReplaceLogin(),
];
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbReadWebSSOConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbReadWebSSOConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Repository;
use Centreon\Infrastructure\DatabaseConnection;
use Centreon\Infrastructure\Repository\AbstractRepositoryDRB;
use Core\Security\ProviderConfiguration\Application\WebSSO\Repository\{
ReadWebSSOConfigurationRepositoryInterface as ReadRepositoryInterface
};
use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration;
class DbReadWebSSOConfigurationRepository extends AbstractRepositoryDRB implements ReadRepositoryInterface
{
/**
* @param DatabaseConnection $db
*/
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}
/**
* @inheritDoc
*/
public function findConfiguration(): ?WebSSOConfiguration
{
$statement = $this->db->query(
$this->translateDbName(
"SELECT * FROM `:db`.provider_configuration WHERE name='web-sso'"
)
);
$configuration = null;
if ($statement !== false && $result = $statement->fetch(\PDO::FETCH_ASSOC)) {
$this->validateJsonRecord($result['custom_configuration'], __DIR__ . '/CustomConfigurationSchema.json');
$customConfiguration = json_decode($result['custom_configuration'], true);
$configuration = DbWebSSOConfigurationFactory::createFromRecord($customConfiguration, $result);
}
return $configuration;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbWebSSOConfigurationFactory.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/WebSSO/Repository/DbWebSSOConfigurationFactory.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\WebSSO\Repository;
use Centreon\Domain\Common\Assertion\AssertionException;
use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration;
class DbWebSSOConfigurationFactory
{
/**
* @param array<string,mixed> $customConfiguration
* @param array<string,mixed> $configuration
*
* @throws AssertionException
*
* @return WebSSOConfiguration
*/
public static function createFromRecord(array $customConfiguration, array $configuration): WebSSOConfiguration
{
$webSSOConfiguration = new WebSSOConfiguration(
$configuration['is_active'] === 1,
$configuration['is_forced'] === 1,
$customConfiguration['trusted_client_addresses'],
$customConfiguration['blacklist_client_addresses'],
$customConfiguration['login_header_attribute'],
$customConfiguration['pattern_matching_login'],
$customConfiguration['pattern_replace_login']
);
$webSSOConfiguration->setId((int) $configuration['id']);
return $webSSOConfiguration;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Api\FindProviderConfigurations;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\ResponseStatusInterface;
use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\{
FindProviderConfigurationsPresenterInterface, FindProviderConfigurationsResponse, ProviderConfigurationDto};
class FindProviderConfigurationsPresenter extends AbstractPresenter implements FindProviderConfigurationsPresenterInterface
{
/**
* @inheritDoc
*/
public function presentResponse(ResponseStatusInterface|FindProviderConfigurationsResponse $data): void
{
if ($data instanceof ResponseStatusInterface) {
if ($data instanceof ErrorResponse && ! is_null($data->getException())) {
ExceptionLogger::create()->log($data->getException());
}
$this->setResponseStatus($data);
return;
}
$this->present(array_map(
fn (ProviderConfigurationDto $dto): array => [
'id' => $dto->id,
'type' => $dto->type,
'name' => $dto->name,
'authentication_uri' => $dto->authenticationUri,
'is_active' => $dto->isActive,
'is_forced' => $dto->isForced,
],
$data->providerConfigurations
));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/FindProviderConfigurationsController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Api\FindProviderConfigurations;
use Centreon\Application\Controller\AbstractController;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\{
FindProviderConfigurationsPresenterInterface
};
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\FindProviderConfigurations;
final class FindProviderConfigurationsController extends AbstractController
{
/**
* @param FindProviderConfigurations $findProviderConfigurations
* @param FindProviderConfigurationsPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
FindProviderConfigurations $findProviderConfigurations,
FindProviderConfigurationsPresenterInterface $presenter,
): object {
$findProviderConfigurations($presenter);
return $presenter->show();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/OpenIdProviderDtoFactory.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/OpenIdProviderDtoFactory.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Api\FindProviderConfigurations\Factory;
use Core\Common\Application\Repository\ReadVaultRepositoryInterface;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDto;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDtoFactoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\OpenIdConfigurationException;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration;
use Core\Security\Vault\Application\Repository\ReadVaultConfigurationRepositoryInterface;
use Core\Security\Vault\Domain\Model\VaultConfiguration;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class OpenIdProviderDtoFactory implements ProviderConfigurationDtoFactoryInterface
{
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly ReadVaultConfigurationRepositoryInterface $readVaultConfigurationRepository,
private readonly ReadVaultRepositoryInterface $readVaultRepository,
) {
}
/**
* @inheritDoc
*/
public function supports(string $type): bool
{
return $type === Provider::OPENID;
}
/**
* @inheritDoc
*/
public function createResponse(Configuration $configuration): ProviderConfigurationDto
{
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
$dto = new ProviderConfigurationDto();
$dto->id = $configuration->getId();
$dto->type = $configuration->getType();
$dto->name = $configuration->getName();
$dto->authenticationUri = $this->buildAuthenticationUri($customConfiguration);
$dto->isActive = $configuration->isActive();
$dto->isForced = $configuration->isForced();
return $dto;
}
/**
* @param CustomConfiguration $customConfiguration
*
* @throws OpenIdConfigurationException
* @throws \Throwable
*
* @return string
*/
private function buildAuthenticationUri(CustomConfiguration $customConfiguration): string
{
$redirectUri = $customConfiguration->getRedirectUrl() !== null
? $customConfiguration->getRedirectUrl() . $this->urlGenerator->generate(
'centreon_security_authentication_login_openid',
[],
UrlGeneratorInterface::ABSOLUTE_PATH
)
: $this->urlGenerator->generate(
'centreon_security_authentication_login_openid',
[],
UrlGeneratorInterface::ABSOLUTE_URL
);
if (
$customConfiguration->getBaseUrl() === null
|| $customConfiguration->getClientId() === null
|| $customConfiguration->getAuthorizationEndpoint() === null
) {
return '';
}
if (
$this->readVaultConfigurationRepository->exists()
&& str_starts_with($customConfiguration->getClientId(), VaultConfiguration::VAULT_PATH_PATTERN)
) {
$openIDCredentialsFromVault = $this->readVaultRepository->findFromPath($customConfiguration->getClientId());
if (! array_key_exists(VaultConfiguration::OPENID_CLIENT_ID_KEY, $openIDCredentialsFromVault)) {
throw OpenIdConfigurationException::unableToRetrieveCredentialFromVault(
VaultConfiguration::OPENID_CLIENT_ID_KEY
);
}
$customConfiguration->setClientId($openIDCredentialsFromVault[VaultConfiguration::OPENID_CLIENT_ID_KEY]);
}
$authenticationUriParts = [
'client_id' => $customConfiguration->getClientId(),
'response_type' => 'code',
'redirect_uri' => rtrim($redirectUri, '/'),
'state' => uniqid(),
];
$authorizationEndpointBase = parse_url(
$customConfiguration->getAuthorizationEndpoint(),
PHP_URL_PATH
);
$authorizationEndpointParts = parse_url(
$customConfiguration->getAuthorizationEndpoint(),
PHP_URL_QUERY
);
if ($authorizationEndpointBase === false || $authorizationEndpointParts === false) {
throw new \ValueError(_('Unable to parse authorization url'));
}
$queryParams = http_build_query($authenticationUriParts);
if ($authorizationEndpointParts !== null) {
$queryParams .= '&' . $authorizationEndpointParts;
}
return $customConfiguration->getBaseUrl() . '/'
. ltrim($authorizationEndpointBase ?? '', '/')
. '?' . $queryParams
. (
! empty($customConfiguration->getConnectionScopes())
? '&scope=' . implode('%20', $customConfiguration->getConnectionScopes())
: ''
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/SamlProviderDtoFactory.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/SamlProviderDtoFactory.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Api\FindProviderConfigurations\Factory;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDto;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDtoFactoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class SamlProviderDtoFactory implements ProviderConfigurationDtoFactoryInterface
{
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
}
/**
* @inheritDoc
*/
public function supports(string $type): bool
{
return $type === Provider::SAML;
}
/**
* @inheritDoc
*/
public function createResponse(Configuration $configuration): ProviderConfigurationDto
{
$dto = new ProviderConfigurationDto();
$dto->id = $configuration->getId();
$dto->type = $configuration->getType();
$dto->name = $configuration->getName();
$dto->authenticationUri = $this->urlGenerator->generate(
'centreon_application_authentication_login_saml',
[],
UrlGeneratorInterface::ABSOLUTE_URL
);
$dto->isActive = $configuration->isActive();
$dto->isForced = $configuration->isForced();
return $dto;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/LocalProviderDtoFactory.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Api/FindProviderConfigurations/Factory/LocalProviderDtoFactory.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Api\FindProviderConfigurations\Factory;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDto;
use Core\Security\ProviderConfiguration\Application\UseCase\FindProviderConfigurations\ProviderConfigurationDtoFactoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class LocalProviderDtoFactory implements ProviderConfigurationDtoFactoryInterface
{
public function __construct(private readonly UrlGeneratorInterface $urlGenerator)
{
}
/**
* @inheritDoc
*/
public function supports(string $type): bool
{
return $type === Provider::LOCAL;
}
/**
* @inheritDoc
*/
public function createResponse(Configuration $configuration): ProviderConfigurationDto
{
$dto = new ProviderConfigurationDto();
$dto->id = $configuration->getId();
$dto->type = $configuration->getType();
$dto->name = $configuration->getName();
$dto->authenticationUri = $this->urlGenerator->generate(
'centreon_security_authentication_login',
['providerName' => Provider::LOCAL]
);
$dto->isActive = $configuration->isActive();
$dto->isForced = $configuration->isForced();
return $dto;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\PartialUpdateOpenIdConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\PartialUpdateOpenIdConfiguration\{
PartialUpdateOpenIdConfiguration,
PartialUpdateOpenIdConfigurationPresenterInterface,
PartialUpdateOpenIdConfigurationRequest
};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class PartialUpdateOpenIdConfigurationController extends AbstractController
{
/**
* @param PartialUpdateOpenIdConfiguration $useCase
* @param Request $request
* @param PartialUpdateOpenIdConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
PartialUpdateOpenIdConfiguration $useCase,
Request $request,
PartialUpdateOpenIdConfigurationPresenterInterface $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__ . '/PartialUpdateOpenIdConfigurationSchema.json');
$updateOpenIdConfigurationRequest = $this->createPartialUpdateOpenIdConfigurationRequest($request);
$useCase($presenter, $updateOpenIdConfigurationRequest);
return $presenter->show();
}
/**
* @param Request $request
*
* @return PartialUpdateOpenIdConfigurationRequest
*/
private function createPartialUpdateOpenIdConfigurationRequest(Request $request): PartialUpdateOpenIdConfigurationRequest
{
$json = (string) $request->getContent();
/**
* @var array{
* is_active?:bool,
* is_forced?:bool,
* base_url?:string|null,
* authorization_endpoint?:string|null,
* token_endpoint?:string|null,
* introspection_token_endpoint?:string|null,
* userinfo_endpoint?:string|null,
* endsession_endpoint?:string|null,
* connection_scopes?:string[],
* login_claim?:string|null,
* client_id?:string|null,
* client_secret?:string|null,
* authentication_type?:string|null,
* verify_peer?:bool,
* auto_import?:bool,
* contact_template?:array{id:int,name:string}|null,
* email_bind_attribute?:string|null,
* fullname_bind_attribute?:string|null,
* redirect_url?:string|null,
* authentication_conditions?:array{
* is_enabled?:bool,
* attribute_path?:string,
* authorized_values?:string[],
* trusted_client_addresses?:string[],
* blacklist_client_addresses?:string[],
* endpoint?:array{type:string,custom_endpoint:string|null}
* },
* roles_mapping?:array{
* is_enabled?:bool,
* apply_only_first_role?:bool,
* attribute_path?:string,
* endpoint?:array{type:string,custom_endpoint:string|null},
* relations?:array<array{claim_value:string,access_group_id:int,priority:int}>
* },
* groups_mapping?:array{
* is_enabled?:bool,
* attribute_path?:string,
* endpoint?:array{type:string,custom_endpoint:string|null},
* relations?:array<array{group_value:string,contact_group_id:int}>
* }
* } $requestData
*/
$requestData = json_decode($json, true);
$updateOpenIdConfigurationRequest = new PartialUpdateOpenIdConfigurationRequest();
if (array_key_exists('is_active', $requestData)) {
$updateOpenIdConfigurationRequest->isActive = $requestData['is_active'];
}
if (array_key_exists('is_forced', $requestData)) {
$updateOpenIdConfigurationRequest->isForced = $requestData['is_forced'];
}
if (array_key_exists('base_url', $requestData)) {
$updateOpenIdConfigurationRequest->baseUrl = $requestData['base_url'];
}
if (array_key_exists('authorization_endpoint', $requestData)) {
$updateOpenIdConfigurationRequest->authorizationEndpoint = $requestData['authorization_endpoint'];
}
if (array_key_exists('token_endpoint', $requestData)) {
$updateOpenIdConfigurationRequest->tokenEndpoint = $requestData['token_endpoint'];
}
if (array_key_exists('introspection_token_endpoint', $requestData)) {
$updateOpenIdConfigurationRequest->introspectionTokenEndpoint = $requestData['introspection_token_endpoint'];
}
if (array_key_exists('userinfo_endpoint', $requestData)) {
$updateOpenIdConfigurationRequest->userInformationEndpoint = $requestData['userinfo_endpoint'];
}
if (array_key_exists('endsession_endpoint', $requestData)) {
$updateOpenIdConfigurationRequest->endSessionEndpoint = $requestData['endsession_endpoint'];
}
if (array_key_exists('connection_scopes', $requestData)) {
$updateOpenIdConfigurationRequest->connectionScopes = $requestData['connection_scopes'];
}
if (array_key_exists('login_claim', $requestData)) {
$updateOpenIdConfigurationRequest->loginClaim = $requestData['login_claim'];
}
if (array_key_exists('client_id', $requestData)) {
$updateOpenIdConfigurationRequest->clientId = $requestData['client_id'];
}
if (array_key_exists('client_secret', $requestData)) {
$updateOpenIdConfigurationRequest->clientSecret = $requestData['client_secret'];
}
if (array_key_exists('authentication_type', $requestData)) {
$updateOpenIdConfigurationRequest->authenticationType = $requestData['authentication_type'];
}
if (array_key_exists('verify_peer', $requestData)) {
$updateOpenIdConfigurationRequest->verifyPeer = $requestData['verify_peer'];
}
if (array_key_exists('auto_import', $requestData)) {
$updateOpenIdConfigurationRequest->isAutoImportEnabled = $requestData['auto_import'];
}
if (array_key_exists('contact_template', $requestData)) {
$updateOpenIdConfigurationRequest->contactTemplate = $requestData['contact_template'];
}
if (array_key_exists('email_bind_attribute', $requestData)) {
$updateOpenIdConfigurationRequest->emailBindAttribute = $requestData['email_bind_attribute'];
}
if (array_key_exists('fullname_bind_attribute', $requestData)) {
$updateOpenIdConfigurationRequest->userNameBindAttribute = $requestData['fullname_bind_attribute'];
}
if (array_key_exists('redirect_url', $requestData)) {
$updateOpenIdConfigurationRequest->redirectUrl = $requestData['redirect_url'];
}
if (array_key_exists('authentication_conditions', $requestData)) {
if (array_key_exists('is_enabled', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['is_enabled']
= $requestData['authentication_conditions']['is_enabled'];
}
if (array_key_exists('attribute_path', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['attribute_path']
= $requestData['authentication_conditions']['attribute_path'];
}
if (array_key_exists('authorized_values', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['authorized_values']
= $requestData['authentication_conditions']['authorized_values'];
}
if (array_key_exists('trusted_client_addresses', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['trusted_client_addresses']
= $requestData['authentication_conditions']['trusted_client_addresses'];
}
if (array_key_exists('blacklist_client_addresses', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['blacklist_client_addresses']
= $requestData['authentication_conditions']['blacklist_client_addresses'];
}
if (array_key_exists('endpoint', $requestData['authentication_conditions'])) {
$updateOpenIdConfigurationRequest->authenticationConditions['endpoint']
= $requestData['authentication_conditions']['endpoint'];
}
}
if (array_key_exists('roles_mapping', $requestData)) {
if (array_key_exists('is_enabled', $requestData['roles_mapping'])) {
$updateOpenIdConfigurationRequest->rolesMapping['is_enabled']
= $requestData['roles_mapping']['is_enabled'];
}
if (array_key_exists('apply_only_first_role', $requestData['roles_mapping'])) {
$updateOpenIdConfigurationRequest->rolesMapping['apply_only_first_role']
= $requestData['roles_mapping']['apply_only_first_role'];
}
if (array_key_exists('attribute_path', $requestData['roles_mapping'])) {
$updateOpenIdConfigurationRequest->rolesMapping['attribute_path']
= $requestData['roles_mapping']['attribute_path'];
}
if (array_key_exists('endpoint', $requestData['roles_mapping'])) {
$updateOpenIdConfigurationRequest->rolesMapping['endpoint']
= $requestData['roles_mapping']['endpoint'];
}
if (array_key_exists('relations', $requestData['roles_mapping'])) {
$updateOpenIdConfigurationRequest->rolesMapping['relations']
= $requestData['roles_mapping']['relations'];
}
}
if (array_key_exists('groups_mapping', $requestData)) {
if (array_key_exists('is_enabled', $requestData['groups_mapping'])) {
$updateOpenIdConfigurationRequest->groupsMapping['is_enabled']
= $requestData['groups_mapping']['is_enabled'];
}
if (array_key_exists('attribute_path', $requestData['groups_mapping'])) {
$updateOpenIdConfigurationRequest->groupsMapping['attribute_path']
= $requestData['groups_mapping']['attribute_path'];
}
if (array_key_exists('endpoint', $requestData['groups_mapping'])) {
$updateOpenIdConfigurationRequest->groupsMapping['endpoint']
= $requestData['groups_mapping']['endpoint'];
}
if (array_key_exists('relations', $requestData['groups_mapping'])) {
$updateOpenIdConfigurationRequest->groupsMapping['relations']
= $requestData['groups_mapping']['relations'];
}
}
return $updateOpenIdConfigurationRequest;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\PartialUpdateOpenIdConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\PartialUpdateOpenIdConfiguration\{
PartialUpdateOpenIdConfigurationPresenterInterface as PresenterInterface
};
class PartialUpdateOpenIdConfigurationPresenter extends AbstractPresenter implements PresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\FindOpenIdConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\FindOpenIdConfiguration\{
FindOpenIdConfiguration,
FindOpenIdConfigurationPresenterInterface
};
use Symfony\Component\HttpFoundation\Response;
final class FindOpenIdConfigurationController extends AbstractController
{
/**
* @param FindOpenIdConfiguration $useCase
* @param FindOpenIdConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
FindOpenIdConfiguration $useCase,
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();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/FindOpenIdConfiguration/FindOpenIdConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\FindOpenIdConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\FindOpenIdConfiguration\{
FindOpenIdConfigurationPresenterInterface,
FindOpenIdConfigurationResponse
};
class FindOpenIdConfigurationPresenter extends AbstractPresenter implements FindOpenIdConfigurationPresenterInterface
{
/**
* {@inheritDoc}
*
* @param FindOpenIdConfigurationResponse $data
*/
public function present(mixed $data): void
{
$presenterResponse = [
'is_active' => $data->isActive,
'is_forced' => $data->isForced,
'base_url' => $data->baseUrl,
'authorization_endpoint' => $data->authorizationEndpoint,
'token_endpoint' => $data->tokenEndpoint,
'introspection_token_endpoint' => $data->introspectionTokenEndpoint,
'userinfo_endpoint' => $data->userInformationEndpoint,
'endsession_endpoint' => $data->endSessionEndpoint,
'connection_scopes' => $data->connectionScopes,
'login_claim' => $data->loginClaim,
'client_id' => $data->clientId,
'client_secret' => $data->clientSecret,
'authentication_type' => $data->authenticationType,
'verify_peer' => $data->verifyPeer,
'auto_import' => $data->isAutoImportEnabled,
'contact_template' => $data->contactTemplate,
'email_bind_attribute' => $data->emailBindAttribute,
'fullname_bind_attribute' => $data->userNameBindAttribute,
'roles_mapping' => $data->aclConditions,
'authentication_conditions' => $data->authenticationConditions,
'groups_mapping' => $data->groupsMapping,
'redirect_url' => $data->redirectUrl,
];
parent::present($presenterResponse);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\UpdateOpenIdConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\UpdateOpenIdConfiguration\{
UpdateOpenIdConfigurationPresenterInterface as PresenterInterface
};
class UpdateOpenIdConfigurationPresenter extends AbstractPresenter implements PresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Api/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Api\UpdateOpenIdConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\OpenId\UseCase\UpdateOpenIdConfiguration\{
UpdateOpenIdConfiguration,
UpdateOpenIdConfigurationPresenterInterface,
UpdateOpenIdConfigurationRequest
};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class UpdateOpenIdConfigurationController extends AbstractController
{
/**
* @param UpdateOpenIdConfiguration $useCase
* @param Request $request
* @param UpdateOpenIdConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
UpdateOpenIdConfiguration $useCase,
Request $request,
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);
return $presenter->show();
}
/**
* @param Request $request
*
* @return UpdateOpenIdConfigurationRequest
*/
private function createUpdateOpenIdConfigurationRequest(Request $request): UpdateOpenIdConfigurationRequest
{
$json = (string) $request->getContent();
$requestData = json_decode($json, true);
$updateOpenIdConfigurationRequest = new UpdateOpenIdConfigurationRequest();
$updateOpenIdConfigurationRequest->isActive = $requestData['is_active'];
$updateOpenIdConfigurationRequest->isForced = $requestData['is_forced'];
$updateOpenIdConfigurationRequest->baseUrl = $requestData['base_url'];
$updateOpenIdConfigurationRequest->authorizationEndpoint = $requestData['authorization_endpoint'];
$updateOpenIdConfigurationRequest->tokenEndpoint = $requestData['token_endpoint'];
$updateOpenIdConfigurationRequest->introspectionTokenEndpoint = $requestData['introspection_token_endpoint'];
$updateOpenIdConfigurationRequest->userInformationEndpoint = $requestData['userinfo_endpoint'];
$updateOpenIdConfigurationRequest->endSessionEndpoint = $requestData['endsession_endpoint'];
$updateOpenIdConfigurationRequest->connectionScopes = $requestData['connection_scopes'];
$updateOpenIdConfigurationRequest->loginClaim = $requestData['login_claim'];
$updateOpenIdConfigurationRequest->clientId = $requestData['client_id'];
$updateOpenIdConfigurationRequest->clientSecret = $requestData['client_secret'];
$updateOpenIdConfigurationRequest->authenticationType = $requestData['authentication_type'];
$updateOpenIdConfigurationRequest->verifyPeer = $requestData['verify_peer'];
$updateOpenIdConfigurationRequest->isAutoImportEnabled = $requestData['auto_import'];
$updateOpenIdConfigurationRequest->contactTemplate = $requestData['contact_template'];
$updateOpenIdConfigurationRequest->emailBindAttribute = $requestData['email_bind_attribute'];
$updateOpenIdConfigurationRequest->userNameBindAttribute = $requestData['fullname_bind_attribute'];
$updateOpenIdConfigurationRequest->rolesMapping = $requestData['roles_mapping'];
$updateOpenIdConfigurationRequest->authenticationConditions = $requestData['authentication_conditions'];
$updateOpenIdConfigurationRequest->groupsMapping = $requestData['groups_mapping'];
$updateOpenIdConfigurationRequest->redirectUrl = $requestData['redirect_url'];
return $updateOpenIdConfigurationRequest;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Repository/DbReadOpenIdConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Repository/DbReadOpenIdConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Repository;
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\Exception\ConnectionException;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
use Adaptation\Database\QueryBuilder\Exception\QueryBuilderException;
use Assert\AssertionFailedException;
use Core\Common\Domain\Exception\CollectionException;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Common\Domain\Exception\ValueObjectException;
use Core\Common\Infrastructure\Repository\DatabaseRepository;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Contact\Infrastructure\Repository\DbContactGroupFactory;
use Core\Contact\Infrastructure\Repository\DbContactTemplateFactory;
use Core\Security\AccessGroup\Infrastructure\Repository\DbAccessGroupFactory;
use Core\Security\ProviderConfiguration\Application\OpenId\Repository\ReadOpenIdConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
/**
* @phpstan-import-type _AccessGroupRecord from DbAccessGroupFactory
*/
class DbReadOpenIdConfigurationRepository extends DatabaseRepository implements ReadOpenIdConfigurationRepositoryInterface
{
/**
* @inheritDoc
*/
public function findOneContactTemplate(int $contactTemplateId): ?ContactTemplate
{
try {
$query = $this->connection->createQueryBuilder()
->select('contact_id', 'contact_name')
->from('`:db`.contact')
->where('contact_id = :contactTemplateId')
->andWhere('contact_register = :contactRegister')
->getQuery();
$queryParameters = QueryParameters::create([
QueryParameter::int('contactTemplateId', $contactTemplateId),
QueryParameter::int('contactRegister', 0),
]);
$entry = $this->connection->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact template from database for OpenID configuration: ' . $e->getMessage(),
context: ['contactTemplateId' => $contactTemplateId],
previous: $e
);
}
return $entry !== false ? DbContactTemplateFactory::createFromRecord($entry) : null;
}
/**
* @inheritDoc
*/
public function findOneContactGroup(int $contactGroupId): ?ContactGroup
{
try {
$query = $this->connection->createQueryBuilder()
->select('cg_id', 'cg_name', 'cg_alias', 'cg_comment', 'cg_activate', 'cg_type')
->from('`:db`.contactgroup')
->where('cg_id = :contactGroupId')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::int('contactGroupId', $contactGroupId)]);
$entry = $this->connection->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact group from database for OpenID configuration: ' . $e->getMessage(),
context: ['contactGroupId' => $contactGroupId],
previous: $e
);
}
try {
/** @var array{
* cg_id: int,
* cg_name: string,
* cg_alias: string,
* cg_comment?: string,
* cg_activate: string,
* cg_type: string
* }|false $entry
*/
return $entry !== false ? DbContactGroupFactory::createFromRecord($entry) : null;
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Contact group record is invalid for OpenID configuration: ' . $e->getMessage(),
context: ['contact_group_id' => $contactGroupId, 'record' => $entry],
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function findAuthorizationRulesByConfigurationId(int $providerConfigurationId): array
{
$query = <<<'SQL'
SELECT * from security_provider_access_group_relation spagn
INNER JOIN acl_groups ON acl_group_id = spagn.access_group_id
WHERE spagn.provider_configuration_id = :providerConfigurationId
ORDER BY spagn.priority ASC
SQL;
try {
$queryParameters = QueryParameters::create([QueryParameter::int('providerConfigurationId', $providerConfigurationId)]);
$entries = $this->connection->fetchAllAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch authorization rules from database for OpenID configuration: ' . $e->getMessage(),
context: ['providerConfigurationId' => $providerConfigurationId],
previous: $e
);
}
$authorizationRules = [];
foreach ($entries as $entry) {
try {
/** @var _AccessGroupRecord $entry */
$accessGroup = DbAccessGroupFactory::createFromRecord($entry);
$authorizationRules[] = new AuthorizationRule($entry['claim_value'], $accessGroup, $entry['priority']);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Access group record is invalid for OpenID configuration: ' . $e->getMessage(),
context: ['record' => $entry, 'provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
}
return $authorizationRules;
}
/**
* @inheritDoc
*/
public function findContactGroupRelationsByConfigurationId(int $providerConfigurationId): array
{
$query = <<<'SQL'
SELECT *
FROM `:db`.security_provider_contact_group_relation spcgn
INNER JOIN `:db`.contactgroup
ON cg_id = spcgn.contact_group_id
WHERE spcgn.provider_configuration_id = :providerConfigurationId
SQL;
try {
$queryParameters = QueryParameters::create([QueryParameter::int('providerConfigurationId', $providerConfigurationId)]);
$entries = $this->connection->fetchAllAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact group relations from database for OpenID configuration: ' . $e->getMessage(),
context: ['providerConfigurationId' => $providerConfigurationId],
previous: $e
);
}
$contactGroupRelations = [];
foreach ($entries as $entry) {
try {
/** @var array{
* cg_id: int,
* cg_name: string,
* cg_alias: string,
* cg_comment?: string,
* cg_activate: string,
* cg_type: string,
* claim_value: string
* } $entry
*/
$contactGroup = DbContactGroupFactory::createFromRecord($entry);
$contactGroupRelations[] = new ContactGroupRelation($entry['claim_value'], $contactGroup);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Contact group record is invalid for OpenID configuration: ' . $e->getMessage(),
context: ['record' => $entry, 'provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
}
return $contactGroupRelations;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Repository/DbWriteOpenIdConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/OpenId/Repository/DbWriteOpenIdConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\OpenId\Repository;
use Centreon\Domain\Log\LoggerTrait;
use Centreon\Infrastructure\DatabaseConnection;
use Centreon\Infrastructure\Repository\AbstractRepositoryDRB;
use Core\Security\ProviderConfiguration\Application\OpenId\Repository\WriteOpenIdConfigurationRepositoryInterface as WriteRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration;
/**
* @phpstan-import-type _EndpointArray from \Core\Security\ProviderConfiguration\Domain\Model\Endpoint
*/
class DbWriteOpenIdConfigurationRepository extends AbstractRepositoryDRB implements WriteRepositoryInterface
{
use LoggerTrait;
/**
* @param DatabaseConnection $db
*/
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}
/**
* @inheritDoc
*/
public function updateConfiguration(Configuration $configuration): void
{
$isAlreadyInTransaction = $this->db->inTransaction();
try {
if (! $isAlreadyInTransaction) {
$this->db->beginTransaction();
$this->debug('Start transaction');
}
$this->info('Updating OpenID Provider in DBMS');
$statement = $this->db->prepare(
$this->translateDbName(
"UPDATE `:db`.`provider_configuration` SET
`custom_configuration` = :customConfiguration, `is_active` = :isActive, `is_forced` = :isForced
WHERE `name`='openid'"
)
);
$statement->bindValue(
':customConfiguration',
json_encode($this->buildCustomConfigurationFromOpenIdConfiguration($configuration))
);
$statement->bindValue(':isActive', $configuration->isActive() ? '1' : '0');
$statement->bindValue(':isForced', $configuration->isForced() ? '1' : '0');
$statement->execute();
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
$authorizationRules = $customConfiguration->getACLConditions()->getRelations();
$this->info('Removing existing authorization rules');
$this->deleteAuthorizationRules();
$this->info('Inserting new authorization rules');
$this->insertAuthorizationRules($authorizationRules);
$contactGroupRelations = $customConfiguration->getGroupsMapping()->getContactGroupRelations();
$this->info('Removing existing group mappings');
$this->deleteContactGroupRelations();
$this->info('Inserting new group mappings');
$this->insertContactGroupRelations($contactGroupRelations);
if (! $isAlreadyInTransaction) {
$this->db->commit();
$this->debug('Commit transaction');
}
} catch (\Throwable $ex) {
$this->debug('update openId configuration error');
if (! $isAlreadyInTransaction) {
$this->debug('Roll back transaction');
$this->db->rollBack();
throw $ex;
}
}
}
/**
* @inheritDoc
*/
public function deleteAuthorizationRules(): void
{
$statement = $this->db->query("SELECT id FROM provider_configuration WHERE name='openid'");
if ($statement !== false && ($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) {
/** @var array{id:int} $result */
$providerConfigurationId = (int) $result['id'];
$deleteStatement = $this->db->prepare(
'DELETE FROM security_provider_access_group_relation
WHERE provider_configuration_id = :providerConfigurationId'
);
$deleteStatement->bindValue(':providerConfigurationId', $providerConfigurationId, \PDO::PARAM_INT);
$deleteStatement->execute();
}
}
/**
* @inheritDoc
*/
public function insertAuthorizationRules(array $authorizationRules): void
{
$statement = $this->db->query("SELECT id FROM provider_configuration WHERE name='openid'");
if ($statement !== false && ($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) {
/** @var array{id:int} $result */
$providerConfigurationId = (int) $result['id'];
$insertStatement = $this->db->prepare(
'INSERT INTO security_provider_access_group_relation
(claim_value, access_group_id, provider_configuration_id, priority)
VALUES (:claimValue, :accessGroupId, :providerConfigurationId, :priority)'
);
foreach ($authorizationRules as $authorizationRule) {
$insertStatement->bindValue(':claimValue', $authorizationRule->getClaimValue());
$insertStatement->bindValue(
':accessGroupId',
$authorizationRule->getAccessGroup()->getId(),
\PDO::PARAM_INT
);
$insertStatement->bindValue(
':providerConfigurationId',
$providerConfigurationId,
\PDO::PARAM_INT
);
$insertStatement->bindValue(
':priority',
$authorizationRule->getPriority(),
\PDO::PARAM_INT
);
$insertStatement->execute();
}
}
}
/**
* Format OpenIdConfiguration for custom_configuration.
*
* @param Configuration $configuration
*
* @return array<string, mixed>
*/
private function buildCustomConfigurationFromOpenIdConfiguration(Configuration $configuration): array
{
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
return [
'is_active' => $configuration->isActive(),
'is_forced' => $configuration->isForced(),
'base_url' => $customConfiguration->getBaseUrl(),
'authorization_endpoint' => $customConfiguration->getAuthorizationEndpoint(),
'token_endpoint' => $customConfiguration->getTokenEndpoint(),
'introspection_token_endpoint' => $customConfiguration->getIntrospectionTokenEndpoint(),
'userinfo_endpoint' => $customConfiguration->getUserInformationEndpoint(),
'endsession_endpoint' => $customConfiguration->getEndSessionEndpoint(),
'connection_scopes' => $customConfiguration->getConnectionScopes(),
'login_claim' => $customConfiguration->getLoginClaim(),
'client_id' => $customConfiguration->getClientId(),
'client_secret' => $customConfiguration->getClientSecret(),
'authentication_type' => $customConfiguration->getAuthenticationType(),
'verify_peer' => $customConfiguration->verifyPeer(),
'auto_import' => $customConfiguration->isAutoImportEnabled(),
'contact_template_id' => $customConfiguration->getContactTemplate()?->getId(),
'email_bind_attribute' => $customConfiguration->getEmailBindAttribute(),
'fullname_bind_attribute' => $customConfiguration->getUserNameBindAttribute(),
'roles_mapping' => $this->aclConditionsToArray($customConfiguration->getACLConditions()),
'authentication_conditions' => $this->authenticationConditionsToArray(
$customConfiguration->getAuthenticationConditions()
),
'groups_mapping' => $this->groupsMappingToArray(
$customConfiguration->getGroupsMapping()
),
'redirect_url' => $customConfiguration->getRedirectUrl(),
];
}
/**
* Delete Contact Group relations.
*/
private function deleteContactGroupRelations(): void
{
$statement = $this->db->query("SELECT id FROM provider_configuration WHERE name='openid'");
if ($statement !== false && ($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) {
/** @var array{id:int} $result */
$providerConfigurationId = (int) $result['id'];
$deleteStatement = $this->db->prepare(
'DELETE FROM security_provider_contact_group_relation
WHERE provider_configuration_id = :providerConfigurationId'
);
$deleteStatement->bindValue(':providerConfigurationId', $providerConfigurationId, \PDO::PARAM_INT);
$deleteStatement->execute();
}
}
/**
* Insert Contact Group Relations.
*
* @param ContactGroupRelation[] $contactGroupRelations
*/
private function insertContactGroupRelations(array $contactGroupRelations): void
{
$statement = $this->db->query("SELECT id FROM provider_configuration WHERE name='openid'");
if ($statement !== false && ($result = $statement->fetch(\PDO::FETCH_ASSOC)) !== false) {
/** @var array{id:int} $result */
$providerConfigurationId = (int) $result['id'];
$insertStatement = $this->db->prepare(
'INSERT INTO security_provider_contact_group_relation
(claim_value, contact_group_id, provider_configuration_id)
VALUES (:claimValue, :contactGroupId, :providerConfigurationId)'
);
foreach ($contactGroupRelations as $contactGroupRelation) {
$insertStatement->bindValue(':claimValue', $contactGroupRelation->getClaimValue());
$insertStatement->bindValue(
':contactGroupId',
$contactGroupRelation->getContactGroup()->getId(),
\PDO::PARAM_INT
);
$insertStatement->bindValue(
':providerConfigurationId',
$providerConfigurationId,
\PDO::PARAM_INT
);
$insertStatement->execute();
}
}
}
/**
* @param AuthenticationConditions $authenticationConditions
*
* @return array{
* is_enabled: bool,
* attribute_path: string,
* endpoint: _EndpointArray|null,
* authorized_values: array<string>,
* trusted_client_addresses: array<string>,
* blacklist_client_addresses: array<string>,
* }
*/
private function authenticationConditionsToArray(AuthenticationConditions $authenticationConditions): array
{
return [
'is_enabled' => $authenticationConditions->isEnabled(),
'attribute_path' => $authenticationConditions->getAttributePath(),
'endpoint' => $authenticationConditions->getEndpoint()?->toArray(),
'authorized_values' => $authenticationConditions->getAuthorizedValues(),
'trusted_client_addresses' => $authenticationConditions->getTrustedClientAddresses(),
'blacklist_client_addresses' => $authenticationConditions->getBlacklistClientAddresses(),
];
}
/**
* @param GroupsMapping $groupsMapping
*
* @return array{
* is_enabled: bool,
* attribute_path: string,
* endpoint: _EndpointArray|null,
* }
*/
private function groupsMappingToArray(GroupsMapping $groupsMapping): array
{
return [
'is_enabled' => $groupsMapping->isEnabled(),
'attribute_path' => $groupsMapping->getAttributePath(),
'endpoint' => $groupsMapping->getEndpoint()?->toArray(),
];
}
/**
* @param ACLConditions $aclConditions
*
* @return array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* endpoint: _EndpointArray|null,
* }
*/
private function aclConditionsToArray(ACLConditions $aclConditions): array
{
return [
'is_enabled' => $aclConditions->isEnabled(),
'apply_only_first_role' => $aclConditions->onlyFirstRoleIsApplied(),
'attribute_path' => $aclConditions->getAttributePath(),
'endpoint' => $aclConditions->getEndpoint()?->toArray(),
];
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Api\FindConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\FindConfiguration\FindConfigurationPresenterInterface;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\FindConfiguration\FindConfigurationResponse;
class FindConfigurationPresenter extends AbstractPresenter implements FindConfigurationPresenterInterface
{
/**
* {@inheritDoc}
*
* @param FindConfigurationResponse $data
*/
public function present(mixed $data): void
{
$presenterResponse = [
'password_security_policy' => [
'password_min_length' => $data->passwordMinimumLength,
'has_uppercase' => $data->hasUppercase,
'has_lowercase' => $data->hasLowercase,
'has_number' => $data->hasNumber,
'has_special_character' => $data->hasSpecialCharacter,
'attempts' => $data->attempts,
'blocking_duration' => $data->blockingDuration,
'password_expiration' => [
'expiration_delay' => $data->passwordExpirationDelay,
'excluded_users' => $data->passwordExpirationExcludedUserAliases,
],
'can_reuse_passwords' => $data->canReusePasswords,
'delay_before_new_password' => $data->delayBeforeNewPassword,
],
];
parent::present($presenterResponse);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/FindConfiguration/FindConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Api\FindConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\FindConfiguration\FindConfiguration;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\FindConfiguration\FindConfigurationPresenterInterface;
use Symfony\Component\HttpFoundation\Response;
final class FindConfigurationController extends AbstractController
{
/**
* @param FindConfiguration $useCase
* @param FindConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
FindConfiguration $useCase,
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);
return $presenter->show();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/Exception/ConfigurationException.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/Exception/ConfigurationException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Api\Exception;
class ConfigurationException extends \Exception
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/UpdateConfiguration/UpdateConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/UpdateConfiguration/UpdateConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Api\UpdateConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration\{
UpdateConfigurationPresenterInterface
};
use Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration\UpdateConfiguration;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration\UpdateConfigurationRequest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class UpdateConfigurationController extends AbstractController
{
/**
* @param UpdateConfiguration $useCase
* @param Request $request
* @param UpdateConfigurationPresenterInterface $presenter
*
* @return object
*/
public function __invoke(
UpdateConfiguration $useCase,
Request $request,
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);
return $presenter->show();
}
/**
* Create a DTO from HTTP Request or throw an exception if the body is incorrect.
*
* @param Request $request
*
* @return UpdateConfigurationRequest
*/
private function createUpdateConfigurationRequest(
Request $request,
): UpdateConfigurationRequest {
$jsonBody = (string) $request->getContent();
$requestData = json_decode($jsonBody, true);
$passwordPolicy = $requestData['password_security_policy'];
$updateRequest = new UpdateConfigurationRequest();
$updateRequest->passwordMinimumLength = $passwordPolicy['password_min_length'];
$updateRequest->hasUppercase = $passwordPolicy['has_uppercase'];
$updateRequest->hasLowercase = $passwordPolicy['has_lowercase'];
$updateRequest->hasNumber = $passwordPolicy['has_number'];
$updateRequest->hasSpecialCharacter = $passwordPolicy['has_special_character'];
$updateRequest->attempts = $passwordPolicy['attempts'];
$updateRequest->blockingDuration = $passwordPolicy['blocking_duration'];
$updateRequest->passwordExpirationDelay = $passwordPolicy['password_expiration']['expiration_delay'];
$updateRequest->passwordExpirationExcludedUserAliases
= $passwordPolicy['password_expiration']['excluded_users'];
$updateRequest->canReusePasswords = $passwordPolicy['can_reuse_passwords'];
$updateRequest->delayBeforeNewPassword = $passwordPolicy['delay_before_new_password'];
return $updateRequest;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/UpdateConfiguration/UpdateConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Api/UpdateConfiguration/UpdateConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Api\UpdateConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Security\ProviderConfiguration\Application\Local\UseCase\UpdateConfiguration\{
UpdateConfigurationPresenterInterface
};
class UpdateConfigurationPresenter extends AbstractPresenter implements UpdateConfigurationPresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Repository/ConfigurationException.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Repository/ConfigurationException.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Repository;
use Centreon\Domain\Repository\RepositoryException;
class ConfigurationException extends RepositoryException
{
/**
* @return self
*/
public static function errorWhileReadingConfiguration(): self
{
return new self(_('Error while reading local provider configuration'));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Repository/DbWriteConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Local/Repository/DbWriteConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Local\Repository;
use Centreon\Domain\Log\LoggerTrait;
use Centreon\Infrastructure\DatabaseConnection;
use Centreon\Infrastructure\Repository\AbstractRepositoryDRB;
use Core\Security\ProviderConfiguration\Application\Local\Repository\WriteConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Local\Model\CustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
class DbWriteConfigurationRepository extends AbstractRepositoryDRB implements WriteConfigurationRepositoryInterface
{
use LoggerTrait;
/**
* @param DatabaseConnection $db
*/
public function __construct(DatabaseConnection $db)
{
$this->db = $db;
}
/**
* @inheritDoc
*/
public function updateConfiguration(
Configuration $configuration,
array $excludedUserIds,
): void {
$beginInTransaction = $this->db->inTransaction();
try {
if ($beginInTransaction === false) {
$this->db->beginTransaction();
}
$this->updateCustomConfiguration($configuration);
$this->updateExcludedUsers($excludedUserIds);
if ($beginInTransaction === false && $this->db->inTransaction()) {
$this->db->commit();
}
} catch (\Exception $ex) {
$this->error($ex->getMessage(), ['trace' => $ex->getTraceAsString()]);
if ($beginInTransaction === false && $this->db->inTransaction()) {
$this->db->rollBack();
}
throw $ex;
}
}
/**
* Update custom configuration.
*
* @param Configuration $configuration
*/
private function updateCustomConfiguration(Configuration $configuration): void
{
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
$securityPolicy = $customConfiguration->getSecurityPolicy();
$configuration = json_encode([
'password_security_policy' => [
'password_length' => $securityPolicy->getPasswordMinimumLength(),
'has_uppercase_characters' => $securityPolicy->hasUppercase(),
'has_lowercase_characters' => $securityPolicy->hasLowercase(),
'has_numbers' => $securityPolicy->hasNumber(),
'has_special_characters' => $securityPolicy->hasSpecialCharacter(),
'attempts' => $securityPolicy->getAttempts(),
'blocking_duration' => $securityPolicy->getBlockingDuration(),
'password_expiration_delay' => $securityPolicy->getPasswordExpirationDelay(),
'delay_before_new_password' => $securityPolicy->getDelayBeforeNewPassword(),
'can_reuse_passwords' => $securityPolicy->canReusePasswords(),
],
]);
$statement = $this->db->prepare(
$this->translateDbName(
"UPDATE `:db`.`provider_configuration`
SET `custom_configuration` = :localProviderConfiguration
WHERE `name` = 'local'"
)
);
$statement->bindValue(':localProviderConfiguration', $configuration);
$statement->execute();
}
/**
* Update excluded users.
*
* @param int[] $excludedUserIds
*/
private function updateExcludedUsers(array $excludedUserIds): void
{
$this->deleteExcludedUsers();
$this->addExcludedUsers($excludedUserIds);
}
/**
* Delete excluded users.
*/
private function deleteExcludedUsers(): void
{
$statement = $this->db->prepare(
$this->translateDbName(
"DELETE pceu FROM `:db`.`password_expiration_excluded_users` pceu
INNER JOIN `:db`.`provider_configuration` pc ON pc.`id` = pceu.`provider_configuration_id`
AND pc.`name` = 'local'"
)
);
$statement->execute();
}
/**
* Add excluded users.
*
* @param int[] $excludedUserIds
*/
private function addExcludedUsers(array $excludedUserIds): void
{
if ($excludedUserIds === []) {
return;
}
$query = 'INSERT INTO `:db`.`password_expiration_excluded_users`
(`provider_configuration_id`, `user_id`) ';
$subQueries = [];
foreach ($excludedUserIds as $userId) {
$subQueries[] = "(SELECT pc.`id`, :user_{$userId} FROM `:db`.`provider_configuration` pc
WHERE pc.`name` = 'local')";
}
$query .= implode(' UNION ', $subQueries);
$statement = $this->db->prepare(
$this->translateDbName($query)
);
foreach ($excludedUserIds as $userId) {
$statement->bindValue(":user_{$userId}", $userId, \PDO::PARAM_INT);
}
$statement->execute();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/FindSAMLConfiguration/FindSAMLConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/FindSAMLConfiguration/FindSAMLConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Api\FindSAMLConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\ResponseStatusInterface;
use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger;
use Core\Security\ProviderConfiguration\Application\SAML\UseCase\FindSAMLConfiguration\{
FindSAMLConfigurationPresenterInterface,
FindSAMLConfigurationResponse
};
class FindSAMLConfigurationPresenter extends AbstractPresenter implements FindSAMLConfigurationPresenterInterface
{
public function presentResponse(FindSAMLConfigurationResponse|ResponseStatusInterface $response): void
{
if ($response instanceof ResponseStatusInterface) {
if ($response instanceof ErrorResponse && ! is_null($response->getException())) {
ExceptionLogger::create()->log($response->getException());
}
$this->setResponseStatus($response);
return;
}
$this->present([
'is_active' => $response->isActive,
'is_forced' => $response->isForced,
'entity_id_url' => $response->entityIdUrl,
'remote_login_url' => $response->remoteLoginUrl,
'certificate' => $response->publicCertificate,
'user_id_attribute' => $response->userIdAttribute,
'requested_authn_context' => $response->requestAuthnContext,
'requested_authn_context_comparison' => $response->requestedAuthnContextComparison->value,
'logout_from' => $response->logoutFrom,
'logout_from_url' => $response->logoutFromUrl,
'auto_import' => $response->isAutoImportEnabled,
'contact_template' => $response->contactTemplate,
'email_bind_attribute' => $response->emailBindAttribute,
'fullname_bind_attribute' => $response->userNameBindAttribute,
'roles_mapping' => $response->aclConditions,
'authentication_conditions' => $response->authenticationConditions,
'groups_mapping' => $response->groupsMapping,
]);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/FindSAMLConfiguration/FindSAMLConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/FindSAMLConfiguration/FindSAMLConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Api\FindSAMLConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Centreon\Domain\Log\Logger;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger;
use Core\Security\ProviderConfiguration\Application\SAML\UseCase\FindSAMLConfiguration\FindSAMLConfiguration;
use Symfony\Component\HttpFoundation\Response;
final class FindSAMLConfigurationController extends AbstractController
{
public function __invoke(
FindSAMLConfiguration $useCase,
FindSAMLConfigurationPresenter $presenter,
): object {
try {
/** @var Contact $contact */
$contact = $this->getUser();
} catch (\LogicException $e) {
ExceptionLogger::create()->log($e);
$presenter->setResponseStatus(
new ErrorResponse('User not found when trying to get SAML configuration')
);
return $presenter->show();
}
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
Logger::create()->warning(
'User does not have the rights to get SAML configuration',
['user_id' => $contact->getId()]
);
return $this->view(null, Response::HTTP_FORBIDDEN);
}
$useCase($presenter);
return $presenter->show();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/UpdateSAMLConfiguration/UpdateSAMLConfigurationPresenter.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/UpdateSAMLConfiguration/UpdateSAMLConfigurationPresenter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Api\UpdateSAMLConfiguration;
use Core\Application\Common\UseCase\AbstractPresenter;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\ResponseStatusInterface;
use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger;
use Core\Security\ProviderConfiguration\Application\SAML\UseCase\UpdateSAMLConfiguration\UpdateSAMLConfigurationPresenterInterface;
class UpdateSAMLConfigurationPresenter extends AbstractPresenter implements UpdateSAMLConfigurationPresenterInterface
{
public function presentResponse(ResponseStatusInterface $response): void
{
if ($response instanceof ErrorResponse && ! is_null($response->getException())) {
ExceptionLogger::create()->log($response->getException());
}
$this->setResponseStatus($response);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/UpdateSAMLConfiguration/UpdateSAMLConfigurationController.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Api/UpdateSAMLConfiguration/UpdateSAMLConfigurationController.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Api\UpdateSAMLConfiguration;
use Centreon\Application\Controller\AbstractController;
use Centreon\Domain\Contact\Contact;
use Centreon\Domain\Log\Logger;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Application\Common\UseCase\InvalidArgumentResponse;
use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger;
use Core\Security\ProviderConfiguration\Application\SAML\UseCase\UpdateSAMLConfiguration\{UpdateSAMLConfiguration,
UpdateSAMLConfigurationRequest};
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class UpdateSAMLConfigurationController extends AbstractController
{
public function __invoke(
UpdateSAMLConfiguration $useCase,
Request $request,
UpdateSAMLConfigurationPresenter $presenter,
): object {
try {
/** @var Contact $contact */
$contact = $this->getUser();
} catch (\LogicException $e) {
ExceptionLogger::create()->log($e);
$presenter->setResponseStatus(
new ErrorResponse('User not found when trying to update SAML configuration.')
);
return $presenter->show();
}
if (! $contact->hasTopologyRole(Contact::ROLE_ADMINISTRATION_AUTHENTICATION_READ_WRITE)) {
Logger::create()->warning(
'User does not have the rights to update SAML configuration.',
['user_id' => $contact->getId()]
);
return $this->view(null, Response::HTTP_FORBIDDEN);
}
try {
$this->validateDataSent($request, __DIR__ . '/UpdateSAMLConfigurationSchema.json');
$updateRequest = $this->createUpdateSAMLConfigurationRequest($request);
} catch (\InvalidArgumentException $e) {
$presenter->setResponseStatus(
new InvalidArgumentResponse($e->getMessage())
);
return $presenter->show();
} catch (\JsonException $e) {
ExceptionLogger::create()->log($e);
$presenter->setResponseStatus(
new ErrorResponse('Invalid JSON body when trying to update SAML configuration.')
);
return $presenter->show();
}
$useCase($presenter, $updateRequest);
return $presenter->show();
}
/**
* @throws \InvalidArgumentException|\JsonException
*/
private function createUpdateSAMLConfigurationRequest(Request $request): UpdateSAMLConfigurationRequest
{
$json = (string) $request->getContent();
$requestData = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
return new UpdateSAMLConfigurationRequest(
isActive: $requestData['is_active'],
isForced: $requestData['is_forced'],
remoteLoginUrl: $requestData['remote_login_url'],
entityIdUrl: $requestData['entity_id_url'],
publicCertificate: $requestData['certificate'] ?? null,
userIdAttribute: $requestData['user_id_attribute'],
requestedAuthnContext: $requestData['requested_authn_context'] ?? false,
requestedAuthnContextComparison: $requestData['requested_authn_context_comparison'],
logoutFrom: $requestData['logout_from'],
logoutFromUrl: $requestData['logout_from_url'] ?? null,
isAutoImportEnabled: $requestData['auto_import'] ?? false,
contactTemplate: $requestData['contact_template'] ?? null,
emailBindAttribute: $requestData['email_bind_attribute'] ?? null,
userNameBindAttribute: $requestData['fullname_bind_attribute'] ?? null,
rolesMapping: $requestData['roles_mapping'] ?? [],
authenticationConditions: $requestData['authentication_conditions'] ?? [],
groupsMapping: $requestData['groups_mapping'] ?? []
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Repository/DbWriteSAMLConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Repository/DbWriteSAMLConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Repository;
use Adaptation\Database\Connection\Collection\BatchInsertParameters;
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\Exception\ConnectionException;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
use Adaptation\Database\QueryBuilder\Exception\QueryBuilderException;
use Core\Common\Domain\Exception\CollectionException;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Common\Domain\Exception\ValueObjectException;
use Core\Common\Infrastructure\Repository\DatabaseRepository;
use Core\Security\ProviderConfiguration\Application\SAML\Repository\WriteSAMLConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration;
class DbWriteSAMLConfigurationRepository extends DatabaseRepository implements WriteSAMLConfigurationRepositoryInterface
{
/**
* @inheritDoc
*/
public function updateConfiguration(Configuration $configuration): void
{
try {
$customConfiguration = json_encode(
$this->buildCustomConfigurationFromSAMLConfiguration($configuration),
JSON_THROW_ON_ERROR
);
} catch (\JsonException $e) {
throw new RepositoryException(
message: 'Could not encode SAML custom configuration to JSON: ' . $e->getMessage(),
context: ['configuration' => $configuration],
previous: $e
);
}
try {
$query = $this->connection->createQueryBuilder()
->update('`:db`.`provider_configuration`')
->set('`custom_configuration`', ':customConfiguration')
->set('`is_active`', ':isActive')
->set('`is_forced`', ':isForced')
->where('`name` = :name')
->getQuery();
$queryParameters = QueryParameters::create(
[
QueryParameter::string('customConfiguration', $customConfiguration),
QueryParameter::bool('isActive', $configuration->isActive()),
QueryParameter::bool('isForced', $configuration->isForced()),
QueryParameter::string('name', Provider::SAML),
]
);
$this->connection->update($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not update SAML configuration: ' . $e->getMessage(),
context: ['configuration' => $configuration],
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function deleteAuthorizationRules(): void
{
try {
$query = $this->connection->createQueryBuilder()
->select('id')
->from('`:db`.`provider_configuration`')
->where('`name` = :name')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::string('name', Provider::SAML)]);
$providerConfigurationId = $this->connection->fetchOne($this->translateDbName($query), $queryParameters);
$query = $this->connection->createQueryBuilder()
->delete('`:db`.`security_provider_access_group_relation`')
->where('`provider_configuration_id` = :providerConfigurationId')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::int('providerConfigurationId', $providerConfigurationId)]);
$this->connection->delete($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not delete authorization rules for SAML configuration: ' . $e->getMessage(),
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function insertAuthorizationRules(array $authorizationRules): void
{
if ($authorizationRules === []) {
throw new RepositoryException(
message: 'No authorization rules to insert for SAML configuration.',
context: ['authorizationRules' => $authorizationRules]
);
}
try {
$query = $this->connection->createQueryBuilder()
->select('id')
->from('`:db`.`provider_configuration`')
->where('`name` = :name')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::string('name', Provider::SAML)]);
$providerConfigurationId = $this->connection->fetchOne($this->translateDbName($query), $queryParameters);
$batchInsertParameters = new BatchInsertParameters();
foreach ($authorizationRules as $index => $authorizationRule) {
$batchInsertParameters->add(
$index,
QueryParameters::create([
QueryParameter::string('claimValue', $authorizationRule->getClaimValue()),
QueryParameter::int('accessGroupId', $authorizationRule->getAccessGroup()->getId()),
QueryParameter::int('providerConfigurationId', $providerConfigurationId),
QueryParameter::int('priority', $authorizationRule->getPriority()),
])
);
}
$this->connection->batchInsert(
$this->translateDbName('`:db`.`security_provider_access_group_relation`'),
['claim_value', 'access_group_id', 'provider_configuration_id', 'priority'],
$batchInsertParameters
);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not insert authorization rules for SAML configuration: ' . $e->getMessage(),
context: ['authorizationRules' => $authorizationRules],
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function deleteContactGroupRelations(): void
{
try {
$query = $this->connection->createQueryBuilder()
->select('id')
->from('`:db`.`provider_configuration`')
->where('`name` = :name')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::string('name', Provider::SAML)]);
$providerConfigurationId = $this->connection->fetchOne($this->translateDbName($query), $queryParameters);
$query = $this->connection->createQueryBuilder()
->delete('`:db`.`security_provider_contact_group_relation`')
->where('`provider_configuration_id` = :providerConfigurationId')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::int('providerConfigurationId', $providerConfigurationId)]);
$this->connection->delete($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not delete contact group relations:' . $e->getMessage(),
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function insertContactGroupRelations(array $contactGroupRelations): void
{
if ($contactGroupRelations === []) {
throw new RepositoryException(
message: 'No contact group relations to insert for SAML configuration.',
context: ['contactGroupRelations' => $contactGroupRelations]
);
}
try {
$query = $this->connection->createQueryBuilder()
->select('id')
->from('`:db`.`provider_configuration`')
->where('`name` = :name')
->getQuery();
$queryParameters = QueryParameters::create([QueryParameter::string('name', Provider::SAML)]);
$providerConfigurationId = $this->connection->fetchOne($this->translateDbName($query), $queryParameters);
$batchInsertParameters = new BatchInsertParameters();
foreach ($contactGroupRelations as $index => $contactGroupRelation) {
$batchInsertParameters->add(
$index,
QueryParameters::create([
QueryParameter::string('claimValue', $contactGroupRelation->getClaimValue()),
QueryParameter::int('contactGroupId', $contactGroupRelation->getContactGroup()->getId()),
QueryParameter::int('providerConfigurationId', $providerConfigurationId),
])
);
}
$this->connection->batchInsert(
$this->translateDbName('`:db`.`security_provider_contact_group_relation`'),
['claim_value', 'contact_group_id', 'provider_configuration_id'],
$batchInsertParameters
);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not insert contact group relations for SAML configuration: ' . $e->getMessage(),
context: ['contactGroupRelations' => $contactGroupRelations],
previous: $e
);
}
}
/**
* Format SAMLConfiguration for custom_configuration.
*
* @param Configuration $configuration
*
* @return array<string, mixed>
*/
private function buildCustomConfigurationFromSAMLConfiguration(Configuration $configuration): array
{
/** @var CustomConfiguration $customConfiguration */
$customConfiguration = $configuration->getCustomConfiguration();
return [
'remote_login_url' => $customConfiguration->getRemoteLoginUrl(),
'entity_id_url' => $customConfiguration->getEntityIDUrl(),
'certificate' => $customConfiguration->getPublicCertificate(),
'user_id_attribute' => $customConfiguration->getUserIdAttribute(),
'requested_authn_context' => $customConfiguration->hasRequestedAuthnContext(),
'requested_authn_context_comparison' => $customConfiguration->getRequestedAuthnContextComparison()->value,
'logout_from' => $customConfiguration->getLogoutFrom(),
'logout_from_url' => $customConfiguration->getLogoutFromUrl(),
'auto_import' => $customConfiguration->isAutoImportEnabled(),
'contact_template_id' => $customConfiguration->getContactTemplate()?->getId(),
'email_bind_attribute' => $customConfiguration->getEmailBindAttribute(),
'fullname_bind_attribute' => $customConfiguration->getUserNameBindAttribute(),
'roles_mapping' => $this->aclConditionsToArray($customConfiguration->getACLConditions()),
'authentication_conditions' => $this->authenticationConditionsToArray(
$customConfiguration->getAuthenticationConditions()
),
'groups_mapping' => $this->groupsMappingToArray(
$customConfiguration->getGroupsMapping()
),
];
}
/**
* @param AuthenticationConditions $authenticationConditions
*
* @return array<string,array<string|null>|bool|string>
*/
private function authenticationConditionsToArray(AuthenticationConditions $authenticationConditions): array
{
$conditionsSettings = [
'is_enabled' => $authenticationConditions->isEnabled(),
'attribute_path' => $authenticationConditions->getAttributePath(),
'authorized_values' => $authenticationConditions->getAuthorizedValues(),
'trusted_client_addresses' => $authenticationConditions->getTrustedClientAddresses(),
'blacklist_client_addresses' => $authenticationConditions->getBlacklistClientAddresses(),
];
$endpoint = $authenticationConditions->getEndpoint();
if ($endpoint) {
$conditionsSettings['endpoint'] = $endpoint->toArray();
}
return $conditionsSettings;
}
/**
* @param GroupsMapping $groupsMapping
*
* @return array<string,bool|string|array<string,string|null>>
*/
private function groupsMappingToArray(GroupsMapping $groupsMapping): array
{
$groupsSettings = [
'is_enabled' => $groupsMapping->isEnabled(),
'attribute_path' => $groupsMapping->getAttributePath(),
];
$endpoint = $groupsMapping->getEndpoint();
if ($endpoint) {
$groupsSettings['endpoint'] = $endpoint->toArray();
}
return $groupsSettings;
}
/**
* @param ACLConditions $aclConditions
*
* @return array<string,bool|string|array<string,string|null>>
*/
private function aclConditionsToArray(ACLConditions $aclConditions): array
{
$rolesSettings = [
'is_enabled' => $aclConditions->isEnabled(),
'apply_only_first_role' => $aclConditions->onlyFirstRoleIsApplied(),
'attribute_path' => $aclConditions->getAttributePath(),
];
$endpoint = $aclConditions->getEndpoint();
if ($endpoint) {
$rolesSettings['endpoint'] = $endpoint->toArray();
}
return $rolesSettings;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Repository/DbReadSAMLConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/SAML/Repository/DbReadSAMLConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\SAML\Repository;
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\Exception\ConnectionException;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
use Adaptation\Database\QueryBuilder\Exception\QueryBuilderException;
use Assert\AssertionFailedException;
use Core\Common\Domain\Exception\CollectionException;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Common\Domain\Exception\ValueObjectException;
use Core\Common\Infrastructure\Repository\DatabaseRepository;
use Core\Contact\Domain\Model\ContactGroup;
use Core\Contact\Domain\Model\ContactTemplate;
use Core\Contact\Infrastructure\Repository\DbContactGroupFactory;
use Core\Contact\Infrastructure\Repository\DbContactTemplateFactory;
use Core\Security\AccessGroup\Infrastructure\Repository\DbAccessGroupFactory;
use Core\Security\ProviderConfiguration\Application\SAML\Repository\ReadSAMLConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule;
use Core\Security\ProviderConfiguration\Domain\Model\ContactGroupRelation;
/**
* @phpstan-import-type _AccessGroupRecord from DbAccessGroupFactory
*/
class DbReadSAMLConfigurationRepository extends DatabaseRepository implements ReadSAMLConfigurationRepositoryInterface
{
/**
* @inheritDoc
*/
public function findOneContactTemplate(int $contactTemplateId): ?ContactTemplate
{
try {
$query = $this->connection->createQueryBuilder()
->select('contact_id', 'contact_name')
->from('`:db`.contact')
->where('contact_id = :contactTemplateId')
->andWhere('contact_register = :contactRegister')
->getQuery();
$queryParameters = QueryParameters::create([
QueryParameter::int('contactTemplateId', $contactTemplateId),
QueryParameter::int('contactRegister', 0),
]);
$entry = $this->connection->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact template from database for SAML configuration: ' . $e->getMessage(),
context: ['contact_template_id' => $contactTemplateId],
previous: $e
);
}
return $entry !== false ? DbContactTemplateFactory::createFromRecord($entry) : null;
}
/**
* @inheritDoc
*/
public function findOneContactGroup(int $contactGroupId): ?ContactGroup
{
try {
$query = $this->connection->createQueryBuilder()
->select('cg_id', 'cg_name', 'cg_alias', 'cg_comment', 'cg_activate', 'cg_type')
->from('`:db`.contactgroup')
->where('cg_id = :contactGroupId')
->getQuery();
$queryParameters = QueryParameters::create([
QueryParameter::int('contactGroupId', $contactGroupId),
]);
$entry = $this->connection->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact group from database for SAML configuration: ' . $e->getMessage(),
context: ['contact_group_id' => $contactGroupId],
previous: $e
);
}
try {
/** @var array{
* cg_id: int,
* cg_name: string,
* cg_alias: string,
* cg_comment?: string,
* cg_activate: string,
* cg_type: string,
* claim_value: string
* }|false $entry
*/
return $entry !== false ? DbContactGroupFactory::createFromRecord($entry) : null;
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Contact group record is invalid for SAML configuration: ' . $e->getMessage(),
context: ['contact_group_id' => $contactGroupId, 'record' => $entry],
previous: $e
);
}
}
/**
* @inheritDoc
*/
public function findAuthorizationRulesByConfigurationId(int $providerConfigurationId): array
{
$query = <<<'SQL'
SELECT * from `:db`.security_provider_access_group_relation spagn
INNER JOIN `:db`.acl_groups ag
ON ag.acl_group_id = spagn.access_group_id
WHERE spagn.provider_configuration_id = :providerConfigurationId
ORDER BY spagn.priority asc
SQL;
try {
$queryParameters = QueryParameters::create([
QueryParameter::int('providerConfigurationId', $providerConfigurationId),
]);
$entries = $this->connection->fetchAllAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch authorization rules from database for SAML configuration: ' . $e->getMessage(),
context: ['provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
$authorizationRules = [];
foreach ($entries as $entry) {
try {
/** @var _AccessGroupRecord $entry */
$accessGroup = DbAccessGroupFactory::createFromRecord($entry);
$authorizationRules[] = new AuthorizationRule($entry['claim_value'], $accessGroup, $entry['priority']);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Access group record is invalid for SAML configuration: ' . $e->getMessage(),
context: ['record' => $entry, 'provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
}
return $authorizationRules;
}
/**
* @inheritDoc
*/
public function findContactGroupRelationsByConfigurationId(int $providerConfigurationId): array
{
$query = <<<'SQL'
SELECT *
FROM `:db`.security_provider_contact_group_relation spcgn
INNER JOIN `:db`.contactgroup
ON cg_id = spcgn.contact_group_id
WHERE spcgn.provider_configuration_id = :providerConfigurationId
SQL;
try {
$queryParameters = QueryParameters::create([
QueryParameter::int('providerConfigurationId', $providerConfigurationId),
]);
$entries = $this->connection->fetchAllAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch contact group relations from database for SAML configuration: ' . $e->getMessage(),
context: ['provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
$contactGroupRelations = [];
foreach ($entries as $entry) {
try {
/** @var array{
* cg_id: int,
* cg_name: string,
* cg_alias: string,
* cg_comment?: string,
* cg_activate: string,
* cg_type: string,
* claim_value: string
* } $entry
*/
$contactGroup = DbContactGroupFactory::createFromRecord($entry);
$contactGroupRelations[] = new ContactGroupRelation($entry['claim_value'], $contactGroup);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Contact group record is invalid for SAML configuration: ' . $e->getMessage(),
context: ['record' => $entry, 'provider_configuration_id' => $providerConfigurationId],
previous: $e
);
}
}
return $contactGroupRelations;
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Repository/HttpReadAttributePathRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Repository/HttpReadAttributePathRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Repository;
use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidContentException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidResponseException;
use Core\Security\ProviderConfiguration\Domain\Exception\Http\InvalidStatusCodeException;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\OpenIdCustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Repository\ReadAttributePathRepositoryInterface;
use Exception;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;
final class HttpReadAttributePathRepository implements ReadAttributePathRepositoryInterface
{
/**
* @param HttpClientInterface $client
*/
public function __construct(private readonly HttpClientInterface $client)
{
}
/**
* @param string $url
* @param string $token
* @param Configuration $configuration
* @param string $endpointType
*
* @throws ClientExceptionInterface
* @throws RedirectionExceptionInterface
* @throws SSOAuthenticationException
* @throws ServerExceptionInterface
* @throws TransportExceptionInterface
*
* @return array<mixed>
*/
public function getData(string $url, string $token, Configuration $configuration, string $endpointType): array
{
try {
$response = $this->getResponseOrFail($url, $token, $configuration, $endpointType);
$this->statusCodeIsValidOrFail($response);
return $this->getContentOrFail($response);
} catch (Exception $exception) {
throw $exception;
}
}
/**
* @param string $url
* @param string $token
* @param Configuration $configuration
* @param string $endpointType
*
* @throws SSOAuthenticationException
* @throws TransportExceptionInterface
* @throws Exception
*
* @return ResponseInterface
*/
private function getResponseOrFail(
string $url,
string $token,
Configuration $configuration,
string $endpointType,
): ResponseInterface {
$customConfiguration = $configuration->getCustomConfiguration();
if (! $customConfiguration instanceof OpenIdCustomConfigurationInterface) {
throw ConfigurationException::unexpectedCustomConfiguration($customConfiguration::class);
}
$headers = ['Authorization' => 'Bearer ' . trim($token)];
$options = ['verify_peer' => $customConfiguration->verifyPeer(), 'headers' => $headers];
if ($endpointType !== Endpoint::CUSTOM) {
$body = [
'token' => $token,
'client_id' => $customConfiguration->getClientId(),
'client_secret' => $customConfiguration->getClientSecret(),
];
$options['body'] = $body;
}
try {
$response = $this->client->request($this->getHttpMethodFromEndpointType($endpointType), $url, $options);
} catch (Exception) {
throw new InvalidResponseException();
}
return $response;
}
/**
* @param ResponseInterface $response
*
* @throws TransportExceptionInterface
*/
private function statusCodeIsValidOrFail(ResponseInterface $response): void
{
$statusCode = $response->getStatusCode();
if ($statusCode !== Response::HTTP_OK) {
throw new InvalidStatusCodeException('Invalid status code received', $statusCode);
}
}
/**
* @param ResponseInterface $response
*
* @throws TransportExceptionInterface
* @throws ClientExceptionInterface
* @throws RedirectionExceptionInterface
* @throws ServerExceptionInterface
*
* @return array<mixed>
*/
private function getContentOrFail(ResponseInterface $response): array
{
$content = $response->getContent(false);
$content = json_decode($content, true);
if (empty($content) || ! is_array($content) || array_key_exists('error', $content)) {
throw InvalidContentException::createWithContent($content);
}
return $content;
}
/**
* Get the HTTP Method from Endpoint Type.
*
* @param string $endpointType
*
* @return string
*/
private function getHttpMethodFromEndpointType(string $endpointType): string
{
return $endpointType === Endpoint::INTROSPECTION ? 'POST' : 'GET';
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Repository/DbReadConfigurationRepository.php | centreon/src/Core/Security/ProviderConfiguration/Infrastructure/Repository/DbReadConfigurationRepository.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\ProviderConfiguration\Infrastructure\Repository;
use Adaptation\Database\Connection\Collection\QueryParameters;
use Adaptation\Database\Connection\Exception\ConnectionException;
use Adaptation\Database\Connection\ValueObject\QueryParameter;
use Assert\AssertionFailedException;
use Centreon\Domain\Common\Assertion\AssertionException;
use Centreon\Domain\Repository\RepositoryException as LegacyRepositoryException;
use Centreon\Infrastructure\DatabaseConnection;
use Centreon\Infrastructure\Repository\AbstractRepositoryDRB;
use Core\Common\Domain\Exception\CollectionException;
use Core\Common\Domain\Exception\RepositoryException;
use Core\Common\Domain\Exception\ValueObjectException;
use Core\Security\ProviderConfiguration\Application\OpenId\Repository\ReadOpenIdConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Application\Repository\ReadConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Application\SAML\Repository\ReadSAMLConfigurationRepositoryInterface;
use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface;
use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException;
use Core\Security\ProviderConfiguration\Domain\Exception\InvalidEndpointException;
use Core\Security\ProviderConfiguration\Domain\Local\Model\CustomConfiguration as LocalCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\Local\Model\SecurityPolicy;
use Core\Security\ProviderConfiguration\Domain\Model\ACLConditions;
use Core\Security\ProviderConfiguration\Domain\Model\AuthenticationConditions;
use Core\Security\ProviderConfiguration\Domain\Model\Configuration;
use Core\Security\ProviderConfiguration\Domain\Model\Endpoint;
use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping;
use Core\Security\ProviderConfiguration\Domain\Model\Provider;
use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\ACLConditionsException;
use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration as OpenIdCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\SAML\Exception\MissingLogoutUrlException;
use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration as SAMLCustomConfiguration;
use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\CustomConfiguration as WebSSOCustomConfiguration;
use JsonSchema\Exception\InvalidArgumentException;
/**
* @phpstan-import-type _EndpointArray from Endpoint
*
* @phpstan-type _authenticationConditionsRecord array{
* is_enabled: bool,
* attribute_path: string,
* authorized_values: string[],
* trusted_client_addresses: string[],
* blacklist_client_addresses: string[],
* endpoint: _EndpointArray
* }
* @phpstan-type _groupsMappingRecord array{
* is_enabled: bool,
* attribute_path: string,
* endpoint: _EndpointArray
* }
* @phpstan-type _rolesMapping array{
* is_enabled: bool,
* apply_only_first_role: bool,
* attribute_path: string,
* endpoint?: _EndpointArray
* }
*/
final class DbReadConfigurationRepository extends AbstractRepositoryDRB implements ReadConfigurationRepositoryInterface
{
public function __construct(
DatabaseConnection $db,
private readonly ReadOpenIdConfigurationRepositoryInterface $readOpenIdConfigurationRepository,
private readonly ReadSAMLConfigurationRepositoryInterface $readSamlConfigurationRepository,
) {
$this->db = $db;
}
/**
* @inheritDoc
*/
public function getConfigurationByType(string $providerType): Configuration
{
$configuration = $this->loadConfigurationByType($providerType);
$customConfiguration = $this->loadCustomConfigurationFromConfiguration($configuration);
$configuration->setCustomConfiguration($customConfiguration);
return $configuration;
}
/**
* @inheritDoc
*/
public function getConfigurationById(int $id): Configuration
{
$configuration = $this->loadConfigurationById($id);
$customConfiguration = $this->loadCustomConfigurationFromConfiguration($configuration);
$configuration->setCustomConfiguration($customConfiguration);
return $configuration;
}
/**
* @inheritDoc
*/
public function findConfigurations(): array
{
$query = <<<'SQL'
SELECT name
FROM `:db`.`provider_configuration`
SQL;
try {
$entries = $this->db->fetchAllAssociative($this->translateDbName($query));
} catch (ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch provider configurations count from database: ' . $e->getMessage(),
previous: $e
);
}
$configurations = [];
foreach ($entries as $entry) {
$configurations[] = $this->getConfigurationByType($entry['name']);
}
return $configurations;
}
/**
* @inheritDoc
*/
public function findExcludedUsers(): array
{
try {
$query = <<<'SQL'
SELECT c.`contact_alias`
FROM `:db`.`password_expiration_excluded_users` peeu
INNER JOIN `:db`.`provider_configuration` pc ON pc.`id` = peeu.`provider_configuration_id`
AND pc.`name` = 'local'
INNER JOIN `:db`.`contact` c ON c.`contact_id` = peeu.`user_id`
AND c.`contact_register` = :contactRegister
SQL;
$queryParameters = QueryParameters::create([QueryParameter::int('contactRegister', 1)]);
return $this->db->fetchAllAssociative($this->translateDbName($query), $queryParameters);
} catch (ConnectionException|ValueObjectException|CollectionException $e) {
throw new RepositoryException(
message: 'Could not fetch excluded users from database for local provider configuration: ' . $e->getMessage(),
previous: $e
);
}
}
/**
* @throws RepositoryException
*/
private function loadCustomConfigurationFromConfiguration(
Configuration $configuration,
): CustomConfigurationInterface {
return match ($configuration->getType()) {
Provider::LOCAL => $this->loadLocalCustomConfiguration($configuration),
Provider::OPENID => $this->loadOpenIdCustomConfiguration($configuration),
Provider::WEB_SSO => $this->loadWebSsoCustomConfiguration($configuration),
Provider::SAML => $this->loadSamlCustomConfiguration($configuration),
default => throw new RepositoryException(
message: "Unknown provider configuration type named {$configuration->getType()}, can't load custom configuration",
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
'provider_configuration_name' => $configuration->getName(),
]
),
};
}
/**
* @throws RepositoryException
*/
private function loadSamlCustomConfiguration(Configuration $configuration): SAMLCustomConfiguration
{
try {
$jsonSchemaValidatorFile = __DIR__ . '/../SAML/Repository/CustomConfigurationSchema.json';
$json = $configuration->getJsonCustomConfiguration();
$this->validateJsonRecord($json, $jsonSchemaValidatorFile);
} catch (LegacyRepositoryException|InvalidArgumentException $e) {
throw new RepositoryException(
message: 'Could not validate json record for SAML provider configuration: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
try {
$jsonDecoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new RepositoryException(
message: 'Could not decode SAML provider configuration from json: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
$jsonDecoded['contact_template'] = $jsonDecoded['contact_template_id'] !== null
? $this->readSamlConfigurationRepository->findOneContactTemplate(
$jsonDecoded['contact_template_id']
)
: null;
$jsonDecoded['roles_mapping'] = $this->createAclConditions(
Provider::SAML,
$configuration->getId(),
$jsonDecoded['roles_mapping']
);
$jsonDecoded['authentication_conditions'] = $this->createAuthenticationConditionsFromRecord(
$jsonDecoded['authentication_conditions']
);
$jsonDecoded['groups_mapping'] = $this->createGroupsMappingFromRecord(
Provider::SAML,
$jsonDecoded['groups_mapping'],
$configuration->getId()
);
try {
return SAMLCustomConfiguration::createFromValues($jsonDecoded);
} catch (ConfigurationException|MissingLogoutUrlException $e) {
throw new RepositoryException(
message: 'Could not create SAML custom configuration from json record: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
'json_decoded' => $jsonDecoded,
],
previous: $e
);
}
}
/**
* @throws RepositoryException
*/
private function loadWebSsoCustomConfiguration(Configuration $configuration): WebSSOCustomConfiguration
{
try {
$jsonSchemaValidatorFile = __DIR__ . '/../WebSSO/Repository/CustomConfigurationSchema.json';
$json = $configuration->getJsonCustomConfiguration();
$this->validateJsonRecord($json, $jsonSchemaValidatorFile);
} catch (LegacyRepositoryException|InvalidArgumentException $e) {
throw new RepositoryException(
message: 'Could not validate json record for WebSSO provider configuration: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
try {
$json = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new RepositoryException(
message: 'Could not decode WebSSO provider configuration from json: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
return new WebSSOCustomConfiguration(
$json['trusted_client_addresses'],
$json['blacklist_client_addresses'],
$json['login_header_attribute'],
$json['pattern_matching_login'],
$json['pattern_replace_login']
);
}
/**
* @throws RepositoryException
*/
private function loadOpenIdCustomConfiguration(Configuration $configuration): OpenIdCustomConfiguration
{
try {
$jsonSchemaValidatorFile = __DIR__ . '/../OpenId/Repository/CustomConfigurationSchema.json';
$json = $configuration->getJsonCustomConfiguration();
$this->validateJsonRecord($json, $jsonSchemaValidatorFile);
} catch (LegacyRepositoryException|InvalidArgumentException $e) {
throw new RepositoryException(
message: 'Could not validate json record for OpenID provider configuration: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
try {
/** @var array{
* contact_template_id: int|null,
* authentication_conditions: _authenticationConditionsRecord,
* groups_mapping: _groupsMappingRecord,
* roles_mapping: _rolesMapping
* } $jsonDecoded
*/
$jsonDecoded = json_decode($json, true, flags: JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new RepositoryException(
message: 'Could not decode OpenID provider configuration from json record: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
$jsonDecoded['contact_template'] = $jsonDecoded['contact_template_id'] !== null
? $this->readOpenIdConfigurationRepository->findOneContactTemplate($jsonDecoded['contact_template_id'])
: null;
$jsonDecoded['roles_mapping'] = $this->createAclConditions(
Provider::OPENID,
$configuration->getId(),
$jsonDecoded['roles_mapping']
);
$jsonDecoded['authentication_conditions'] = $this->createAuthenticationConditionsFromRecord(
$jsonDecoded['authentication_conditions']
);
$jsonDecoded['groups_mapping'] = $this->createGroupsMappingFromRecord(
Provider::OPENID,
$jsonDecoded['groups_mapping'],
$configuration->getId()
);
try {
return new OpenIdCustomConfiguration($jsonDecoded);
} catch (ConfigurationException $e) {
throw new RepositoryException(
message: 'Could not create OpenID custom configuration from json record: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
}
/**
* @throws RepositoryException
*/
private function loadLocalCustomConfiguration(Configuration $configuration): LocalCustomConfiguration
{
try {
$jsonSchemaValidatorFile = __DIR__ . '/../Local/Repository/CustomConfigurationSchema.json';
$this->validateJsonRecord($configuration->getJsonCustomConfiguration(), $jsonSchemaValidatorFile);
} catch (LegacyRepositoryException|InvalidArgumentException $e) {
throw new RepositoryException(
message: 'Could not validate json record for Local provider configuration: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
$excludedUserAliases = array_map(
fn ($user) => $user['contact_alias'],
$this->findExcludedUsers()
);
try {
$json = json_decode($configuration->getJsonCustomConfiguration(), true, flags: JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new RepositoryException(
message: 'Could not decode Local provider configuration from json: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
try {
$securityPolicy = new SecurityPolicy(
$json['password_security_policy']['password_length'],
$json['password_security_policy']['has_uppercase_characters'],
$json['password_security_policy']['has_lowercase_characters'],
$json['password_security_policy']['has_numbers'],
$json['password_security_policy']['has_special_characters'],
$json['password_security_policy']['can_reuse_passwords'],
$json['password_security_policy']['attempts'],
$json['password_security_policy']['blocking_duration'],
$json['password_security_policy']['password_expiration_delay'],
$excludedUserAliases,
$json['password_security_policy']['delay_before_new_password'],
);
} catch (AssertionException $e) {
throw new RepositoryException(
message: 'Could not create security policy from json record for Local provider configuration: ' . $e->getMessage(),
context: [
'provider_configuration_id' => $configuration->getId(),
'provider_configuration_type' => $configuration->getType(),
],
previous: $e
);
}
return new LocalCustomConfiguration($securityPolicy);
}
/**
* @param _rolesMapping $rolesMapping
*
* @throws RepositoryException
*/
private function createAclConditions(string $providerName, int $configurationId, array $rolesMapping): ACLConditions
{
$rules = [];
match ($providerName) {
Provider::OPENID => $rules = $this->readOpenIdConfigurationRepository->findAuthorizationRulesByConfigurationId(
$configurationId
),
Provider::SAML => $rules = $this->readSamlConfigurationRepository->findAuthorizationRulesByConfigurationId(
$configurationId
),
default => throw new RepositoryException(
message: 'ACL Conditions can only be created for OpenID or SAML providers.',
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
]
),
};
$endpoint = null;
if (array_key_exists('endpoint', $rolesMapping)) {
try {
$endpoint = new Endpoint(
$rolesMapping['endpoint']['type'],
$rolesMapping['endpoint']['custom_endpoint']
);
} catch (InvalidEndpointException $e) {
throw new RepositoryException(
message: "Could not create endpoint for ACL conditions from roles mapping record for {$providerName} provider: " . $e->getMessage(),
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
'endpoint_type' => $rolesMapping['endpoint']['type'],
'custom_endpoint' => $rolesMapping['endpoint']['custom_endpoint'],
],
previous: $e
);
}
}
try {
return new ACLConditions(
$rolesMapping['is_enabled'],
$rolesMapping['apply_only_first_role'],
$rolesMapping['attribute_path'],
$endpoint,
$rules
);
} catch (ACLConditionsException $e) {
throw new RepositoryException(
message: "Could not create ACL conditions for {$providerName} provider: " . $e->getMessage(),
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
'is_enabled' => $rolesMapping['is_enabled'],
'apply_only_first_role' => $rolesMapping['apply_only_first_role'],
'attribute_path' => $rolesMapping['attribute_path'],
'endpoint' => $endpoint,
'authorization_rules' => $rules,
],
previous: $e
);
}
}
/**
* @throws RepositoryException
*/
private function loadConfigurationByType(string $providerName): Configuration
{
$query = <<<'SQL'
SELECT *
FROM `:db`.`provider_configuration`
WHERE `type` = :providerName
SQL;
try {
$queryParameters = QueryParameters::create([QueryParameter::string('providerName', $providerName)]);
$entry = $this->db->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: "Could not fetch provider configuration from database for {$providerName} provider: " . $e->getMessage(),
context: ['provider_name' => $providerName],
previous: $e
);
}
if ($entry !== false) {
return new Configuration(
(int) $entry['id'],
$entry['type'],
$entry['name'],
$entry['custom_configuration'],
(bool) $entry['is_active'],
(bool) $entry['is_forced']
);
}
throw new RepositoryException(
message: sprintf('Provider configuration with name %s not found', $providerName),
context: ['provider_name' => $providerName]
);
}
/**
* @throws RepositoryException
*/
private function loadConfigurationById(int $id): Configuration
{
$query = <<<'SQL'
SELECT *
FROM `:db`.`provider_configuration`
WHERE `id` = :id
SQL;
try {
$queryParameters = QueryParameters::create([QueryParameter::int('id', $id)]);
$entry = $this->db->fetchAssociative($this->translateDbName($query), $queryParameters);
} catch (ValueObjectException|CollectionException|ConnectionException $e) {
throw new RepositoryException(
message: 'Could not fetch provider configuration from database: ' . $e->getMessage(),
context: ['id_provider_configuration' => $id],
previous: $e
);
}
if ($entry !== false) {
return new Configuration(
(int) $entry['id'],
$entry['type'],
$entry['name'],
$entry['custom_configuration'],
(bool) $entry['is_active'],
(bool) $entry['is_forced']
);
}
throw new RepositoryException(
message: sprintf('Provider configuration with id %d not found', $id),
context: ['id_provider_configuration' => $id]
);
}
/**
* @param _authenticationConditionsRecord $authenticationConditionsRecord
*
* @throws RepositoryException
*/
private function createAuthenticationConditionsFromRecord(
array $authenticationConditionsRecord,
): AuthenticationConditions {
$endpoint = null;
if (array_key_exists('endpoint', $authenticationConditionsRecord)) {
try {
$endpoint = new Endpoint(
$authenticationConditionsRecord['endpoint']['type'],
$authenticationConditionsRecord['endpoint']['custom_endpoint']
);
} catch (InvalidEndpointException $e) {
throw new RepositoryException(
message: 'Could not create endpoint for authentication conditions from authentication conditions record: ' . $e->getMessage(),
context: [
'endpoint_type' => $authenticationConditionsRecord['endpoint']['type'],
'custom_endpoint' => $authenticationConditionsRecord['endpoint']['custom_endpoint'],
],
previous: $e
);
}
}
try {
$authenticationConditions = new AuthenticationConditions(
$authenticationConditionsRecord['is_enabled'],
$authenticationConditionsRecord['attribute_path'],
$endpoint,
$authenticationConditionsRecord['authorized_values']
);
} catch (ConfigurationException $e) {
throw new RepositoryException(
message: 'Could not create authentication conditions: ' . $e->getMessage(),
context: [
'is_enabled' => $authenticationConditionsRecord['is_enabled'],
'attribute_path' => $authenticationConditionsRecord['attribute_path'],
'authorized_values' => $authenticationConditionsRecord['authorized_values'],
'endpoint' => $endpoint,
],
previous: $e
);
}
if (! empty($authenticationConditionsRecord['trusted_client_addresses'])) {
try {
$authenticationConditions->setTrustedClientAddresses(
$authenticationConditionsRecord['trusted_client_addresses']
);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Could not set trusted client addresses for authentication conditions: ' . $e->getMessage(),
context: ['trusted_client_addresses' => $authenticationConditionsRecord['trusted_client_addresses']],
previous: $e
);
}
}
if (! empty($authenticationConditionsRecord['blacklist_client_addresses'])) {
try {
$authenticationConditions->setBlacklistClientAddresses(
$authenticationConditionsRecord['blacklist_client_addresses']
);
} catch (AssertionFailedException $e) {
throw new RepositoryException(
message: 'Could not set blacklist client addresses for authentication conditions: ' . $e->getMessage(),
context: ['blacklist_client_addresses' => $authenticationConditionsRecord['blacklist_client_addresses']],
previous: $e
);
}
}
return $authenticationConditions;
}
/**
* @param _groupsMappingRecord $groupsMappingRecord
*
* @throws RepositoryException
*/
private function createGroupsMappingFromRecord(
string $providerName,
array $groupsMappingRecord,
int $configurationId,
): GroupsMapping {
$endpoint = null;
if (array_key_exists('endpoint', $groupsMappingRecord)) {
try {
$endpoint = new Endpoint(
$groupsMappingRecord['endpoint']['type'],
$groupsMappingRecord['endpoint']['custom_endpoint']
);
} catch (InvalidEndpointException $e) {
throw new RepositoryException(
message: 'Could not create endpoint for groups mapping from groups mapping record: ' . $e->getMessage(),
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
'endpoint_type' => $groupsMappingRecord['endpoint']['type'],
'custom_endpoint' => $groupsMappingRecord['endpoint']['custom_endpoint'],
],
previous: $e
);
}
}
$contactGroupRelations = [];
match ($providerName) {
Provider::OPENID => $contactGroupRelations = $this->readOpenIdConfigurationRepository->findContactGroupRelationsByConfigurationId(
$configurationId
),
Provider::SAML => $contactGroupRelations = $this->readSamlConfigurationRepository->findContactGroupRelationsByConfigurationId(
$configurationId
),
default => throw new RepositoryException(
message: 'Groups Mapping can only be created for OpenID or SAML providers.',
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
]
),
};
try {
return new GroupsMapping(
$groupsMappingRecord['is_enabled'],
$groupsMappingRecord['attribute_path'],
$endpoint,
$contactGroupRelations
);
} catch (ConfigurationException $e) {
throw new RepositoryException(
message: 'Could not create groups mapping: ' . $e->getMessage(),
context: [
'provider_name' => $providerName,
'provider_configuration_id' => $configurationId,
'is_enabled' => $groupsMappingRecord['is_enabled'],
'attribute_path' => $groupsMappingRecord['attribute_path'],
'endpoint' => $endpoint,
'contact_group_relations' => $contactGroupRelations,
],
previous: $e
);
}
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/Infrastructure/Voters/ApiRealtimeVoter.php | centreon/src/Core/Security/Infrastructure/Voters/ApiRealtimeVoter.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\Infrastructure\Voters;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* @extends Voter<string, mixed>
*/
final class ApiRealtimeVoter extends Voter
{
public const ROLE_API_REALTIME = 'ROLE_API_REALTIME';
/**
* @inheritDoc
*/
protected function supports(string $attribute, mixed $subject): bool
{
return $attribute === self::ROLE_API_REALTIME;
}
/**
* @inheritDoc
*/
protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
{
$user = $token->getUser();
if (! $user instanceof ContactInterface) {
return false;
}
return $user->hasAccessToApiRealTime();
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroups.php | centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroups.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\AccessGroup\Application\UseCase\FindLocalUserAccessGroups;
use Centreon\Domain\Contact\Interfaces\ContactInterface;
use Centreon\Domain\Log\LoggerTrait;
use Core\Application\Common\UseCase\ErrorResponse;
use Core\Security\AccessGroup\Application\Repository\ReadAccessGroupRepositoryInterface;
class FindLocalUserAccessGroups
{
use LoggerTrait;
/**
* @param ReadAccessGroupRepositoryInterface $repository
* @param ContactInterface $user
*/
public function __construct(private ReadAccessGroupRepositoryInterface $repository, private ContactInterface $user)
{
}
/**
* @param FindLocalUserAccessGroupsPresenterInterface $presenter
*/
public function __invoke(FindLocalUserAccessGroupsPresenterInterface $presenter): void
{
try {
if ($this->user->isAdmin()) {
$accessGroups = $this->repository->findAllWithFilter();
} else {
$accessGroups = $this->repository->findByContactWithFilter($this->user);
}
} catch (\Throwable $ex) {
$this->error(
'An error occured in data storage while getting contact groups',
['trace' => $ex->getTraceAsString()]
);
$presenter->setResponseStatus(
new ErrorResponse('Impossible to get contact groups from data storage')
);
return;
}
$presenter->present(new FindLocalUserAccessGroupsResponse($accessGroups));
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroupsPresenterInterface.php | centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroupsPresenterInterface.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\AccessGroup\Application\UseCase\FindLocalUserAccessGroups;
use Core\Application\Common\UseCase\PresenterInterface;
interface FindLocalUserAccessGroupsPresenterInterface extends PresenterInterface
{
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
centreon/centreon | https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroupsResponse.php | centreon/src/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroupsResponse.php | <?php
/*
* Copyright 2005 - 2025 Centreon (https://www.centreon.com/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* For more information : contact@centreon.com
*
*/
declare(strict_types=1);
namespace Core\Security\AccessGroup\Application\UseCase\FindLocalUserAccessGroups;
use Core\Security\AccessGroup\Domain\Model\AccessGroup;
final class FindLocalUserAccessGroupsResponse
{
/** @var array<array<string,mixed>> */
public array $accessGroups;
/**
* @param array<AccessGroup> $accessGroups
*/
public function __construct(array $accessGroups)
{
$this->accessGroups = $this->accessGroupsToArray($accessGroups);
}
/**
* @param array<AccessGroup> $accessGroups
*
* @return array<array<string,mixed>>
*/
private function accessGroupsToArray(array $accessGroups): array
{
return array_map(
fn (AccessGroup $accessGroup) => [
'id' => $accessGroup->getId(),
'name' => $accessGroup->getName(),
'alias' => $accessGroup->getAlias(),
'has_changed' => $accessGroup->hasChanged(),
'is_activated' => $accessGroup->isActivate(),
],
$accessGroups
);
}
}
| php | Apache-2.0 | 6ae83001e94de0a4cec11e084780fcfa63f1c985 | 2026-01-05T04:45:18.914281Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.