@@ -20,7 +20,7 @@ |
||
20 | 20 | */ |
21 | 21 | |
22 | 22 | |
23 | -require_once __DIR__ . '/../lib/base.php'; |
|
23 | +require_once __DIR__.'/../lib/base.php'; |
|
24 | 24 | |
25 | 25 | header('Content-Type: application/json'); |
26 | 26 |
@@ -29,12 +29,12 @@ |
||
29 | 29 | $isEnabled = $server->getAppManager()->isEnabledForUser('cloud_federation_api'); |
30 | 30 | |
31 | 31 | if ($isEnabled) { |
32 | - // Make sure the routes are loaded |
|
33 | - \OC_App::loadApp('cloud_federation_api'); |
|
34 | - $capabilities = new OCA\CloudFederationAPI\Capabilities($server->getURLGenerator()); |
|
35 | - header('Content-Type: application/json'); |
|
36 | - echo json_encode($capabilities->getCapabilities()['ocm']); |
|
32 | + // Make sure the routes are loaded |
|
33 | + \OC_App::loadApp('cloud_federation_api'); |
|
34 | + $capabilities = new OCA\CloudFederationAPI\Capabilities($server->getURLGenerator()); |
|
35 | + header('Content-Type: application/json'); |
|
36 | + echo json_encode($capabilities->getCapabilities()['ocm']); |
|
37 | 37 | } else { |
38 | - header($_SERVER["SERVER_PROTOCOL"]." 501 Not Implemented", true, 501); |
|
39 | - exit("501 Not Implemented"); |
|
38 | + header($_SERVER["SERVER_PROTOCOL"]." 501 Not Implemented", true, 501); |
|
39 | + exit("501 Not Implemented"); |
|
40 | 40 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | */ |
33 | 33 | public function __construct($providerId) { |
34 | 34 | $l = \OC::$server->getL10N('federation'); |
35 | - $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.'; |
|
35 | + $message = 'Cloud Federation Provider with ID: "'.$providerId.'" does not exist.'; |
|
36 | 36 | $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); |
37 | 37 | parent::__construct($message, $hint); |
38 | 38 | } |
@@ -31,17 +31,17 @@ |
||
31 | 31 | * @since 14.0.0 |
32 | 32 | */ |
33 | 33 | class ProviderDoesNotExistsException extends HintException { |
34 | - /** |
|
35 | - * ProviderDoesNotExistsException constructor. |
|
36 | - * |
|
37 | - * @since 14.0.0 |
|
38 | - * |
|
39 | - * @param string $providerId cloud federation provider ID |
|
40 | - */ |
|
41 | - public function __construct($providerId) { |
|
42 | - $l = \OC::$server->getL10N('federation'); |
|
43 | - $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.'; |
|
44 | - $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); |
|
45 | - parent::__construct($message, $hint); |
|
46 | - } |
|
34 | + /** |
|
35 | + * ProviderDoesNotExistsException constructor. |
|
36 | + * |
|
37 | + * @since 14.0.0 |
|
38 | + * |
|
39 | + * @param string $providerId cloud federation provider ID |
|
40 | + */ |
|
41 | + public function __construct($providerId) { |
|
42 | + $l = \OC::$server->getL10N('federation'); |
|
43 | + $message = 'Cloud Federation Provider with ID: "' . $providerId . '" does not exist.'; |
|
44 | + $hint = $l->t('Cloud Federation Provider with ID: "%s" does not exist.', [$providerId]); |
|
45 | + parent::__construct($message, $hint); |
|
46 | + } |
|
47 | 47 | } |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function __construct($action) { |
33 | 33 | $l = \OC::$server->getL10N('federation'); |
34 | - $message = 'Action "' . $action . '" not supported or implemented.'; |
|
34 | + $message = 'Action "'.$action.'" not supported or implemented.'; |
|
35 | 35 | $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
36 | 36 | parent::__construct($message, $hint); |
37 | 37 | } |
@@ -31,16 +31,16 @@ |
||
31 | 31 | * @since 14.0.0 |
32 | 32 | */ |
33 | 33 | class ActionNotSupportedException extends HintException { |
34 | - /** |
|
35 | - * ActionNotSupportedException constructor. |
|
36 | - * |
|
37 | - * @since 14.0.0 |
|
38 | - * |
|
39 | - */ |
|
40 | - public function __construct($action) { |
|
41 | - $l = \OC::$server->getL10N('federation'); |
|
42 | - $message = 'Action "' . $action . '" not supported or implemented.'; |
|
43 | - $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
|
44 | - parent::__construct($message, $hint); |
|
45 | - } |
|
34 | + /** |
|
35 | + * ActionNotSupportedException constructor. |
|
36 | + * |
|
37 | + * @since 14.0.0 |
|
38 | + * |
|
39 | + */ |
|
40 | + public function __construct($action) { |
|
41 | + $l = \OC::$server->getL10N('federation'); |
|
42 | + $message = 'Action "' . $action . '" not supported or implemented.'; |
|
43 | + $hint = $l->t('Action "%s" not supported or implemented.', [$action]); |
|
44 | + parent::__construct($message, $hint); |
|
45 | + } |
|
46 | 46 | } |
@@ -55,7 +55,7 @@ |
||
55 | 55 | } |
56 | 56 | |
57 | 57 | try { |
58 | - $folder = $this->appData->getFolder((string)$node->getId()); |
|
58 | + $folder = $this->appData->getFolder((string) $node->getId()); |
|
59 | 59 | $folder->delete(); |
60 | 60 | } catch (NotFoundException $e) { |
61 | 61 | //Nothing to do |
@@ -36,39 +36,39 @@ |
||
36 | 36 | * Class that will watch filesystem activity and remove previews as needed. |
37 | 37 | */ |
38 | 38 | class Watcher { |
39 | - /** @var IAppData */ |
|
40 | - private $appData; |
|
39 | + /** @var IAppData */ |
|
40 | + private $appData; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Watcher constructor. |
|
44 | - * |
|
45 | - * @param IAppData $appData |
|
46 | - */ |
|
47 | - public function __construct(IAppData $appData) { |
|
48 | - $this->appData = $appData; |
|
49 | - } |
|
42 | + /** |
|
43 | + * Watcher constructor. |
|
44 | + * |
|
45 | + * @param IAppData $appData |
|
46 | + */ |
|
47 | + public function __construct(IAppData $appData) { |
|
48 | + $this->appData = $appData; |
|
49 | + } |
|
50 | 50 | |
51 | - public function postWrite(Node $node) { |
|
52 | - $this->deleteNode($node); |
|
53 | - } |
|
51 | + public function postWrite(Node $node) { |
|
52 | + $this->deleteNode($node); |
|
53 | + } |
|
54 | 54 | |
55 | - protected function deleteNode(Node $node) { |
|
56 | - // We only handle files |
|
57 | - if ($node instanceof Folder) { |
|
58 | - return; |
|
59 | - } |
|
55 | + protected function deleteNode(Node $node) { |
|
56 | + // We only handle files |
|
57 | + if ($node instanceof Folder) { |
|
58 | + return; |
|
59 | + } |
|
60 | 60 | |
61 | - try { |
|
62 | - $folder = $this->appData->getFolder((string)$node->getId()); |
|
63 | - $folder->delete(); |
|
64 | - } catch (NotFoundException $e) { |
|
65 | - //Nothing to do |
|
66 | - } |
|
67 | - } |
|
61 | + try { |
|
62 | + $folder = $this->appData->getFolder((string)$node->getId()); |
|
63 | + $folder->delete(); |
|
64 | + } catch (NotFoundException $e) { |
|
65 | + //Nothing to do |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - public function versionRollback(array $data) { |
|
70 | - if (isset($data['node'])) { |
|
71 | - $this->deleteNode($data['node']); |
|
72 | - } |
|
73 | - } |
|
69 | + public function versionRollback(array $data) { |
|
70 | + if (isset($data['node'])) { |
|
71 | + $this->deleteNode($data['node']); |
|
72 | + } |
|
73 | + } |
|
74 | 74 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | public function connectWatcher() { |
58 | 58 | // Do not connect if we are not setup yet! |
59 | 59 | if ($this->config->getValue('instanceid', null) !== null) { |
60 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
60 | + $this->root->listen('\OC\Files', 'postWrite', function(Node $node) { |
|
61 | 61 | $this->getWatcher()->postWrite($node); |
62 | 62 | }); |
63 | 63 |
@@ -30,39 +30,39 @@ |
||
30 | 30 | use OCP\Files\Node; |
31 | 31 | |
32 | 32 | class WatcherConnector { |
33 | - /** @var IRootFolder */ |
|
34 | - private $root; |
|
33 | + /** @var IRootFolder */ |
|
34 | + private $root; |
|
35 | 35 | |
36 | - /** @var SystemConfig */ |
|
37 | - private $config; |
|
36 | + /** @var SystemConfig */ |
|
37 | + private $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * WatcherConnector constructor. |
|
41 | - * |
|
42 | - * @param IRootFolder $root |
|
43 | - * @param SystemConfig $config |
|
44 | - */ |
|
45 | - public function __construct(IRootFolder $root, |
|
46 | - SystemConfig $config) { |
|
47 | - $this->root = $root; |
|
48 | - $this->config = $config; |
|
49 | - } |
|
39 | + /** |
|
40 | + * WatcherConnector constructor. |
|
41 | + * |
|
42 | + * @param IRootFolder $root |
|
43 | + * @param SystemConfig $config |
|
44 | + */ |
|
45 | + public function __construct(IRootFolder $root, |
|
46 | + SystemConfig $config) { |
|
47 | + $this->root = $root; |
|
48 | + $this->config = $config; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * @return Watcher |
|
53 | - */ |
|
54 | - private function getWatcher(): Watcher { |
|
55 | - return \OC::$server->query(Watcher::class); |
|
56 | - } |
|
51 | + /** |
|
52 | + * @return Watcher |
|
53 | + */ |
|
54 | + private function getWatcher(): Watcher { |
|
55 | + return \OC::$server->query(Watcher::class); |
|
56 | + } |
|
57 | 57 | |
58 | - public function connectWatcher() { |
|
59 | - // Do not connect if we are not setup yet! |
|
60 | - if ($this->config->getValue('instanceid', null) !== null) { |
|
61 | - $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
62 | - $this->getWatcher()->postWrite($node); |
|
63 | - }); |
|
58 | + public function connectWatcher() { |
|
59 | + // Do not connect if we are not setup yet! |
|
60 | + if ($this->config->getValue('instanceid', null) !== null) { |
|
61 | + $this->root->listen('\OC\Files', 'postWrite', function (Node $node) { |
|
62 | + $this->getWatcher()->postWrite($node); |
|
63 | + }); |
|
64 | 64 | |
65 | - \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback'); |
|
66 | - } |
|
67 | - } |
|
65 | + \OC_Hook::connect('\OCP\Versions', 'rollback', $this->getWatcher(), 'versionRollback'); |
|
66 | + } |
|
67 | + } |
|
68 | 68 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | |
72 | 72 | if ($response_type !== 'code') { |
73 | 73 | //Fail |
74 | - $url = $client->getRedirectUri() . '?error=unsupported_response_type&state=' . $state; |
|
74 | + $url = $client->getRedirectUri().'?error=unsupported_response_type&state='.$state; |
|
75 | 75 | return new RedirectResponse($url); |
76 | 76 | } |
77 | 77 |
@@ -39,72 +39,72 @@ |
||
39 | 39 | use OCP\IURLGenerator; |
40 | 40 | |
41 | 41 | class LoginRedirectorController extends Controller { |
42 | - /** @var IURLGenerator */ |
|
43 | - private $urlGenerator; |
|
44 | - /** @var ClientMapper */ |
|
45 | - private $clientMapper; |
|
46 | - /** @var ISession */ |
|
47 | - private $session; |
|
48 | - /** @var IL10N */ |
|
49 | - private $l; |
|
42 | + /** @var IURLGenerator */ |
|
43 | + private $urlGenerator; |
|
44 | + /** @var ClientMapper */ |
|
45 | + private $clientMapper; |
|
46 | + /** @var ISession */ |
|
47 | + private $session; |
|
48 | + /** @var IL10N */ |
|
49 | + private $l; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @param string $appName |
|
53 | - * @param IRequest $request |
|
54 | - * @param IURLGenerator $urlGenerator |
|
55 | - * @param ClientMapper $clientMapper |
|
56 | - * @param ISession $session |
|
57 | - * @param IL10N $l |
|
58 | - */ |
|
59 | - public function __construct(string $appName, |
|
60 | - IRequest $request, |
|
61 | - IURLGenerator $urlGenerator, |
|
62 | - ClientMapper $clientMapper, |
|
63 | - ISession $session, |
|
64 | - IL10N $l) { |
|
65 | - parent::__construct($appName, $request); |
|
66 | - $this->urlGenerator = $urlGenerator; |
|
67 | - $this->clientMapper = $clientMapper; |
|
68 | - $this->session = $session; |
|
69 | - $this->l = $l; |
|
70 | - } |
|
51 | + /** |
|
52 | + * @param string $appName |
|
53 | + * @param IRequest $request |
|
54 | + * @param IURLGenerator $urlGenerator |
|
55 | + * @param ClientMapper $clientMapper |
|
56 | + * @param ISession $session |
|
57 | + * @param IL10N $l |
|
58 | + */ |
|
59 | + public function __construct(string $appName, |
|
60 | + IRequest $request, |
|
61 | + IURLGenerator $urlGenerator, |
|
62 | + ClientMapper $clientMapper, |
|
63 | + ISession $session, |
|
64 | + IL10N $l) { |
|
65 | + parent::__construct($appName, $request); |
|
66 | + $this->urlGenerator = $urlGenerator; |
|
67 | + $this->clientMapper = $clientMapper; |
|
68 | + $this->session = $session; |
|
69 | + $this->l = $l; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @PublicPage |
|
74 | - * @NoCSRFRequired |
|
75 | - * @UseSession |
|
76 | - * |
|
77 | - * @param string $client_id |
|
78 | - * @param string $state |
|
79 | - * @param string $response_type |
|
80 | - * @return Response |
|
81 | - */ |
|
82 | - public function authorize($client_id, |
|
83 | - $state, |
|
84 | - $response_type): Response { |
|
85 | - try { |
|
86 | - $client = $this->clientMapper->getByIdentifier($client_id); |
|
87 | - } catch (ClientNotFoundException $e) { |
|
88 | - $params = [ |
|
89 | - 'content' => $this->l->t('Your client is not authorized to connect. Please inform the administrator of your client.'), |
|
90 | - ]; |
|
91 | - return new TemplateResponse('core', '404', $params, 'guest'); |
|
92 | - } |
|
72 | + /** |
|
73 | + * @PublicPage |
|
74 | + * @NoCSRFRequired |
|
75 | + * @UseSession |
|
76 | + * |
|
77 | + * @param string $client_id |
|
78 | + * @param string $state |
|
79 | + * @param string $response_type |
|
80 | + * @return Response |
|
81 | + */ |
|
82 | + public function authorize($client_id, |
|
83 | + $state, |
|
84 | + $response_type): Response { |
|
85 | + try { |
|
86 | + $client = $this->clientMapper->getByIdentifier($client_id); |
|
87 | + } catch (ClientNotFoundException $e) { |
|
88 | + $params = [ |
|
89 | + 'content' => $this->l->t('Your client is not authorized to connect. Please inform the administrator of your client.'), |
|
90 | + ]; |
|
91 | + return new TemplateResponse('core', '404', $params, 'guest'); |
|
92 | + } |
|
93 | 93 | |
94 | - if ($response_type !== 'code') { |
|
95 | - //Fail |
|
96 | - $url = $client->getRedirectUri() . '?error=unsupported_response_type&state=' . $state; |
|
97 | - return new RedirectResponse($url); |
|
98 | - } |
|
94 | + if ($response_type !== 'code') { |
|
95 | + //Fail |
|
96 | + $url = $client->getRedirectUri() . '?error=unsupported_response_type&state=' . $state; |
|
97 | + return new RedirectResponse($url); |
|
98 | + } |
|
99 | 99 | |
100 | - $this->session->set('oauth.state', $state); |
|
100 | + $this->session->set('oauth.state', $state); |
|
101 | 101 | |
102 | - $targetUrl = $this->urlGenerator->linkToRouteAbsolute( |
|
103 | - 'core.ClientFlowLogin.showAuthPickerPage', |
|
104 | - [ |
|
105 | - 'clientIdentifier' => $client->getClientIdentifier(), |
|
106 | - ] |
|
107 | - ); |
|
108 | - return new RedirectResponse($targetUrl); |
|
109 | - } |
|
102 | + $targetUrl = $this->urlGenerator->linkToRouteAbsolute( |
|
103 | + 'core.ClientFlowLogin.showAuthPickerPage', |
|
104 | + [ |
|
105 | + 'clientIdentifier' => $client->getClientIdentifier(), |
|
106 | + ] |
|
107 | + ); |
|
108 | + return new RedirectResponse($targetUrl); |
|
109 | + } |
|
110 | 110 | } |
@@ -25,10 +25,10 @@ |
||
25 | 25 | use OCP\IL10N; |
26 | 26 | |
27 | 27 | class KerberosAuth extends AuthMechanism { |
28 | - public function __construct(IL10N $l) { |
|
29 | - $this |
|
30 | - ->setIdentifier('smb::kerberos') |
|
31 | - ->setScheme(self::SCHEME_SMB) |
|
32 | - ->setText($l->t('Kerberos ticket')); |
|
33 | - } |
|
28 | + public function __construct(IL10N $l) { |
|
29 | + $this |
|
30 | + ->setIdentifier('smb::kerberos') |
|
31 | + ->setScheme(self::SCHEME_SMB) |
|
32 | + ->setText($l->t('Kerberos ticket')); |
|
33 | + } |
|
34 | 34 | } |
@@ -129,7 +129,7 @@ |
||
129 | 129 | $data = $result->fetchAll(); |
130 | 130 | $result->closeCursor(); |
131 | 131 | |
132 | - $entities = array_map(function ($row) { |
|
132 | + $entities = array_map(function($row) { |
|
133 | 133 | return PublicKeyToken::fromRow($row); |
134 | 134 | }, $data); |
135 | 135 |
@@ -36,224 +36,224 @@ |
||
36 | 36 | * @template-extends QBMapper<PublicKeyToken> |
37 | 37 | */ |
38 | 38 | class PublicKeyTokenMapper extends QBMapper { |
39 | - public function __construct(IDBConnection $db) { |
|
40 | - parent::__construct($db, 'authtoken'); |
|
41 | - } |
|
39 | + public function __construct(IDBConnection $db) { |
|
40 | + parent::__construct($db, 'authtoken'); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Invalidate (delete) a given token |
|
45 | - * |
|
46 | - * @param string $token |
|
47 | - */ |
|
48 | - public function invalidate(string $token) { |
|
49 | - /* @var $qb IQueryBuilder */ |
|
50 | - $qb = $this->db->getQueryBuilder(); |
|
51 | - $qb->delete($this->tableName) |
|
52 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
53 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | - ->execute(); |
|
55 | - } |
|
43 | + /** |
|
44 | + * Invalidate (delete) a given token |
|
45 | + * |
|
46 | + * @param string $token |
|
47 | + */ |
|
48 | + public function invalidate(string $token) { |
|
49 | + /* @var $qb IQueryBuilder */ |
|
50 | + $qb = $this->db->getQueryBuilder(); |
|
51 | + $qb->delete($this->tableName) |
|
52 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
53 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
54 | + ->execute(); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param int $olderThan |
|
59 | - * @param int $remember |
|
60 | - */ |
|
61 | - public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | - /* @var $qb IQueryBuilder */ |
|
63 | - $qb = $this->db->getQueryBuilder(); |
|
64 | - $qb->delete($this->tableName) |
|
65 | - ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | - ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | - ->execute(); |
|
70 | - } |
|
57 | + /** |
|
58 | + * @param int $olderThan |
|
59 | + * @param int $remember |
|
60 | + */ |
|
61 | + public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) { |
|
62 | + /* @var $qb IQueryBuilder */ |
|
63 | + $qb = $this->db->getQueryBuilder(); |
|
64 | + $qb->delete($this->tableName) |
|
65 | + ->where($qb->expr()->lt('last_activity', $qb->createNamedParameter($olderThan, IQueryBuilder::PARAM_INT))) |
|
66 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN, IQueryBuilder::PARAM_INT))) |
|
67 | + ->andWhere($qb->expr()->eq('remember', $qb->createNamedParameter($remember, IQueryBuilder::PARAM_INT))) |
|
68 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
69 | + ->execute(); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get the user UID for the given token |
|
74 | - * |
|
75 | - * @throws DoesNotExistException |
|
76 | - */ |
|
77 | - public function getToken(string $token): PublicKeyToken { |
|
78 | - /* @var $qb IQueryBuilder */ |
|
79 | - $qb = $this->db->getQueryBuilder(); |
|
80 | - $result = $qb->select('*') |
|
81 | - ->from($this->tableName) |
|
82 | - ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
83 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
84 | - ->execute(); |
|
72 | + /** |
|
73 | + * Get the user UID for the given token |
|
74 | + * |
|
75 | + * @throws DoesNotExistException |
|
76 | + */ |
|
77 | + public function getToken(string $token): PublicKeyToken { |
|
78 | + /* @var $qb IQueryBuilder */ |
|
79 | + $qb = $this->db->getQueryBuilder(); |
|
80 | + $result = $qb->select('*') |
|
81 | + ->from($this->tableName) |
|
82 | + ->where($qb->expr()->eq('token', $qb->createNamedParameter($token))) |
|
83 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
84 | + ->execute(); |
|
85 | 85 | |
86 | - $data = $result->fetch(); |
|
87 | - $result->closeCursor(); |
|
88 | - if ($data === false) { |
|
89 | - throw new DoesNotExistException('token does not exist'); |
|
90 | - } |
|
91 | - return PublicKeyToken::fromRow($data); |
|
92 | - } |
|
86 | + $data = $result->fetch(); |
|
87 | + $result->closeCursor(); |
|
88 | + if ($data === false) { |
|
89 | + throw new DoesNotExistException('token does not exist'); |
|
90 | + } |
|
91 | + return PublicKeyToken::fromRow($data); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Get the token for $id |
|
96 | - * |
|
97 | - * @throws DoesNotExistException |
|
98 | - */ |
|
99 | - public function getTokenById(int $id): PublicKeyToken { |
|
100 | - /* @var $qb IQueryBuilder */ |
|
101 | - $qb = $this->db->getQueryBuilder(); |
|
102 | - $result = $qb->select('*') |
|
103 | - ->from($this->tableName) |
|
104 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
105 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
106 | - ->execute(); |
|
94 | + /** |
|
95 | + * Get the token for $id |
|
96 | + * |
|
97 | + * @throws DoesNotExistException |
|
98 | + */ |
|
99 | + public function getTokenById(int $id): PublicKeyToken { |
|
100 | + /* @var $qb IQueryBuilder */ |
|
101 | + $qb = $this->db->getQueryBuilder(); |
|
102 | + $result = $qb->select('*') |
|
103 | + ->from($this->tableName) |
|
104 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
105 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
106 | + ->execute(); |
|
107 | 107 | |
108 | - $data = $result->fetch(); |
|
109 | - $result->closeCursor(); |
|
110 | - if ($data === false) { |
|
111 | - throw new DoesNotExistException('token does not exist'); |
|
112 | - } |
|
113 | - return PublicKeyToken::fromRow($data); |
|
114 | - } |
|
108 | + $data = $result->fetch(); |
|
109 | + $result->closeCursor(); |
|
110 | + if ($data === false) { |
|
111 | + throw new DoesNotExistException('token does not exist'); |
|
112 | + } |
|
113 | + return PublicKeyToken::fromRow($data); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Get all tokens of a user |
|
118 | - * |
|
119 | - * The provider may limit the number of result rows in case of an abuse |
|
120 | - * where a high number of (session) tokens is generated |
|
121 | - * |
|
122 | - * @param string $uid |
|
123 | - * @return PublicKeyToken[] |
|
124 | - */ |
|
125 | - public function getTokenByUser(string $uid): array { |
|
126 | - /* @var $qb IQueryBuilder */ |
|
127 | - $qb = $this->db->getQueryBuilder(); |
|
128 | - $qb->select('*') |
|
129 | - ->from($this->tableName) |
|
130 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
131 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
132 | - ->setMaxResults(1000); |
|
133 | - $result = $qb->execute(); |
|
134 | - $data = $result->fetchAll(); |
|
135 | - $result->closeCursor(); |
|
116 | + /** |
|
117 | + * Get all tokens of a user |
|
118 | + * |
|
119 | + * The provider may limit the number of result rows in case of an abuse |
|
120 | + * where a high number of (session) tokens is generated |
|
121 | + * |
|
122 | + * @param string $uid |
|
123 | + * @return PublicKeyToken[] |
|
124 | + */ |
|
125 | + public function getTokenByUser(string $uid): array { |
|
126 | + /* @var $qb IQueryBuilder */ |
|
127 | + $qb = $this->db->getQueryBuilder(); |
|
128 | + $qb->select('*') |
|
129 | + ->from($this->tableName) |
|
130 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
131 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))) |
|
132 | + ->setMaxResults(1000); |
|
133 | + $result = $qb->execute(); |
|
134 | + $data = $result->fetchAll(); |
|
135 | + $result->closeCursor(); |
|
136 | 136 | |
137 | - $entities = array_map(function ($row) { |
|
138 | - return PublicKeyToken::fromRow($row); |
|
139 | - }, $data); |
|
137 | + $entities = array_map(function ($row) { |
|
138 | + return PublicKeyToken::fromRow($row); |
|
139 | + }, $data); |
|
140 | 140 | |
141 | - return $entities; |
|
142 | - } |
|
141 | + return $entities; |
|
142 | + } |
|
143 | 143 | |
144 | - public function deleteById(string $uid, int $id) { |
|
145 | - /* @var $qb IQueryBuilder */ |
|
146 | - $qb = $this->db->getQueryBuilder(); |
|
147 | - $qb->delete($this->tableName) |
|
148 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
149 | - ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
150 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
151 | - $qb->execute(); |
|
152 | - } |
|
144 | + public function deleteById(string $uid, int $id) { |
|
145 | + /* @var $qb IQueryBuilder */ |
|
146 | + $qb = $this->db->getQueryBuilder(); |
|
147 | + $qb->delete($this->tableName) |
|
148 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) |
|
149 | + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
150 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
151 | + $qb->execute(); |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
155 | - * delete all auth token which belong to a specific client if the client was deleted |
|
156 | - * |
|
157 | - * @param string $name |
|
158 | - */ |
|
159 | - public function deleteByName(string $name) { |
|
160 | - $qb = $this->db->getQueryBuilder(); |
|
161 | - $qb->delete($this->tableName) |
|
162 | - ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
163 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
164 | - $qb->execute(); |
|
165 | - } |
|
154 | + /** |
|
155 | + * delete all auth token which belong to a specific client if the client was deleted |
|
156 | + * |
|
157 | + * @param string $name |
|
158 | + */ |
|
159 | + public function deleteByName(string $name) { |
|
160 | + $qb = $this->db->getQueryBuilder(); |
|
161 | + $qb->delete($this->tableName) |
|
162 | + ->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR)) |
|
163 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
164 | + $qb->execute(); |
|
165 | + } |
|
166 | 166 | |
167 | - public function deleteTempToken(PublicKeyToken $except) { |
|
168 | - $qb = $this->db->getQueryBuilder(); |
|
167 | + public function deleteTempToken(PublicKeyToken $except) { |
|
168 | + $qb = $this->db->getQueryBuilder(); |
|
169 | 169 | |
170 | - $qb->delete($this->tableName) |
|
171 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
172 | - ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
173 | - ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
174 | - ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
170 | + $qb->delete($this->tableName) |
|
171 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($except->getUID()))) |
|
172 | + ->andWhere($qb->expr()->eq('type', $qb->createNamedParameter(IToken::TEMPORARY_TOKEN))) |
|
173 | + ->andWhere($qb->expr()->neq('id', $qb->createNamedParameter($except->getId()))) |
|
174 | + ->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(PublicKeyToken::VERSION, IQueryBuilder::PARAM_INT))); |
|
175 | 175 | |
176 | - $qb->execute(); |
|
177 | - } |
|
176 | + $qb->execute(); |
|
177 | + } |
|
178 | 178 | |
179 | - public function hasExpiredTokens(string $uid): bool { |
|
180 | - $qb = $this->db->getQueryBuilder(); |
|
181 | - $qb->select('*') |
|
182 | - ->from($this->tableName) |
|
183 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
184 | - ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
185 | - ->setMaxResults(1); |
|
179 | + public function hasExpiredTokens(string $uid): bool { |
|
180 | + $qb = $this->db->getQueryBuilder(); |
|
181 | + $qb->select('*') |
|
182 | + ->from($this->tableName) |
|
183 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) |
|
184 | + ->andWhere($qb->expr()->eq('password_invalid', $qb->createNamedParameter(true), IQueryBuilder::PARAM_BOOL)) |
|
185 | + ->setMaxResults(1); |
|
186 | 186 | |
187 | - $cursor = $qb->execute(); |
|
188 | - $data = $cursor->fetchAll(); |
|
189 | - $cursor->closeCursor(); |
|
187 | + $cursor = $qb->execute(); |
|
188 | + $data = $cursor->fetchAll(); |
|
189 | + $cursor->closeCursor(); |
|
190 | 190 | |
191 | - return count($data) === 1; |
|
192 | - } |
|
191 | + return count($data) === 1; |
|
192 | + } |
|
193 | 193 | |
194 | - /** |
|
195 | - * Update the last activity timestamp |
|
196 | - * |
|
197 | - * In highly concurrent setups it can happen that two parallel processes |
|
198 | - * trigger the update at (nearly) the same time. In that special case it's |
|
199 | - * not necessary to hit the database with two actual updates. Therefore the |
|
200 | - * target last activity is included in the WHERE clause with a few seconds |
|
201 | - * of tolerance. |
|
202 | - * |
|
203 | - * Example: |
|
204 | - * - process 1 (P1) reads the token at timestamp 1500 |
|
205 | - * - process 1 (P2) reads the token at timestamp 1501 |
|
206 | - * - activity update interval is 100 |
|
207 | - * |
|
208 | - * This means |
|
209 | - * |
|
210 | - * - P1 will see a last_activity smaller than the current time and update |
|
211 | - * the token row |
|
212 | - * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
213 | - * and the comparison on last_activity won't be truthy. This means no rows |
|
214 | - * need to be updated a second time |
|
215 | - * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
216 | - * but the comparison on last_activity will still not be truthy and the |
|
217 | - * token row is not updated a second time |
|
218 | - * |
|
219 | - * @param IToken $token |
|
220 | - * @param int $now |
|
221 | - */ |
|
222 | - public function updateActivity(IToken $token, int $now): void { |
|
223 | - $qb = $this->db->getQueryBuilder(); |
|
224 | - $update = $qb->update($this->getTableName()) |
|
225 | - ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
226 | - ->where( |
|
227 | - $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
228 | - $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
229 | - ); |
|
230 | - $update->executeStatement(); |
|
231 | - } |
|
194 | + /** |
|
195 | + * Update the last activity timestamp |
|
196 | + * |
|
197 | + * In highly concurrent setups it can happen that two parallel processes |
|
198 | + * trigger the update at (nearly) the same time. In that special case it's |
|
199 | + * not necessary to hit the database with two actual updates. Therefore the |
|
200 | + * target last activity is included in the WHERE clause with a few seconds |
|
201 | + * of tolerance. |
|
202 | + * |
|
203 | + * Example: |
|
204 | + * - process 1 (P1) reads the token at timestamp 1500 |
|
205 | + * - process 1 (P2) reads the token at timestamp 1501 |
|
206 | + * - activity update interval is 100 |
|
207 | + * |
|
208 | + * This means |
|
209 | + * |
|
210 | + * - P1 will see a last_activity smaller than the current time and update |
|
211 | + * the token row |
|
212 | + * - If P2 reads after P1 had written, it will see 1600 as last activity |
|
213 | + * and the comparison on last_activity won't be truthy. This means no rows |
|
214 | + * need to be updated a second time |
|
215 | + * - If P2 reads before P1 had written, it will see 1501 as last activity, |
|
216 | + * but the comparison on last_activity will still not be truthy and the |
|
217 | + * token row is not updated a second time |
|
218 | + * |
|
219 | + * @param IToken $token |
|
220 | + * @param int $now |
|
221 | + */ |
|
222 | + public function updateActivity(IToken $token, int $now): void { |
|
223 | + $qb = $this->db->getQueryBuilder(); |
|
224 | + $update = $qb->update($this->getTableName()) |
|
225 | + ->set('last_activity', $qb->createNamedParameter($now, IQueryBuilder::PARAM_INT)) |
|
226 | + ->where( |
|
227 | + $qb->expr()->eq('id', $qb->createNamedParameter($token->getId(), IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT), |
|
228 | + $qb->expr()->lt('last_activity', $qb->createNamedParameter($now - 15, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT) |
|
229 | + ); |
|
230 | + $update->executeStatement(); |
|
231 | + } |
|
232 | 232 | |
233 | - public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
234 | - $qb = $this->db->getQueryBuilder(); |
|
235 | - $update = $qb->update($this->getTableName()) |
|
236 | - ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
237 | - ->where( |
|
238 | - $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
239 | - ); |
|
240 | - $update->executeStatement(); |
|
241 | - } |
|
233 | + public function updateHashesForUser(string $userId, string $passwordHash): void { |
|
234 | + $qb = $this->db->getQueryBuilder(); |
|
235 | + $update = $qb->update($this->getTableName()) |
|
236 | + ->set('password_hash', $qb->createNamedParameter($passwordHash)) |
|
237 | + ->where( |
|
238 | + $qb->expr()->eq('uid', $qb->createNamedParameter($userId)) |
|
239 | + ); |
|
240 | + $update->executeStatement(); |
|
241 | + } |
|
242 | 242 | |
243 | - public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
244 | - $qb = $this->db->getQueryBuilder(); |
|
245 | - $qb->select('*') |
|
246 | - ->from($this->getTableName()) |
|
247 | - ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
248 | - ->setMaxResults(1) |
|
249 | - ->orderBy('id'); |
|
250 | - $result = $qb->executeQuery(); |
|
243 | + public function getFirstTokenForUser(string $userId): ?PublicKeyToken { |
|
244 | + $qb = $this->db->getQueryBuilder(); |
|
245 | + $qb->select('*') |
|
246 | + ->from($this->getTableName()) |
|
247 | + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($userId))) |
|
248 | + ->setMaxResults(1) |
|
249 | + ->orderBy('id'); |
|
250 | + $result = $qb->executeQuery(); |
|
251 | 251 | |
252 | - $data = $result->fetch(); |
|
253 | - $result->closeCursor(); |
|
254 | - if ($data === false) { |
|
255 | - return null; |
|
256 | - } |
|
257 | - return PublicKeyToken::fromRow($data); |
|
258 | - } |
|
252 | + $data = $result->fetch(); |
|
253 | + $result->closeCursor(); |
|
254 | + if ($data === false) { |
|
255 | + return null; |
|
256 | + } |
|
257 | + return PublicKeyToken::fromRow($data); |
|
258 | + } |
|
259 | 259 | } |
@@ -36,7 +36,7 @@ |
||
36 | 36 | $l = \OC::$server->getL10N('federation'); |
37 | 37 | $this->parameterList = $missingParameters; |
38 | 38 | $parameterList = implode(',', $missingParameters); |
39 | - $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
39 | + $message = 'Parameters missing in order to complete the request. Missing Parameters: '.$parameterList; |
|
40 | 40 | $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
41 | 41 | parent::__construct($message, $hint); |
42 | 42 | } |
@@ -32,45 +32,45 @@ |
||
32 | 32 | * @since 14.0.0 |
33 | 33 | */ |
34 | 34 | class BadRequestException extends HintException { |
35 | - private $parameterList; |
|
35 | + private $parameterList; |
|
36 | 36 | |
37 | - /** |
|
38 | - * BadRequestException constructor. |
|
39 | - * |
|
40 | - * @since 14.0.0 |
|
41 | - * |
|
42 | - * @param array $missingParameters |
|
43 | - */ |
|
44 | - public function __construct(array $missingParameters) { |
|
45 | - $l = \OC::$server->getL10N('federation'); |
|
46 | - $this->parameterList = $missingParameters; |
|
47 | - $parameterList = implode(',', $missingParameters); |
|
48 | - $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
49 | - $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
|
50 | - parent::__construct($message, $hint); |
|
51 | - } |
|
37 | + /** |
|
38 | + * BadRequestException constructor. |
|
39 | + * |
|
40 | + * @since 14.0.0 |
|
41 | + * |
|
42 | + * @param array $missingParameters |
|
43 | + */ |
|
44 | + public function __construct(array $missingParameters) { |
|
45 | + $l = \OC::$server->getL10N('federation'); |
|
46 | + $this->parameterList = $missingParameters; |
|
47 | + $parameterList = implode(',', $missingParameters); |
|
48 | + $message = 'Parameters missing in order to complete the request. Missing Parameters: ' . $parameterList; |
|
49 | + $hint = $l->t('Parameters missing in order to complete the request. Missing Parameters: "%s"', [$parameterList]); |
|
50 | + parent::__construct($message, $hint); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * get array with the return message as defined in the OCM API |
|
55 | - * |
|
56 | - * @since 14.0.0 |
|
57 | - * |
|
58 | - * @return array |
|
59 | - */ |
|
60 | - public function getReturnMessage() { |
|
61 | - $result = [ |
|
62 | - 'message' => 'RESOURCE_NOT_FOUND', |
|
63 | - 'validationErrors' => [ |
|
64 | - ] |
|
65 | - ]; |
|
53 | + /** |
|
54 | + * get array with the return message as defined in the OCM API |
|
55 | + * |
|
56 | + * @since 14.0.0 |
|
57 | + * |
|
58 | + * @return array |
|
59 | + */ |
|
60 | + public function getReturnMessage() { |
|
61 | + $result = [ |
|
62 | + 'message' => 'RESOURCE_NOT_FOUND', |
|
63 | + 'validationErrors' => [ |
|
64 | + ] |
|
65 | + ]; |
|
66 | 66 | |
67 | - foreach ($this->parameterList as $missingParameter) { |
|
68 | - $result['validationErrors'] = [ |
|
69 | - 'name' => $missingParameter, |
|
70 | - 'message' => 'NOT_FOUND' |
|
71 | - ]; |
|
72 | - } |
|
67 | + foreach ($this->parameterList as $missingParameter) { |
|
68 | + $result['validationErrors'] = [ |
|
69 | + 'name' => $missingParameter, |
|
70 | + 'message' => 'NOT_FOUND' |
|
71 | + ]; |
|
72 | + } |
|
73 | 73 | |
74 | - return $result; |
|
75 | - } |
|
74 | + return $result; |
|
75 | + } |
|
76 | 76 | } |