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/Authentication/Application/UseCase/LogoutSession/LogoutSessionPresenterInterface.php
centreon/src/Core/Security/Authentication/Application/UseCase/LogoutSession/LogoutSessionPresenterInterface.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\Authentication\Application\UseCase\LogoutSession; use Core\Application\Common\UseCase\PresenterInterface; interface LogoutSessionPresenterInterface 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/Authentication/Application/UseCase/LogoutSession/LogoutSession.php
centreon/src/Core/Security/Authentication/Application/UseCase/LogoutSession/LogoutSession.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\Authentication\Application\UseCase\LogoutSession; use Centreon\Domain\Log\LoggerTrait; use Core\Application\Common\UseCase\ErrorResponse; use Core\Security\Authentication\Application\Repository\WriteSessionRepositoryInterface; class LogoutSession { use LoggerTrait; /** * @param WriteSessionRepositoryInterface $writeSessionRepository */ public function __construct( private readonly WriteSessionRepositoryInterface $writeSessionRepository, ) { } /** * @param mixed $token * @param LogoutSessionPresenterInterface $presenter */ public function __invoke( mixed $token, LogoutSessionPresenterInterface $presenter, ): void { $this->info('Processing session logout...'); if ($token === null || is_string($token) === false) { $this->debug('Try to logout without token'); $presenter->setResponseStatus(new ErrorResponse(_('No session token provided'))); return; } $this->writeSessionRepository->invalidate(); } }
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/Authentication/Application/UseCase/LogoutSession/SAML/LogoutFromIdp.php
centreon/src/Core/Security/Authentication/Application/UseCase/LogoutSession/SAML/LogoutFromIdp.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\Authentication\Application\UseCase\LogoutSession\SAML; use Centreon\Domain\Log\LoggerTrait; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\Authentication\Application\Repository\WriteSessionRepositoryInterface; use Core\Security\Authentication\Infrastructure\Provider\SAML; use Core\Security\ProviderConfiguration\Domain\Model\Provider; class LogoutFromIdp { use LoggerTrait; /** * @param WriteSessionRepositoryInterface $writeSessionRepository * @param ProviderAuthenticationFactoryInterface $providerFactory */ public function __construct( private readonly WriteSessionRepositoryInterface $writeSessionRepository, private readonly ProviderAuthenticationFactoryInterface $providerFactory, ) { } public function __invoke(): void { session_start(); $this->info('SAML SLS invoked'); /** @var SAML $provider */ $provider = $this->providerFactory->create(Provider::SAML); $this->writeSessionRepository->invalidate(); $provider->handleCallbackLogoutResponse(); } }
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/Authentication/Application/UseCase/Login/Login.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/Login.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\Authentication\Application\UseCase\Login; use Centreon\Domain\Authentication\Exception\AuthenticationException as LegacyAuthenticationException; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Menu\Interfaces\MenuServiceInterface; use Centreon\Domain\Menu\Model\Page; use Centreon\Domain\Repository\Interfaces\DataStorageEngineInterface; use Core\Application\Common\UseCase\ErrorAuthenticationConditionsResponse; use Core\Application\Common\UseCase\ErrorResponse; use Core\Application\Common\UseCase\PresenterInterface; use Core\Application\Common\UseCase\UnauthorizedResponse; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\Repository\ReadTokenRepositoryInterface; use Core\Security\Authentication\Application\Repository\WriteSessionRepositoryInterface; use Core\Security\Authentication\Application\Repository\WriteSessionTokenRepositoryInterface; use Core\Security\Authentication\Application\Repository\WriteTokenRepositoryInterface; use Core\Security\Authentication\Domain\Exception\AclConditionsException; use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException; use Core\Security\Authentication\Domain\Exception\AuthenticationException; use Core\Security\Authentication\Domain\Exception\PasswordExpiredException; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Infrastructure\Provider\AclUpdaterInterface; use Core\Security\Authentication\Infrastructure\Provider\OpenId; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Security\Domain\Authentication\Model\Session; use Security\Encryption; use Symfony\Component\HttpFoundation\RequestStack; final class Login { use LoggerTrait; /** @var ProviderAuthenticationInterface */ private ProviderAuthenticationInterface $provider; /** * @param ProviderAuthenticationFactoryInterface $providerFactory * @param RequestStack $requestStack * @param DataStorageEngineInterface $dataStorageEngine * @param WriteSessionRepositoryInterface $sessionRepository * @param ReadTokenRepositoryInterface $readTokenRepository * @param WriteTokenRepositoryInterface $writeTokenRepository * @param WriteSessionTokenRepositoryInterface $writeSessionTokenRepository * @param AclUpdaterInterface $aclUpdater * @param MenuServiceInterface $menuService * @param string $defaultRedirectUri * @param ThirdPartyLoginForm $thirdPartyLoginForm */ public function __construct( private ProviderAuthenticationFactoryInterface $providerFactory, private RequestStack $requestStack, private DataStorageEngineInterface $dataStorageEngine, private WriteSessionRepositoryInterface $sessionRepository, private ReadTokenRepositoryInterface $readTokenRepository, private WriteTokenRepositoryInterface $writeTokenRepository, private WriteSessionTokenRepositoryInterface $writeSessionTokenRepository, private AclUpdaterInterface $aclUpdater, private MenuServiceInterface $menuService, private string $defaultRedirectUri, private readonly ThirdPartyLoginForm $thirdPartyLoginForm, ) { } /** * @param LoginRequest $loginRequest * @param PresenterInterface $presenter */ public function __invoke(LoginRequest $loginRequest, PresenterInterface $presenter): void { try { $this->provider = $this->providerFactory->create($loginRequest->providerName); $this->provider->authenticateOrFail($loginRequest); if ($this->provider->isAutoImportEnabled()) { $this->provider->importUser(); } $user = $this->provider->findUserOrFail(); if ($loginRequest->providerName === Provider::LOCAL && ! $user->isAllowedToReachWeb()) { throw LegacyAuthenticationException::notAllowedToReachWebApplication(); } $this->updateACL($user); if ($this->sessionRepository->start($this->provider->getLegacySession())) { if ($this->readTokenRepository->hasAuthenticationTokensByToken($this->requestStack->getSession()->getId()) === false) { if ($loginRequest->providerName === Provider::SAML && $this->thirdPartyLoginForm->isActive()) { $this->createAuthenticationTokens( $authToken = Encryption::generateRandomString(), $user, $this->provider->getProviderToken($this->requestStack->getSession()->getId()), $this->provider->getProviderRefreshToken(), $loginRequest->clientIp ); $this->thirdPartyLoginForm->setToken($authToken); } if ($loginRequest->providerName === Provider::OPENID) { // Store the OpenID ID token in the session for later use $provider = $this->provider; if (! $provider instanceof OpenId) { throw new AuthenticationException('Expected OpenIdProvider for OpenID login'); } $request = $this->requestStack->getCurrentRequest(); if ($request === null) { throw new AuthenticationException('Request is not available for OpenID login'); } try { $request->getSession() ->set('openid_id_token', $provider->getTokenForSession()); } catch (SSOAuthenticationException $e) { throw new AuthenticationException('OpenID authentication failed: ' . $e->getMessage(), previous: $e); } $this->createAuthenticationTokens( Encryption::generateRandomString(), $user, $provider->getProviderToken(), $provider->getProviderRefreshToken(), $loginRequest->clientIp ); } $this->createAuthenticationTokens( $this->requestStack->getSession()->getId(), $user, $this->provider->getProviderToken($this->requestStack->getSession()->getId()), $this->provider->getProviderRefreshToken(), $loginRequest->clientIp ); } } $redirectionInfo = $this->getRedirectionInfo($user, $loginRequest->refererQueryParameters); $presenter->present( new LoginResponse( (string) $redirectionInfo['redirect_uri'], (bool) $redirectionInfo['is_react'], ) ); } catch (PasswordExpiredException $exception) { $this->info('The password expired', ['trace' => (string) $exception]); $response = new PasswordExpiredResponse($exception->getMessage()); $response->setBody(['password_is_expired' => true]); $presenter->setResponseStatus($response); return; } catch (AuthenticationException $exception) { $this->error('An error occurred during authentication', ['trace' => (string) $exception]); $presenter->setResponseStatus(new UnauthorizedResponse($exception->getMessage())); return; } catch (AclConditionsException $exception) { $this->error('An error occured while matching your ACL conditions', ['trace' => (string) $exception]); $presenter->setResponseStatus(new ErrorAclConditionsResponse($exception->getMessage())); } catch (AuthenticationConditionsException $ex) { $this->error('An error occured while matching your authentication conditions', ['trace' => (string) $ex]); $presenter->setResponseStatus(new ErrorAuthenticationConditionsResponse($ex->getMessage())); return; } catch (\Throwable $ex) { $this->error('An error occurred during authentication', ['trace' => (string) $ex]); $presenter->setResponseStatus(new ErrorResponse('An error occurred during authentication')); return; } } /** * Create Authentication tokens. * * @param string $sessionToken * @param ContactInterface $contact * @param NewProviderToken $providerToken * @param NewProviderToken|null $providerRefreshToken * @param string|null $clientIp * * @throws AuthenticationException */ private function createAuthenticationTokens( string $sessionToken, ContactInterface $contact, NewProviderToken $providerToken, ?NewProviderToken $providerRefreshToken, ?string $clientIp, ): void { $isAlreadyInTransaction = $this->dataStorageEngine->isAlreadyinTransaction(); if (! $isAlreadyInTransaction) { $this->dataStorageEngine->startTransaction(); } try { $session = new Session($sessionToken, $contact->getId(), $clientIp); $this->writeSessionTokenRepository->createSession($session); $this->writeTokenRepository->createAuthenticationTokens( $sessionToken, $this->provider->getConfiguration()->getId(), $contact->getId(), $providerToken, $providerRefreshToken ); if (! $isAlreadyInTransaction) { $this->dataStorageEngine->commitTransaction(); } } catch (\Exception) { if (! $isAlreadyInTransaction) { $this->dataStorageEngine->rollbackTransaction(); } throw AuthenticationException::notAuthenticated(); } } /** * Get the redirection uri where user will be redirect once logged. * * @param ContactInterface $authenticatedUser * @param string|null $refererQueryParameters * * @return array<string,bool|string> */ private function getRedirectionInfo(ContactInterface $authenticatedUser, ?string $refererQueryParameters): array { $refererRedirectionPage = $this->getRedirectionPageFromRefererQueryParameters($refererQueryParameters); if ($refererRedirectionPage !== null) { $redirectionInfo = $this->buildDefaultRedirectionUri($refererRedirectionPage); } elseif ($authenticatedUser->getDefaultPage()?->getUrl() !== null) { $redirectionInfo = $this->buildDefaultRedirectionUri($authenticatedUser->getDefaultPage()); } else { $redirectionInfo['redirect_uri'] = $this->defaultRedirectUri; $redirectionInfo['is_react'] = true; } return $redirectionInfo; } /** * build the redirection uri based on isReact page property. * * @param Page $defaultPage * * @return array<string,bool|string> */ private function buildDefaultRedirectionUri(Page $defaultPage): array { $redirectionInfo = [ 'is_react' => $defaultPage->isReact(), ]; if ($defaultPage->isReact() === true) { $redirectionInfo['redirect_uri'] = $defaultPage->getUrl(); } else { $redirectUri = '/main.php?p=' . $defaultPage->getPageNumber(); if ($defaultPage->getUrlOptions() !== null) { $redirectUri .= $defaultPage->getUrlOptions(); } $redirectionInfo['redirect_uri'] = $redirectUri; } return $redirectionInfo; } /** * Get a Page from referer page number. * * @param string|null $refererQueryParameters * * @return Page|null */ private function getRedirectionPageFromRefererQueryParameters(?string $refererQueryParameters): ?Page { if ($refererQueryParameters === null) { return null; } $refererRedirectionPage = null; $queryParameters = []; parse_str($refererQueryParameters, $queryParameters); if (array_key_exists('redirect', $queryParameters) && is_string($queryParameters['redirect'])) { $redirectionPageParameters = []; parse_str($queryParameters['redirect'], $redirectionPageParameters); if (array_key_exists('p', $redirectionPageParameters)) { $refererRedirectionPage = $this->menuService->findPageByTopologyPageNumber( (int) $redirectionPageParameters['p'] ); unset($redirectionPageParameters['p']); if ($refererRedirectionPage !== null) { $refererRedirectionPage->setUrlOptions('&' . http_build_query($redirectionPageParameters)); } } } return $refererRedirectionPage; } /** * @param ContactInterface $user */ private function updateACL(ContactInterface $user): void { $this->aclUpdater->updateForProviderAndUser($this->provider, $user); } }
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/Authentication/Application/UseCase/Login/LoginResponse.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/LoginResponse.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\Authentication\Application\UseCase\Login; use Core\Application\Common\UseCase\ResponseStatusInterface; use Exception; final class LoginResponse implements ResponseStatusInterface { /** * @param string $redirectUri * @param bool $redirectIsReact * @param Exception|null $exception */ public function __construct( private readonly string $redirectUri, private readonly bool $redirectIsReact, private readonly ?Exception $exception = null, ) { } /** * @return string */ public function getRedirectUri(): string { return $this->redirectUri; } /** * @return Exception|null */ public function getException(): ?Exception { return $this->exception; } /** * @return string */ public function getMessage(): string { return $this->redirectUri; } /** * @return bool */ public function redirectIsReact(): bool { return $this->redirectIsReact; } }
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/Authentication/Application/UseCase/Login/PasswordExpiredResponse.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/PasswordExpiredResponse.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\Authentication\Application\UseCase\Login; use Core\Application\Common\UseCase\BodyResponseInterface; use Core\Application\Common\UseCase\UnauthorizedResponse; final class PasswordExpiredResponse extends UnauthorizedResponse implements BodyResponseInterface { /** @var mixed */ private $body; /** * @inheritDoc */ public function setBody(mixed $body): void { $this->body = $body; } /** * @inheritDoc */ public function getBody(): mixed { return $this->body; } }
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/Authentication/Application/UseCase/Login/LoginInterface.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/LoginInterface.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\Authentication\Application\UseCase\Login; interface LoginInterface { /** * @param LoginRequest $request */ public function authenticateWithRequest(LoginRequest $request): 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/Authentication/Application/UseCase/Login/LoginRequest.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/LoginRequest.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\Authentication\Application\UseCase\Login; use Core\Security\ProviderConfiguration\Domain\Model\Provider; final class LoginRequest { /** * @param string $providerName * @param string|null $clientIp * @param string|null $username * @param string|null $password * @param string|null $code * @param string|null $refererQueryParameters * @param string|null $requestId * @param string|null $assertion */ private function __construct( public string $providerName, public ?string $clientIp = null, public ?string $username = null, public ?string $password = null, public ?string $code = null, public ?string $refererQueryParameters = null, public ?string $requestId = null, public ?string $assertion = null, ) { } /** * @param string $username * @param string $password * @param string|null $clientIp * @param string|null $refererQueryParameters * * @return LoginRequest */ public static function createForLocal( string $username, string $password, ?string $clientIp = null, ?string $refererQueryParameters = null, ): self { return new self( Provider::LOCAL, $clientIp, $username, $password, null, $refererQueryParameters ); } /** * @param string $clientIp * @param string $code * * @return LoginRequest */ public static function createForOpenId(string $clientIp, string $code): self { return new self(Provider::OPENID, $clientIp, null, null, $code); } /** * @param string $clientIp * * @return LoginRequest */ public static function createForSSO(string $clientIp): self { return new self(Provider::WEB_SSO, $clientIp); } /** * @param string $clientIp * * @return LoginRequest */ public static function createForSAML(string $clientIp): self { return new self(Provider::SAML, $clientIp); } }
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/Authentication/Application/UseCase/Login/ErrorAclConditionsResponse.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/ErrorAclConditionsResponse.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\Authentication\Application\UseCase\Login; use Core\Application\Common\UseCase\ForbiddenResponse; final class ErrorAclConditionsResponse extends ForbiddenResponse { }
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/Authentication/Application/UseCase/Login/LoginPresenterInterface.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/LoginPresenterInterface.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\Authentication\Application\UseCase\Login; use Core\Application\Common\UseCase\PresenterInterface; interface LoginPresenterInterface 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/Authentication/Application/UseCase/Login/ThirdPartyLoginForm.php
centreon/src/Core/Security/Authentication/Application/UseCase/Login/ThirdPartyLoginForm.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\Authentication\Application\UseCase\Login; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; /** * This class aims to centralize the return login behaviour when initiated by a third party login form. * * It concerns : * - {@see https://mobile.centreon.com} progressive web app (PWA). * * This class is not 100% compliant about the Infrastructure and Application separation * but its nature is by definition a bit hacky. * * At the moment of its creation, we don't have a better idea to respond the need while * keeping track of the calls regarding this behaviour. */ final class ThirdPartyLoginForm { private string $token = ''; private ?bool $isActive = null; public function __construct( private readonly UrlGeneratorInterface $urlGenerator, ) { } /** * Store the token used for building the final redirect Uri. * We need to forward the token to the original login page. * * @param string $token */ public function setToken(string $token): void { $this->token = $token; } /** * Used to get the return URL from the referer, before the auth. * The value is forwarded to the IDP to get it back after auth. * * @param Request $request */ public function getReturnUrlBeforeAuth(Request $request): string { // Initiated by https://mobile.centreon.com if ($request->query->get('mobile') === '1') { return (string) $request->headers->get('referer'); } return ''; } /** * Retrieve the redirectUrl after auth from the IDP information. * For SAML, this is the request parameter RelayState. */ public function getReturnUrlAfterAuth(): string { if ($this->token === '' || ! $this->isActive()) { return ''; } return $_REQUEST['RelayState'] . '#/callback?' . http_build_query(['token' => $this->token]); } /** * Tells whether the authentication was initiated by a third party login form in our context. */ public function isActive(): bool { if ($this->isActive !== null) { return $this->isActive; } if (empty($returnTo = $_REQUEST['RelayState'] ?? null)) { return $this->isActive = false; } // We want to avoid possible loop redirects because the use of the RelayState in the SAML case is a bit hacky. $ourACS = $this->urlGenerator ->generate('centreon_application_authentication_login_saml', [], UrlGeneratorInterface::ABSOLUTE_URL); return $this->isActive = $returnTo !== $ourACS; } }
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/Authentication/Application/Provider/ProviderAuthenticationInterface.php
centreon/src/Core/Security/Authentication/Application/Provider/ProviderAuthenticationInterface.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\Authentication\Application\Provider; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Core\Contact\Domain\Model\ContactGroup; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; interface ProviderAuthenticationInterface { /** * @return \Centreon */ public function getLegacySession(): \Centreon; /** * @return Configuration */ public function getConfiguration(): Configuration; /** * @param Configuration $configuration */ public function setConfiguration(Configuration $configuration): void; /** * @return bool */ public function isUpdateACLSupported(): bool; /** * Indicates if the provider has a mechanism to refresh the token. * * @return bool */ public function canRefreshToken(): bool; /** * Refresh the provider token. * * @param AuthenticationTokens $authenticationTokens * * @return AuthenticationTokens|null Return the new AuthenticationTokens object if success otherwise null */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens; /** * @return ContactInterface|null */ public function getAuthenticatedUser(): ?ContactInterface; /** * @param LoginRequest $request * * @throws SSOAuthenticationException */ public function authenticateOrFail(LoginRequest $request): void; /** * @return ContactInterface */ public function findUserOrFail(): ContactInterface; /** * Return the contact username. * * @return string */ public function getUsername(): string; /** * If isAutoImportEnabled method returns true, the user will be imported to the database. */ public function importUser(): void; public function updateUser(): void; /** * @param string|null $token * * @return NewProviderToken */ public function getProviderToken(?string $token = null): NewProviderToken; /** * @return NewProviderToken|null */ public function getProviderRefreshToken(): ?NewProviderToken; /** * @return bool */ public function isAutoImportEnabled(): bool; /** * Get User information gathered from IdP. * * @return array<string,mixed> */ public function getUserInformation(): array; /** * Get information store in id_token JWT Payload. * * @return array<string,mixed> */ public function getIdTokenPayload(): array; /** * @return string[] */ public function getAclConditionsMatches(): array; /** * @return ContactGroup[] */ public function getUserContactGroups(): 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/Authentication/Application/Provider/ProviderAuthenticationFactoryInterface.php
centreon/src/Core/Security/Authentication/Application/Provider/ProviderAuthenticationFactoryInterface.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\Authentication\Application\Provider; use Security\Domain\Authentication\Exceptions\ProviderException; interface ProviderAuthenticationFactoryInterface { /** * @throws ProviderException */ public function create(string $providerType): ProviderAuthenticationInterface; }
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/Authentication/Application/Repository/WriteTokenRepositoryInterface.php
centreon/src/Core/Security/Authentication/Application/Repository/WriteTokenRepositoryInterface.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\Authentication\Application\Repository; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Domain\Model\ProviderToken; interface WriteTokenRepositoryInterface { /** * @param string $token * @param int $providerConfigurationId * @param int $contactId * @param NewProviderToken $providerToken * @param NewProviderToken|null $providerRefreshToken */ public function createAuthenticationTokens( string $token, int $providerConfigurationId, int $contactId, NewProviderToken $providerToken, ?NewProviderToken $providerRefreshToken, ): void; /** * Updates the provider authentication tokens. * * @param AuthenticationTokens $authenticationTokens Provider tokens */ public function updateAuthenticationTokens(AuthenticationTokens $authenticationTokens): void; /** * Updates the provider token. * * @param ProviderToken $providerToken */ public function updateProviderToken(ProviderToken $providerToken): void; /** * Delete a security token. * * @param string $token */ public function deleteSecurityToken(string $token): 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/Authentication/Application/Repository/ReadTokenRepositoryInterface.php
centreon/src/Core/Security/Authentication/Application/Repository/ReadTokenRepositoryInterface.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\Authentication\Application\Repository; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; interface ReadTokenRepositoryInterface { /** * Find the authentication token using the session token. * * @param string $token Session token * * @return AuthenticationTokens|null */ public function findAuthenticationTokensByToken(string $token): ?AuthenticationTokens; /** * Check if authentication token has a session token. * * @param string $token Session token * * @return bool */ public function hasAuthenticationTokensByToken(string $token): 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/Authentication/Application/Repository/WriteSessionTokenRepositoryInterface.php
centreon/src/Core/Security/Authentication/Application/Repository/WriteSessionTokenRepositoryInterface.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\Authentication\Application\Repository; use Security\Domain\Authentication\Model\Session; interface WriteSessionTokenRepositoryInterface { /** * Delete a session. * * @param string $token */ public function deleteSession(string $token): void; /** * @param Session $session */ public function createSession(Session $session): 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/Authentication/Application/Repository/WriteSessionRepositoryInterface.php
centreon/src/Core/Security/Authentication/Application/Repository/WriteSessionRepositoryInterface.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\Authentication\Application\Repository; interface WriteSessionRepositoryInterface { /** * Invalidate a session. */ public function invalidate(): void; /** * @param \Centreon $legacySession * * @return bool */ public function start(\Centreon $legacySession): 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/Authentication/Domain/Model/AuthenticationTokens.php
centreon/src/Core/Security/Authentication/Domain/Model/AuthenticationTokens.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\Authentication\Domain\Model; class AuthenticationTokens { /** * @param int $userId * @param int $configurationProviderId * @param string $sessionToken * @param NewProviderToken|ProviderToken $providerToken * @param NewProviderToken|ProviderToken|null $providerRefreshToken */ public function __construct( private int $userId, private int $configurationProviderId, private string $sessionToken, private NewProviderToken|ProviderToken $providerToken, private NewProviderToken|ProviderToken|null $providerRefreshToken, ) { } /** * @return string */ public function getSessionToken(): string { return $this->sessionToken; } /** * @return ProviderToken|NewProviderToken */ public function getProviderToken(): ProviderToken|NewProviderToken { return $this->providerToken; } /** * @return ProviderToken|NewProviderToken|null */ public function getProviderRefreshToken(): ProviderToken|NewProviderToken|null { return $this->providerRefreshToken; } /** * @return int */ public function getUserId(): int { return $this->userId; } /** * @return int */ public function getConfigurationProviderId(): int { return $this->configurationProviderId; } }
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/Authentication/Domain/Model/ProviderToken.php
centreon/src/Core/Security/Authentication/Domain/Model/ProviderToken.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\Authentication\Domain\Model; use DateTimeImmutable; class ProviderToken extends NewProviderToken { public function __construct( private int $id, private string $token, private DateTimeImmutable $creationDate, private ?DateTimeImmutable $expirationDate = null, ) { parent::__construct($this->token, $this->creationDate, $this->expirationDate); } /** * @return int */ public function getId(): int { return $this->id; } /** * @param int $id */ public function setId(int $id): void { $this->id = $id; } }
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/Authentication/Domain/Model/NewProviderToken.php
centreon/src/Core/Security/Authentication/Domain/Model/NewProviderToken.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\Authentication\Domain\Model; use DateTime; use DateTimeImmutable; class NewProviderToken { /** * ProviderToken constructor. * * @param string $token * @param DateTimeImmutable $creationDate * @param DateTimeImmutable|null $expirationDate */ public function __construct( private string $token, private DateTimeImmutable $creationDate, private ?DateTimeImmutable $expirationDate = null, ) { } /** * @return string */ public function getToken(): string { return $this->token; } /** * @return DateTimeImmutable */ public function getCreationDate(): DateTimeImmutable { return $this->creationDate; } /** * @return DateTimeImmutable|null */ public function getExpirationDate(): ?DateTimeImmutable { return $this->expirationDate; } /** * // TODO To be removed. * * @param DateTimeImmutable|null $expirationDate * * @return self */ public function setExpirationDate(?DateTimeImmutable $expirationDate): self { $this->expirationDate = $expirationDate; return $this; } /** * @param DateTimeImmutable|null $now * * @return bool */ public function isExpired(?DateTimeImmutable $now = null): bool { if ($this->expirationDate === null) { return false; } if ($now === null) { $now = new DateTime(); } return $this->expirationDate->getTimestamp() < $now->getTimestamp(); } }
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/Authentication/Domain/Exception/ProviderException.php
centreon/src/Core/Security/Authentication/Domain/Exception/ProviderException.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\Authentication\Domain\Exception; class ProviderException extends \Exception { /** * Exception thrown when a Provider class was unexpected. * * @param class-string $class * * @return self */ public static function unexpectedProvider(string $class): self { return new self(sprintf(_('Must not Happen, got unexpected Provider type %s'), $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/Authentication/Domain/Exception/SSOAuthenticationException.php
centreon/src/Core/Security/Authentication/Domain/Exception/SSOAuthenticationException.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\Authentication\Domain\Exception; class SSOAuthenticationException extends \Exception { /** * Exception thrown when tokens are expired. * * @param string $providerName * * @return self */ public static function tokensExpired(string $providerName): self { return new self(sprintf(_('[%s]: Both provider and refresh tokens have expired'), $providerName)); } /** * Exception thrown when request for connection token failed. * * @return self */ public static function requestForConnectionTokenFail(): self { return new self(_('Request for connection token to external provider has failed')); } /** * Exception thrown when the external provider return an error. * * @param string $providerName * * @return self */ public static function errorFromExternalProvider(string $providerName): self { return new self(sprintf(_('[%s]: An error occured during your request'), $providerName)); } /** * Exception thrown when the request for refresh token failed. * * @return self */ public static function requestForRefreshTokenFail(): self { return new self(_('Request for refresh token to external provider has failed')); } /** * Exception thrown when the request for introspection token failed. * * @return self */ public static function requestForIntrospectionTokenFail(): self { return new self(_('Request for introspection token to external provider has failed')); } /** * Exception thrown when the request for user information failed. * * @return self */ public static function requestForUserInformationFail(): self { return new self(_('Request for user information to external provider has failed')); } /** * Exception thrown when the IP is blacklisted. * * @return self */ public static function blackListedClient(): self { return new self(_('Your IP is blacklisted')); } /** * Exception thrown when the IP is not whitelisted. * * @return self */ public static function notWhiteListedClient(): self { return new self(_('Your IP is not whitelisted')); } /** * Exception thrown when the login claim was not found. * * @param string $providerName * @param string $loginClaim * * @return self */ public static function loginClaimNotFound(string $providerName, string $loginClaim): self { return new self( sprintf( _('[%s]: Login claim [%s] not found from external provider user'), $providerName, $loginClaim ) ); } /** * Exception thrown when no Authorization Code has been return. * * @param string $providerName * * @return self */ public static function noAuthorizationCode(string $providerName): self { return new self(sprintf(_('[%s]: No authorization code return by external provider'), $providerName)); } /** * Exception thrown when no refresh token could be found. * * @return self */ public static function noRefreshToken(): self { return new self(_('No refresh token has been found')); } /** * Exception thrown when the username can't be extract with matching regexp. * * @return self */ public static function unableToRetrieveUsernameFromLoginClaim(): self { return new self(_('Can\'t resolve username from login claim using configured regular expression')); } /** * Exception thrown when bind attributes for auto import are not found in user informations from external provider. * * @param array<string|null> $missingAttributes * * @return self */ public static function autoImportBindAttributeNotFound(array $missingAttributes): self { return new self( sprintf( _('The following bound attributes are missing: %s'), implode(', ', $missingAttributes) ) ); } /** * Exception thrown when the id_token couldn't be decoded. * * @return self */ public static function unableToDecodeIdToken(): self { return new self(_('An error occured while decoding Identity Provider ID Token')); } /** * @return SSOAuthenticationException */ public static function requestForCustomACLConditionsEndpointFail(): self { return new self(_('The request for roles mapping on custom endpoint has failed')); } /** * Exception thrown when the request to authentication condition fail. * * @return self */ public static function requestForCustomAuthenticationConditionsEndpointFail(): self { return new self(_('Request for authentication conditions custom endpoint has failed')); } /** * Exception thrown when the request to authentication condition fail. * * @return self */ public static function missingRemoteLoginAttribute(): self { return new self('Missing Login Attribute', 400); } /** * Exception thrown when the user is authenticated on IDP but the contact does not exist in the database. * * @param string $alias * * @return self */ public static function aliasNotFound(string $alias): self { return new self(sprintf('Contact %s does not exist', $alias), 404); } /** * Exception thrown when the user is authenticated on IDP but the contact does not exist in the database. * * @param string $message * @param int $code * * @return self */ public static function withMessageAndCode(string $message, int $code): self { return new self($message, $code); } /** * Exception thrown when the request to custom endpoint fail. * * @return self */ public static function requestOnCustomEndpointFailed(): self { return new self(_('Request on custom endpoint failed')); } }
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/Authentication/Domain/Exception/PasswordExpiredException.php
centreon/src/Core/Security/Authentication/Domain/Exception/PasswordExpiredException.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\Authentication\Domain\Exception; class PasswordExpiredException extends AuthenticationException { /** * @return self */ public static function passwordIsExpired(): self { return new self(_('Password is expired')); } }
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/Authentication/Domain/Exception/AclConditionsException.php
centreon/src/Core/Security/Authentication/Domain/Exception/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\Authentication\Domain\Exception; class AclConditionsException extends \Exception { /** * Exceptions thrown when authentication conditions are invalid. * * @return self */ public static function invalidAclConditions(): self { return new self(_('Invalid roles mapping fetched from provider')); } /** * Exceptions thrown when authentication are not found. * * @return self */ public static function conditionsNotFound(): self { return new self(_('Role mapping conditions do not match')); } }
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/Authentication/Domain/Exception/AuthenticationException.php
centreon/src/Core/Security/Authentication/Domain/Exception/AuthenticationException.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\Authentication\Domain\Exception; class AuthenticationException extends \Exception { public static function notAuthenticated(?\Throwable $throwable = null): self { return new self(_('Authentication failed'), previous: $throwable); } public static function userBlocked(): self { return new self(_('Authentication failed')); } }
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/Authentication/Domain/Exception/AuthenticationConditionsException.php
centreon/src/Core/Security/Authentication/Domain/Exception/AuthenticationConditionsException.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\Authentication\Domain\Exception; class AuthenticationConditionsException extends \Exception { /** * Exceptions thrown when authentication conditions are invalid. * * @return self */ public static function invalidAuthenticationConditions(): self { return new self(_('Invalid Provider authentication conditions')); } /** * Exceptions thrown when authentication are not found. * * @return self */ public static function conditionsNotFound(): self { return new self(_('Authorized conditions not found in provider conditions')); } }
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/Authentication/Domain/Provider/OpenIdProvider.php
centreon/src/Core/Security/Authentication/Domain/Provider/OpenIdProvider.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\Authentication\Domain\Provider; use Centreon; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Contact\Interfaces\ContactServiceInterface; use Centreon\Domain\Log\LoggerTrait; use CentreonLog; use Core\Application\Configuration\User\Repository\WriteUserRepositoryInterface; use Core\Common\Application\Repository\ReadVaultRepositoryInterface; use Core\Contact\Domain\Model\ContactGroup; use Core\Domain\Configuration\User\Model\NewUser; use Core\Security\Authentication\Domain\Exception\AclConditionsException; use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Domain\Model\ProviderToken; use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\OpenIdConfigurationException; use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\AttributePath\AttributePathFetcher; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\Conditions; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\GroupsMapping as GroupsMappingSecurityAccess; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\RolesMapping; use Core\Security\Vault\Domain\Model\VaultConfiguration; use DateInterval; use Exception; use Security\Domain\Authentication\Interfaces\OpenIdProviderInterface; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 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; use Throwable; class OpenIdProvider implements OpenIdProviderInterface { use LoggerTrait; public const NAME = 'openid'; /** @var Configuration */ private Configuration $configuration; /** @var NewProviderToken */ private NewProviderToken $providerToken; /** @var NewProviderToken|null */ private ?NewProviderToken $refreshToken = null; /** @var array<string,mixed> */ private array $userInformations = []; /** @var string */ private string $username; /** @var Centreon */ private Centreon $legacySession; /** * Array of information store in id_token JWT Payload. * * @var array<string,mixed> */ private array $idTokenPayload = []; /** * Content of the connexion token response. * * @var array<string,mixed> */ private array $connectionTokenResponseContent = []; /** @var string[] */ private array $aclConditionsMatches = []; /** * @param HttpClientInterface $client * @param UrlGeneratorInterface $router * @param ContactServiceInterface $contactService * @param WriteUserRepositoryInterface $userRepository * @param Conditions $conditions * @param RolesMapping $rolesMapping * @param GroupsMappingSecurityAccess $groupsMapping * @param AttributePathFetcher $attributePathFetcher * @param ReadVaultRepositoryInterface $readVaultRepository * @param bool $isCloudPlatform */ public function __construct( private HttpClientInterface $client, private UrlGeneratorInterface $router, private ContactServiceInterface $contactService, private WriteUserRepositoryInterface $userRepository, private readonly Conditions $conditions, private readonly RolesMapping $rolesMapping, private readonly GroupsMappingSecurityAccess $groupsMapping, private readonly AttributePathFetcher $attributePathFetcher, private readonly ReadVaultRepositoryInterface $readVaultRepository, private readonly bool $isCloudPlatform, ) { } /** * @inheritDoc */ public function getConfiguration(): Configuration { return $this->configuration; } /** * @inheritDoc */ public function getProviderToken(): NewProviderToken { return $this->providerToken; } /** * @inheritDoc */ public function getProviderRefreshToken(): ?NewProviderToken { return $this->refreshToken; } /** * @inheritDoc */ public function setConfiguration(Configuration $configuration): void { $this->configuration = $configuration; } /** * @inheritDoc */ public function canCreateUser(): bool { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); return $customConfiguration->isAutoImportEnabled(); } /** * {@inheritDoc} * * @throws SSOAuthenticationException */ public function createUser(): void { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $this->info('Auto import starting...', [ 'user' => $this->username, ]); $this->validateAutoImportAttributesOrFail(); $user = new NewUser( $this->username, $this->userInformations[$customConfiguration->getUserNameBindAttribute()], $this->userInformations[$customConfiguration->getEmailBindAttribute()], ); if ($user->canReachFrontend()) { $user->setCanReachRealtimeApi(true); } if ($this->isCloudPlatform) { $user->setCanReachConfigurationApi(true); } $user->setContactTemplate($customConfiguration->getContactTemplate()); $this->userRepository->create($user); $this->info('Auto import complete', [ 'user_alias' => $this->username, 'user_fullname' => $this->userInformations[$customConfiguration->getUserNameBindAttribute()], 'user_email' => $this->userInformations[$customConfiguration->getEmailBindAttribute()], ]); } /** * @inheritDoc */ public function getLegacySession(): Centreon { return $this->legacySession; } /** * @inheritDoc */ public function setLegacySession(Centreon $legacySession): void { $this->legacySession = $legacySession; } /** * @inheritDoc */ public function getName(): string { return $this->configuration->getName(); } /** * @inheritDoc */ public function canRefreshToken(): bool { return true; } /** * {@inheritDoc} * * @param string|null $authorizationCode * @param string $clientIp * * @throws AclConditionsException * @throws AuthenticationConditionsException * @throws ConfigurationException * @throws SSOAuthenticationException * @throws OpenIdConfigurationException */ public function authenticateOrFail(?string $authorizationCode, string $clientIp): string { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $this->info('Start authenticating user...', [ 'provider' => $this->configuration->getName(), ]); if (empty($authorizationCode)) { $this->error( 'No authorization code returned from external provider', [ 'provider' => $this->configuration->getName(), ] ); throw SSOAuthenticationException::noAuthorizationCode($this->configuration->getName()); } if ($customConfiguration->getTokenEndpoint() === null) { throw ConfigurationException::missingTokenEndpoint(); } if ( $customConfiguration->getIntrospectionTokenEndpoint() === null && $customConfiguration->getUserInformationEndpoint() === null ) { throw ConfigurationException::missingInformationEndpoint(); } $this->sendRequestForConnectionTokenOrFail($authorizationCode, $customConfiguration->getRedirectUrl()); $this->createAuthenticationTokens(); if (array_key_exists('id_token', $this->connectionTokenResponseContent)) { $this->idTokenPayload = $this->extractTokenPayload($this->connectionTokenResponseContent['id_token']); } $this->verifyThatClientIsAllowedToConnectOrFail($clientIp); if ($this->providerToken->isExpired() && $this->refreshToken?->isExpired()) { throw SSOAuthenticationException::tokensExpired($this->configuration->getName()); } if ($customConfiguration->getIntrospectionTokenEndpoint() !== null) { $this->getUserInformationFromIntrospectionEndpoint(); } return $this->username = $this->getUsernameFromLoginClaim(); } /** * @inheritDoc */ public function getUser(): ?ContactInterface { $this->info('Searching user : ' . $this->username); return $this->contactService->findByName($this->username) ?? $this->contactService->findByEmail($this->username); } /** * @inheritDoc */ public function refreshToken(AuthenticationTokens $authenticationTokens): AuthenticationTokens { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); if ($authenticationTokens->getProviderRefreshToken() === null) { throw SSOAuthenticationException::noRefreshToken(); } $this->info( 'Refreshing token using refresh token', [ 'refresh_token' => mb_substr($authenticationTokens->getProviderRefreshToken()->getToken(), -10), ] ); // Define parameters for the request $data = [ 'grant_type' => 'refresh_token', 'refresh_token' => $authenticationTokens->getProviderRefreshToken()->getToken(), 'scope' => ! empty($customConfiguration->getConnectionScopes()) ? implode(' ', $customConfiguration->getConnectionScopes()) : null, ]; $response = $this->sendRequestToTokenEndpoint($data); // Get the status code and throw an Exception if not a 200 $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true, 512, JSON_THROW_ON_ERROR) ?: []; if ($statusCode !== Response::HTTP_OK) { $this->logErrorForInvalidStatusCode($statusCode, Response::HTTP_OK); $this->logErrorInLoginLogFile('Refresh Token Request Error:', $content); $this->logErrorFromExternalProvider($content); $this->logExceptionInLoginLogFile( 'Unable to get Refresh Token Information: %s, message: %s', SSOAuthenticationException::requestForRefreshTokenFail() ); throw SSOAuthenticationException::requestForRefreshTokenFail(); } $this->logAuthenticationDebug('Token Access Information:', $content); $creationDate = new \DateTimeImmutable(); $providerTokenExpiration = (new \DateTimeImmutable())->add(new DateInterval('PT' . $content['expires_in'] . 'S')); /** @var ProviderToken $providerToken */ $providerToken = $authenticationTokens->getProviderToken(); $this->providerToken = new ProviderToken( $providerToken->getId(), $content['access_token'], $creationDate, $providerTokenExpiration ); if (array_key_exists('refresh_token', $content)) { $expirationDelay = $content['expires_in'] + 3600; if (array_key_exists('refresh_expires_in', $content)) { $expirationDelay = $content['refresh_expires_in']; } $refreshTokenExpiration = (new \DateTimeImmutable()) ->add(new DateInterval('PT' . $expirationDelay . 'S')); if ($authenticationTokens->getProviderRefreshToken() instanceof ProviderToken) { $this->refreshToken = new ProviderToken( $authenticationTokens->getProviderRefreshToken()->getId(), $content['refresh_token'], $creationDate, $refreshTokenExpiration ); } else { $this->refreshToken = new NewProviderToken( $content['refresh_token'], $creationDate, $refreshTokenExpiration ); } } return new AuthenticationTokens( $authenticationTokens->getUserId(), $authenticationTokens->getConfigurationProviderId(), $authenticationTokens->getSessionToken(), $this->providerToken, $this->refreshToken ); } /** * @inheritDoc */ public function getUserInformation(): array { return $this->userInformations; } /** * @inheritDoc */ public function getIdTokenPayload(): array { return $this->idTokenPayload; } /** * @inheritDoc */ public function getAclConditionsMatches(): array { return $this->aclConditionsMatches; } /** * @return ContactGroup[] */ public function getUserContactGroups(): array { return $this->groupsMapping->getUserContactGroups(); } /** * Get OIDC token for session. * * @return string|null */ public function getTokenForSession(): ?string { if (! array_key_exists('id_token', $this->connectionTokenResponseContent)) { throw SSOAuthenticationException::requestForConnectionTokenFail(); } return $this->connectionTokenResponseContent['id_token']; } /** * Extract Payload from JWT token. * * @param string $token * * @throws SSOAuthenticationException * * @return array<string,mixed> */ private function extractTokenPayload(string $token): array { try { $tokenParts = explode('.', $token); return json_decode($this->urlSafeTokenDecode($tokenParts[1]), true); } catch (Throwable $ex) { $this->error( SSOAuthenticationException::unableToDecodeIdToken()->getMessage(), ['trace' => $ex->getTraceAsString()] ); throw SSOAuthenticationException::unableToDecodeIdToken(); } } /** * Get Connection Token from OpenId Provider. * * @param string $authorizationCode * @param string|null $redirectUrl * * @throws SSOAuthenticationException */ private function sendRequestForConnectionTokenOrFail(string $authorizationCode, ?string $redirectUrl): void { $this->info('Send request to external provider for connection token...'); // Define parameters for the request $redirectUri = $redirectUrl !== null ? $redirectUrl . $this->router->generate( 'centreon_security_authentication_login_openid', [], UrlGeneratorInterface::ABSOLUTE_PATH ) : $this->router->generate( 'centreon_security_authentication_login_openid', [], UrlGeneratorInterface::ABSOLUTE_URL ); $data = [ 'grant_type' => 'authorization_code', 'code' => $authorizationCode, 'redirect_uri' => $redirectUri, ]; $response = $this->sendRequestToTokenEndpoint($data); // Get the status code and throw an Exception if not a 200 $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true, 512, JSON_THROW_ON_ERROR) ?: []; if ($statusCode !== Response::HTTP_OK) { $this->logErrorForInvalidStatusCode($statusCode, Response::HTTP_OK); $this->logErrorInLoginLogFile('Connection Token Request Error: ', $content); $this->logErrorFromExternalProvider($content); $this->logExceptionInLoginLogFile( 'Unable to get Token Access Information: %s, message: %s', SSOAuthenticationException::requestForConnectionTokenFail() ); throw SSOAuthenticationException::requestForConnectionTokenFail(); } $this->logAuthenticationDebug('Token Access Information:', $content); $this->connectionTokenResponseContent = $content; } /** * Create Authentication Tokens. */ private function createAuthenticationTokens(): void { $creationDate = new \DateTimeImmutable(); $expirationDelay = array_key_exists('expires_in', $this->connectionTokenResponseContent) ? $this->connectionTokenResponseContent['expires_in'] : 3600; $providerTokenExpiration = (new \DateTimeImmutable())->add( new DateInterval('PT' . $expirationDelay . 'S') ); $this->providerToken = new NewProviderToken( $this->connectionTokenResponseContent['access_token'], $creationDate, $providerTokenExpiration ); if (array_key_exists('refresh_token', $this->connectionTokenResponseContent)) { $expirationDelay = $this->connectionTokenResponseContent['expires_in'] + 3600; if (array_key_exists('refresh_expires_in', $this->connectionTokenResponseContent)) { $expirationDelay = $this->connectionTokenResponseContent['refresh_expires_in']; } $refreshTokenExpiration = (new \DateTimeImmutable()) ->add(new DateInterval('PT' . $expirationDelay . 'S')); $this->refreshToken = new NewProviderToken( $this->connectionTokenResponseContent['refresh_token'], $creationDate, $refreshTokenExpiration ); } } /** * Send a request to get introspection token information. * * @throws SSOAuthenticationException|OpenIdConfigurationException */ private function getUserInformationFromIntrospectionEndpoint(): void { $this->userInformations = $this->sendRequestForIntrospectionEndpoint(); } /** * Send a request to get introspection token information. * * @throws SSOAuthenticationException|OpenIdConfigurationException * * @return array<string,mixed> */ private function sendRequestForIntrospectionEndpoint(): array { $this->info('Sending request for introspection token information'); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); if ( $customConfiguration->getClientId() !== null && str_starts_with($customConfiguration->getClientId(), VaultConfiguration::VAULT_PATH_PATTERN) ) { $vaultData = $this->readVaultRepository->findFromPath($customConfiguration->getClientId()); if (! array_key_exists(VaultConfiguration::OPENID_CLIENT_ID_KEY, $vaultData)) { throw OpenIdConfigurationException::unableToRetrieveCredentialFromVault( VaultConfiguration::OPENID_CLIENT_ID_KEY ); } $customConfiguration->setClientId($vaultData[VaultConfiguration::OPENID_CLIENT_ID_KEY]); } if ( $customConfiguration->getClientSecret() !== null && str_starts_with($customConfiguration->getClientSecret(), VaultConfiguration::VAULT_PATH_PATTERN) ) { $vaultData = $this->readVaultRepository->findFromPath($customConfiguration->getClientSecret()); if (! array_key_exists(VaultConfiguration::OPENID_CLIENT_SECRET_KEY, $vaultData)) { throw OpenIdConfigurationException::unableToRetrieveCredentialFromVault( VaultConfiguration::OPENID_CLIENT_SECRET_KEY ); } $customConfiguration->setClientSecret($vaultData[VaultConfiguration::OPENID_CLIENT_SECRET_KEY]); } // Define parameters for the request $data = [ 'token' => $this->providerToken->getToken(), 'client_id' => $customConfiguration->getClientId(), 'client_secret' => $customConfiguration->getClientSecret(), ]; $headers = [ 'Authorization' => 'Bearer ' . trim($this->providerToken->getToken()), ]; try { $response = $this->client->request( 'POST', $customConfiguration->getBaseUrl() . '/' . ltrim($customConfiguration->getIntrospectionTokenEndpoint() ?? '', '/'), [ 'headers' => $headers, 'body' => $data, 'verify_peer' => $customConfiguration->verifyPeer(), ] ); } catch (Exception $exception) { $this->logExceptionInLoginLogFile('Unable to get Introspection Information: %s, message: %s', $exception); $this->error( sprintf( '[Error] Unable to get Introspection Token Information:, message: %s', $exception->getMessage() ) ); throw SSOAuthenticationException::requestForIntrospectionTokenFail(); } $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true, 512, JSON_THROW_ON_ERROR) ?: []; if ($statusCode !== Response::HTTP_OK) { $this->logErrorForInvalidStatusCode($statusCode, Response::HTTP_OK); $this->logErrorInLoginLogFile('Introspection Token Info: ', $content); $this->logErrorFromExternalProvider($content); $this->logExceptionInLoginLogFile( 'Unable to get Introspection Information: %s, message: %s', SSOAuthenticationException::requestForIntrospectionTokenFail() ); throw SSOAuthenticationException::requestForIntrospectionTokenFail(); } $this->logAuthenticationInfo('Token Introspection Information: ', $content); return $content; } /** * Send a request to get user information. * * @throws ClientExceptionInterface * @throws RedirectionExceptionInterface * @throws SSOAuthenticationException * @throws ServerExceptionInterface * @throws TransportExceptionInterface */ private function getUserInformationFromUserInfoEndpoint(): void { $this->userInformations = $this->sendRequestForUserInformationEndpoint(); } /** * Send a request to get user information. * * @throws ClientExceptionInterface * @throws RedirectionExceptionInterface * @throws SSOAuthenticationException * @throws ServerExceptionInterface * @throws TransportExceptionInterface * * @return array<string,mixed> */ private function sendRequestForUserInformationEndpoint(): array { $this->info('Sending Request for User Information...'); $headers = [ 'Authorization' => 'Bearer ' . trim($this->providerToken->getToken()), ]; /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $url = str_starts_with($customConfiguration->getUserInformationEndpoint() ?? '', '/') ? $customConfiguration->getBaseUrl() . $customConfiguration->getUserInformationEndpoint() : $customConfiguration->getUserInformationEndpoint() ?? ''; try { $response = $this->client->request( 'GET', $url, [ 'headers' => $headers, 'verify_peer' => $customConfiguration->verifyPeer(), ] ); } catch (Exception) { throw SSOAuthenticationException::requestForUserInformationFail(); } $statusCode = $response->getStatusCode(); $content = json_decode($response->getContent(false), true, 512, JSON_THROW_ON_ERROR) ?: []; if ($statusCode !== Response::HTTP_OK) { $this->logErrorForInvalidStatusCode($statusCode, Response::HTTP_OK); $this->logErrorInLoginLogFile('User Information Info: ', $content); $this->logErrorFromExternalProvider($content); $this->logExceptionInLoginLogFile( 'Unable to get User Information: %s, message: %s', SSOAuthenticationException::requestForUserInformationFail() ); throw SSOAuthenticationException::requestForUserInformationFail(); } $this->logAuthenticationDebug('User Information: ', $content); return $content; } /** * Validate that Client IP is allowed to connect to external provider. * * @param string $clientIp * * @throws AclConditionsException * @throws AuthenticationConditionsException * @throws SSOAuthenticationException */ private function verifyThatClientIsAllowedToConnectOrFail(string $clientIp): void { $this->info('Check Client IP against blacklist/whitelist addresses'); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $authenticationConditions = $customConfiguration->getAuthenticationConditions(); $rolesMapping = $customConfiguration->getACLConditions(); $groupsMapping = $customConfiguration->getGroupsMapping(); foreach ($authenticationConditions->getBlacklistClientAddresses() as $blackListedAddress) { if ($blackListedAddress !== '' && preg_match('/' . $blackListedAddress . '/', $clientIp)) { $this->error('IP Blacklisted', ['ip' => '...' . mb_substr($clientIp, -5)]); throw SSOAuthenticationException::blackListedClient(); } } foreach ($authenticationConditions->getTrustedClientAddresses() as $trustedClientAddress) { if ( $trustedClientAddress !== '' && preg_match('/' . $trustedClientAddress . '/', $clientIp) ) { $this->error('IP not Whitelisted', ['ip' => '...' . mb_substr($clientIp, -5)]); throw SSOAuthenticationException::notWhiteListedClient(); } } $accessToken = $this->providerToken->getToken(); $this->conditions->validate( $this->configuration, $authenticationConditions->isEnabled() ? array_merge( $this->idTokenPayload, array_diff_key( $this->attributePathFetcher->fetch( $accessToken, $this->configuration, $authenticationConditions->getEndpoint() ?? throw new \LogicException() ), $this->idTokenPayload ) ) : $this->idTokenPayload ); $this->rolesMapping->validate( $this->configuration, $rolesMapping->isEnabled() ? array_merge( $this->idTokenPayload, array_diff_key( $this->attributePathFetcher->fetch( $accessToken, $this->configuration, $rolesMapping->getEndpoint() ?? throw new \LogicException() ), $this->idTokenPayload ) ) : $this->idTokenPayload ); $this->aclConditionsMatches = $this->rolesMapping->getConditionMatches(); $this->groupsMapping->validate( $this->configuration, $groupsMapping->isEnabled() ? array_merge( $this->idTokenPayload, array_diff_key( $this->attributePathFetcher->fetch( $accessToken, $this->configuration, $groupsMapping->getEndpoint() ?? throw new \LogicException() ), $this->idTokenPayload ) ) : $this->idTokenPayload ); } /** * Return username from login claim. * * @throws SSOAuthenticationException * * @return string */ private function getUsernameFromLoginClaim(): string { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $loginClaim = ! empty($customConfiguration->getLoginClaim()) ? $customConfiguration->getLoginClaim() : CustomConfiguration::DEFAULT_LOGIN_CLAIM; if ( ! array_key_exists($loginClaim, $this->userInformations) && $customConfiguration->getUserInformationEndpoint() !== null ) { $this->getUserInformationFromUserInfoEndpoint(); } if (! array_key_exists($loginClaim, $this->userInformations)) { CentreonLog::create()->error( CentreonLog::TYPE_LOGIN, '[Openid] Unable to get login from claim: ' . $loginClaim ); $this->error('Login Claim not found', ['login_claim' => $loginClaim]); throw SSOAuthenticationException::loginClaimNotFound($this->configuration->getName(), $loginClaim); } return $this->userInformations[$loginClaim]; } /** * Define authentication type based on configuration. * * @param array<string,mixed> $data * * @throws SSOAuthenticationException * * @return ResponseInterface */ private function sendRequestToTokenEndpoint(array $data): ResponseInterface { $headers = [ 'Content-Type' => 'application/x-www-form-urlencoded', ]; /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); if ( $customConfiguration->getClientId() !== null && str_starts_with($customConfiguration->getClientId(), VaultConfiguration::VAULT_PATH_PATTERN) ) { $vaultData = $this->readVaultRepository->findFromPath($customConfiguration->getClientId()); if (! array_key_exists(VaultConfiguration::OPENID_CLIENT_ID_KEY, $vaultData)) { throw OpenIdConfigurationException::unableToRetrieveCredentialFromVault( VaultConfiguration::OPENID_CLIENT_ID_KEY ); } $customConfiguration->setClientId($vaultData[VaultConfiguration::OPENID_CLIENT_ID_KEY]); } if ( $customConfiguration->getClientSecret() !== null && str_starts_with($customConfiguration->getClientSecret(), VaultConfiguration::VAULT_PATH_PATTERN) ) {
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
true
centreon/centreon
https://github.com/centreon/centreon/blob/6ae83001e94de0a4cec11e084780fcfa63f1c985/centreon/src/Core/Security/Authentication/Domain/Provider/WebSSOProvider.php
centreon/src/Core/Security/Authentication/Domain/Provider/WebSSOProvider.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\Authentication\Domain\Provider; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Security\Domain\Authentication\Interfaces\WebSSOProviderInterface; class WebSSOProvider implements WebSSOProviderInterface { public const NAME = 'web-sso'; public const TYPE = 'web-sso'; /** @var \Centreon */ private \Centreon $legacySession; /** @var Configuration */ private Configuration $configuration; /** * @inheritDoc */ public function getLegacySession(): \Centreon { return $this->legacySession; } /** * @inheritDoc */ public function setLegacySession(\Centreon $legacySession): void { $this->legacySession = $legacySession; } /** * @inheritDoc */ public function canCreateUser(): bool { return false; } /** * @inheritDoc */ public function canRefreshToken(): bool { return false; } /** * @inheritDoc */ public function getName(): string { return self::NAME; } /** * @inheritDoc */ public function getUser(): ?ContactInterface { return null; } /** * @inheritDoc */ public function setConfiguration(Configuration $configuration): void { $this->configuration = $configuration; } /** * @inheritDoc */ public function getConfiguration(): Configuration { return $this->configuration; } /** * @inheritDoc */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens { 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/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionPresenter.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionPresenter.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\Authentication\Infrastructure\Api\LogoutSession; use Core\Application\Common\UseCase\AbstractPresenter; use Core\Security\Authentication\Application\UseCase\LogoutSession\LogoutSessionPresenterInterface; class LogoutSessionPresenter extends AbstractPresenter implements LogoutSessionPresenterInterface { }
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/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/LogoutSession/LogoutSessionController.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\Authentication\Infrastructure\Api\LogoutSession; use Centreon\Application\Controller\AbstractController; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\LogoutSession\LogoutSession; use Core\Security\Authentication\Application\UseCase\LogoutSession\LogoutSessionPresenterInterface; use Symfony\Component\HttpFoundation\Request; final class LogoutSessionController extends AbstractController { use HttpUrlTrait; /** * @param LogoutSession $useCase * @param Request $request * @param LogoutSessionPresenterInterface $presenter * * @return object */ public function __invoke( LogoutSession $useCase, Request $request, LogoutSessionPresenterInterface $presenter, ): object { $useCase($request->cookies->get('PHPSESSID'), $presenter); return $this->redirect($this->getBaseUrl() . '/login'); } }
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/Authentication/Infrastructure/Api/Login/OpenId/LoginController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/OpenId/LoginController.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\Authentication\Infrastructure\Api\Login\OpenId; use Centreon\Application\Controller\AbstractController; use Core\Application\Common\UseCase\ErrorAuthenticationConditionsResponse; use Core\Application\Common\UseCase\ErrorResponse; use Core\Application\Common\UseCase\UnauthorizedResponse; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\Login\ErrorAclConditionsResponse; use Core\Security\Authentication\Application\UseCase\Login\Login; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Application\UseCase\Login\LoginResponse; use Core\Security\Authentication\Application\UseCase\Login\PasswordExpiredResponse; use FOS\RestBundle\View\View; use Symfony\Component\HttpFoundation\Request; final class LoginController extends AbstractController { use HttpUrlTrait; /** * @param Request $request * @param Login $useCase * @param LoginPresenter $presenter * * @return View */ public function __invoke( Request $request, Login $useCase, LoginPresenter $presenter, ): View { $loginRequest = LoginRequest::createForOpenId( $request->getClientIp() ?: '', (string) $request->query->get('code', '') ); $useCase($loginRequest, $presenter); $response = $presenter->getResponseStatus() ?? $presenter->getPresentedData(); switch (true) { case $response instanceof PasswordExpiredResponse: case $response instanceof UnauthorizedResponse: case $response instanceof ErrorResponse: return View::createRedirect( $this->getBaseUrl() . '/login?' . http_build_query([ 'authenticationError' => $response->getMessage(), ]), ); case $response instanceof ErrorAclConditionsResponse: case $response instanceof ErrorAuthenticationConditionsResponse: return View::createRedirect( $this->getBaseUrl() . '/authentication-denied', ); case $response instanceof LoginResponse: return View::createRedirect( $this->getBaseUrl() . $response->getRedirectUri(), ); default: return View::createRedirect( $this->getBaseUrl() . '/login?' . http_build_query([ 'authenticationError' => 'Unknown error', ]), ); } } }
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/Authentication/Infrastructure/Api/Login/OpenId/LoginPresenter.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/OpenId/LoginPresenter.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\Authentication\Infrastructure\Api\Login\OpenId; use Core\Application\Common\UseCase\AbstractPresenter; use Core\Security\Authentication\Application\UseCase\Login\LoginPresenterInterface; class LoginPresenter extends AbstractPresenter implements LoginPresenterInterface { }
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/Authentication/Infrastructure/Api/Login/Local/LoginController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/Local/LoginController.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\Authentication\Infrastructure\Api\Login\Local; use Centreon\Application\Controller\AbstractController; use Centreon\Domain\Log\LoggerTrait; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\Login\Login; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Response; final class LoginController extends AbstractController { use HttpUrlTrait; use LoggerTrait; /** * @param Request $request * @param Login $useCase * @param LoginPresenter $presenter * @param RequestStack $requestStack * * @return Response */ public function __invoke( Request $request, Login $useCase, LoginPresenter $presenter, RequestStack $requestStack, ): Response { /** @var string $content */ $content = $request->getContent(); /** @var array{login?: string, password?: string} $payload */ $payload = json_decode($content, true); if ($referer = $request->headers->get('referer')) { $referer = parse_url($referer, PHP_URL_QUERY); } $loginRequest = LoginRequest::createForLocal( (string) ($payload['login'] ?? ''), (string) ($payload['password'] ?? ''), $request->getClientIp(), $referer ?: null ); try { $useCase($loginRequest, $presenter); } catch (\Exception $exception) { $this->error($exception->getMessage()); } $presenter->setResponseHeaders( ['Set-Cookie' => 'PHPSESSID=' . $requestStack->getSession()->getId()] ); 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/Authentication/Infrastructure/Api/Login/Local/LoginPresenter.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/Local/LoginPresenter.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\Authentication\Infrastructure\Api\Login\Local; use Core\Application\Common\UseCase\AbstractPresenter; use Core\Security\Authentication\Application\UseCase\Login\LoginPresenterInterface; class LoginPresenter extends AbstractPresenter implements LoginPresenterInterface { /** * @param mixed $response */ public function present(mixed $response): void { $presenterResponse = [ 'redirect_uri' => $response->getRedirectUri(), ]; 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/Authentication/Infrastructure/Api/Login/SAML/CallbackController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/SAML/CallbackController.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\Authentication\Infrastructure\Api\Login\SAML; use Centreon\Application\Controller\AbstractController; use Core\Application\Common\UseCase\{ErrorAuthenticationConditionsResponse, ErrorResponse, UnauthorizedResponse}; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\Login\{ErrorAclConditionsResponse, Login, LoginRequest, LoginResponse, PasswordExpiredResponse, ThirdPartyLoginForm}; use FOS\RestBundle\View\View; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; final class CallbackController extends AbstractController { use HttpUrlTrait; /** * @param Request $request * @param Login $useCase * @param CallbackPresenter $presenter * @param RequestStack $requestStack * @param ThirdPartyLoginForm $thirdPartyLoginForm * * @return View */ public function __invoke( Request $request, Login $useCase, CallbackPresenter $presenter, RequestStack $requestStack, ThirdPartyLoginForm $thirdPartyLoginForm, ): View { $samlLoginRequest = LoginRequest::createForSAML((string) $request->getClientIp()); $useCase($samlLoginRequest, $presenter); $response = $presenter->getResponseStatus() ?? $presenter->getPresentedData(); switch (true) { case $response instanceof PasswordExpiredResponse: case $response instanceof UnauthorizedResponse: case $response instanceof ErrorResponse: return View::createRedirect( $this->getBaseUrl() . '/login?' . http_build_query([ 'authenticationError' => $response->getMessage(), ]), ); case $response instanceof ErrorAclConditionsResponse: case $response instanceof ErrorAuthenticationConditionsResponse: return View::createRedirect( $this->getBaseUrl() . '/authentication-denied' ); case $response instanceof LoginResponse: if ($redirectToThirdPartyLoginForm = $thirdPartyLoginForm->getReturnUrlAfterAuth()) { return View::createRedirect($redirectToThirdPartyLoginForm); } if ($response->redirectIsReact()) { return View::createRedirect( $this->getBaseUrl() . $response->getRedirectUri(), headers: ['Set-Cookie' => 'PHPSESSID=' . $requestStack->getSession()->getId()] ); } return View::createRedirect( $this->getBaseUrl() . $response->getRedirectUri(), headers: ['Set-Cookie' => 'REDIRECT_URI=' . $this->getBaseUrl() . $response->getRedirectUri() . ';Max-Age=10'] ); default: return View::createRedirect( $this->getBaseUrl() . '/login?' . http_build_query([ 'authenticationError' => 'Unknown error', ]), ); } } }
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/Authentication/Infrastructure/Api/Login/SAML/LoginController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/SAML/LoginController.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\Authentication\Infrastructure\Api\Login\SAML; use Centreon\Application\Controller\AbstractController; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\Login\ThirdPartyLoginForm; use Core\Security\Authentication\Infrastructure\Provider\ProviderAuthenticationFactory; use Core\Security\Authentication\Infrastructure\Provider\SAML; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Symfony\Component\HttpFoundation\Request; final class LoginController extends AbstractController { use HttpUrlTrait; /** * @param ProviderAuthenticationFactory $providerAuthenticationFactory * @param ThirdPartyLoginForm $thirdPartyLoginForm */ public function __construct( private readonly ProviderAuthenticationFactory $providerAuthenticationFactory, private readonly ThirdPartyLoginForm $thirdPartyLoginForm, ) { } public function __invoke(Request $request): void { /** @var SAML $provider */ $provider = $this->providerAuthenticationFactory->create(Provider::SAML); $provider->login($this->thirdPartyLoginForm->getReturnUrlBeforeAuth($request)); } }
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/Authentication/Infrastructure/Api/Login/SAML/SLSController.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/SAML/SLSController.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\Authentication\Infrastructure\Api\Login\SAML; use Centreon\Application\Controller\AbstractController; use Centreon\Domain\Log\LoggerTrait; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\Authentication\Application\UseCase\LogoutSession\SAML\LogoutFromIdp; use OneLogin\Saml2\Error; final class SLSController extends AbstractController { use HttpUrlTrait; use LoggerTrait; /** * @param LogoutFromIdp $usecase * * @throws Error */ public function __invoke(LogoutFromIdp $usecase): void { $this->info('SAML SLS invoked'); $usecase(); } }
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/Authentication/Infrastructure/Api/Login/SAML/CallbackPresenter.php
centreon/src/Core/Security/Authentication/Infrastructure/Api/Login/SAML/CallbackPresenter.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\Authentication\Infrastructure\Api\Login\SAML; use Core\Application\Common\UseCase\AbstractPresenter; use Core\Security\Authentication\Application\UseCase\Login\LoginPresenterInterface; class CallbackPresenter extends AbstractPresenter implements LoginPresenterInterface { }
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/Authentication/Infrastructure/Provider/AclUpdaterInterface.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/AclUpdaterInterface.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\Authentication\Infrastructure\Provider; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; interface AclUpdaterInterface { /** * @param ProviderAuthenticationInterface $provider * @param ContactInterface $user */ public function updateForProviderAndUser(ProviderAuthenticationInterface $provider, ContactInterface $user): 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/Authentication/Infrastructure/Provider/AclUpdater.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/AclUpdater.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\Authentication\Infrastructure\Provider; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Repository\Interfaces\DataStorageEngineInterface; use Core\Contact\Application\Repository\WriteContactGroupRepositoryInterface; use Core\Contact\Domain\Model\ContactGroup; use Core\Security\AccessGroup\Application\Repository\WriteAccessGroupRepositoryInterface; use Core\Security\AccessGroup\Domain\Model\AccessGroup; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Domain\Exception\ProviderException; use Core\Security\Authentication\Infrastructure\Provider\OpenId as OpenIdProvider; use Core\Security\Authentication\Infrastructure\Provider\SAML as SamlProvider; use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration; class AclUpdater implements AclUpdaterInterface { use LoggerTrait; /** @var ProviderAuthenticationInterface */ private ProviderAuthenticationInterface $provider; /** * @param DataStorageEngineInterface $dataStorageEngine * @param WriteContactGroupRepositoryInterface $contactGroupRepository * @param WriteAccessGroupRepositoryInterface $accessGroupRepository */ public function __construct( private DataStorageEngineInterface $dataStorageEngine, private WriteContactGroupRepositoryInterface $contactGroupRepository, private WriteAccessGroupRepositoryInterface $accessGroupRepository, ) { } /** * @param ProviderAuthenticationInterface $provider * @param ContactInterface $user */ public function updateForProviderAndUser(ProviderAuthenticationInterface $provider, ContactInterface $user): void { $this->provider = $provider; if ($provider->isUpdateACLSupported()) { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $provider->getConfiguration()->getCustomConfiguration(); $aclConditions = $customConfiguration->getACLConditions(); if ($aclConditions->isEnabled()) { $aclConditionMatches = $provider->getAclConditionsMatches(); if ( ! $this->provider instanceof OpenIdProvider && ! $this->provider instanceof SamlProvider ) { throw ProviderException::unexpectedProvider(($this->provider)::class); } $userAccessGroups = $this->provider->getUserAccessGroupsFromClaims($aclConditionMatches); $this->updateAccessGroupsForUser($user, $userAccessGroups); } $groupMappings = $customConfiguration->getGroupsMapping(); if ($groupMappings->isEnabled()) { $this->updateContactGroupsForUser($user, $this->provider->getUserContactGroups()); } } } /** * Delete and Insert Access Groups for authenticated user. * * @param ContactInterface $user * @param AccessGroup[] $userAccessGroups */ private function updateAccessGroupsForUser(ContactInterface $user, array $userAccessGroups): void { try { $this->info('Updating User Access Groups', [ 'user_id' => $user->getId(), 'access_groups' => $userAccessGroups, ]); $this->dataStorageEngine->startTransaction(); $this->accessGroupRepository->deleteAccessGroupsForUser($user); $this->accessGroupRepository->insertAccessGroupsForUser($user, $userAccessGroups); $this->dataStorageEngine->commitTransaction(); } catch (\Exception $ex) { $this->dataStorageEngine->rollbackTransaction(); $this->error('Error during ACL update', [ 'user_id' => $user->getId(), 'access_groups' => $userAccessGroups, 'trace' => $ex->getTraceAsString(), ]); } } /** * Delete and Insert Contact Group for authenticated user. * * @param ContactInterface $user * @param ContactGroup[] $contactGroups */ private function updateContactGroupsForUser(ContactInterface $user, array $contactGroups): void { $contactGroup = null; try { $this->info('Updating user contact group', [ 'user_id' => $user->getId(), 'contact_group_id' => [ array_map(fn ($contactGroup) => $contactGroup->getId(), $contactGroups), ], ]); $this->dataStorageEngine->startTransaction(); $this->contactGroupRepository->deleteContactGroupsForUser($user); foreach ($contactGroups as $contactGroup) { $this->contactGroupRepository->insertContactGroupForUser($user, $contactGroup); } $this->dataStorageEngine->commitTransaction(); } catch (\Exception $ex) { $this->dataStorageEngine->rollbackTransaction(); $this->error('Error during contact group update', [ 'user_id' => $user->getId(), 'contact_group_id' => $contactGroup?->getId(), 'trace' => $ex->getTraceAsString(), ]); } } }
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/Authentication/Infrastructure/Provider/SAML.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/SAML.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\Authentication\Infrastructure\Provider; use Assert\AssertionFailedException; use Centreon; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Contact\Interfaces\ContactRepositoryInterface; use Centreon\Domain\Log\LoggerTrait; use CentreonSession; use Core\Application\Configuration\User\Repository\WriteUserRepositoryInterface; use Core\Domain\Configuration\User\Model\NewUser; use Core\Security\AccessGroup\Domain\Model\AccessGroup; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Exception\AclConditionsException; use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Infrastructure\Provider\Exception\InvalidArgumentProvidedException; use Core\Security\Authentication\Infrastructure\Provider\Exception\InvalidUserIdAttributeException; use Core\Security\Authentication\Infrastructure\Provider\Exception\SAML\InvalidMetadataException; use Core\Security\Authentication\Infrastructure\Provider\Exception\SAML\ProcessAuthenticationResponseException; use Core\Security\Authentication\Infrastructure\Provider\Exception\UserNotAuthenticatedException; use Core\Security\Authentication\Infrastructure\Provider\Settings\Formatter\SettingsFormatterInterface; 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\SAML\Model\CustomConfiguration; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\Conditions; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\GroupsMapping as GroupsMappingSecurityAccess; use Core\Security\ProviderConfiguration\Domain\SecurityAccess\RolesMapping; use DateInterval; use DateTimeImmutable; use Exception; use OneLogin\Saml2\Auth; use OneLogin\Saml2\Error; use OneLogin\Saml2\Utils; use OneLogin\Saml2\ValidationError; use Pimple\Container; use Throwable; class SAML implements ProviderAuthenticationInterface { use LoggerTrait; /** @var Configuration */ private Configuration $configuration; /** @var Centreon */ private Centreon $legacySession; /** @var string */ private string $username; /** @var ContactInterface|null */ private ?ContactInterface $authenticatedUser = null; /** @var Auth|null */ private ?Auth $auth = null; /** * @param Container $dependencyInjector * @param ContactRepositoryInterface $contactRepository * @param LoginLoggerInterface $loginLogger * @param WriteUserRepositoryInterface $userRepository * @param Conditions $conditions * @param RolesMapping $rolesMapping * @param GroupsMappingSecurityAccess $groupsMapping * @param SettingsFormatterInterface $formatter */ public function __construct( private readonly Container $dependencyInjector, private readonly ContactRepositoryInterface $contactRepository, private readonly LoginLoggerInterface $loginLogger, private readonly WriteUserRepositoryInterface $userRepository, private readonly Conditions $conditions, private readonly RolesMapping $rolesMapping, private readonly GroupsMappingSecurityAccess $groupsMapping, private readonly SettingsFormatterInterface $formatter, ) { } /** * @param LoginRequest $request * * @throws AclConditionsException * @throws Error * @throws ValidationError * @throws AuthenticationConditionsException * @throws Exception */ public function authenticateOrFail(LoginRequest $request): void { $this->loginLogger->info(Provider::SAML, 'authenticate the user through SAML'); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $this->auth = new Auth($this->formatter->format($customConfiguration)); $auth = $this->auth; $auth->processResponse($_SESSION['AuthNRequestID'] ?? null); $errors = $auth->getErrors(); if (! empty($errors)) { $ex = ProcessAuthenticationResponseException::create(); $this->loginLogger->error(Provider::SAML, $ex->getMessage(), ['context' => (string) json_encode($errors), 'error' => $this->auth->getLastErrorReason()]); throw $ex; } if (! $auth->isAuthenticated()) { $ex = UserNotAuthenticatedException::create(); $this->loginLogger->error(Provider::SAML, $ex->getMessage()); throw $ex; } $settings = $auth->getSettings(); $metadata = $settings->getSPMetadata(); $errors = $settings->validateMetadata($metadata); if (! empty($errors)) { $ex = InvalidMetadataException::create(); $this->info($ex->getMessage(), ['errors' => $errors]); throw $ex; } $this->loginLogger->info( Provider::SAML, 'User information: ' . json_encode($auth->getAttributes()) ); $this->info('User information: ', $auth->getAttributes()); $attrs = $auth->getAttribute($customConfiguration->getUserIdAttribute()); if (! is_array($attrs) || ! is_string($attrs[0] ?? null)) { throw InvalidUserIdAttributeException::create(); } $this->username = $attrs[0]; CentreonSession::writeSessionClose('saml', [ 'samlSessionIndex' => $auth->getSessionIndex(), 'samlNameId' => $auth->getNameId(), ]); $this->loginLogger->info(Provider::SAML, 'checking security access rules'); $this->conditions->validate($this->configuration, $auth->getAttributes()); $this->rolesMapping->validate($this->configuration, $auth->getAttributes()); $this->groupsMapping->validate($this->configuration, $auth->getAttributes()); } /** * @throws SSOAuthenticationException * * @return ContactInterface */ public function findUserOrFail(): ContactInterface { return $this->contactRepository->findByEmail($this->username) ?? $this->contactRepository->findByName($this->username) ?? throw SSOAuthenticationException::aliasNotFound($this->username); } /** * @throws Exception * * @return ContactInterface|null */ public function getUser(): ?ContactInterface { $this->info('Searching user : ' . $this->username); return $this->contactRepository->findByName($this->username) ?? $this->contactRepository->findByEmail($this->username); } /** * @return string */ public function getUsername(): string { return $this->username; } /** * @return bool */ public function isAutoImportEnabled(): bool { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); return $customConfiguration->isAutoImportEnabled(); } /** * @throws SSOAuthenticationException * @throws Throwable */ public function importUser(): void { $user = $this->getUser(); if ($this->isAutoImportEnabled() && $user === null) { $this->info('Start auto import'); $this->loginLogger->info($this->configuration->getType(), 'start auto import'); $this->createUser(); $user = $this->findUserOrFail(); $this->info('User imported: ' . $user->getName()); $this->loginLogger->info( $this->configuration->getType(), 'user imported', ['email' => $user->getEmail()] ); } } /** * @throws SSOAuthenticationException * @throws Throwable */ public function updateUser(): void { $user = $this->getAuthenticatedUser(); if ($this->isAutoImportEnabled() === true && $user === null) { $this->info('Start auto import'); $this->createUser(); if ($user = $this->getAuthenticatedUser()) { $this->info('User imported: ' . $user->getName()); } } } /** * @throws Exception * * @return Centreon */ public function getLegacySession(): Centreon { global $pearDB; $pearDB = $this->dependencyInjector['configuration_db']; $user = $this->findUserOrFail(); $sessionUserInfos = [ 'contact_id' => $user->getId(), 'contact_name' => $user->getName(), 'contact_alias' => $user->getAlias(), 'contact_email' => $user->getEmail(), 'contact_lang' => $user->getLang(), 'contact_passwd' => $user->getEncodedPassword(), 'contact_autologin_key' => '', 'contact_admin' => $user->isAdmin() ? '1' : '0', 'default_page' => $user->getDefaultPage(), 'contact_location' => (string) $user->getTimezoneId(), 'show_deprecated_pages' => $user->isUsingDeprecatedPages(), 'show_deprecated_custom_views' => $user->isUsingDeprecatedCustomViews(), 'reach_api' => $user->hasAccessToApiConfiguration() ? 1 : 0, 'reach_api_rt' => $user->hasAccessToApiRealTime() ? 1 : 0, 'contact_theme' => $user->getTheme() ?? 'light', 'auth_type' => Provider::SAML, ]; $this->authenticatedUser = $user; $this->legacySession = new Centreon($sessionUserInfos); return $this->legacySession; } /** * @param string|null $token * * @return NewProviderToken */ public function getProviderToken(?string $token = null): NewProviderToken { return new NewProviderToken( $token ?? '', new DateTimeImmutable(), (new DateTimeImmutable())->add(new DateInterval('PT28800M')) ); } /** * @return NewProviderToken|null */ public function getProviderRefreshToken(): ?NewProviderToken { return null; } /** * @return Configuration */ public function getConfiguration(): Configuration { return $this->configuration; } /** * @param Configuration $configuration */ public function setConfiguration(Configuration $configuration): void { $this->configuration = $configuration; } /** * @return bool */ public function isUpdateACLSupported(): bool { return true; } /** * @param array<string> $claims * * @return array<int,AccessGroup> */ public function getUserAccessGroupsFromClaims(array $claims): array { $userAccessGroups = []; /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); foreach ($customConfiguration->getACLConditions()->getRelations() as $authorizationRule) { $claimValue = $authorizationRule->getClaimValue(); if (! in_array($claimValue, $claims, true)) { $this->info( 'Configured claim value not found in user claims', ['claim_value' => $claimValue] ); continue; } // We ensure here to not duplicate access group while using their id as index $userAccessGroups[$authorizationRule->getAccessGroup()->getId()] = $authorizationRule->getAccessGroup(); } return $userAccessGroups; } /** * @return bool */ public function canRefreshToken(): bool { return false; } /** * @param AuthenticationTokens $authenticationTokens * * @return AuthenticationTokens|null */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens { return null; } /** * @return ContactInterface|null */ public function getAuthenticatedUser(): ?ContactInterface { return $this->authenticatedUser; } /** * @return array<string,mixed> */ public function getUserInformation(): array { return []; } /** * @inheritDoc */ public function getUserContactGroups(): array { return $this->groupsMapping->getUserContactGroups(); } public function getIdTokenPayload(): array { return []; } /** * @param string $returnTo * * @throws Error */ public function login(string $returnTo = ''): void { $auth = new Auth($this->formatter->format($this->configuration->getCustomConfiguration())); $auth->login($returnTo ?: null); } /** * @throws Error */ public function logout(): void { $returnTo = '/login'; $parameters = []; $nameId = null; $sessionIndex = null; if (isset($_SESSION['saml']['samlNameId'])) { $nameId = $_SESSION['saml']['samlNameId']; } if (isset($_SESSION['saml']['samlSessionIndex'])) { $sessionIndex = $_SESSION['saml']['samlSessionIndex']; } $this->info('logout from SAML and redirect'); $auth = new Auth($this->formatter->format($this->configuration->getCustomConfiguration())); $auth->logout($returnTo, $parameters, $nameId, $sessionIndex); } public function handleCallbackLogoutResponse(): void { $this->info('SAML SLS invoked'); $auth = new Auth($this->formatter->format($this->configuration->getCustomConfiguration())); $requestID = isset($_SESSION, $_SESSION['LogoutRequestID']) ? $_SESSION['LogoutRequestID'] : null; $auth->processSLO(true, $requestID, false, null, true); // Avoid 'Open Redirect' attacks if (isset($_GET['RelayState']) && Utils::getSelfURL() !== $_GET['RelayState']) { $auth->redirectTo($_GET['RelayState']); } } /** * @inheritDoc */ public function getAclConditionsMatches(): array { return $this->rolesMapping->getConditionMatches(); } /** * @throws Throwable * @throws AssertionFailedException */ private function createUser(): void { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->configuration->getCustomConfiguration(); $this->info('Auto import starting...', ['user' => $this->username]); $this->loginLogger->info( $this->configuration->getType(), 'auto import starting...', ['user' => $this->username] ); $auth = $this->auth ?? throw new \LogicException('Property auth MUST be initialized'); $usernameAttrs = $auth->getAttribute($customConfiguration->getUserNameBindAttribute() ?? ''); $emailAttrs = $auth->getAttribute($customConfiguration->getEmailBindAttribute() ?? ''); if (! isset($usernameAttrs[0]) || ! isset($emailAttrs[0])) { throw InvalidArgumentProvidedException::create('invalid bind attributes provided for auto import'); } $fullname = $usernameAttrs[0]; $email = $emailAttrs[0]; $alias = $this->username; $user = new NewUser($alias, $fullname, $email); if ($user->canReachFrontend()) { $user->setCanReachRealtimeApi(true); } $user->setContactTemplate($customConfiguration->getContactTemplate()); $this->userRepository->create($user); $this->info('Auto import complete', [ 'user_alias' => $alias, 'user_fullname' => $fullname, 'user_email' => $email, ]); } }
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/Authentication/Infrastructure/Provider/Local.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Local.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\Authentication\Infrastructure\Provider; use Centreon\Domain\Authentication\Exception\AuthenticationException as LegacyAuthenticationException; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Contact\Interfaces\ContactServiceInterface; use Centreon\Domain\Log\LoggerTrait; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Security\Domain\Authentication\Interfaces\LocalProviderInterface; use Security\Domain\Authentication\Model\LocalProvider; use Symfony\Component\HttpFoundation\RequestStack; use Throwable; class Local implements ProviderAuthenticationInterface { use LoggerTrait; /** @var string */ private string $username; /** * @param LocalProviderInterface $provider * @param RequestStack $requestStack * @param ContactServiceInterface $contactService */ public function __construct( readonly private LocalProviderInterface $provider, readonly private RequestStack $requestStack, readonly private ContactServiceInterface $contactService, ) { } /** * @param LoginRequest $request * * @throws Throwable */ public function authenticateOrFail(LoginRequest $request): void { $this->debug( '[AUTHENTICATE] Authentication using provider', ['provider_name' => LocalProvider::NAME] ); $this->provider->authenticateOrFail([ 'login' => $request->username, 'password' => $request->password, ]); $this->username = $request->username ?? ''; } /** * @throws \Exception * * @return ContactInterface */ public function findUserOrFail(): ContactInterface { $this->info('[AUTHENTICATE] Retrieving user information from provider'); $user = $this->getAuthenticatedUser(); if ($user === null) { $this->critical( '[AUTHENTICATE] No contact could be found from provider', ['provider_name' => $this->provider->getConfiguration()->getName()] ); throw LegacyAuthenticationException::userNotFound(); } return $user; } /** * @return string */ public function getUsername(): string { return $this->username; } /** * @return bool */ public function isAutoImportEnabled(): bool { return $this->provider->canCreateUser(); } /** * @throws LegacyAuthenticationException * @throws \Exception */ public function importUser(): void { throw new \Exception('Feature not available for Local provider'); } /** * Update user in data storage. */ public function updateUser(): void { if ($user = $this->provider->getUser()) { $this->contactService->updateUser($user); } } /** * @return \Centreon */ public function getLegacySession(): \Centreon { return $this->provider->getLegacySession(); } /** * @param ?string $token * * @return NewProviderToken */ public function getProviderToken(?string $token = null): NewProviderToken { return $this->provider->getProviderToken($token ?? ''); } /** * @return NewProviderToken|null */ public function getProviderRefreshToken(): ?NewProviderToken { return $this->provider->getProviderRefreshToken($this->requestStack->getSession()->getId()); } /** * @return Configuration */ public function getConfiguration(): Configuration { return $this->provider->getConfiguration(); } /** * @param Configuration $configuration */ public function setConfiguration(Configuration $configuration): void { $this->provider->setConfiguration($configuration); } /** * @return bool */ public function isUpdateACLSupported(): bool { return false; } /** * @return bool */ public function canRefreshToken(): bool { return $this->provider->canRefreshToken(); } /** * @param AuthenticationTokens $authenticationTokens * * @return AuthenticationTokens|null */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens { return $this->provider->refreshToken($authenticationTokens); } /** * @return ContactInterface|null */ public function getAuthenticatedUser(): ?ContactInterface { return $this->provider->getUser(); } public function getUserInformation(): array { return []; } public function getIdTokenPayload(): array { return []; } public function getAclConditionsMatches(): array { return []; } public function getUserContactGroups(): 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/Authentication/Infrastructure/Provider/WebSSO.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/WebSSO.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\Authentication\Infrastructure\Provider; use Centreon; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Domain\Provider\WebSSOProvider; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\CustomConfiguration; use DateInterval; use DateTimeImmutable; use Pimple\Container; use Security\Domain\Authentication\Interfaces\WebSSOProviderInterface as LegacyWebSSOProviderInterface; class WebSSO implements ProviderAuthenticationInterface { use Centreon\Domain\Log\LoggerTrait; private ?ContactInterface $authenticatedUser = null; /** * @param Container $dependencyInjector * @param LegacyWebSSOProviderInterface $provider * @param Centreon\Domain\Contact\Interfaces\ContactRepositoryInterface $contactRepository */ public function __construct( private Container $dependencyInjector, private LegacyWebSSOProviderInterface $provider, private Centreon\Domain\Contact\Interfaces\ContactRepositoryInterface $contactRepository, ) { } /** * @return bool */ public function isAutoImportEnabled(): bool { return false; } /** * @throws \Exception * * @return Centreon */ public function getLegacySession(): Centreon { global $pearDB; $pearDB = $this->dependencyInjector['configuration_db']; $user = $this->findUserOrFail(); $sessionUserInfos = [ 'contact_id' => $user->getId(), 'contact_name' => $user->getName(), 'contact_alias' => $user->getAlias(), 'contact_email' => $user->getEmail(), 'contact_lang' => $user->getLang(), 'contact_passwd' => $user->getEncodedPassword(), 'contact_autologin_key' => '', 'contact_admin' => $user->isAdmin() ? '1' : '0', 'default_page' => $user->getDefaultPage(), 'contact_location' => (string) $user->getTimezoneId(), 'show_deprecated_pages' => $user->isUsingDeprecatedPages(), 'show_deprecated_custom_views' => $user->isUsingDeprecatedCustomViews(), 'reach_api' => $user->hasAccessToApiConfiguration() ? 1 : 0, 'reach_api_rt' => $user->hasAccessToApiRealTime() ? 1 : 0, 'contact_theme' => $user->getTheme() ?? 'light', 'auth_type' => Provider::WEB_SSO, ]; $this->provider->setLegacySession(new Centreon($sessionUserInfos)); $this->authenticatedUser = $user; return $this->provider->getLegacySession(); } /** * @return Configuration */ public function getConfiguration(): Configuration { /** @var WebSSOProvider $provider */ $provider = $this->provider; return $provider->getConfiguration(); } /** * @param Configuration $configuration */ public function setConfiguration(Configuration $configuration): void { $this->provider->setConfiguration($configuration); } /** * @param AuthenticationTokens $authenticationTokens * * @return AuthenticationTokens|null */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens { if ($this->canRefreshToken()) { $this->provider->refreshToken($authenticationTokens); } return null; } /** * @return bool */ public function isUpdateACLSupported(): bool { return false; } /** * @return bool */ public function canRefreshToken(): bool { return true; } /** * @return ContactInterface|null */ public function getAuthenticatedUser(): ?ContactInterface { return $this->authenticatedUser; } /** * @param LoginRequest $request * * @throws SSOAuthenticationException */ public function authenticateOrFail(LoginRequest $request): void { $this->info('Authenticate the user'); $this->ipIsAllowToConnect($request->clientIp ?? ''); $this->validateLoginAttributeOrFail(); } /** * @throws SSOAuthenticationException * @throws \Exception * * @return ContactInterface */ public function findUserOrFail(): ContactInterface { $alias = $this->extractUsernameFromLoginClaimOrFail(); $this->info('searching for user', ['user' => $alias]); $user = $this->contactRepository->findByName($alias); if ($user === null) { throw SSOAuthenticationException::aliasNotFound($alias); } return $user; } public function getUsername(): string { return $this->provider->getUser()?->getEmail() ?? ''; } /** * @param string $ipAddress * * @throws SSOAuthenticationException */ public function ipIsAllowToConnect(string $ipAddress): void { $this->info('Check Client IP from blacklist/whitelist addresses'); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->getConfiguration()->getCustomConfiguration(); if (in_array($ipAddress, $customConfiguration->getBlackListClientAddresses(), true)) { $this->error('IP Blacklisted', ['ip' => '...' . mb_substr($ipAddress, -5)]); throw SSOAuthenticationException::blackListedClient(); } if ( ! empty($customConfiguration->getTrustedClientAddresses()) && ! in_array($ipAddress, $customConfiguration->getTrustedClientAddresses(), true) ) { $this->error('IP not Whitelisted', ['ip' => '...' . mb_substr($ipAddress, -5)]); throw SSOAuthenticationException::notWhiteListedClient(); } } /** * Validate that login attribute is defined in server environment variables. * * @throws SSOAuthenticationException */ public function validateLoginAttributeOrFail(): void { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->getConfiguration()->getCustomConfiguration(); if (! $this->getConfiguration()->isActive()) { return; } $this->info('Validating login header attribute'); if (! array_key_exists($customConfiguration->getLoginHeaderAttribute() ?? '', $_SERVER)) { $this->error('login header attribute not found in server environment', [ 'login_header_attribute' => $customConfiguration->getLoginHeaderAttribute(), ]); throw SSOAuthenticationException::missingRemoteLoginAttribute(); } } /** * Extract username using configured regexp for login matching. * * @throws SSOAuthenticationException * * @return string */ public function extractUsernameFromLoginClaimOrFail(): string { $this->info('Retrieving username from login claim'); $this->validateLoginAttributeOrFail(); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->getConfiguration()->getCustomConfiguration(); $userAlias = $_SERVER[$customConfiguration->getLoginHeaderAttribute()]; if ($customConfiguration->getPatternMatchingLogin() !== null) { $userAlias = preg_replace( '/' . trim($customConfiguration->getPatternMatchingLogin(), '/') . '/', $customConfiguration->getPatternReplaceLogin() ?? '', $_SERVER[$customConfiguration->getLoginHeaderAttribute()] ); if (empty($userAlias)) { $this->error('Regex does not match anything', [ 'regex' => $customConfiguration->getPatternMatchingLogin(), 'subject' => $_SERVER[$customConfiguration->getLoginHeaderAttribute()], ]); throw SSOAuthenticationException::unableToRetrieveUsernameFromLoginClaim(); } } return $userAlias; } /** * @throws \Exception */ public function importUser(): void { throw new \Exception('Feature not available for WebSSO provider'); } /** * Update user in data storage. */ public function updateUser(): void { throw new \Exception('Feature not available for WebSSO provider'); } /** * @param string|null $token * * @throws \Exception * * @return NewProviderToken */ public function getProviderToken(?string $token = null): NewProviderToken { return new NewProviderToken( $token ?? '', new DateTimeImmutable(), (new DateTimeImmutable())->add(new DateInterval('PT28800M')) ); } /** * @return NewProviderToken|null */ public function getProviderRefreshToken(): ?NewProviderToken { return null; } /** * @return array<string,mixed> */ public function getUserInformation(): array { return []; } /** * @return array<string,mixed> */ public function getIdTokenPayload(): array { return []; } public function getAclConditionsMatches(): array { return []; } public function getUserContactGroups(): 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/Authentication/Infrastructure/Provider/OpenId.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/OpenId.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\Authentication\Infrastructure\Provider; use Centreon\Domain\Contact\Interfaces\ContactInterface; use Centreon\Domain\Log\LoggerTrait; use Centreon\Infrastructure\Service\Exception\NotFoundException; use Core\Security\AccessGroup\Domain\Model\AccessGroup; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\Authentication\Application\UseCase\Login\LoginRequest; use Core\Security\Authentication\Domain\Exception\AclConditionsException; use Core\Security\Authentication\Domain\Exception\AuthenticationConditionsException; use Core\Security\Authentication\Domain\Exception\SSOAuthenticationException; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Domain\Provider\OpenIdProvider; use Core\Security\ProviderConfiguration\Domain\Exception\ConfigurationException; 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 Exception; use Pimple\Container; use Security\Domain\Authentication\Interfaces\OpenIdProviderInterface; use Symfony\Component\HttpFoundation\RequestStack; use Throwable; class OpenId implements ProviderAuthenticationInterface { use LoggerTrait; /** @var string */ private string $username; /** * @param Container $dependencyInjector * @param RequestStack $requestStack * @param OpenIdProvider $provider */ public function __construct( private Container $dependencyInjector, private RequestStack $requestStack, private OpenIdProviderInterface $provider, ) { } /** * @param LoginRequest $request * * @throws ConfigurationException * @throws SSOAuthenticationException * @throws AclConditionsException * @throws AuthenticationConditionsException * @throws OpenIdConfigurationException */ public function authenticateOrFail(LoginRequest $request): void { $this->username = $this->provider->authenticateOrFail($request->code, $request->clientIp ?? ''); } /** * @throws SSOAuthenticationException * @throws Throwable * * @return ContactInterface */ public function findUserOrFail(): ContactInterface { $user = $this->getAuthenticatedUser(); if ($user === null) { $this->info('User not found'); if (! $this->isAutoImportEnabled()) { throw new NotFoundException('User could not be created'); } $this->info('Start auto import'); $this->provider->createUser(); $user = $this->getAuthenticatedUser(); if ($user === null) { throw new NotFoundException('User not found'); } $this->info('User imported: ' . $user->getName()); } return $user; } /** * @return string */ public function getUsername(): string { return $this->username; } /** * @return bool */ public function isAutoImportEnabled(): bool { return $this->provider->canCreateUser(); } /** * @throws SSOAuthenticationException * @throws Throwable */ public function importUser(): void { $user = $this->provider->getUser(); if ($this->isAutoImportEnabled() && $user === null) { $this->info('Start auto import'); $this->provider->createUser(); $user = $this->findUserOrFail(); $this->info('User imported: ' . $user->getName()); } } /** * @throws SSOAuthenticationException * @throws Throwable */ public function updateUser(): void { $user = $this->provider->getUser(); if ($this->isAutoImportEnabled() === true && $user === null) { $this->info('Start auto import'); $this->provider->createUser(); if ($user = $this->provider->getUser()) { $this->info('User imported: ' . $user->getName()); } } } /** * @throws Exception * * @return \Centreon */ public function getLegacySession(): \Centreon { global $pearDB; $pearDB = $this->dependencyInjector['configuration_db']; $user = $this->provider->getUser(); if ($user === null) { throw new Exception("can't initialize legacy session, user does not exist"); } $sessionUserInfos = [ 'contact_id' => $user->getId(), 'contact_name' => $user->getName(), 'contact_alias' => $user->getAlias(), 'contact_email' => $user->getEmail(), 'contact_lang' => $user->getLang(), 'contact_passwd' => $user->getEncodedPassword(), 'contact_autologin_key' => '', 'contact_admin' => $user->isAdmin() ? '1' : '0', 'default_page' => $user->getDefaultPage(), 'contact_location' => (string) $user->getTimezoneId(), 'show_deprecated_pages' => $user->isUsingDeprecatedPages(), 'show_deprecated_custom_views' => $user->isUsingDeprecatedCustomViews(), 'reach_api' => $user->hasAccessToApiConfiguration() ? 1 : 0, 'reach_api_rt' => $user->hasAccessToApiRealTime() ? 1 : 0, 'contact_theme' => $user->getTheme() ?? 'light', 'auth_type' => Provider::OPENID, ]; $this->provider->setLegacySession(new \Centreon($sessionUserInfos)); return $this->provider->getLegacySession(); } /** * @param string|null $token * * @return NewProviderToken */ public function getProviderToken(?string $token = null): NewProviderToken { return $this->provider->getProviderToken(); } /** * @return NewProviderToken|null */ public function getProviderRefreshToken(): ?NewProviderToken { return $this->provider->getProviderRefreshToken(); } /** * @return Configuration */ public function getConfiguration(): Configuration { return $this->provider->getConfiguration(); } /** * @param Configuration $configuration */ public function setConfiguration(Configuration $configuration): void { $this->provider->setConfiguration($configuration); } /** * @return bool */ public function isUpdateACLSupported(): bool { return true; } /** * @param array<string> $claims * * @return array<int,AccessGroup> */ public function getUserAccessGroupsFromClaims(array $claims): array { $userAccessGroups = []; /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $this->provider->getConfiguration()->getCustomConfiguration(); foreach ($customConfiguration->getACLConditions()->getRelations() as $authorizationRule) { $claimValue = $authorizationRule->getClaimValue(); if (! in_array($claimValue, $this->provider->getAclConditionsMatches(), true)) { $this->info( 'Configured claim value not found in user claims', ['claim_value' => $claimValue] ); continue; } // We ensure here to not duplicate access group while using their id as index $userAccessGroups[$authorizationRule->getAccessGroup()->getId()] = $authorizationRule->getAccessGroup(); } return $userAccessGroups; } /** * @return bool */ public function canRefreshToken(): bool { return $this->provider->canRefreshToken(); } /** * @param AuthenticationTokens $authenticationTokens * * @return AuthenticationTokens|null */ public function refreshToken(AuthenticationTokens $authenticationTokens): ?AuthenticationTokens { return $this->provider->refreshToken($authenticationTokens); } /** * @return ContactInterface|null */ public function getAuthenticatedUser(): ?ContactInterface { return $this->provider->getUser(); } /** * @return array<string,mixed> */ public function getUserInformation(): array { return $this->provider->getUserInformation(); } /** * @return array<string,mixed> */ public function getIdTokenPayload(): array { return $this->provider->getIdTokenPayload(); } /** * @inheritDoc */ public function getUserContactGroups(): array { return $this->provider->getUserContactGroups(); } /** * @inheritDoc */ public function getAclConditionsMatches(): array { return $this->provider->getAclConditionsMatches(); } public function getTokenForSession(): ?string { return $this->provider->getTokenForSession(); } /** * Redirect the user to the OIDC end-session endpoint * * @param string $idToken * * @throws Exception * * @return string|null */ public function logout(string $idToken, bool $stay = false): string|null { $request = $this->requestStack->getCurrentRequest(); if ($request === null) { throw new Exception('Request is not available for OpenID logout'); } /** @var CustomConfiguration $customConfig */ $customConfig = $this->provider->getConfiguration()->getCustomConfiguration(); $baseUrl = $customConfig->getBaseUrl(); $endSessionEndpoint = $customConfig->getEndSessionEndpoint(); if (empty($baseUrl) || empty($endSessionEndpoint)) { throw new Exception('Missing required OpenID configuration for logout'); } $endSessionUrl = $baseUrl . $endSessionEndpoint; $centreonBase = $request->getSchemeAndHttpHost() . $request->getBaseUrl(); $postLogout = $centreonBase . '/login'; $params = [ 'post_logout_redirect_uri' => $postLogout, 'id_token_hint' => $idToken, ]; $logoutUrl = $endSessionUrl . '?' . http_build_query($params); if ($stay !== false) { return $postLogout; } try { header('Location: ' . $logoutUrl, true, 302); if (function_exists('fastcgi_finish_request')) { fastcgi_finish_request(); } exit; } catch (Exception $e) { throw new Exception('Failed to redirect to logout URL: ' . $e->getMessage(), 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/Authentication/Infrastructure/Provider/ProviderAuthenticationFactory.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/ProviderAuthenticationFactory.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\Authentication\Infrastructure\Provider; use Core\Common\Domain\Exception\RepositoryException; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationInterface; use Core\Security\ProviderConfiguration\Application\Repository\ReadConfigurationRepositoryInterface; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Security\Domain\Authentication\Exceptions\ProviderException; readonly class ProviderAuthenticationFactory implements ProviderAuthenticationFactoryInterface { public function __construct( private Local $local, private OpenId $openId, private WebSSO $webSSO, private SAML $saml, private ReadConfigurationRepositoryInterface $readConfigurationRepository, ) { } /** * @inheritDoc */ public function create(string $providerType): ProviderAuthenticationInterface { $provider = match ($providerType) { Provider::LOCAL => $this->local, Provider::OPENID => $this->openId, Provider::WEB_SSO => $this->webSSO, Provider::SAML => $this->saml, default => throw ProviderException::providerConfigurationNotFound($providerType), }; try { $provider->setConfiguration($this->readConfigurationRepository->getConfigurationByType($providerType)); } catch (RepositoryException $e) { throw ProviderException::findProviderConfiguration($providerType, $e); } return $provider; } }
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/Authentication/Infrastructure/Provider/Exception/InvalidUserIdAttributeException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/InvalidUserIdAttributeException.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\Authentication\Infrastructure\Provider\Exception; class InvalidUserIdAttributeException extends \DomainException { public static function create(): self { return new self('Invalid user ID attribute provided', 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/Authentication/Infrastructure/Provider/Exception/InvalidArgumentProvidedException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/InvalidArgumentProvidedException.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\Authentication\Infrastructure\Provider\Exception; class InvalidArgumentProvidedException extends \DomainException { public static function create(string $message): self { return new self($message, 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/Authentication/Infrastructure/Provider/Exception/UserNotAuthenticatedException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/UserNotAuthenticatedException.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\Authentication\Infrastructure\Provider\Exception; class UserNotAuthenticatedException extends \DomainException { public static function create(): self { return new self('Failed to authenticate the user', 401); } }
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/Authentication/Infrastructure/Provider/Exception/MissingArgumentProvidedException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/MissingArgumentProvidedException.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\Authentication\Infrastructure\Provider\Exception; class MissingArgumentProvidedException extends \DomainException { public static function create(string $message): self { return new self($message, 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/Authentication/Infrastructure/Provider/Exception/SAML/InvalidMetadataException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/SAML/InvalidMetadataException.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\Authentication\Infrastructure\Provider\Exception\SAML; class InvalidMetadataException extends \DomainException { public static function create(): self { return new self('Invalid metadata, the validation failed', 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/Authentication/Infrastructure/Provider/Exception/SAML/ProcessAuthenticationResponseException.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Exception/SAML/ProcessAuthenticationResponseException.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\Authentication\Infrastructure\Provider\Exception\SAML; class ProcessAuthenticationResponseException extends \DomainException { public static function create(): self { return new self('Invalid metadata, the validation failed', 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/Authentication/Infrastructure/Provider/Settings/Formatter/OneLoginSettingsFormatter.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Settings/Formatter/OneLoginSettingsFormatter.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\Authentication\Infrastructure\Provider\Settings\Formatter; use Core\Infrastructure\Common\Api\HttpUrlTrait; use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface; use Core\Security\ProviderConfiguration\Domain\SAML\Model\CustomConfiguration; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; class OneLoginSettingsFormatter implements SettingsFormatterInterface { use HttpUrlTrait; /** * @param UrlGeneratorInterface $urlGenerator */ public function __construct(private readonly UrlGeneratorInterface $urlGenerator) { } /** * @param CustomConfigurationInterface&CustomConfiguration $customConfiguration * * @return array<mixed> */ public function format(CustomConfigurationInterface $customConfiguration): array { $acsUrl = $this->urlGenerator->generate( 'centreon_application_authentication_saml_acs', [], UrlGeneratorInterface::ABSOLUTE_URL ); return [ 'strict' => true, 'debug' => true, 'sp' => [ 'entityId' => $this->getHost(true), 'assertionConsumerService' => [ 'url' => $acsUrl, ], ], 'idp' => [ 'entityId' => $customConfiguration->getEntityIDUrl(), // issuer 'singleSignOnService' => [ 'url' => $customConfiguration->getRemoteLoginUrl(), ], 'singleLogoutService' => [ 'url' => $customConfiguration->getLogoutFromUrl(), ], 'x509cert' => $customConfiguration->getPublicCertificate(), ], 'security' => [ 'requestedAuthnContext' => $customConfiguration->hasRequestedAuthnContext(), 'requestedAuthnContextComparison' => $customConfiguration->getRequestedAuthnContextComparison()->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/Authentication/Infrastructure/Provider/Settings/Formatter/SettingsFormatterInterface.php
centreon/src/Core/Security/Authentication/Infrastructure/Provider/Settings/Formatter/SettingsFormatterInterface.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\Authentication\Infrastructure\Provider\Settings\Formatter; use Core\Security\ProviderConfiguration\Domain\CustomConfigurationInterface; interface SettingsFormatterInterface { /** * @param CustomConfigurationInterface $customConfiguration * * @return array<mixed> */ public function format(CustomConfigurationInterface $customConfiguration): 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/Authentication/Infrastructure/Repository/WriteSessionRepository.php
centreon/src/Core/Security/Authentication/Infrastructure/Repository/WriteSessionRepository.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\Authentication\Infrastructure\Repository; use Centreon\Domain\Log\LoggerTrait; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\Authentication\Application\Repository\WriteSessionRepositoryInterface; use Core\Security\Authentication\Application\Repository\WriteSessionTokenRepositoryInterface; use Core\Security\Authentication\Infrastructure\Provider\OpenId; use Core\Security\Authentication\Infrastructure\Provider\SAML; 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; use Exception; use Symfony\Component\HttpFoundation\RequestStack; class WriteSessionRepository implements WriteSessionRepositoryInterface { use LoggerTrait; /** * @param RequestStack $requestStack * @param WriteSessionTokenRepositoryInterface $writeSessionTokenRepository * @param ProviderAuthenticationFactoryInterface $providerFactory */ public function __construct( private readonly RequestStack $requestStack, private readonly WriteSessionTokenRepositoryInterface $writeSessionTokenRepository, private readonly ProviderAuthenticationFactoryInterface $providerFactory, ) { } /** * @inheritDoc */ public function invalidate(): void { $session = $this->requestStack->getSession(); $idToken = $session->get('openid_id_token') ?? ''; $sessionId = $session->getId(); $this->writeSessionTokenRepository->deleteSession($sessionId); $centreon = $session->get('centreon'); $session->invalidate(); if ($centreon && $centreon->user->authType === Provider::SAML) { /** @var SAML $provider */ $provider = $this->providerFactory->create(Provider::SAML); $configuration = $provider->getConfiguration(); /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $configuration->getCustomConfiguration(); if ( $configuration->isActive() && $customConfiguration->getLogoutFrom() === CustomConfiguration::LOGOUT_FROM_CENTREON_AND_IDP ) { $this->info('Logout from Centreon and SAML IDP...'); $provider->logout(); // The redirection is done here by the IDP } } if ($centreon && $centreon->user->authType === Provider::OPENID) { /** @var OpenId $provider */ $provider = $this->providerFactory->create(Provider::OPENID); $configuration = $provider->getConfiguration(); /** @var OpenIdCustomConfiguration $customConfiguration */ $customConfiguration = $configuration->getCustomConfiguration(); $isLogin = $this->requestStack->getSession()->get('isLogin') ?? false; if ($configuration->isActive()) { try { $provider->logout($idToken, $isLogin); } catch (Exception $e) { $this->error('OpenID logout failed: ' . $e->getMessage(), [ 'exception' => $e, ]); } } } } /** * Start a session (included the legacy session). * * @param \Centreon $legacySession * * @return bool */ public function start(\Centreon $legacySession): bool { if ($this->requestStack->getSession()->isStarted()) { return true; } $this->info('[AUTHENTICATE] Starting Centreon Session'); $this->requestStack->getSession()->start(); $this->requestStack->getSession()->set('centreon', $legacySession); $this->requestStack->getSession()->set('isLogin', true); $_SESSION['centreon'] = $legacySession; $isSessionStarted = $this->requestStack->getSession()->isStarted(); if ($isSessionStarted === false) { $this->invalidate(); } return $isSessionStarted; } }
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/Authentication/Infrastructure/Repository/DbWriteSessionTokenRepository.php
centreon/src/Core/Security/Authentication/Infrastructure/Repository/DbWriteSessionTokenRepository.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\Authentication\Infrastructure\Repository; use Centreon\Domain\Log\LoggerTrait; use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\Repository\AbstractRepositoryDRB; use Core\Security\Authentication\Application\Repository\WriteSessionTokenRepositoryInterface; use Security\Domain\Authentication\Model\Session; class DbWriteSessionTokenRepository extends AbstractRepositoryDRB implements WriteSessionTokenRepositoryInterface { use LoggerTrait; /** * @param DatabaseConnection $db */ public function __construct(DatabaseConnection $db) { $this->db = $db; } /** * @inheritDoc */ public function deleteSession(string $token): void { $deleteSessionStatement = $this->db->prepare( $this->translateDbName( 'DELETE FROM `:db`.session WHERE `session_id` = :token' ) ); $deleteSessionStatement->bindValue(':token', $token, \PDO::PARAM_STR); $deleteSessionStatement->execute(); $deleteTokenStatement = $this->db->prepare( $this->translateDbName( 'DELETE FROM `:db`.security_token WHERE `token` = :token' ) ); $deleteTokenStatement->bindValue(':token', $token, \PDO::PARAM_STR); $deleteTokenStatement->execute(); } /** * @inheritDoc */ public function createSession(Session $session): void { $insertSessionStatement = $this->db->prepare( $this->translateDbName( 'INSERT INTO `:db`.session (`session_id` , `user_id` , `last_reload`, `ip_address`) ' . 'VALUES (:sessionId, :userId, :lastReload, :ipAddress)' ) ); $insertSessionStatement->bindValue(':sessionId', $session->getToken()); $insertSessionStatement->bindValue(':userId', $session->getContactId(), \PDO::PARAM_INT); $insertSessionStatement->bindValue(':lastReload', time(), \PDO::PARAM_INT); $insertSessionStatement->bindValue(':ipAddress', $session->getClientIp()); $insertSessionStatement->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/Authentication/Infrastructure/Repository/DbReadTokenRepositoryInterface.php
centreon/src/Core/Security/Authentication/Infrastructure/Repository/DbReadTokenRepositoryInterface.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\Authentication\Infrastructure\Repository; use Centreon\Domain\Log\LoggerTrait; use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\Repository\AbstractRepositoryDRB; use Core\Security\Authentication\Application\Repository\ReadTokenRepositoryInterface; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\ProviderToken; class DbReadTokenRepositoryInterface extends AbstractRepositoryDRB implements ReadTokenRepositoryInterface { use LoggerTrait; /** * @param DatabaseConnection $db */ public function __construct(DatabaseConnection $db) { $this->db = $db; } /** * {@inheritDoc} * * @param string $token * * @return AuthenticationTokens|null */ public function findAuthenticationTokensByToken(string $token): ?AuthenticationTokens { $statement = $this->db->prepare( $this->translateDbName( <<<'SQL' SELECT sat.user_id, sat.provider_configuration_id, provider_token.id as pt_id, provider_token.token AS provider_token, provider_token.creation_date as provider_token_creation_date, provider_token.expiration_date as provider_token_expiration_date, refresh_token.id as rt_id, refresh_token.token AS refresh_token, refresh_token.creation_date as refresh_token_creation_date, refresh_token.expiration_date as refresh_token_expiration_date FROM `:db`.security_authentication_tokens sat INNER JOIN `:db`.security_token provider_token ON provider_token.id = sat.provider_token_id LEFT JOIN `:db`.security_token refresh_token ON refresh_token.id = sat.provider_token_refresh_id WHERE sat.token = :token AND sat.is_revoked = 0 SQL ) ); $statement->bindValue(':token', $token); $statement->execute(); if ($result = $statement->fetch(\PDO::FETCH_ASSOC)) { $expirationDate = $result['provider_token_expiration_date'] !== null ? (new \DateTimeImmutable())->setTimestamp((int) $result['provider_token_expiration_date']) : null; $providerToken = new ProviderToken( (int) $result['pt_id'], $result['provider_token'], (new \DateTimeImmutable())->setTimestamp((int) $result['provider_token_creation_date']), $expirationDate ); $providerRefreshToken = null; if ($result['refresh_token'] !== null) { $expirationDate = $result['refresh_token_expiration_date'] !== null ? (new \DateTimeImmutable())->setTimestamp((int) $result['refresh_token_expiration_date']) : null; $providerRefreshToken = new ProviderToken( (int) $result['rt_id'], $result['refresh_token'], (new \DateTimeImmutable())->setTimestamp((int) $result['refresh_token_creation_date']), $expirationDate ); } return new AuthenticationTokens( (int) $result['user_id'], (int) $result['provider_configuration_id'], $token, $providerToken, $providerRefreshToken ); } return null; } /** * @param string $token * * @return bool */ public function hasAuthenticationTokensByToken(string $token): bool { return $this->findAuthenticationTokensByToken($token) !== 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/Authentication/Infrastructure/Repository/DbWriteTokenRepository.php
centreon/src/Core/Security/Authentication/Infrastructure/Repository/DbWriteTokenRepository.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\Authentication\Infrastructure\Repository; use Centreon\Domain\Log\LoggerTrait; use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\Repository\AbstractRepositoryDRB; use Core\Security\Authentication\Application\Repository\WriteTokenRepositoryInterface; use Core\Security\Authentication\Domain\Model\AuthenticationTokens; use Core\Security\Authentication\Domain\Model\NewProviderToken; use Core\Security\Authentication\Domain\Model\ProviderToken; use Exception; use PDO; class DbWriteTokenRepository extends AbstractRepositoryDRB implements WriteTokenRepositoryInterface { use LoggerTrait; /** * @param DatabaseConnection $db */ public function __construct(DatabaseConnection $db) { $this->db = $db; } /** * @inheritDoc * * @throws Exception */ public function createAuthenticationTokens( string $token, int $providerConfigurationId, int $contactId, NewProviderToken $providerToken, ?NewProviderToken $providerRefreshToken, ): void { // We avoid to start again a database transaction $isAlreadyInTransaction = $this->db->inTransaction(); if ($isAlreadyInTransaction === false) { $this->db->beginTransaction(); } try { $this->insertProviderTokens( $token, $providerConfigurationId, $contactId, $providerToken, $providerRefreshToken ); if ($isAlreadyInTransaction === false) { $this->db->commit(); } } catch (Exception $exception) { if ($isAlreadyInTransaction === false) { $this->db->rollBack(); } $this->error($exception->getMessage(), ['trace' => $exception->getTraceAsString()]); throw $exception; } } /** * @inheritDoc */ public function updateAuthenticationTokens(AuthenticationTokens $authenticationTokens): void { /** @var ProviderToken $providerToken */ $providerToken = $authenticationTokens->getProviderToken(); /** @var ProviderToken $providerRefreshToken */ $providerRefreshToken = $authenticationTokens->getProviderRefreshToken(); $updateTokenStatement = $this->db->prepare( $this->translateDbName( 'UPDATE `:db`.security_token SET token=:token, creation_date=:creationDate, expiration_date=:expirationDate WHERE id =:tokenId' ) ); // Update Provider Token $updateTokenStatement->bindValue(':token', $providerToken->getToken(), PDO::PARAM_STR); $updateTokenStatement->bindValue( ':creationDate', $providerToken->getCreationDate()->getTimestamp(), PDO::PARAM_INT ); $updateTokenStatement->bindValue( ':expirationDate', $providerToken->getExpirationDate()?->getTimestamp(), PDO::PARAM_INT ); $updateTokenStatement->bindValue(':tokenId', $providerToken->getId(), PDO::PARAM_INT); $updateTokenStatement->execute(); // Update Refresh Token $updateTokenStatement->bindValue(':token', $providerRefreshToken->getToken(), PDO::PARAM_STR); $updateTokenStatement->bindValue( ':creationDate', $providerRefreshToken->getCreationDate()->getTimestamp(), PDO::PARAM_INT ); $updateTokenStatement->bindValue( ':expirationDate', $providerRefreshToken->getExpirationDate()?->getTimestamp(), PDO::PARAM_INT ); $updateTokenStatement->bindValue(':tokenId', $providerRefreshToken->getId(), PDO::PARAM_INT); $updateTokenStatement->execute(); } /** * @inheritDoc */ public function updateProviderToken(ProviderToken $providerToken): void { $updateStatement = $this->db->prepare( $this->translateDbName( 'UPDATE `:db`.security_token SET expiration_date = :expiredAt WHERE token = :token' ) ); $updateStatement->bindValue( ':expiredAt', $providerToken->getExpirationDate() !== null ? $providerToken->getExpirationDate()->getTimestamp() : null, PDO::PARAM_INT ); $updateStatement->bindValue(':token', $providerToken->getToken(), PDO::PARAM_STR); $updateStatement->execute(); } public function deleteSecurityToken(string $token): void { $deleteSecurityTokenStatement = $this->db->prepare( $this->translateDbName( 'DELETE FROM `:db`.security_token WHERE token = :token' ) ); $deleteSecurityTokenStatement->bindValue(':token', $token, PDO::PARAM_STR); $deleteSecurityTokenStatement->execute(); } /** * Insert session, security and refresh tokens. * * @param string $token * @param int $providerConfigurationId * @param int $contactId * @param NewProviderToken $providerToken * @param NewProviderToken|null $providerRefreshToken */ private function insertProviderTokens( string $token, int $providerConfigurationId, int $contactId, NewProviderToken $providerToken, ?NewProviderToken $providerRefreshToken, ): void { $this->insertSecurityToken($providerToken); $securityTokenId = (int) $this->db->lastInsertId(); $securityRefreshTokenId = null; if ($providerRefreshToken !== null) { $this->insertSecurityToken($providerRefreshToken); $securityRefreshTokenId = (int) $this->db->lastInsertId(); } $this->insertSecurityAuthenticationToken( $token, $contactId, $securityTokenId, $securityRefreshTokenId, $providerConfigurationId ); } /** * Insert provider token into security_token table. * * @param NewProviderToken $providerToken */ private function insertSecurityToken(NewProviderToken $providerToken): void { $insertSecurityTokenStatement = $this->db->prepare( $this->translateDbName( 'INSERT INTO `:db`.security_token (`token`, `creation_date`, `expiration_date`) ' . 'VALUES (:token, :createdAt, :expireAt)' ) ); $insertSecurityTokenStatement->bindValue(':token', $providerToken->getToken(), PDO::PARAM_STR); $insertSecurityTokenStatement->bindValue( ':createdAt', $providerToken->getCreationDate()->getTimestamp(), PDO::PARAM_INT ); $insertSecurityTokenStatement->bindValue( ':expireAt', $providerToken->getExpirationDate()?->getTimestamp(), PDO::PARAM_INT ); $insertSecurityTokenStatement->execute(); } /** * Insert tokens and configuration id in security_authentication_tokens table. * * @param string $sessionId * @param int $contactId * @param int $securityTokenId * @param int|null $securityRefreshTokenId * @param int $providerConfigurationId */ private function insertSecurityAuthenticationToken( string $sessionId, int $contactId, int $securityTokenId, ?int $securityRefreshTokenId, int $providerConfigurationId, ): void { $insertSecurityAuthenticationStatement = $this->db->prepare( $this->translateDbName( 'INSERT INTO `:db`.security_authentication_tokens ' . '(`token`, `provider_token_id`, `provider_token_refresh_id`, `provider_configuration_id`, `user_id`) ' . 'VALUES (:sessionTokenId, :tokenId, :refreshTokenId, :configurationId, :userId)' ) ); $insertSecurityAuthenticationStatement->bindValue(':sessionTokenId', $sessionId, PDO::PARAM_STR); $insertSecurityAuthenticationStatement->bindValue(':tokenId', $securityTokenId, PDO::PARAM_INT); $insertSecurityAuthenticationStatement->bindValue(':refreshTokenId', $securityRefreshTokenId, PDO::PARAM_INT); $insertSecurityAuthenticationStatement->bindValue( ':configurationId', $providerConfigurationId, PDO::PARAM_INT ); $insertSecurityAuthenticationStatement->bindValue(':userId', $contactId, PDO::PARAM_INT); $insertSecurityAuthenticationStatement->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/User/Application/UseCase/RenewPassword/RenewPasswordPresenterInterface.php
centreon/src/Core/Security/User/Application/UseCase/RenewPassword/RenewPasswordPresenterInterface.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\User\Application\UseCase\RenewPassword; use Core\Application\Common\UseCase\PresenterInterface; interface RenewPasswordPresenterInterface 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/User/Application/UseCase/RenewPassword/RenewPassword.php
centreon/src/Core/Security/User/Application/UseCase/RenewPassword/RenewPassword.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\User\Application\UseCase\RenewPassword; use Assert\AssertionFailedException; use Centreon\Domain\Log\LoggerTrait; use Core\Application\Common\UseCase\ErrorResponse; use Core\Application\Common\UseCase\InvalidArgumentResponse; use Core\Application\Common\UseCase\NoContentResponse; use Core\Application\Common\UseCase\NotFoundResponse; use Core\Application\Common\UseCase\UnauthorizedResponse; use Core\Common\Domain\Exception\RepositoryException; use Core\Common\Infrastructure\ExceptionLogger\ExceptionLogger; use Core\Security\ProviderConfiguration\Application\Repository\ReadConfigurationRepositoryInterface; use Core\Security\ProviderConfiguration\Domain\Local\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Core\Security\ProviderConfiguration\Infrastructure\Local\Api\Exception\ConfigurationException; use Core\Security\User\Application\Repository\ReadUserRepositoryInterface; use Core\Security\User\Application\Repository\WriteUserRepositoryInterface; use Core\Security\User\Domain\Exception\UserPasswordException; use Core\Security\User\Domain\Model\UserPasswordFactory; class RenewPassword { use LoggerTrait; /** * @param ReadUserRepositoryInterface $readRepository * @param WriteUserRepositoryInterface $writeRepository * @param ReadConfigurationRepositoryInterface $readConfigurationRepository */ public function __construct( private readonly ReadUserRepositoryInterface $readRepository, private readonly WriteUserRepositoryInterface $writeRepository, private readonly ReadConfigurationRepositoryInterface $readConfigurationRepository, ) { } /** * @param RenewPasswordPresenterInterface $presenter * @param RenewPasswordRequest $renewPasswordRequest */ public function __invoke( RenewPasswordPresenterInterface $presenter, RenewPasswordRequest $renewPasswordRequest, ): void { $this->info('Processing password renewal...'); try { $user = $this->readRepository->findUserByAlias($renewPasswordRequest->userAlias); } catch (RepositoryException $e) { ExceptionLogger::create()->log($e); $presenter->setResponseStatus(new ErrorResponse('An error occurred while updating password')); return; } if ($user === null) { $this->error('No user could be found', [ 'user_alias' => $renewPasswordRequest->userAlias, ]); $presenter->setResponseStatus(new NotFoundResponse('User')); return; } // Validate that old password matches the current user password if (password_verify($renewPasswordRequest->oldPassword, $user->getPassword()->getPasswordValue()) === false) { $this->notice('Credentials are invalid'); $presenter->setResponseStatus(new UnauthorizedResponse('Invalid credentials')); return; } try { /** @var Configuration $providerConfiguration */ $providerConfiguration = $this->readConfigurationRepository->getConfigurationByType(Provider::LOCAL); $this->info('Validate password against security policy'); $newPassword = UserPasswordFactory::create( $renewPasswordRequest->newPassword, $user, $providerConfiguration->getCustomConfiguration()->getSecurityPolicy() ); } catch (UserPasswordException|ConfigurationException|AssertionFailedException $e) { ExceptionLogger::create()->log($e); $presenter->setResponseStatus(new InvalidArgumentResponse($e->getMessage())); return; } catch (\Throwable $e) { ExceptionLogger::create()->log($e); $presenter->setResponseStatus(new ErrorResponse('An error occurred while updating password')); return; } $user->setPassword($newPassword); $this->info('Updating user password', [ 'user_alias' => $user->getAlias(), ]); $this->writeRepository->renewPassword($user); $presenter->setResponseStatus(new NoContentResponse()); } }
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/User/Application/UseCase/RenewPassword/RenewPasswordRequest.php
centreon/src/Core/Security/User/Application/UseCase/RenewPassword/RenewPasswordRequest.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\User\Application\UseCase\RenewPassword; final class RenewPasswordRequest { /** @var string */ public string $userAlias; /** @var string */ public string $oldPassword; /** @var string */ public string $newPassword; }
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/User/Application/Repository/WriteUserRepositoryInterface.php
centreon/src/Core/Security/User/Application/Repository/WriteUserRepositoryInterface.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\User\Application\Repository; use Core\Security\User\Domain\Model\User; interface WriteUserRepositoryInterface { /** * Update user blocking information (login attempts and blocking time). * * @param User $user */ public function updateBlockingInformation(User $user): void; /** * Renew password of user. * * @param User $user */ public function renewPassword(User $user): 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/User/Application/Repository/ReadUserRepositoryInterface.php
centreon/src/Core/Security/User/Application/Repository/ReadUserRepositoryInterface.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\User\Application\Repository; use Core\Common\Domain\Exception\RepositoryException; use Core\Security\User\Domain\Model\User; interface ReadUserRepositoryInterface { /** * @throws RepositoryException */ public function findUserByAlias(string $alias): ?User; }
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/User/Domain/Model/User.php
centreon/src/Core/Security/User/Domain/Model/User.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\User\Domain\Model; class User { /** * @param int $id * @param string $alias * @param UserPassword[] $oldPasswords * @param UserPassword $password * @param int|null $loginAttempts * @param \DateTimeImmutable|null $blockingTime */ public function __construct( private int $id, private string $alias, private array $oldPasswords, private UserPassword $password, private ?int $loginAttempts, private ?\DateTimeImmutable $blockingTime, ) { } /** * @return int */ public function getId(): int { return $this->id; } /** * @return string */ public function getAlias(): string { return $this->alias; } /** * @return UserPassword[] */ public function getOldPasswords(): array { return $this->oldPasswords; } /** * @return UserPassword */ public function getPassword(): UserPassword { return $this->password; } /** * @param UserPassword $password * * @return static */ public function setPassword(UserPassword $password): static { $this->password = $password; return $this; } /** * @return int|null */ public function getLoginAttempts(): ?int { return $this->loginAttempts; } /** * @param int|null $loginAttempts * * @return static */ public function setLoginAttempts(?int $loginAttempts): static { $this->loginAttempts = $loginAttempts; return $this; } /** * @return \DateTimeImmutable|null */ public function getBlockingTime(): ?\DateTimeImmutable { return $this->blockingTime; } /** * @param \DateTimeImmutable|null $blockingTime * * @return static */ public function setBlockingTime(?\DateTimeImmutable $blockingTime): static { $this->blockingTime = $blockingTime; 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/User/Domain/Model/UserPasswordFactory.php
centreon/src/Core/Security/User/Domain/Model/UserPasswordFactory.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\User\Domain\Model; use Assert\AssertionFailedException; use Centreon\Domain\Common\Assertion\Assertion; use Centreon\Domain\Common\Assertion\AssertionException; use Core\Security\ProviderConfiguration\Domain\Local\Model\SecurityPolicy; use Core\Security\ProviderConfiguration\Infrastructure\Local\Api\Exception\ConfigurationException; use Core\Security\User\Domain\Exception\UserPasswordException; class UserPasswordFactory { /** * Validate the security policy and create the User password. * * @param string $password * @param User $user * @param SecurityPolicy $securityPolicy * * @throws UserPasswordException|ConfigurationException|AssertionFailedException * * @return UserPassword */ public static function create(string $password, User $user, SecurityPolicy $securityPolicy): UserPassword { try { Assertion::minLength( $password, $securityPolicy->getPasswordMinimumLength(), 'UserPassword::passwordValue' ); if ($securityPolicy->hasNumber()) { Assertion::regex($password, '/[0-9]/', 'UserPassword::passwordValue'); } if ($securityPolicy->hasUppercase()) { Assertion::regex($password, '/[A-Z]/', 'UserPassword::passwordValue'); } if ($securityPolicy->hasLowercase()) { Assertion::regex($password, '/[a-z]/', 'UserPassword::passwordValue'); } if ($securityPolicy->hasSpecialCharacter()) { Assertion::regex( $password, '/[' . SecurityPolicy::SPECIAL_CHARACTERS_LIST . ']/', 'UserPassword::passwordValue' ); } } catch (AssertionException) { // Throw a generic user password exception to avoid returning a plain password in the AssertionException. throw UserPasswordException::passwordDoesnotMatchSecurityPolicy(); } // Verify that an old passwords is not reused if ($securityPolicy->canReusePasswords() === false) { foreach ($user->getOldPasswords() as $oldPassword) { if (password_verify($password, $oldPassword->getPasswordValue())) { throw new ConfigurationException(_('Old password usage is disable')); } } } $newPasswordValue = password_hash($password, \CentreonAuth::PASSWORD_HASH_ALGORITHM); return new UserPassword($user->getId(), $newPasswordValue, new \DateTimeImmutable()); } }
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/User/Domain/Model/UserPassword.php
centreon/src/Core/Security/User/Domain/Model/UserPassword.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\User\Domain\Model; class UserPassword { /** * @param int $userId * @param string $passwordValue * @param \DateTimeImmutable $creationDate */ public function __construct( private int $userId, private string $passwordValue, private \DateTimeImmutable $creationDate, ) { } /** * @return int */ public function getUserId(): int { return $this->userId; } /** * @return string */ public function getPasswordValue(): string { return $this->passwordValue; } /** * @return \DateTimeImmutable */ public function getCreationDate(): \DateTimeImmutable { return $this->creationDate; } /** * @param string $passwordValue * * @return self */ public function setPasswordValue(string $passwordValue): self { $this->passwordValue = $passwordValue; return $this; } /** * @param \DateTimeImmutable $creationDate * * @return self */ public function setCreationDate(\DateTimeImmutable $creationDate): self { $this->creationDate = $creationDate; 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/User/Domain/Exception/UserPasswordException.php
centreon/src/Core/Security/User/Domain/Exception/UserPasswordException.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\User\Domain\Exception; class UserPasswordException extends \Exception { /** * Exception thrown when a password doesn't match the security policy. * * @return self */ public static function passwordDoesnotMatchSecurityPolicy(): self { return new self(_("Your password doesn't match the security policy")); } }
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/User/Infrastructure/Api/RenewPassword/RenewPasswordController.php
centreon/src/Core/Security/User/Infrastructure/Api/RenewPassword/RenewPasswordController.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\User\Infrastructure\Api\RenewPassword; use Centreon\Application\Controller\AbstractController; use Core\Security\User\Application\UseCase\RenewPassword\RenewPassword; use Core\Security\User\Application\UseCase\RenewPassword\RenewPasswordPresenterInterface; use Core\Security\User\Application\UseCase\RenewPassword\RenewPasswordRequest; use Symfony\Component\HttpFoundation\Request; final class RenewPasswordController extends AbstractController { /** * @param RenewPassword $useCase * @param Request $request * @param RenewPasswordPresenterInterface $presenter * @param string $alias * * @return object */ public function __invoke( RenewPassword $useCase, Request $request, RenewPasswordPresenterInterface $presenter, string $alias, ): object { $this->validateDataSent($request, __DIR__ . '/RenewPasswordSchema.json'); $renewPasswordRequest = $this->createRenewPasswordRequest($request, $alias); $useCase($presenter, $renewPasswordRequest); return $presenter->show(); } /** * @param Request $request * @param string $userAlias * * @return RenewPasswordRequest */ private function createRenewPasswordRequest(Request $request, string $userAlias): RenewPasswordRequest { $requestData = json_decode((string) $request->getContent(), true); $renewPasswordRequest = new RenewPasswordRequest(); $renewPasswordRequest->userAlias = $userAlias; $renewPasswordRequest->oldPassword = $requestData['old_password']; $renewPasswordRequest->newPassword = $requestData['new_password']; return $renewPasswordRequest; } }
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/User/Infrastructure/Api/RenewPassword/RenewPasswordPresenter.php
centreon/src/Core/Security/User/Infrastructure/Api/RenewPassword/RenewPasswordPresenter.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\User\Infrastructure\Api\RenewPassword; use Core\Application\Common\UseCase\AbstractPresenter; use Core\Security\User\Application\UseCase\RenewPassword\RenewPasswordPresenterInterface; class RenewPasswordPresenter extends AbstractPresenter implements RenewPasswordPresenterInterface { }
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/User/Infrastructure/Repository/DbUserTransformer.php
centreon/src/Core/Security/User/Infrastructure/Repository/DbUserTransformer.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\User\Infrastructure\Repository; use App\Shared\Infrastructure\TransformerInterface; use Core\Security\User\Domain\Model\User; use Core\Security\User\Domain\Model\UserPassword; /** * @implements TransformerInterface<array<string, mixed>, User> */ class DbUserTransformer implements TransformerInterface { /** * @param array<string, mixed> $from * * @throws \InvalidArgumentException * @return User */ public function transform(mixed $from): User { if (! is_array($from) || $from === []) { throw new \InvalidArgumentException('Cannot transform empty record to User'); } if (! isset($from['passwords']) || ! is_array($from['passwords']) || $from['passwords'] === []) { throw new \InvalidArgumentException('Cannot transform record to User without passwords'); } $loginAttempts = isset($from['login_attempts']) ? (int) $from['login_attempts'] : null; $blockingTime = isset($from['blocking_time']) ? (new \DateTimeImmutable())->setTimestamp((int) $from['blocking_time']) : null; $passwords = []; foreach ($from['passwords'] as $password) { $passwords[] = new UserPassword( (int) $from['contact_id'], $password['password'], (new \DateTimeImmutable())->setTimestamp((int) $password['creation_date']), ); } return new User( (int) $from['contact_id'], $from['contact_alias'], $passwords, end($passwords), $loginAttempts, $blockingTime, ); } }
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/User/Infrastructure/Repository/DbWriteUserRepository.php
centreon/src/Core/Security/User/Infrastructure/Repository/DbWriteUserRepository.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\User\Infrastructure\Repository; use Centreon\Domain\Log\LoggerTrait; use Centreon\Infrastructure\DatabaseConnection; use Centreon\Infrastructure\Repository\AbstractRepositoryDRB; use Core\Security\User\Application\Repository\WriteUserRepositoryInterface; use Core\Security\User\Domain\Model\User; use Core\Security\User\Domain\Model\UserPassword; class DbWriteUserRepository extends AbstractRepositoryDRB implements WriteUserRepositoryInterface { use LoggerTrait; /** * @param DatabaseConnection $db */ public function __construct(DatabaseConnection $db) { $this->db = $db; } /** * @inheritDoc */ public function updateBlockingInformation(User $user): void { $statement = $this->db->prepare( $this->translateDbName( 'UPDATE `:db`.`contact` SET login_attempts = :loginAttempts, blocking_time = :blockingTime WHERE contact_id = :contactId' ) ); $statement->bindValue(':loginAttempts', $user->getLoginAttempts(), \PDO::PARAM_INT); $statement->bindValue(':blockingTime', $user->getBlockingTime()?->getTimestamp(), \PDO::PARAM_INT); $statement->bindValue(':contactId', $user->getId(), \PDO::PARAM_INT); $statement->execute(); } /** * @inheritDoc */ public function renewPassword(User $user): void { $this->addPassword($user->getPassword()); $this->deleteOldPasswords($user->getId()); } /** * Add new password to the user. * * @param UserPassword $password */ private function addPassword(UserPassword $password): void { $this->info('add new password for user in DBMS', [ 'user_id' => $password->getUserId(), ]); $statement = $this->db->prepare( $this->translateDbName( 'INSERT INTO `:db`.`contact_password` (`password`, `contact_id`, `creation_date`) VALUES (:password, :contactId, :creationDate)' ) ); $statement->bindValue(':password', $password->getPasswordValue(), \PDO::PARAM_STR); $statement->bindValue(':contactId', $password->getUserId(), \PDO::PARAM_INT); $statement->bindValue(':creationDate', $password->getCreationDate()->getTimestamp(), \PDO::PARAM_INT); $statement->execute(); } /** * Delete old passwords to store only 3 last passwords. * * @param int $userId */ private function deleteOldPasswords(int $userId): void { $this->info('removing old passwords for user from DBMS', [ 'user_id' => $userId, ]); $statement = $this->db->prepare( $this->translateDbName( 'SELECT creation_date FROM `:db`.`contact_password` WHERE `contact_id` = :contactId ORDER BY `creation_date` DESC' ) ); $statement->bindValue(':contactId', $userId, \PDO::PARAM_INT); $statement->execute(); // If 3 or more passwords are saved, delete the oldest ones. if (($result = $statement->fetchAll()) && count($result) > 3) { $maxCreationDateToDelete = $result[3]['creation_date']; $statement = $this->db->prepare( $this->translateDbName( 'DELETE FROM `:db`.`contact_password` WHERE contact_id = :contactId AND creation_date <= :creationDate' ) ); $statement->bindValue(':contactId', $userId, \PDO::PARAM_INT); $statement->bindValue(':creationDate', $maxCreationDateToDelete, \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/User/Infrastructure/Repository/DbReadUserRepository.php
centreon/src/Core/Security/User/Infrastructure/Repository/DbReadUserRepository.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\User\Infrastructure\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 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\User\Application\Repository\ReadUserRepositoryInterface; use Core\Security\User\Domain\Model\User; class DbReadUserRepository extends DatabaseRepository implements ReadUserRepositoryInterface { /** * @inheritDoc */ public function findUserByAlias(string $alias): ?User { try { $query = $this->connection->createQueryBuilder() ->select( 'c.contact_alias', 'c.contact_id', 'c.login_attempts', 'c.blocking_time' ) ->from('contact', 'c') ->where('c.contact_alias = :alias') ->getQuery(); $entry = $this->connection->fetchAssociative( $query, QueryParameters::create([QueryParameter::string('alias', $alias)]) ); } catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) { throw new RepositoryException( message: 'Could not fetch user from database: ' . $e->getMessage(), context: ['alias' => $alias], previous: $e ); } if ($entry === false || $entry === []) { return null; } try { $passwordQuery = $this->connection->createQueryBuilder() ->select('cp.password', 'cp.creation_date') ->from('contact_password', 'cp') ->where('cp.contact_id = :contact_id') ->orderBy('cp.creation_date', 'ASC') ->getQuery(); $passwordEntries = $this->connection->fetchAllAssociative( $passwordQuery, QueryParameters::create([QueryParameter::int('contact_id', (int) $entry['contact_id'])]) ); } catch (QueryBuilderException|ValueObjectException|CollectionException|ConnectionException $e) { throw new RepositoryException( message: 'Could not fetch user passwords from database: ' . $e->getMessage(), context: ['alias' => $alias, 'contact_id' => $entry['contact_id']], previous: $e ); } if ($passwordEntries === []) { return null; } $entry['passwords'] = $passwordEntries; try { return (new DbUserTransformer())->transform($entry); } catch (\InvalidArgumentException $e) { throw new RepositoryException( message: 'Could not transform database record to User', context: ['alias' => $alias], 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/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/ProviderConfigurationDto.php
centreon/src/Core/Security/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/ProviderConfigurationDto.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\UseCase\FindProviderConfigurations; class ProviderConfigurationDto { public int $id = 0; public string $type = ''; public string $name = ''; public string $authenticationUri = ''; public bool $isActive = false; public bool $isForced = false; }
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/UseCase/FindProviderConfigurations/ProviderConfigurationDtoFactoryInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/ProviderConfigurationDtoFactoryInterface.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\UseCase\FindProviderConfigurations; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\OpenId\Exceptions\OpenIdConfigurationException; interface ProviderConfigurationDtoFactoryInterface { /** * Validate Factory is valid for provider type. * * @param string $type * * @return bool */ public function supports(string $type): bool; /** * @param Configuration $configuration * * @throws OpenIdConfigurationException * @throws \Throwable * * @return ProviderConfigurationDto */ public function createResponse(Configuration $configuration): ProviderConfigurationDto; }
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/UseCase/FindProviderConfigurations/FindProviderConfigurationsPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/FindProviderConfigurationsPresenterInterface.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\UseCase\FindProviderConfigurations; use Core\Application\Common\UseCase\PresenterInterface; use Core\Application\Common\UseCase\ResponseStatusInterface; interface FindProviderConfigurationsPresenterInterface extends PresenterInterface { /** * @param FindProviderConfigurationsResponse|ResponseStatusInterface $data */ public function presentResponse(FindProviderConfigurationsResponse|ResponseStatusInterface $data): 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/UseCase/FindProviderConfigurations/FindProviderConfigurationsResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/FindProviderConfigurationsResponse.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\UseCase\FindProviderConfigurations; final class FindProviderConfigurationsResponse { /** @var ProviderConfigurationDto[] */ public array $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/Application/UseCase/FindProviderConfigurations/FindProviderConfigurations.php
centreon/src/Core/Security/ProviderConfiguration/Application/UseCase/FindProviderConfigurations/FindProviderConfigurations.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\UseCase\FindProviderConfigurations; use Core\Application\Common\UseCase\ErrorResponse; use Core\Security\ProviderConfiguration\Application\Repository\ReadConfigurationRepositoryInterface; final class FindProviderConfigurations { /** @var ProviderConfigurationDtoFactoryInterface[] */ private array $providerResponseFactories; /** * @param \Traversable<ProviderConfigurationDtoFactoryInterface> $providerDtoFactories * @param ReadConfigurationRepositoryInterface $readConfigurationRepository */ public function __construct( \Traversable $providerDtoFactories, private readonly ReadConfigurationRepositoryInterface $readConfigurationRepository, ) { $this->providerResponseFactories = iterator_to_array($providerDtoFactories); } /** * @param FindProviderConfigurationsPresenterInterface $presenter */ public function __invoke(FindProviderConfigurationsPresenterInterface $presenter): void { try { $configurations = $this->readConfigurationRepository->findConfigurations(); /** * match configuration type and factory supporting type to bind automatically corresponding * configuration and Factory. * e.g configuration type 'local' will match LocalProviderDtoFactory, * ProviderConfigurationDtoFactoryInterface::createResponse will take LocalConfiguration. */ $responses = []; foreach ($configurations as $configuration) { foreach ($this->providerResponseFactories as $providerFactory) { if ($providerFactory->supports($configuration->getType())) { $responses[] = $providerFactory->createResponse($configuration); } } } $response = new FindProviderConfigurationsResponse(); $response->providerConfigurations = $responses; $presenter->presentResponse($response); } catch (\Throwable $e) { $presenter->setResponseStatus( new ErrorResponse($e->getMessage(), exception: $e), ); 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/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationRequest.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationRequest.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\WebSSO\UseCase\UpdateWebSSOConfiguration; final class UpdateWebSSOConfigurationRequest { /** @var bool */ public bool $isActive; /** @var bool */ public bool $isForced; /** @var array<string> */ public array $trustedClientAddresses; /** @var array<string> */ public array $blacklistClientAddresses; /** @var string|null */ public ?string $loginHeaderAttribute = null; /** @var string|null */ public ?string $patternMatchingLogin = null; /** @var string|null */ public ?string $patternReplaceLogin = 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/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfiguration.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\WebSSO\UseCase\UpdateWebSSOConfiguration; 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\Security\ProviderConfiguration\Application\WebSSO\Repository\WriteWebSSOConfigurationRepositoryInterface; use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfigurationFactory; class UpdateWebSSOConfiguration { use LoggerTrait; /** * @param WriteWebSSOConfigurationRepositoryInterface $repository */ public function __construct(private WriteWebSSOConfigurationRepositoryInterface $repository) { } /** * @param UpdateWebSSOConfigurationPresenterInterface $presenter * @param UpdateWebSSOConfigurationRequest $request */ public function __invoke( UpdateWebSSOConfigurationPresenterInterface $presenter, UpdateWebSSOConfigurationRequest $request, ): void { $this->info('Updating WebSSO Provider ...'); try { $configuration = WebSSOConfigurationFactory::createFromRequest($request); } catch (AssertionException $ex) { $this->error('Unable to create WebSSO Provider'); $presenter->setResponseStatus(new ErrorResponse($ex->getMessage())); return; } $this->repository->updateConfiguration($configuration); $presenter->setResponseStatus(new NoContentResponse()); } }
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/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/UpdateWebSSOConfiguration/UpdateWebSSOConfigurationPresenterInterface.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\WebSSO\UseCase\UpdateWebSSOConfiguration; use Core\Application\Common\UseCase\PresenterInterface; interface UpdateWebSSOConfigurationPresenterInterface 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/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfigurationPresenterInterface.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\WebSSO\UseCase\FindWebSSOConfiguration; use Core\Application\Common\UseCase\PresenterInterface; interface FindWebSSOConfigurationPresenterInterface 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/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfigurationResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfigurationResponse.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\WebSSO\UseCase\FindWebSSOConfiguration; final class FindWebSSOConfigurationResponse { /** @var bool */ public bool $isActive; /** @var bool */ public bool $isForced; /** @var array<string> */ public array $trustedClientAddresses; /** @var array<string> */ public array $blacklistClientAddresses; /** @var string|null */ public ?string $loginHeaderAttribute = null; /** @var string|null */ public ?string $patternMatchingLogin = null; /** @var string|null */ public ?string $patternReplaceLogin = 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/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/UseCase/FindWebSSOConfiguration/FindWebSSOConfiguration.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\WebSSO\UseCase\FindWebSSOConfiguration; use Centreon\Domain\Common\Assertion\AssertionException; use Centreon\Domain\Log\LoggerTrait; use Centreon\Domain\Repository\RepositoryException; use Core\Application\Common\UseCase\ErrorResponse; use Core\Application\Common\UseCase\NotFoundResponse; use Core\Security\ProviderConfiguration\Application\WebSSO\Repository\ReadWebSSOConfigurationRepositoryInterface; use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration; class FindWebSSOConfiguration { use LoggerTrait; /** * @param ReadWebSSOConfigurationRepositoryInterface $repository */ public function __construct(private ReadWebSSOConfigurationRepositoryInterface $repository) { } /** * @param FindWebSSOConfigurationPresenterInterface $presenter */ public function __invoke(FindWebSSOConfigurationPresenterInterface $presenter): void { try { $configuration = $this->repository->findConfiguration(); } catch (RepositoryException|AssertionException $ex) { $this->error($ex->getMessage(), ['trace' => $ex->getTraceAsString()]); $presenter->setResponseStatus(new ErrorResponse($ex->getMessage())); return; } if ($configuration === null) { $presenter->setResponseStatus(new NotFoundResponse('WebSSOConfiguration')); return; } $presenter->present($this->createResponse($configuration)); } /** * @param WebSSOConfiguration $configuration * * @return FindWebSSOConfigurationResponse */ private function createResponse(WebSSOConfiguration $configuration): FindWebSSOConfigurationResponse { $response = new FindWebSSOConfigurationResponse(); $response->isActive = $configuration->isActive(); $response->isForced = $configuration->isForced(); $response->trustedClientAddresses = $configuration->getTrustedClientAddresses(); $response->blacklistClientAddresses = $configuration->getBlackListClientAddresses(); $response->loginHeaderAttribute = $configuration->getLoginHeaderAttribute(); $response->patternMatchingLogin = $configuration->getPatternMatchingLogin(); $response->patternReplaceLogin = $configuration->getPatternReplaceLogin(); 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/WebSSO/Repository/ReadWebSSOConfigurationRepositoryInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/Repository/ReadWebSSOConfigurationRepositoryInterface.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\WebSSO\Repository; use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration; interface ReadWebSSOConfigurationRepositoryInterface { /** * Find WebSSO Provider. * * @return WebSSOConfiguration|null */ public function findConfiguration(): ?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/Application/WebSSO/Repository/WriteWebSSOConfigurationRepositoryInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/WebSSO/Repository/WriteWebSSOConfigurationRepositoryInterface.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\WebSSO\Repository; use Core\Security\ProviderConfiguration\Domain\WebSSO\Model\WebSSOConfiguration; interface WriteWebSSOConfigurationRepositoryInterface { /** * @param WebSSOConfiguration $configuration */ public function updateConfiguration(WebSSOConfiguration $configuration): 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/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationErrorResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationErrorResponse.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\OpenId\UseCase\PartialUpdateOpenIdConfiguration; use Core\Application\Common\UseCase\ErrorResponse; final class PartialUpdateOpenIdConfigurationErrorResponse extends ErrorResponse { public function __construct() { parent::__construct('Error during OpenID Provider partial update'); } }
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/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfiguration.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\OpenId\UseCase\PartialUpdateOpenIdConfiguration; use Assert\AssertionFailedException; 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\Common\Application\Repository\WriteVaultRepositoryInterface; use Core\Common\Application\Type\NoValue; use Core\Common\Application\UseCase\VaultTrait; use Core\Common\Domain\Exception\RepositoryException; use Core\Common\Infrastructure\Repository\AbstractVaultRepository; 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\OpenId\Repository\WriteOpenIdConfigurationRepositoryInterface; 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\ContactGroupRelation; 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\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration; use Core\Security\Vault\Application\Repository\ReadVaultConfigurationRepositoryInterface; use Core\Security\Vault\Domain\Model\VaultConfiguration; /** * @phpstan-import-type _RoleMapping from PartialUpdateOpenIdConfigurationRequest * @phpstan-import-type _GroupsMapping from PartialUpdateOpenIdConfigurationRequest * @phpstan-import-type _AuthConditions from PartialUpdateOpenIdConfigurationRequest * @phpstan-import-type _PartialUpdateOpenIdConfigurationRequest from PartialUpdateOpenIdConfigurationRequest * * @phpstan-type _CustomConfigurationAsArray array<string, mixed> */ final class PartialUpdateOpenIdConfiguration { use LoggerTrait; use VaultTrait; /** * @param WriteOpenIdConfigurationRepositoryInterface $repository * @param ReadContactTemplateRepositoryInterface $contactTemplateRepository * @param ReadContactGroupRepositoryInterface $contactGroupRepository * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param ProviderAuthenticationFactoryInterface $providerAuthenticationFactory * @param ReadVaultConfigurationRepositoryInterface $vaultConfigurationRepository * @param WriteVaultRepositoryInterface $writeVaultRepository */ public function __construct( private WriteOpenIdConfigurationRepositoryInterface $repository, private ReadContactTemplateRepositoryInterface $contactTemplateRepository, private ReadContactGroupRepositoryInterface $contactGroupRepository, private ReadAccessGroupRepositoryInterface $accessGroupRepository, private ProviderAuthenticationFactoryInterface $providerAuthenticationFactory, private ReadVaultConfigurationRepositoryInterface $vaultConfigurationRepository, private WriteVaultRepositoryInterface $writeVaultRepository, ) { $this->writeVaultRepository->setCustomPath(AbstractVaultRepository::OPEN_ID_CREDENTIALS_VAULT_PATH); } /** * @param PartialUpdateOpenIdConfigurationPresenterInterface $presenter * @param PartialUpdateOpenIdConfigurationRequest $request */ public function __invoke( PartialUpdateOpenIdConfigurationPresenterInterface $presenter, PartialUpdateOpenIdConfigurationRequest $request, ): void { $this->info('Partially Updating OpenID Provider'); try { $provider = $this->providerAuthenticationFactory->create(Provider::OPENID); /** @var Configuration */ $configuration = $provider->getConfiguration(); $customConfiguration = $this->createUpdatedCustomConfiguration( $configuration->getCustomConfiguration(), $request ); $configuration->update( isActive: $request->isActive instanceof NoValue ? $configuration->isActive() : $request->isActive, isForced: $request->isForced instanceof NoValue ? $configuration->isForced() : $request->isForced ); $configuration->setCustomConfiguration($customConfiguration); $this->repository->updateConfiguration($configuration); } catch (AssertionException|AssertionFailedException|ConfigurationException $ex) { $this->error( 'Unable to perform partial update on OpenID Provider because one or several parameters are invalid', [ 'exception' => [ 'type' => $ex::class, 'message' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTraceAsString(), ], ] ); $presenter->setResponseStatus(new ErrorResponse($ex->getMessage())); return; } catch (RepositoryException $exception) { $this->error( 'Error during Opend ID Provider Partial Update', ['exception' => $exception->getContext()] ); $presenter->setResponseStatus(new ErrorResponse($exception->getMessage())); return; } catch (\Throwable $ex) { $this->error('Error during Opend ID Provider Partial Update', [ 'exception' => [ 'type' => $ex::class, 'message' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTraceAsString(), ], ]); $presenter->setResponseStatus(new PartialUpdateOpenIdConfigurationErrorResponse()); return; } $presenter->setResponseStatus(new NoContentResponse()); } /** * @param CustomConfiguration $customConfig * @param PartialUpdateOpenIdConfigurationRequest $request * * @throws \Throwable * @return CustomConfiguration */ private function createUpdatedCustomConfiguration( CustomConfigurationInterface $customConfig, PartialUpdateOpenIdConfigurationRequest $request, ): CustomConfiguration { $requestArray = $request->toArray(); /** @var CustomConfiguration $customConfig */ $oldConfigArray = $customConfig->toArray(); $customConfigurationAsArray = []; foreach ($requestArray as $paramName => $paramValue) { if ($paramName === 'contact_template') { $customConfigurationAsArray['contact_template'] = $paramValue instanceof NoValue ? $customConfig->getContactTemplate() : ( $paramValue && array_key_exists('id', $paramValue) !== null ? $this->getContactTemplateOrFail($paramValue) : null ); } elseif ($paramName === 'roles_mapping') { $customConfigurationAsArray['roles_mapping'] = $this->createUpdatedAclConditions( $paramValue, $customConfig->getACLConditions() ); } elseif ($paramName === 'authentication_conditions') { $customConfigurationAsArray['authentication_conditions'] = $this->createUpdatedAuthenticationConditions( $paramValue, $customConfig->getAuthenticationConditions() ); } elseif ($paramName === 'groups_mapping') { $customConfigurationAsArray['groups_mapping'] = $this->createUpdatedGroupsMapping( $paramValue, $customConfig->getGroupsMapping() ); } elseif ($paramValue instanceof NoValue) { $customConfigurationAsArray[$paramName] = $oldConfigArray[$paramName]; } else { $customConfigurationAsArray[$paramName] = $requestArray[$paramName]; } } $customConfigurationAsArray = $this->manageClientIdAndClientSecretIntoVault( $customConfigurationAsArray, $customConfig ); return new CustomConfiguration($customConfigurationAsArray); } /** * Get Contact template or throw an Exception. * * @param array{id: int, name: string}|null $contactTemplateFromRequest * * @throws \Throwable|ConfigurationException * * @return ContactTemplate|null */ 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; } /** * @param _RoleMapping $paramValue * @param ACLConditions $aclConditions * * @throws \Throwable * @return ACLConditions */ private function createUpdatedAclConditions(array $paramValue, ACLConditions $aclConditions): ACLConditions { return new ACLConditions( isEnabled: $paramValue['is_enabled'] instanceof NoValue ? $aclConditions->isEnabled() : $paramValue['is_enabled'], applyOnlyFirstRole: $paramValue['apply_only_first_role'] instanceof NoValue ? $aclConditions->onlyFirstRoleIsApplied() : $paramValue['apply_only_first_role'], attributePath: $paramValue['attribute_path'] instanceof NoValue ? $aclConditions->getAttributePath() : $paramValue['attribute_path'], endpoint: $paramValue['endpoint'] instanceof NoValue ? $aclConditions->getEndpoint() : new Endpoint( $paramValue['endpoint']['type'], $paramValue['endpoint']['custom_endpoint'] ), relations: $paramValue['relations'] instanceof NoValue ? $aclConditions->getRelations() : $this->createAuthorizationRules($paramValue['relations']), ); } /** * Create Authorization Rules. * * @param array<array{claim_value: string, access_group_id: int, priority: int}> $authorizationRulesFromRequest * * @throws \Throwable * * @return AuthorizationRule[] */ private function createAuthorizationRules(array $authorizationRulesFromRequest): array { $this->info('Creating Authorization Rules'); $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; } /** * 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 !== []) { $this->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 int $accessGroupIdFromRequest Access group id sent in the request * @param AccessGroup[] $foundAccessGroups Access groups found in data storage * * @return AccessGroup|null */ 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); } /** * @param _AuthConditions $requestParam * @param AuthenticationConditions $authConditions * * @return AuthenticationConditions */ private function createUpdatedAuthenticationConditions( array $requestParam, AuthenticationConditions $authConditions, ): AuthenticationConditions { $newAuthConditions = new AuthenticationConditions( isEnabled: $requestParam['is_enabled'] instanceof NoValue ? $authConditions->isEnabled() : $requestParam['is_enabled'], attributePath: $requestParam['attribute_path'] instanceof NoValue ? $authConditions->getAttributePath() : $requestParam['attribute_path'], endpoint: $requestParam['endpoint'] instanceof NoValue ? $authConditions->getEndpoint() : new Endpoint( $requestParam['endpoint']['type'], $requestParam['endpoint']['custom_endpoint'] ), authorizedValues: $requestParam['authorized_values'] instanceof NoValue ? $authConditions->getAuthorizedValues() : $requestParam['authorized_values'], ); $newAuthConditions->setTrustedClientAddresses( $requestParam['trusted_client_addresses'] instanceof NoValue ? $authConditions->getTrustedClientAddresses() : $requestParam['trusted_client_addresses'] ); $newAuthConditions->setBlacklistClientAddresses( $requestParam['blacklist_client_addresses'] instanceof NoValue ? $authConditions->getBlacklistClientAddresses() : $requestParam['blacklist_client_addresses'] ); return $newAuthConditions; } /** * @param _GroupsMapping $requestParam * @param GroupsMapping $groupsMapping * * @return GroupsMapping */ private function createUpdatedGroupsMapping( array $requestParam, GroupsMapping $groupsMapping, ): GroupsMapping { $contactGroupRelations = []; if (! $requestParam['relations'] instanceof NoValue) { $contactGroupIds = $this->getContactGroupIds($requestParam['relations']); $foundContactGroups = $this->contactGroupRepository->findByIds($contactGroupIds); $this->logNonExistentContactGroupsIds($contactGroupIds, $foundContactGroups); foreach ($requestParam['relations'] as $contactGroupRelation) { $contactGroup = $this->findContactGroupFromFoundcontactGroups( $contactGroupRelation['contact_group_id'], $foundContactGroups ); if ($contactGroup !== null) { $contactGroupRelations[] = new ContactGroupRelation( $contactGroupRelation['group_value'], $contactGroup ); } } } return new GroupsMapping( isEnabled: $requestParam['is_enabled'] instanceof NoValue ? $groupsMapping->isEnabled() : $requestParam['is_enabled'], attributePath: $requestParam['attribute_path'] instanceof NoValue ? $groupsMapping->getAttributePath() : $requestParam['attribute_path'], endpoint: $requestParam['endpoint'] instanceof NoValue ? $groupsMapping->getEndpoint() : new Endpoint( $requestParam['endpoint']['type'], $requestParam['endpoint']['custom_endpoint'] ), contactGroupRelations: $requestParam['relations'] instanceof NoValue ? $groupsMapping->getContactGroupRelations() : $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 !== []) { $this->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 int $contactGroupIdFromRequest contact group id sent in the request * @param ContactGroup[] $foundContactGroups contact groups found in data storage * * @return ContactGroup|null */ private function findContactGroupFromFoundcontactGroups( int $contactGroupIdFromRequest, array $foundContactGroups, ): ?ContactGroup { foreach ($foundContactGroups as $foundContactGroup) { if ($contactGroupIdFromRequest === $foundContactGroup->getId()) { return $foundContactGroup; } } return null; } /** * Manage the client id and client secret into the vault. * This method will upsert the client id and the client secret if one of those values change and are not already * stored into the vault. * * @param _CustomConfigurationAsArray $requestArray * @param CustomConfiguration $customConfiguration * * @throws \Throwable * * @return _CustomConfigurationAsArray */ private function manageClientIdAndClientSecretIntoVault( array $requestArray, CustomConfiguration $customConfiguration, ): array { // No need to do anything if vault is not configured if (! $this->vaultConfigurationRepository->exists()) { return $requestArray; } // Retrieve the uuid from the vault path if the client id or client secret is already stored $uuid = null; $clientId = $customConfiguration->getClientId(); $clientSecret = $customConfiguration->getClientSecret(); if ($clientId !== null && str_starts_with($clientId, VaultConfiguration::VAULT_PATH_PATTERN)) { $uuid = $this->getUuidFromPath($clientId); } elseif ($clientSecret !== null && str_starts_with($clientSecret, VaultConfiguration::VAULT_PATH_PATTERN)) { $uuid = $this->getUuidFromPath($clientSecret); } // Update the vault with the new client id and client secret if the value are not a vault path. $data = []; if ( $requestArray['client_id'] !== null && ! str_starts_with($requestArray['client_id'], VaultConfiguration::VAULT_PATH_PATTERN) ) { $data[VaultConfiguration::OPENID_CLIENT_ID_KEY] = $requestArray['client_id']; } if ( $requestArray['client_secret'] !== null && ! str_starts_with($requestArray['client_secret'], VaultConfiguration::VAULT_PATH_PATTERN) ) { $data[VaultConfiguration::OPENID_CLIENT_SECRET_KEY] = $requestArray['client_secret']; } if ($data !== []) { $vaultPaths = $this->writeVaultRepository->upsert( $uuid, $data ); // Assign new values to the request array $requestArray['client_id'] = $vaultPaths[VaultConfiguration::OPENID_CLIENT_ID_KEY]; $requestArray['client_secret'] = $vaultPaths[VaultConfiguration::OPENID_CLIENT_SECRET_KEY]; } return $requestArray; } }
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/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationRequest.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationRequest.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\OpenId\UseCase\PartialUpdateOpenIdConfiguration; use Core\Common\Application\Type\NoValue; /** * @phpstan-type _RoleMapping array{ * is_enabled: NoValue|bool, * apply_only_first_role: NoValue|bool, * attribute_path: NoValue|string, * endpoint: NoValue|array{ * type: string, * custom_endpoint:string|null * }, * relations:NoValue|array<array{ * claim_value: string, * access_group_id: int, * priority: int * }> * } * @phpstan-type _GroupsMapping array{ * is_enabled: NoValue|bool, * attribute_path: NoValue|string, * endpoint: NoValue|array{ * type: string, * custom_endpoint:string|null * }, * relations:NoValue|array<array{ * group_value: string, * contact_group_id: int * }> * } * @phpstan-type _AuthConditions array{ * is_enabled: NoValue|bool, * attribute_path: NoValue|string, * authorized_values: NoValue|string[], * trusted_client_addresses: NoValue|string[], * blacklist_client_addresses: NoValue|string[], * endpoint: NoValue|array{ * type: string, * custom_endpoint:string|null * } * } * @phpstan-type _PartialUpdateOpenIdConfigurationRequest array{ * is_active:NoValue|bool, * is_forced:NoValue|bool, * base_url:NoValue|string|null, * authorization_endpoint:NoValue|string|null, * token_endpoint:NoValue|string|null, * introspection_token_endpoint:NoValue|string|null, * userinfo_endpoint:NoValue|string|null, * endsession_endpoint:NoValue|string|null, * connection_scopes:NoValue|string[], * login_claim:NoValue|string|null, * client_id:NoValue|string|null, * client_secret:NoValue|string|null, * authentication_type:NoValue|string|null, * verify_peer:NoValue|bool, * auto_import:NoValue|bool, * contact_template:NoValue|array{id:int,name:string}|null, * email_bind_attribute:NoValue|string|null, * fullname_bind_attribute:NoValue|string|null, * redirect_url:NoValue|string|null, * authentication_conditions:array{ * is_enabled:NoValue|bool, * attribute_path:NoValue|string, * authorized_values:NoValue|string[], * trusted_client_addresses:NoValue|string[], * blacklist_client_addresses:NoValue|string[], * endpoint:NoValue|array{type:string,custom_endpoint:string|null} * }, * roles_mapping:array{ * is_enabled:NoValue|bool, * apply_only_first_role:NoValue|bool, * attribute_path:NoValue|string, * endpoint:NoValue|array{type:string,custom_endpoint:string|null}, * relations:NoValue|array<array{claim_value:string,access_group_id:int,priority:int}> * }, * groups_mapping:array{ * is_enabled:NoValue|bool, * attribute_path:NoValue|string, * endpoint:NoValue|array{type:string,custom_endpoint:string|null}, * relations:NoValue|array<array{group_value:string,contact_group_id:int}> * } * } */ final class PartialUpdateOpenIdConfigurationRequest { /** * @param NoValue|bool $isActive * @param NoValue|bool $isForced * @param NoValue|string|null $baseUrl * @param NoValue|string|null $authorizationEndpoint * @param NoValue|string|null $tokenEndpoint * @param NoValue|string|null $introspectionTokenEndpoint * @param NoValue|string|null $userInformationEndpoint * @param NoValue|string|null $endSessionEndpoint * @param NoValue|string[] $connectionScopes * @param NoValue|string|null $loginClaim * @param NoValue|string|null $clientId * @param NoValue|string|null $clientSecret * @param NoValue|string|null $authenticationType * @param NoValue|bool $verifyPeer * @param NoValue|bool $isAutoImportEnabled * @param NoValue|array{id: int, name: string}|null $contactTemplate * @param NoValue|string|null $emailBindAttribute * @param NoValue|string|null $userNameBindAttribute * @param NoValue|string|null $redirectUrl * @param _AuthConditions $authenticationConditions * @param _RoleMapping $rolesMapping * @param _GroupsMapping $groupsMapping */ public function __construct( public NoValue|bool $isActive = new NoValue(), public NoValue|bool $isForced = new NoValue(), public NoValue|string|null $baseUrl = new NoValue(), public NoValue|string|null $authorizationEndpoint = new NoValue(), public NoValue|string|null $tokenEndpoint = new NoValue(), public NoValue|string|null $introspectionTokenEndpoint = new NoValue(), public NoValue|string|null $userInformationEndpoint = new NoValue(), public NoValue|string|null $endSessionEndpoint = new NoValue(), public NoValue|array $connectionScopes = new NoValue(), public NoValue|string|null $loginClaim = new NoValue(), public NoValue|string|null $clientId = new NoValue(), public NoValue|string|null $clientSecret = new NoValue(), public NoValue|string|null $authenticationType = new NoValue(), public NoValue|bool $verifyPeer = new NoValue(), public NoValue|bool $isAutoImportEnabled = new NoValue(), public NoValue|array|null $contactTemplate = new NoValue(), public NoValue|string|null $emailBindAttribute = new NoValue(), public NoValue|string|null $userNameBindAttribute = new NoValue(), public NoValue|string|null $redirectUrl = new NoValue(), public array $authenticationConditions = [ 'is_enabled' => new NoValue(), 'attribute_path' => new NoValue(), 'authorized_values' => new NoValue(), 'trusted_client_addresses' => new NoValue(), 'blacklist_client_addresses' => new NoValue(), 'endpoint' => new NoValue(), ], public array $rolesMapping = [ 'is_enabled' => new NoValue(), 'apply_only_first_role' => new NoValue(), 'attribute_path' => new NoValue(), 'endpoint' => new NoValue(), 'relations' => new NoValue(), ], public array $groupsMapping = [ 'is_enabled' => new NoValue(), 'attribute_path' => new NoValue(), 'endpoint' => new NoValue(), 'relations' => new NoValue(), ], ) { } /** * @return _PartialUpdateOpenIdConfigurationRequest */ public function toArray(): array { return [ 'is_forced' => $this->isForced, 'is_active' => $this->isActive, 'contact_template' => $this->contactTemplate, 'auto_import' => $this->isAutoImportEnabled, 'client_id' => $this->clientId, 'authentication_type' => $this->authenticationType, 'authorization_endpoint' => $this->authorizationEndpoint, 'base_url' => $this->baseUrl, 'client_secret' => $this->clientSecret, 'connection_scopes' => $this->connectionScopes, 'email_bind_attribute' => $this->emailBindAttribute, 'endsession_endpoint' => $this->endSessionEndpoint, 'introspection_token_endpoint' => $this->introspectionTokenEndpoint, 'login_claim' => $this->loginClaim, 'token_endpoint' => $this->tokenEndpoint, 'userinfo_endpoint' => $this->userInformationEndpoint, 'fullname_bind_attribute' => $this->userNameBindAttribute, 'verify_peer' => $this->verifyPeer, 'authentication_conditions' => $this->authenticationConditions, 'groups_mapping' => $this->groupsMapping, 'roles_mapping' => $this->rolesMapping, 'redirect_url' => $this->redirectUrl, ]; } }
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/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/PartialUpdateOpenIdConfiguration/PartialUpdateOpenIdConfigurationPresenterInterface.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\OpenId\UseCase\PartialUpdateOpenIdConfiguration; use Core\Application\Common\UseCase\PresenterInterface; interface PartialUpdateOpenIdConfigurationPresenterInterface 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/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfigurationPresenterInterface.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\OpenId\UseCase\FindOpenIdConfiguration; use Core\Application\Common\UseCase\PresenterInterface; interface FindOpenIdConfigurationPresenterInterface 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/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfigurationResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfigurationResponse.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\OpenId\UseCase\FindOpenIdConfiguration; 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\Endpoint; use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping; /** * @phpstan-import-type _EndpointArray from Endpoint * * @phpstan-type _authorizationRules array{ * claim_value: string, * access_group: array{ * id: int, * name: string * }, * priority: int, * } * @phpstan-type _aclConditions array{ * is_enabled: bool, * apply_only_first_role: bool, * attribute_path: string, * endpoint: null|_EndpointArray, * relations: array<_authorizationRules>, * } * @phpstan-type _authenticationConditions array{ * is_enabled: bool, * attribute_path: string, * authorized_values: string[], * trusted_client_addresses: string[], * blacklist_client_addresses: string[], * endpoint: _EndpointArray|null * } * @phpstan-type _groupsMapping array{ * is_enabled: bool, * attribute_path: string, * endpoint: _EndpointArray|null, * relations: array< * array{ * group_value: string, * contact_group: array{ * id: int, * name: string * } * } * > * } */ final class FindOpenIdConfigurationResponse { /** @var bool */ public bool $isActive = false; /** @var bool */ public bool $isForced = false; /** @var string|null */ public ?string $baseUrl = null; /** @var string|null */ public ?string $authorizationEndpoint = null; /** @var string|null */ public ?string $tokenEndpoint = null; /** @var string|null */ public ?string $introspectionTokenEndpoint = null; /** @var string|null */ public ?string $userInformationEndpoint = null; /** @var string|null */ public ?string $endSessionEndpoint = null; /** @var string[] */ public array $connectionScopes = []; /** @var string|null */ public ?string $loginClaim = null; /** @var string|null */ public ?string $clientId = null; /** @var string|null */ public ?string $clientSecret = null; /** @var string|null */ public ?string $authenticationType = null; /** @var bool */ public bool $verifyPeer = false; /** @var bool */ public bool $isAutoImportEnabled = false; /** @var array{id: int, name: string}|null */ public ?array $contactTemplate = null; /** @var string|null */ public ?string $emailBindAttribute = null; /** @var string|null */ public ?string $userNameBindAttribute = null; /** @var _aclConditions|array{} */ public array $aclConditions = []; /** @var _authenticationConditions|array{} */ public array $authenticationConditions = []; /** @var array{}|_groupsMapping */ public array $groupsMapping = []; public ?string $redirectUrl = null; /** * @param ContactTemplate $contactTemplate * * @return array{id: int, name: 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 _authenticationConditions */ public static 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 _groupsMapping */ public static function groupsMappingToArray(GroupsMapping $groupsMapping): array { $relations = self::contactGroupRelationsToArray($groupsMapping->getContactGroupRelations()); return [ 'is_enabled' => $groupsMapping->isEnabled(), 'attribute_path' => $groupsMapping->getAttributePath(), 'endpoint' => $groupsMapping->getEndpoint()?->toArray(), '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(), 'endpoint' => $aclConditions->getEndpoint()?->toArray(), '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/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/FindOpenIdConfiguration/FindOpenIdConfiguration.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\OpenId\UseCase\FindOpenIdConfiguration; use Centreon\Domain\Log\LoggerTrait; 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\OpenId\Model\CustomConfiguration; class FindOpenIdConfiguration { use LoggerTrait; /** * @param ProviderAuthenticationFactoryInterface $providerFactory */ public function __construct(private ProviderAuthenticationFactoryInterface $providerFactory) { } /** * @param FindOpenIdConfigurationPresenterInterface $presenter */ public function __invoke(FindOpenIdConfigurationPresenterInterface $presenter): void { try { $provider = $this->providerFactory->create(Provider::OPENID); $configuration = $provider->getConfiguration(); } catch (\Throwable $ex) { $this->error($ex->getMessage(), ['trace' => $ex->getTraceAsString()]); $presenter->setResponseStatus(new ErrorResponse($ex->getMessage())); return; } $presenter->present($this->createResponse($configuration)); } /** * @param Configuration $provider * * @return FindOpenIdConfigurationResponse */ private function createResponse(Configuration $provider): FindOpenIdConfigurationResponse { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $provider->getCustomConfiguration(); $findOpenIdConfigurationResponse = new FindOpenIdConfigurationResponse(); $findOpenIdConfigurationResponse->isActive = $provider->isActive(); $findOpenIdConfigurationResponse->isForced = $provider->isForced(); $findOpenIdConfigurationResponse->baseUrl = $customConfiguration->getBaseUrl(); $findOpenIdConfigurationResponse->authorizationEndpoint = $customConfiguration->getAuthorizationEndpoint(); $findOpenIdConfigurationResponse->tokenEndpoint = $customConfiguration->getTokenEndpoint(); $findOpenIdConfigurationResponse->introspectionTokenEndpoint = $customConfiguration->getIntrospectionTokenEndpoint(); $findOpenIdConfigurationResponse->userInformationEndpoint = $customConfiguration->getUserInformationEndpoint(); $findOpenIdConfigurationResponse->endSessionEndpoint = $customConfiguration->getEndSessionEndpoint(); $findOpenIdConfigurationResponse->connectionScopes = $customConfiguration->getConnectionScopes(); $findOpenIdConfigurationResponse->loginClaim = $customConfiguration->getLoginClaim(); $findOpenIdConfigurationResponse->clientId = $customConfiguration->getClientId(); $findOpenIdConfigurationResponse->clientSecret = $customConfiguration->getClientSecret(); $findOpenIdConfigurationResponse->authenticationType = $customConfiguration->getAuthenticationType(); $findOpenIdConfigurationResponse->verifyPeer = $customConfiguration->verifyPeer(); $findOpenIdConfigurationResponse->isAutoImportEnabled = $customConfiguration->isAutoImportEnabled(); $findOpenIdConfigurationResponse->contactTemplate = $customConfiguration->getContactTemplate() === null ? null : $findOpenIdConfigurationResponse::contactTemplateToArray($customConfiguration->getContactTemplate()); $findOpenIdConfigurationResponse->emailBindAttribute = $customConfiguration->getEmailBindAttribute(); $findOpenIdConfigurationResponse->userNameBindAttribute = $customConfiguration->getUserNameBindAttribute(); $findOpenIdConfigurationResponse->aclConditions = FindOpenIdConfigurationResponse::aclConditionsToArray( $customConfiguration->getACLConditions() ); $findOpenIdConfigurationResponse->authenticationConditions = $findOpenIdConfigurationResponse::authenticationConditionsToArray( $customConfiguration->getAuthenticationConditions() ); $findOpenIdConfigurationResponse->groupsMapping = $findOpenIdConfigurationResponse::groupsMappingToArray( $customConfiguration->getGroupsMapping() ); $findOpenIdConfigurationResponse->redirectUrl = $customConfiguration->getRedirectUrl(); return $findOpenIdConfigurationResponse; } }
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/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationRequest.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationRequest.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\OpenId\UseCase\UpdateOpenIdConfiguration; /** * @phpstan-type _RoleMapping 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 * }> * } * @phpstan-type _GroupMapping 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 * }> * } * @phpstan-type _AuthenticationConditions 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 * } * } * @phpstan-type _UpdateOpenIdConfigurationRequest 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, * roles_mapping: _RoleMapping, * authentication_conditions: _AuthenticationConditions, * groups_mapping: _GroupMapping, * redirect_url: string|null * } */ final class UpdateOpenIdConfigurationRequest { /** @var bool */ public bool $isActive = false; /** @var bool */ public bool $isForced = false; /** @var string|null */ public ?string $baseUrl = null; /** @var string|null */ public ?string $authorizationEndpoint = null; /** @var string|null */ public ?string $tokenEndpoint = null; /** @var string|null */ public ?string $introspectionTokenEndpoint = null; /** @var string|null */ public ?string $userInformationEndpoint = null; /** @var string|null */ public ?string $endSessionEndpoint = null; /** @var string[] */ public array $connectionScopes = []; /** @var string|null */ public ?string $loginClaim = null; /** @var string|null */ public ?string $clientId = null; /** @var string|null */ public ?string $clientSecret = null; /** @var string|null */ public ?string $authenticationType = null; /** @var bool */ public bool $verifyPeer = false; /** @var bool */ public bool $isAutoImportEnabled = false; /** @var array{id: int, name: string}|null */ public ?array $contactTemplate = null; /** @var string|null */ public ?string $emailBindAttribute = null; /** @var string|null */ public ?string $userNameBindAttribute = null; /** @var _RoleMapping */ public array $rolesMapping = [ 'is_enabled' => false, 'apply_only_first_role' => false, 'attribute_path' => '', 'endpoint' => [ 'type' => 'introspection_endpoint', 'custom_endpoint' => '', ], 'relations' => [], ]; /** @var _AuthenticationConditions */ public array $authenticationConditions = [ 'is_enabled' => false, 'attribute_path' => '', 'authorized_values' => [], 'trusted_client_addresses' => [], 'blacklist_client_addresses' => [], 'endpoint' => [ 'type' => 'introspection_endpoint', 'custom_endpoint' => null, ], ]; /** @var _GroupMapping */ public array $groupsMapping = [ 'is_enabled' => false, 'attribute_path' => '', 'endpoint' => [ 'type' => 'introspection_endpoint', 'custom_endpoint' => null, ], 'relations' => [], ]; public ?string $redirectUrl = null; /** * @return _UpdateOpenIdConfigurationRequest */ public function toArray(): array { return [ 'is_forced' => $this->isForced, 'is_active' => $this->isActive, 'contact_template' => $this->contactTemplate, 'auto_import' => $this->isAutoImportEnabled, 'client_id' => $this->clientId, 'authentication_type' => $this->authenticationType, 'authorization_endpoint' => $this->authorizationEndpoint, 'base_url' => $this->baseUrl, 'client_secret' => $this->clientSecret, 'connection_scopes' => $this->connectionScopes, 'email_bind_attribute' => $this->emailBindAttribute, 'endsession_endpoint' => $this->endSessionEndpoint, 'introspection_token_endpoint' => $this->introspectionTokenEndpoint, 'login_claim' => $this->loginClaim, 'token_endpoint' => $this->tokenEndpoint, 'userinfo_endpoint' => $this->userInformationEndpoint, 'fullname_bind_attribute' => $this->userNameBindAttribute, 'verify_peer' => $this->verifyPeer, 'authentication_conditions' => $this->authenticationConditions, 'groups_mapping' => $this->groupsMapping, 'roles_mapping' => $this->rolesMapping, 'redirect_url' => $this->redirectUrl, ]; } }
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/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfiguration.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\OpenId\UseCase\UpdateOpenIdConfiguration; use Assert\AssertionFailedException; 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\Common\Application\Repository\WriteVaultRepositoryInterface; use Core\Common\Application\UseCase\VaultTrait; use Core\Common\Domain\Exception\RepositoryException; use Core\Common\Infrastructure\Repository\AbstractVaultRepository; 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\OpenId\Repository\WriteOpenIdConfigurationRepositoryInterface; 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\Endpoint; use Core\Security\ProviderConfiguration\Domain\Model\GroupsMapping; use Core\Security\ProviderConfiguration\Domain\Model\Provider; use Core\Security\ProviderConfiguration\Domain\OpenId\Model\CustomConfiguration; use Core\Security\Vault\Application\Repository\ReadVaultConfigurationRepositoryInterface; use Core\Security\Vault\Domain\Model\VaultConfiguration; /** * @phpstan-import-type _RoleMapping from UpdateOpenIdConfigurationRequest * @phpstan-import-type _GroupMapping from UpdateOpenIdConfigurationRequest * @phpstan-import-type _AuthenticationConditions from UpdateOpenIdConfigurationRequest * @phpstan-import-type _UpdateOpenIdConfigurationRequest from UpdateOpenIdConfigurationRequest * * @phpstan-type _ConfigurationAsArray array<string, mixed> */ class UpdateOpenIdConfiguration { use LoggerTrait; use VaultTrait; /** * @param WriteOpenIdConfigurationRepositoryInterface $repository * @param ReadContactTemplateRepositoryInterface $contactTemplateRepository * @param ReadContactGroupRepositoryInterface $contactGroupRepository * @param ReadAccessGroupRepositoryInterface $accessGroupRepository * @param ProviderAuthenticationFactoryInterface $providerAuthenticationFactory * @param ReadVaultConfigurationRepositoryInterface $vaultConfigurationRepository * @param WriteVaultRepositoryInterface $writeVaultRepository */ public function __construct( private WriteOpenIdConfigurationRepositoryInterface $repository, private ReadContactTemplateRepositoryInterface $contactTemplateRepository, private ReadContactGroupRepositoryInterface $contactGroupRepository, private ReadAccessGroupRepositoryInterface $accessGroupRepository, private ProviderAuthenticationFactoryInterface $providerAuthenticationFactory, private ReadVaultConfigurationRepositoryInterface $vaultConfigurationRepository, private WriteVaultRepositoryInterface $writeVaultRepository, ) { $this->writeVaultRepository->setCustomPath(AbstractVaultRepository::OPEN_ID_CREDENTIALS_VAULT_PATH); } /** * @param UpdateOpenIdConfigurationPresenterInterface $presenter * @param UpdateOpenIdConfigurationRequest $request */ public function __invoke( UpdateOpenIdConfigurationPresenterInterface $presenter, UpdateOpenIdConfigurationRequest $request, ): void { $this->info('Updating OpenID Provider'); try { $provider = $this->providerAuthenticationFactory->create(Provider::OPENID); /** * @var Configuration $configuration */ $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); $requestArray['is_active'] = $request->isActive; /** * @var CustomConfiguration $customConfiguration */ $customConfiguration = $configuration->getCustomConfiguration(); /** * @var _ConfigurationAsArray $requestArray */ $requestArray = $this->manageClientIdAndClientSecretIntoVault($requestArray, $customConfiguration); $configuration->setCustomConfiguration(new CustomConfiguration($requestArray)); $this->info('Updating OpenID Provider'); $this->repository->updateConfiguration($configuration); } catch (AssertionException|AssertionFailedException|ConfigurationException $ex) { $this->error( 'Unable to create OpenID Provider because one or several parameters are invalid', [ 'exception' => [ 'type' => $ex::class, 'message' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTraceAsString(), ], ] ); $presenter->setResponseStatus(new ErrorResponse($ex->getMessage())); return; } catch (RepositoryException $exception) { $this->error( 'Error during Opend ID Provider Update', ['exception' => $exception->getContext()] ); $presenter->setResponseStatus(new ErrorResponse($exception->getMessage())); return; } catch (\Throwable $ex) { $this->error( 'Error during Opend ID Provider Update', [ 'exception' => [ 'type' => $ex::class, 'message' => $ex->getMessage(), 'file' => $ex->getFile(), 'line' => $ex->getLine(), 'trace' => $ex->getTraceAsString(), ], ] ); $presenter->setResponseStatus(new UpdateOpenIdConfigurationErrorResponse()); return; } $presenter->setResponseStatus(new NoContentResponse()); } /** * Get Contact template or throw an Exception. * * @param array{id: int, name: string}|null $contactTemplateFromRequest * * @throws ConfigurationException|RepositoryException * * @return ContactTemplate|null */ 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 \Throwable * * @return AuthorizationRule[] */ private function createAuthorizationRules(array $authorizationRulesFromRequest): array { $this->info('Creating Authorization Rules'); $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 _RoleMapping $rolesMapping * * @throws \Throwable * * @return ACLConditions */ 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'], new Endpoint($rolesMapping['endpoint']['type'], $rolesMapping['endpoint']['custom_endpoint']), $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 !== []) { $this->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 int $accessGroupIdFromRequest Access group id sent in the request * @param AccessGroup[] $foundAccessGroups Access groups found in data storage * * @return AccessGroup|null */ 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); } /** * Create Authentication Condition from request data. * * @param _AuthenticationConditions $authenticationConditionsParameters * * @throws AssertionFailedException * @throws ConfigurationException * * @return AuthenticationConditions */ private function createAuthenticationConditions(array $authenticationConditionsParameters): AuthenticationConditions { $authenticationConditions = new AuthenticationConditions( $authenticationConditionsParameters['is_enabled'], $authenticationConditionsParameters['attribute_path'], new Endpoint( $authenticationConditionsParameters['endpoint']['type'], $authenticationConditionsParameters['endpoint']['custom_endpoint'] ), $authenticationConditionsParameters['authorized_values'], ); $authenticationConditions->setTrustedClientAddresses( $authenticationConditionsParameters['trusted_client_addresses'] ); $authenticationConditions->setBlacklistClientAddresses( $authenticationConditionsParameters['blacklist_client_addresses'] ); return $authenticationConditions; } /** * Create Groups Mapping from data send to the request. * * @param _GroupMapping $groupsMappingParameters * * @return GroupsMapping */ 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 ); } } $endpoint = new Endpoint( $groupsMappingParameters['endpoint']['type'], $groupsMappingParameters['endpoint']['custom_endpoint'] ); return new GroupsMapping( $groupsMappingParameters['is_enabled'], $groupsMappingParameters['attribute_path'], $endpoint, $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 !== []) { $this->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 int $contactGroupIdFromRequest contact group id sent in the request * @param ContactGroup[] $foundContactGroups contact groups found in data storage * * @return ContactGroup|null */ private function findContactGroupFromFoundcontactGroups( int $contactGroupIdFromRequest, array $foundContactGroups, ): ?ContactGroup { foreach ($foundContactGroups as $foundContactGroup) { if ($contactGroupIdFromRequest === $foundContactGroup->getId()) { return $foundContactGroup; } } return null; } /** * Manage the client id and client secret into the vault. * This method will upsert the client id and the client secret if one of those values change and are not already * stored into the vault. * * @param _ConfigurationAsArray $requestArray * @param CustomConfiguration $customConfiguration * * @throws \Throwable * * @return _ConfigurationAsArray */ private function manageClientIdAndClientSecretIntoVault( array $requestArray, CustomConfiguration $customConfiguration, ): array { // No need to do anything if vault is not configured if (! $this->vaultConfigurationRepository->exists()) { return $requestArray; } // Retrieve the uuid from the vault path if the client id or client secret is already stored $uuid = null; $clientId = $customConfiguration->getClientId(); $clientSecret = $customConfiguration->getClientSecret(); if ($clientId !== null && str_starts_with($clientId, VaultConfiguration::VAULT_PATH_PATTERN)) { $uuid = $this->getUuidFromPath($clientId); } elseif ($clientSecret !== null && str_starts_with($clientSecret, VaultConfiguration::VAULT_PATH_PATTERN)) { $uuid = $this->getUuidFromPath($clientSecret); } // Update the vault with the new client id and client secret if the value are not a vault path. $data = []; if ( $requestArray['client_id'] !== null && ! str_starts_with($requestArray['client_id'], VaultConfiguration::VAULT_PATH_PATTERN) ) { $data[VaultConfiguration::OPENID_CLIENT_ID_KEY] = $requestArray['client_id']; } if ( $requestArray['client_secret'] !== null && ! str_starts_with($requestArray['client_secret'], VaultConfiguration::VAULT_PATH_PATTERN) ) { $data[VaultConfiguration::OPENID_CLIENT_SECRET_KEY] = $requestArray['client_secret']; } if ($data !== []) { $vaultPaths = $this->writeVaultRepository->upsert( $uuid, $data ); // Assign new values to the request array $requestArray['client_id'] = $vaultPaths[VaultConfiguration::OPENID_CLIENT_ID_KEY]; $requestArray['client_secret'] = $vaultPaths[VaultConfiguration::OPENID_CLIENT_SECRET_KEY]; } return $requestArray; } }
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/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationErrorResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationErrorResponse.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\OpenId\UseCase\UpdateOpenIdConfiguration; use Core\Application\Common\UseCase\ErrorResponse; final class UpdateOpenIdConfigurationErrorResponse extends ErrorResponse { public function __construct() { parent::__construct('Error during OpenID Provider Update'); } }
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/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/UseCase/UpdateOpenIdConfiguration/UpdateOpenIdConfigurationPresenterInterface.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\OpenId\UseCase\UpdateOpenIdConfiguration; use Core\Application\Common\UseCase\PresenterInterface; interface UpdateOpenIdConfigurationPresenterInterface 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/OpenId/Repository/WriteOpenIdConfigurationRepositoryInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/Repository/WriteOpenIdConfigurationRepositoryInterface.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\OpenId\Repository; use Core\Security\ProviderConfiguration\Domain\Model\AuthorizationRule; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; interface WriteOpenIdConfigurationRepositoryInterface { /** * Update the OpenId Provider. * * @param Configuration $configuration * * @throws \Throwable */ public function updateConfiguration(Configuration $configuration): void; /** * Delete Authorization rules. * * @throws \Throwable */ public function deleteAuthorizationRules(): void; /** * Insert Authorization rules. * * @param AuthorizationRule[] $authorizationRules * * @throws \Throwable */ public function insertAuthorizationRules(array $authorizationRules): 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/OpenId/Repository/ReadOpenIdConfigurationRepositoryInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/OpenId/Repository/ReadOpenIdConfigurationRepositoryInterface.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\OpenId\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 ReadOpenIdConfigurationRepositoryInterface { /** * @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/Local/UseCase/FindConfiguration/FindConfiguration.php
centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/FindConfiguration/FindConfiguration.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 Centreon\Domain\Log\LoggerTrait; use Core\Security\Authentication\Application\Provider\ProviderAuthenticationFactoryInterface; use Core\Security\ProviderConfiguration\Domain\Local\Model\CustomConfiguration; use Core\Security\ProviderConfiguration\Domain\Model\Configuration; use Core\Security\ProviderConfiguration\Domain\Model\Provider; class FindConfiguration { use LoggerTrait; /** * @param ProviderAuthenticationFactoryInterface $providerFactory */ public function __construct(private ProviderAuthenticationFactoryInterface $providerFactory) { } /** * @param FindConfigurationPresenterInterface $presenter */ public function __invoke(FindConfigurationPresenterInterface $presenter): void { $this->debug('Searching for local provider configuration'); try { $provider = $this->providerFactory->create(Provider::LOCAL); $configuration = $provider->getConfiguration(); } catch (\Throwable $throwable) { $this->critical($throwable->getMessage()); $presenter->setResponseStatus( new FindConfigurationErrorResponse($throwable->getMessage()) ); return; } $presenter->present($this->createResponse($configuration)); } /** * @param Configuration $configuration * * @return FindConfigurationResponse */ public function createResponse(Configuration $configuration): FindConfigurationResponse { /** @var CustomConfiguration $customConfiguration */ $customConfiguration = $configuration->getCustomConfiguration(); $response = new FindConfigurationResponse(); $response->passwordMinimumLength = $customConfiguration->getSecurityPolicy()->getPasswordMinimumLength(); $response->hasUppercase = $customConfiguration->getSecurityPolicy()->hasUppercase(); $response->hasLowercase = $customConfiguration->getSecurityPolicy()->hasLowercase(); $response->hasNumber = $customConfiguration->getSecurityPolicy()->hasNumber(); $response->hasSpecialCharacter = $customConfiguration->getSecurityPolicy()->hasSpecialCharacter(); $response->canReusePasswords = $customConfiguration->getSecurityPolicy()->canReusePasswords(); $response->attempts = $customConfiguration->getSecurityPolicy()->getAttempts(); $response->blockingDuration = $customConfiguration->getSecurityPolicy()->getBlockingDuration(); $response->passwordExpirationDelay = $customConfiguration->getSecurityPolicy()->getPasswordExpirationDelay(); $response->passwordExpirationExcludedUserAliases = $customConfiguration ->getSecurityPolicy() ->getPasswordExpirationExcludedUserAliases(); $response->delayBeforeNewPassword = $customConfiguration->getSecurityPolicy()->getDelayBeforeNewPassword(); 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/Local/UseCase/FindConfiguration/FindConfigurationResponse.php
centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/FindConfiguration/FindConfigurationResponse.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; final class FindConfigurationResponse { /** @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/FindConfiguration/FindConfigurationPresenterInterface.php
centreon/src/Core/Security/ProviderConfiguration/Application/Local/UseCase/FindConfiguration/FindConfigurationPresenterInterface.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\PresenterInterface; interface FindConfigurationPresenterInterface extends PresenterInterface { }
php
Apache-2.0
6ae83001e94de0a4cec11e084780fcfa63f1c985
2026-01-05T04:45:18.914281Z
false