|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * @copyright Copyright (c) 2023 T-Systems International |
| 4 | + * |
| 5 | + * @author B. Rederlechner <bernd.rederlechner@t-systems.com> |
| 6 | + * |
| 7 | + * @license GNU AGPL version 3 or any later version |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +declare(strict_types=1); |
| 12 | + |
| 13 | +namespace OCA\UserOIDC\Event; |
| 14 | + |
| 15 | +use OCP\EventDispatcher\Event; |
| 16 | + |
| 17 | +/** |
| 18 | + * Event to provide custom mapping logic based on the OIDC token data |
| 19 | + * In order to avoid further processing the event propagation should be stopped |
| 20 | + * in the listener after processing as the value might get overwritten afterwards |
| 21 | + * by other listeners through $event->stopPropagation(); |
| 22 | + */ |
| 23 | +class UserAccountChangeEvent extends Event { |
| 24 | + |
| 25 | + /** @var string */ |
| 26 | + private $uid; |
| 27 | + |
| 28 | + /** @var string|null */ |
| 29 | + private $displayname; |
| 30 | + |
| 31 | + /** @var string|null */ |
| 32 | + private $mainEmail; |
| 33 | + |
| 34 | + /** @var string|null */ |
| 35 | + private $quota; |
| 36 | + |
| 37 | + /** @var object */ |
| 38 | + private $claims; |
| 39 | + |
| 40 | + /** @var UserAccountChangeResult */ |
| 41 | + private $result; |
| 42 | + |
| 43 | + public function __construct( |
| 44 | + string $uid, |
| 45 | + ?string $displayname, |
| 46 | + ?string $mainEmail, |
| 47 | + ?string $quota, |
| 48 | + object $claims, |
| 49 | + bool $accessAllowed = false |
| 50 | + ) { |
| 51 | + parent::__construct(); |
| 52 | + $this->uid = $uid; |
| 53 | + $this->displayname = $displayname; |
| 54 | + $this->mainEmail = $mainEmail; |
| 55 | + $this->quota = $quota; |
| 56 | + $this->claims = $claims; |
| 57 | + $this->result = new UserAccountChangeResult($accessAllowed, 'default'); |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Get the user ID (UID) associated with the event. |
| 62 | + * |
| 63 | + * @return string |
| 64 | + */ |
| 65 | + public function getUid(): string { |
| 66 | + return $this->uid; |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Get the display name for the account. |
| 71 | + * |
| 72 | + * @return string|null |
| 73 | + */ |
| 74 | + public function getDisplayName(): ?string { |
| 75 | + return $this->displayname; |
| 76 | + } |
| 77 | + |
| 78 | + /** |
| 79 | + * Get the primary email address. |
| 80 | + * |
| 81 | + * @return string|null |
| 82 | + */ |
| 83 | + public function getMainEmail(): ?string { |
| 84 | + return $this->mainEmail; |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * Get the quota assigned to the account. |
| 89 | + * |
| 90 | + * @return string|null |
| 91 | + */ |
| 92 | + public function getQuota(): ?string { |
| 93 | + return $this->quota; |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Get the OIDC claims associated with the event. |
| 98 | + * |
| 99 | + * @return object |
| 100 | + */ |
| 101 | + public function getClaims(): object { |
| 102 | + return $this->claims; |
| 103 | + } |
| 104 | + |
| 105 | + /** |
| 106 | + * Get the current result object. |
| 107 | + * |
| 108 | + * @return UserAccountChangeResult |
| 109 | + */ |
| 110 | + public function getResult(): UserAccountChangeResult { |
| 111 | + return $this->result; |
| 112 | + } |
| 113 | + |
| 114 | + /** |
| 115 | + * Replace the result object with a new one. |
| 116 | + * |
| 117 | + * @param bool $accessAllowed Whether access should be allowed |
| 118 | + * @param string $reason Optional reason for the decision |
| 119 | + * @param string|null $redirectUrl Optional redirect URL |
| 120 | + * @return void |
| 121 | + */ |
| 122 | + public function setResult(bool $accessAllowed, string $reason = '', ?string $redirectUrl = null): void { |
| 123 | + $this->result = new UserAccountChangeResult($accessAllowed, $reason, $redirectUrl); |
| 124 | + } |
| 125 | +} |
0 commit comments