Browse Source
Move app_password_created to a typed event
Move app_password_created to a typed event
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>pull/25544/head
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
9 changed files with 140 additions and 45 deletions
-
1apps/settings/composer/composer/autoload_classmap.php
-
1apps/settings/composer/composer/autoload_static.php
-
37apps/settings/lib/AppInfo/Application.php
-
73apps/settings/lib/Listener/AppPasswordCreatedActivityListener.php
-
13core/Controller/AppPasswordController.php
-
15core/Controller/ClientFlowLoginController.php
-
1lib/composer/composer/autoload_classmap.php
-
1lib/composer/composer/autoload_static.php
-
43lib/private/Authentication/Events/AppPasswordCreatedEvent.php
@ -0,0 +1,73 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/* |
|||
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at> |
|||
* |
|||
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at> |
|||
* |
|||
* @license GNU AGPL version 3 or any later version |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License as |
|||
* published by the Free Software Foundation, either version 3 of the |
|||
* License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Affero General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Affero General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
namespace OCA\Settings\Listener; |
|||
|
|||
use BadMethodCallException; |
|||
use OC\Authentication\Events\AppPasswordCreatedEvent; |
|||
use OCA\Settings\Activity\Provider; |
|||
use OCP\Activity\IManager as IActivityManager; |
|||
use OCP\EventDispatcher\Event; |
|||
use OCP\EventDispatcher\IEventListener; |
|||
use Psr\Log\LoggerInterface; |
|||
|
|||
/** |
|||
* @template-implements IEventListener<\OC\Authentication\Events\AppPasswordCreatedEvent> |
|||
*/ |
|||
class AppPasswordCreatedActivityListener implements IEventListener { |
|||
/** @var IActivityManager */ |
|||
private $activityManager; |
|||
|
|||
/** @var LoggerInterface */ |
|||
private $logger; |
|||
|
|||
public function __construct(IActivityManager $activityManager, |
|||
LoggerInterface $logger) { |
|||
$this->activityManager = $activityManager; |
|||
$this->logger = $logger; |
|||
} |
|||
|
|||
public function handle(Event $event): void { |
|||
if (!($event instanceof AppPasswordCreatedEvent)) { |
|||
return; |
|||
} |
|||
|
|||
$activity = $this->activityManager->generateEvent(); |
|||
$activity->setApp('settings') |
|||
->setType('security') |
|||
->setAffectedUser($event->getToken()->getUID()) |
|||
->setAuthor($event->getToken()->getUID()) |
|||
->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $event->getToken()->getName()]) |
|||
->setObject('app_token', $event->getToken()->getId()); |
|||
|
|||
try { |
|||
$this->activityManager->publish($activity); |
|||
} catch (BadMethodCallException $e) { |
|||
$this->logger->warning('Could not publish activity: ' . $e->getMessage(), [ |
|||
'exception' => $e |
|||
]); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,43 @@ |
|||
<?php |
|||
|
|||
declare(strict_types=1); |
|||
|
|||
/* |
|||
* @copyright 2021 Christoph Wurst <christoph@winzerhof-wurst.at> |
|||
* |
|||
* @author 2021 Christoph Wurst <christoph@winzerhof-wurst.at> |
|||
* |
|||
* @license GNU AGPL version 3 or any later version |
|||
* |
|||
* This program is free software: you can redistribute it and/or modify |
|||
* it under the terms of the GNU Affero General Public License as |
|||
* published by the Free Software Foundation, either version 3 of the |
|||
* License, or (at your option) any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU Affero General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU Affero General Public License |
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|||
*/ |
|||
|
|||
namespace OC\Authentication\Events; |
|||
|
|||
use OC\Authentication\Token\IToken; |
|||
use OCP\EventDispatcher\Event; |
|||
|
|||
class AppPasswordCreatedEvent extends Event { |
|||
/** @var IToken */ |
|||
private $token; |
|||
|
|||
public function __construct(IToken $token) { |
|||
parent::__construct(); |
|||
$this->token = $token; |
|||
} |
|||
|
|||
public function getToken(): IToken { |
|||
return $this->token; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue