diff options
author | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-17 22:45:05 +0100 |
---|---|---|
committer | Daniel Kesselberg <mail@danielkesselberg.de> | 2019-02-17 23:37:22 +0100 |
commit | 2ade2bef8c7c030258943b680401aec64bcdb9a2 (patch) | |
tree | e57a96b23afabe32fa9d9423d7ec6d6da524360a /core/Controller | |
parent | cb3379e97d965cf95543bf66160d6636e5c50c11 (diff) | |
download | nextcloud-server-2ade2bef8c7c030258943b680401aec64bcdb9a2.tar.gz nextcloud-server-2ade2bef8c7c030258943b680401aec64bcdb9a2.zip |
Publish activity for app token created by ocs api
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
Diffstat (limited to 'core/Controller')
-rw-r--r-- | core/Controller/AppPasswordController.php | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/core/Controller/AppPasswordController.php b/core/Controller/AppPasswordController.php index ce06730694e..b7cbc65e8c0 100644 --- a/core/Controller/AppPasswordController.php +++ b/core/Controller/AppPasswordController.php @@ -24,13 +24,17 @@ declare(strict_types=1); namespace OC\Core\Controller; +use BadMethodCallException; use OC\Authentication\Token\IProvider; use OC\Authentication\Token\IToken; +use OC\Settings\Activity\Provider; +use OCP\Activity\IManager as IActivityManager; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\OCS\OCSForbiddenException; use OCP\Authentication\Exceptions\CredentialsUnavailableException; use OCP\Authentication\Exceptions\PasswordUnavailableException; use OCP\Authentication\LoginCredentials\IStore; +use OCP\ILogger; use OCP\IRequest; use OCP\ISession; use OCP\Security\ISecureRandom; @@ -46,6 +50,12 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { /** @var IProvider */ private $tokenProvider; + /** @var IActivityManager */ + private $activityManager; + + /** @var ILogger */ + private $logger; + /** @var IStore */ private $credentialStore; @@ -54,13 +64,17 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { ISession $session, ISecureRandom $random, IProvider $tokenProvider, - IStore $credentialStore) { + IStore $credentialStore, + IActivityManager $activityManager, + ILogger $logger) { parent::__construct($appName, $request); $this->session = $session; $this->random = $random; $this->tokenProvider = $tokenProvider; $this->credentialStore = $credentialStore; + $this->activityManager = $activityManager; + $this->logger = $logger; } /** @@ -91,7 +105,7 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS); - $this->tokenProvider->generateToken( + $generatedToken = $this->tokenProvider->generateToken( $token, $credentials->getUID(), $credentials->getLoginName(), @@ -101,6 +115,21 @@ class AppPasswordController extends \OCP\AppFramework\OCSController { IToken::DO_NOT_REMEMBER ); + $event = $this->activityManager->generateEvent(); + $event->setApp('settings') + ->setType('security') + ->setAffectedUser($credentials->getUID()) + ->setAuthor($credentials->getUID()) + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $generatedToken->getName()]) + ->setObject('app_token', $generatedToken->getId(), 'App Password'); + + try { + $this->activityManager->publish($event); + } catch (BadMethodCallException $e) { + $this->logger->warning('could not publish activity'); + $this->logger->logException($e); + } + return new DataResponse([ 'apppassword' => $token ]); |