namespace OC\Core\Controller;
+use BadMethodCallException;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
use OC\Authentication\Token\IProvider;
use OC\Authentication\Token\IToken;
+use OC\Settings\Activity\Provider;
use OCA\OAuth2\Db\AccessToken;
use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\ClientMapper;
+use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Response;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\Defaults;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
private $accessTokenMapper;
/** @var ICrypto */
private $crypto;
+ /** @var IActivityManager */
+ private $activityManager;
+ /** @var ILogger */
+ private $logger;
const stateName = 'client.flow.state.token';
* @param ClientMapper $clientMapper
* @param AccessTokenMapper $accessTokenMapper
* @param ICrypto $crypto
+ * @param IActivityManager $activityManager
+ * @param ILogger $logger
*/
public function __construct($appName,
IRequest $request,
IURLGenerator $urlGenerator,
ClientMapper $clientMapper,
AccessTokenMapper $accessTokenMapper,
- ICrypto $crypto) {
+ ICrypto $crypto,
+ IActivityManager $activityManager,
+ ILogger $logger) {
parent::__construct($appName, $request);
$this->userSession = $userSession;
$this->l10n = $l10n;
$this->clientMapper = $clientMapper;
$this->accessTokenMapper = $accessTokenMapper;
$this->crypto = $crypto;
+ $this->activityManager = $activityManager;
+ $this->logger = $logger;
}
/**
$this->tokenProvider->invalidateToken($sessionId);
}
+ $event = $this->activityManager->generateEvent();
+ $event->setApp('settings')
+ ->setType('security')
+ ->setAffectedUser($uid)
+ ->setAuthor($uid)
+ ->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 Http\RedirectResponse($redirectUri);
}
use OCA\OAuth2\Db\AccessTokenMapper;
use OCA\OAuth2\Db\Client;
use OCA\OAuth2\Db\ClientMapper;
+use OCP\Activity\IEvent;
+use OCP\Activity\IManager as IActivityManager;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\StandaloneTemplateResponse;
use OCP\Defaults;
use OCP\IL10N;
+use OCP\ILogger;
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
private $accessTokenMapper;
/** @var ICrypto|\PHPUnit_Framework_MockObject_MockObject */
private $crypto;
+ /** @var IActivityManager|\PHPUnit_Framework_MockObject_MockObject */
+ private $activityManager;
/** @var ClientFlowLoginController */
private $clientFlowLoginController;
$this->clientMapper = $this->createMock(ClientMapper::class);
$this->accessTokenMapper = $this->createMock(AccessTokenMapper::class);
$this->crypto = $this->createMock(ICrypto::class);
+ $this->activityManager = $this->createMock(IActivityManager::class);
+ /** @var ILogger|\PHPUnit_Framework_MockObject_MockObject $logger */
+ $logger = $this->createMock(ILogger::class);
$this->clientFlowLoginController = new ClientFlowLoginController(
'core',
$this->urlGenerator,
$this->clientMapper,
$this->accessTokenMapper,
- $this->crypto
+ $this->crypto,
+ $this->activityManager,
+ $logger
);
}
->method('getHeader')
->willReturn('');
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($this->createMock(IEvent::class));
+ $this->activityManager->expects($this->once())
+ ->method('publish');
+
$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
->with('MyClientIdentifier')
->willReturn($client);
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($this->createMock(IEvent::class));
+ $this->activityManager->expects($this->once())
+ ->method('publish');
+
$expected = new Http\RedirectResponse('https://example.com/redirect.php?state=MyOauthState&code=MyAccessCode');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken', 'MyClientIdentifier'));
}
->method('getHeader')
->willReturn('');
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($this->createMock(IEvent::class));
+ $this->activityManager->expects($this->once())
+ ->method('publish');
+
$expected = new Http\RedirectResponse('nc://login/server:http://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}
->method('getHeader')
->willReturnMap($headers);
+ $this->activityManager->expects($this->once())
+ ->method('generateEvent')
+ ->willReturn($this->createMock(IEvent::class));
+ $this->activityManager->expects($this->once())
+ ->method('publish');
+
$expected = new Http\RedirectResponse('nc://login/server:' . $expected . '://example.com&user:MyLoginName&password:MyGeneratedToken');
$this->assertEquals($expected, $this->clientFlowLoginController->generateAppPassword('MyStateToken'));
}