-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26467 from nextcloud/feature/noid/allow-apps-to-l…
…og-to-audit Allow apps to log actions into the audit_log
- Loading branch information
Showing
7 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/admin_audit/lib/Listener/CriticalActionPerformedEventListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com> | ||
* | ||
* @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\AdminAudit\Listener; | ||
|
||
use OCA\AdminAudit\Actions\Action; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\Log\Audit\CriticalActionPerformedEvent; | ||
|
||
class CriticalActionPerformedEventListener extends Action implements IEventListener { | ||
public function handle(Event $event): void { | ||
if (!($event instanceof CriticalActionPerformedEvent)) { | ||
return; | ||
} | ||
|
||
$this->log( | ||
$event->getLogMessage(), | ||
$event->getParameters(), | ||
array_keys($event->getParameters()), | ||
$event->getObfuscateParameters() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2021 Joas Schilling <coding@schilljs.com> | ||
* | ||
* @author Joas Schilling <coding@schilljs.com> | ||
* | ||
* @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 OCP\Log\Audit; | ||
|
||
use OCP\EventDispatcher\Event; | ||
|
||
/** | ||
* Emitted when the admin_audit app should log an entry | ||
* | ||
* @since 22.0.0 | ||
*/ | ||
class CriticalActionPerformedEvent extends Event { | ||
|
||
/** @var string */ | ||
private $logMessage; | ||
|
||
/** @var array */ | ||
private $parameters; | ||
|
||
/** @var bool */ | ||
private $obfuscateParameters; | ||
|
||
/** | ||
* @param string $logMessage | ||
* @param array $parameters | ||
* @param bool $obfuscateParameters | ||
* @since 22.0.0 | ||
*/ | ||
public function __construct(string $logMessage, | ||
array $parameters = [], | ||
bool $obfuscateParameters = false) { | ||
parent::__construct(); | ||
$this->logMessage = $logMessage; | ||
$this->parameters = $parameters; | ||
$this->obfuscateParameters = $obfuscateParameters; | ||
} | ||
|
||
/** | ||
* @return string | ||
* @since 22.0.0 | ||
*/ | ||
public function getLogMessage(): string { | ||
return $this->logMessage; | ||
} | ||
|
||
/** | ||
* @return array | ||
* @since 22.0.0 | ||
*/ | ||
public function getParameters(): array { | ||
return $this->parameters; | ||
} | ||
|
||
/** | ||
* @return bool | ||
* @since 22.0.0 | ||
*/ | ||
public function getObfuscateParameters(): bool { | ||
return $this->obfuscateParameters; | ||
} | ||
} |