|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/** |
| 6 | + * @copyright Copyright (c) 2023, T-Systems International |
| 7 | + * |
| 8 | + * @author B. Rederlechner <bernd.rederlechner@t-Systems.com> |
| 9 | + * |
| 10 | + * @license AGPL-3.0 |
| 11 | + * |
| 12 | + * This code is free software: you can redistribute it and/or modify |
| 13 | + * it under the terms of the GNU Affero General Public License, version 3, |
| 14 | + * as published by the Free Software Foundation. |
| 15 | + * |
| 16 | + * This program is distributed in the hope that it will be useful, |
| 17 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | + * GNU Affero General Public License for more details. |
| 20 | + * |
| 21 | + * You should have received a copy of the GNU Affero General Public License, version 3, |
| 22 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 23 | + * |
| 24 | + */ |
| 25 | + |
| 26 | +namespace OCA\UserOIDC\Service; |
| 27 | + |
| 28 | +/** |
| 29 | + * Exception if the precondition of the config update method isn't met |
| 30 | + * @since 1.4.0 |
| 31 | + */ |
| 32 | +class ProvisioningDeniedException extends \Exception { |
| 33 | + private $redirectUrl; |
| 34 | + |
| 35 | + /** |
| 36 | + * Exception constructor including an option redirect url. |
| 37 | + * |
| 38 | + * @param string $message The error message. It will be not revealed to the |
| 39 | + * the user (unless the hint is empty) and thus |
| 40 | + * should be not translated. |
| 41 | + * @param string $hint A useful message that is presented to the end |
| 42 | + * user. It should be translated, but must not |
| 43 | + * contain sensitive data. |
| 44 | + * @param int $code Set default to 403 (Forbidden) |
| 45 | + * @param \Exception|null $previous |
| 46 | + */ |
| 47 | + public function __construct(string $message, ?string $redirectUrl = null, int $code = 403, ?\Exception $previous = null) { |
| 48 | + parent::__construct($message, $code, $previous); |
| 49 | + $this->redirectUrl = $redirectUrl; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Read optional failure redirect if available |
| 54 | + * @return string|null |
| 55 | + */ |
| 56 | + public function getRedirectUrl(): ?string { |
| 57 | + return $this->redirectUrl; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Include redirect in string serialisation. |
| 62 | + * |
| 63 | + * @return string |
| 64 | + */ |
| 65 | + public function __toString(): string { |
| 66 | + $redirect = $this->redirectUrl ?? '<no redirect>'; |
| 67 | + return __CLASS__ . ": [{$this->code}]: {$this->message} ({$redirect})\n"; |
| 68 | + } |
| 69 | +} |
0 commit comments