Merge pull request #4894 from nextcloud/generic-security-activities

Change 2FA activities to more generic security activities
This commit is contained in:
Lukas Reschke 2017-05-19 00:50:44 +02:00 committed by GitHub
commit 7976927628
14 changed files with 60 additions and 54 deletions

View File

@ -18,14 +18,7 @@
</dependencies>
<activity>
<filters>
<filter>OCA\TwoFactorBackupCodes\Activity\GenericFilter</filter>
</filters>
<settings>
<setting>OCA\TwoFactorBackupCodes\Activity\GenericSetting</setting>
</settings>
<providers>
<provider>OCA\TwoFactorBackupCodes\Activity\GenericProvider</provider>
<provider>OCA\TwoFactorBackupCodes\Activity\Provider</provider>
</providers>
</activity>

View File

@ -103,7 +103,7 @@ class BackupCodeStorage {
private function publishEvent(IUser $user, $event) {
$activity = $this->activityManager->generateEvent();
$activity->setApp('twofactor_backupcodes')
->setType('twofactor')
->setType('security')
->setAuthor($user->getUID())
->setAffectedUser($user->getUID())
->setSubject($event);

View File

@ -98,7 +98,7 @@ class BackupCodeStorageTest extends TestCase {
->will($this->returnSelf());
$event->expects($this->once())
->method('setType')
->with('twofactor')
->with('security')
->will($this->returnSelf());
$event->expects($this->once())
->method('setAuthor')

View File

@ -786,6 +786,9 @@ return array(
'OC\\Session\\Memory' => $baseDir . '/lib/private/Session/Memory.php',
'OC\\Session\\Session' => $baseDir . '/lib/private/Session/Session.php',
'OC\\Settings\\Activity\\Provider' => $baseDir . '/settings/Activity/Provider.php',
'OC\\Settings\\Activity\\SecurityFilter' => $baseDir . '/settings/Activity/SecurityFilter.php',
'OC\\Settings\\Activity\\SecurityProvider' => $baseDir . '/settings/Activity/SecurityProvider.php',
'OC\\Settings\\Activity\\SecuritySetting' => $baseDir . '/settings/Activity/SecuritySetting.php',
'OC\\Settings\\Activity\\Setting' => $baseDir . '/settings/Activity/Setting.php',
'OC\\Settings\\Admin\\Additional' => $baseDir . '/lib/private/Settings/Admin/Additional.php',
'OC\\Settings\\Admin\\Encryption' => $baseDir . '/lib/private/Settings/Admin/Encryption.php',

View File

@ -816,6 +816,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Session\\Memory' => __DIR__ . '/../../..' . '/lib/private/Session/Memory.php',
'OC\\Session\\Session' => __DIR__ . '/../../..' . '/lib/private/Session/Session.php',
'OC\\Settings\\Activity\\Provider' => __DIR__ . '/../../..' . '/settings/Activity/Provider.php',
'OC\\Settings\\Activity\\SecurityFilter' => __DIR__ . '/../../..' . '/settings/Activity/SecurityFilter.php',
'OC\\Settings\\Activity\\SecurityProvider' => __DIR__ . '/../../..' . '/settings/Activity/SecurityProvider.php',
'OC\\Settings\\Activity\\SecuritySetting' => __DIR__ . '/../../..' . '/settings/Activity/SecuritySetting.php',
'OC\\Settings\\Activity\\Setting' => __DIR__ . '/../../..' . '/settings/Activity/Setting.php',
'OC\\Settings\\Admin\\Additional' => __DIR__ . '/../../..' . '/lib/private/Settings/Admin/Additional.php',
'OC\\Settings\\Admin\\Encryption' => __DIR__ . '/../../..' . '/lib/private/Settings/Admin/Encryption.php',

View File

@ -23,6 +23,7 @@
namespace OC\Authentication\TwoFactorAuth;
use BadMethodCallException;
use Exception;
use OC;
use OC\App\AppManager;
@ -218,16 +219,16 @@ class Manager {
*/
private function publishEvent(IUser $user, $event, array $params) {
$activity = $this->activityManager->generateEvent();
$activity->setApp('twofactor_generic')
->setType('twofactor')
$activity->setApp('core')
->setType('security')
->setAuthor($user->getUID())
->setAffectedUser($user->getUID())
->setSubject($event, $params);
try {
$this->activityManager->publish($activity);
} catch (Exception $e) {
$this->logger->warning('could not publish backup code creation activity', ['app' => 'twofactor_backupcodes']);
$this->logger->logException($e, ['app' => 'twofactor_backupcodes']);
} catch (BadMethodCallException $e) {
$this->logger->warning('could not publish backup code creation activity', ['app' => 'core']);
$this->logger->logException($e, ['app' => 'core']);
}
}

View File

@ -20,13 +20,13 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Activity;
namespace OC\Settings\Activity;
use OCP\Activity\IFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
class GenericFilter implements IFilter {
class SecurityFilter implements IFilter {
/** @var IURLGenerator */
private $urlGenerator;
@ -44,7 +44,7 @@ class GenericFilter implements IFilter {
}
public function filterTypes(array $types) {
return array_intersect(['twofactor'], $types);
return array_intersect(['security'], $types);
}
public function getIcon() {
@ -52,11 +52,11 @@ class GenericFilter implements IFilter {
}
public function getIdentifier() {
return 'twofactor';
return 'security';
}
public function getName() {
return $this->l10n->t('Two-factor authentication');
return $this->l10n->t('Security');
}
public function getPriority() {

View File

@ -20,7 +20,7 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Activity;
namespace OC\Settings\Activity;
use InvalidArgumentException;
use OCP\Activity\IEvent;
@ -29,7 +29,7 @@ use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\L10N\IFactory as L10nFactory;
class GenericProvider implements IProvider {
class SecurityProvider implements IProvider {
/** @var L10nFactory */
private $l10n;
@ -47,7 +47,7 @@ class GenericProvider implements IProvider {
}
public function parse($language, IEvent $event, IEvent $previousEvent = null) {
if ($event->getType() !== 'twofactor') {
if ($event->getType() !== 'security') {
throw new InvalidArgumentException();
}

View File

@ -20,12 +20,12 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Activity;
namespace OC\Settings\Activity;
use OCP\Activity\ISetting;
use OCP\IL10N;
class GenericSetting implements ISetting {
class SecuritySetting implements ISetting {
/** @var IL10N */
private $l10n;
@ -43,11 +43,11 @@ class GenericSetting implements ISetting {
}
public function getIdentifier() {
return 'twofactor';
return 'security';
}
public function getName() {
return $this->l10n->t('Two-factor authentication');
return $this->l10n->t('Security');
}
public function getPriority() {

View File

@ -34,6 +34,9 @@ use OC\AppFramework\Utility\TimeFactory;
use OC\Authentication\Token\IProvider;
use OC\Server;
use OC\Settings\Activity\Provider;
use OC\Settings\Activity\SecurityFilter;
use OC\Settings\Activity\SecurityProvider;
use OC\Settings\Activity\SecuritySetting;
use OC\Settings\Activity\Setting;
use OC\Settings\Mailer\NewUserMailHelper;
use OC\Settings\Middleware\SubadminMiddleware;
@ -114,6 +117,9 @@ class Application extends App {
$activityManager = $this->getContainer()->getServer()->getActivityManager();
$activityManager->registerSetting(Setting::class); // FIXME move to info.xml
$activityManager->registerProvider(Provider::class); // FIXME move to info.xml
$activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml
$activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml
$activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml
Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword');
Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo');

View File

@ -20,19 +20,19 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;
namespace Tests\Settings\Activity;
use OCA\TwoFactorBackupCodes\Activity\GenericFilter;
use OC\Settings\Activity\SecurityFilter;
use OCP\IL10N;
use OCP\IURLGenerator;
use Test\TestCase;
class GenericFilterTest extends TestCase {
class SecurityFilterTest extends TestCase {
private $urlGenerator;
private $l10n;
/** @var GenericFilter */
/** @var SecurityFilter */
private $filter;
protected function setUp() {
@ -41,7 +41,7 @@ class GenericFilterTest extends TestCase {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->l10n = $this->createMock(IL10N::class);
$this->filter = new GenericFilter($this->urlGenerator, $this->l10n);
$this->filter = new SecurityFilter($this->urlGenerator, $this->l10n);
}
public function testAllowedApps() {
@ -49,7 +49,7 @@ class GenericFilterTest extends TestCase {
}
public function testFilterTypes() {
$this->assertEquals(['twofactor'], $this->filter->filterTypes(['comments', 'twofactor']));
$this->assertEquals(['security'], $this->filter->filterTypes(['comments', 'security']));
}
public function testGetIcon() {
@ -65,13 +65,13 @@ class GenericFilterTest extends TestCase {
}
public function testGetIdentifier() {
$this->assertEquals('twofactor', $this->filter->getIdentifier());
$this->assertEquals('security', $this->filter->getIdentifier());
}
public function testGetName() {
$this->l10n->expects($this->once())
->method('t')
->with('Two-factor authentication')
->with('Security')
->will($this->returnValue('translated'));
$this->assertEquals('translated', $this->filter->getName());
}

View File

@ -20,10 +20,10 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;
namespace Tests\Settings\Activity;
use InvalidArgumentException;
use OCA\TwoFactorBackupCodes\Activity\GenericProvider;
use OC\Settings\Activity\SecurityProvider;
use OCP\Activity\IEvent;
use OCP\IL10N;
use OCP\ILogger;
@ -32,7 +32,7 @@ use OCP\L10N\IFactory;
use PHPUnit_Framework_MockObject_MockObject;
use Test\TestCase;
class GenericProviderTest extends TestCase {
class SecurityProviderTest extends TestCase {
/** @var IL10N|PHPUnit_Framework_MockObject_MockObject */
private $l10n;
@ -43,7 +43,7 @@ class GenericProviderTest extends TestCase {
/** @var ILogger|PHPUnit_Framework_MockObject_MockObject */
private $logger;
/** @var GenericProvider */
/** @var SecurityProvider */
private $provider;
protected function setUp() {
@ -53,7 +53,7 @@ class GenericProviderTest extends TestCase {
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->logger = $this->createMock(ILogger::class);
$this->provider = new GenericProvider($this->l10n, $this->urlGenerator, $this->logger);
$this->provider = new SecurityProvider($this->l10n, $this->urlGenerator, $this->logger);
}
public function testParseUnrelated() {
@ -84,7 +84,7 @@ class GenericProviderTest extends TestCase {
$event->expects($this->once())
->method('getType')
->willReturn('twofactor');
->willReturn('security');
$this->l10n->expects($this->once())
->method('get')
->with('core', $lang)
@ -116,7 +116,7 @@ class GenericProviderTest extends TestCase {
$event->expects($this->once())
->method('getType')
->willReturn('twofactor');
->willReturn('security');
$this->l10n->expects($this->once())
->method('get')
->with('core', $lang)

View File

@ -20,17 +20,17 @@
*
*/
namespace OCA\TwoFactorBackupCodes\Test\Unit\Activity;
namespace Tests\Settings\Activity;
use OCA\TwoFactorBackupCodes\Activity\GenericSetting;
use OC\Settings\Activity\SecuritySetting;
use OCP\IL10N;
use Test\TestCase;
class SettingTest extends TestCase {
class SecuritySettingTest extends TestCase {
private $l10n;
/** @var GenericSetting */
/** @var SecuritySetting */
private $setting;
protected function setUp() {
@ -38,7 +38,7 @@ class SettingTest extends TestCase {
$this->l10n = $this->createMock(IL10N::class);
$this->setting = new GenericSetting($this->l10n);
$this->setting = new SecuritySetting($this->l10n);
}
public function testCanChangeMail() {
@ -50,15 +50,15 @@ class SettingTest extends TestCase {
}
public function testGetIdentifier() {
$this->assertEquals('twofactor', $this->setting->getIdentifier());
$this->assertEquals('security', $this->setting->getIdentifier());
}
public function testGetName() {
$this->l10n->expects($this->once())
->method('t')
->with('Two-factor authentication')
->will($this->returnValue('Zwei-Faktor-Authentifizierung'));
$this->assertEquals('Zwei-Faktor-Authentifizierung', $this->setting->getName());
->with('Security')
->will($this->returnValue('Sicherheit'));
$this->assertEquals('Sicherheit', $this->setting->getName());
}
public function testGetPriority() {

View File

@ -260,11 +260,11 @@ class ManagerTest extends TestCase {
->willReturn('jos');
$event->expects($this->once())
->method('setApp')
->with($this->equalTo('twofactor_generic'))
->with($this->equalTo('core'))
->willReturnSelf();
$event->expects($this->once())
->method('setType')
->with($this->equalTo('twofactor'))
->with($this->equalTo('security'))
->willReturnSelf();
$event->expects($this->once())
->method('setAuthor')
@ -319,11 +319,11 @@ class ManagerTest extends TestCase {
->willReturn('jos');
$event->expects($this->once())
->method('setApp')
->with($this->equalTo('twofactor_generic'))
->with($this->equalTo('core'))
->willReturnSelf();
$event->expects($this->once())
->method('setType')
->with($this->equalTo('twofactor'))
->with($this->equalTo('security'))
->willReturnSelf();
$event->expects($this->once())
->method('setAuthor')