Skip to content

Commit 674f944

Browse files
committed
Change Controllers to use the new DPOP trait.
1 parent 9d2f981 commit 674f944

5 files changed

Lines changed: 122 additions & 34 deletions

File tree

solid/lib/Controller/CalendarController.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace OCA\Solid\Controller;
33

4+
use OCA\Solid\DpopFactoryTrait;
45
use OCA\Solid\PlainResponse;
56

67
use OCP\AppFramework\Controller;
@@ -17,20 +18,33 @@
1718
use Pdsinterop\Solid\Resources\Server as ResourceServer;
1819

1920
class CalendarController extends Controller {
21+
use DpopFactoryTrait;
22+
2023
/* @var IURLGenerator */
2124
private $urlGenerator;
2225

2326
/* @var ISession */
2427
private $session;
2528

26-
public function __construct($AppName, IRequest $request, ISession $session, IUserManager $userManager, IURLGenerator $urlGenerator, $userId, IConfig $config, \OCA\Solid\Service\UserService $UserService)
27-
{
29+
public function __construct(
30+
$AppName,
31+
IRequest $request,
32+
ISession $session,
33+
IUserManager $userManager,
34+
IURLGenerator $urlGenerator,
35+
$userId,
36+
IConfig $config,
37+
\OCA\Solid\Service\UserService $UserService,
38+
IDBConnection $connection,
39+
) {
2840
parent::__construct($AppName, $request);
2941
require_once(__DIR__.'/../../vendor/autoload.php');
3042
$this->config = new \OCA\Solid\ServerConfig($config, $urlGenerator, $userManager);
3143
$this->request = $request;
3244
$this->urlGenerator = $urlGenerator;
3345
$this->session = $session;
46+
47+
$this->setJtiStorage($connection);
3448
}
3549

3650
private function getFileSystem($userId) {
@@ -116,7 +130,6 @@ public function handleRequest($userId, $path) {
116130

117131
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
118132
$this->WAC = new WAC($this->filesystem);
119-
$this->DPop = new DPop();
120133

121134
$request = $this->rawRequest;
122135
$baseUrl = $this->getCalendarUrl($userId);
@@ -125,10 +138,13 @@ public function handleRequest($userId, $path) {
125138
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
126139
$this->resourceServer->setPubSubUrl($pubsub);
127140

141+
$dpop = $this->getDpop();
142+
128143
try {
129-
$webId = $this->DPop->getWebId($request);
130-
} catch(\Exception $e) {
131-
$response = $this->resourceServer->getResponse()->withStatus(409, "Invalid token");
144+
$webId = $dpop->getWebId($request);
145+
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
146+
$response = $this->resourceServer->getResponse()
147+
->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
132148
return $this->respond($response);
133149
}
134150

solid/lib/Controller/ContactsController.php

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace OCA\Solid\Controller;
33

4+
use OCA\Solid\DpopFactoryTrait;
45
use OCA\Solid\PlainResponse;
56

67
use OCP\AppFramework\Controller;
@@ -17,20 +18,34 @@
1718
use Pdsinterop\Solid\Resources\Server as ResourceServer;
1819

1920
class ContactsController extends Controller {
21+
22+
use DpopFactoryTrait;
23+
2024
/* @var IURLGenerator */
2125
private $urlGenerator;
2226

2327
/* @var ISession */
2428
private $session;
2529

26-
public function __construct($AppName, IRequest $request, ISession $session, IUserManager $userManager, IURLGenerator $urlGenerator, $userId, IConfig $config, \OCA\Solid\Service\UserService $UserService)
27-
{
30+
public function __construct(
31+
$AppName,
32+
IRequest $request,
33+
ISession $session,
34+
IUserManager $userManager,
35+
IURLGenerator $urlGenerator,
36+
$userId,
37+
IConfig $config,
38+
\OCA\Solid\Service\UserService $UserService,
39+
IDBConnection $connection,
40+
) {
2841
parent::__construct($AppName, $request);
2942
require_once(__DIR__.'/../../vendor/autoload.php');
3043
$this->config = new \OCA\Solid\ServerConfig($config, $urlGenerator, $userManager);
3144
$this->request = $request;
3245
$this->urlGenerator = $urlGenerator;
3346
$this->session = $session;
47+
48+
$this->setJtiStorage($connection);
3449
}
3550

3651
private function getFileSystem($userId) {
@@ -115,8 +130,7 @@ public function handleRequest($userId, $path) {
115130
$this->filesystem = $this->getFileSystem($userId);
116131

117132
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
118-
$this->WAC = new WAC($this->filesystem);
119-
$this->DPop = new DPop();
133+
$this->WAC = new WAC($this->filesystem);
120134

121135
$request = $this->rawRequest;
122136
$baseUrl = $this->getContactsUrl($userId);
@@ -125,10 +139,13 @@ public function handleRequest($userId, $path) {
125139
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
126140
$this->resourceServer->setPubSubUrl($pubsub);
127141

142+
$dpop = $this->getDpop();
143+
128144
try {
129-
$webId = $this->DPop->getWebId($request);
130-
} catch(\Exception $e) {
131-
$response = $this->resourceServer->getResponse()->withStatus(409, "Invalid token");
145+
$webId = $dpop->getWebId($request);
146+
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
147+
$response = $this->resourceServer->getResponse()
148+
->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
132149
return $this->respond($response);
133150
}
134151

solid/lib/Controller/ProfileController.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace OCA\Solid\Controller;
33

4+
use OCA\Solid\DpopFactoryTrait;
45
use OCA\Solid\PlainResponse;
56

67
use OCP\AppFramework\Controller;
@@ -18,14 +19,26 @@
1819
use Pdsinterop\Solid\Resources\Server as ResourceServer;
1920

2021
class ProfileController extends Controller {
22+
use DpopFactoryTrait;
23+
2124
/* @var IURLGenerator */
2225
private $urlGenerator;
2326

2427
/* @var ISession */
2528
private $session;
2629

27-
public function __construct($AppName, IRequest $request, ISession $session, IManager $contactsManager, IUserManager $userManager, IURLGenerator $urlGenerator, $userId, IConfig $config, \OCA\Solid\Service\UserService $UserService)
28-
{
30+
public function __construct(
31+
$AppName,
32+
IRequest $request,
33+
ISession $session,
34+
IManager $contactsManager,
35+
IUserManager $userManager,
36+
IURLGenerator $urlGenerator,
37+
$userId,
38+
IConfig $config,
39+
\OCA\Solid\Service\UserService $UserService,
40+
IDBConnection $connection,
41+
) {
2942
parent::__construct($AppName, $request);
3043
require_once(__DIR__.'/../../vendor/autoload.php');
3144
$this->config = new \OCA\Solid\ServerConfig($config, $urlGenerator, $userManager);
@@ -34,6 +47,8 @@ public function __construct($AppName, IRequest $request, ISession $session, IMan
3447
$this->userManager = $userManager;
3548
$this->contactsManager = $contactsManager;
3649
$this->session = $session;
50+
51+
$this->setJtiStorage($connection);
3752
}
3853

3954
private function getFileSystem($userId) {
@@ -132,7 +147,6 @@ public function handleRequest($userId, $path) {
132147

133148
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
134149
$this->WAC = new WAC($this->filesystem);
135-
$this->DPop = new DPop();
136150

137151
$request = $this->rawRequest;
138152
$baseUrl = $this->getProfileUrl($userId);
@@ -141,11 +155,14 @@ public function handleRequest($userId, $path) {
141155
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
142156
$this->resourceServer->setPubSubUrl($pubsub);
143157

158+
$dpop = $this->getDpop();
159+
144160
if ($request->getHeaderLine("DPop")) {
145161
try {
146-
$webId = $this->DPop->getWebId($request);
147-
} catch(\Exception $e) {
148-
$response = $this->resourceServer->getResponse()->withStatus(409, "Invalid token");
162+
$webId = $dpop->getWebId($request);
163+
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
164+
$response = $this->resourceServer->getResponse()
165+
->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
149166
return $this->respond($response);
150167
}
151168
} else {

solid/lib/Controller/ServerController.php

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace OCA\Solid\Controller;
33

4+
use OCA\Solid\DpopFactoryTrait;
45
use OCA\Solid\ServerConfig;
56

67
use OCP\AppFramework\Controller;
@@ -19,6 +20,9 @@
1920
use Lcobucci\JWT\Signer\Rsa\Sha256;
2021

2122
class ServerController extends Controller {
23+
24+
use DpopFactoryTrait;
25+
2226
private $userId;
2327

2428
/* @var IUserManager */
@@ -42,8 +46,17 @@ class ServerController extends Controller {
4246
/* @var Pdsinterop\Solid\Auth\TokenGenerator */
4347
private $tokenGenerator;
4448

45-
public function __construct($AppName, IRequest $request, ISession $session, IUserManager $userManager, IURLGenerator $urlGenerator, $userId, IConfig $config, \OCA\Solid\Service\UserService $UserService)
46-
{
49+
public function __construct(
50+
$AppName,
51+
IRequest $request,
52+
ISession $session,
53+
IUserManager $userManager,
54+
IURLGenerator $urlGenerator,
55+
$userId,
56+
IConfig $config,
57+
\OCA\Solid\Service\UserService $UserService,
58+
IDBConnection $connection,
59+
) {
4760
parent::__construct($AppName, $request);
4861
require_once(__DIR__.'/../../vendor/autoload.php');
4962
$this->config = new \OCA\Solid\ServerConfig($config, $urlGenerator, $userManager);
@@ -53,9 +66,15 @@ public function __construct($AppName, IRequest $request, ISession $session, IUse
5366
$this->urlGenerator = $urlGenerator;
5467
$this->session = $session;
5568

69+
$this->setJtiStorage($connection);
70+
5671
$this->authServerConfig = $this->createAuthServerConfig();
5772
$this->authServerFactory = (new \Pdsinterop\Solid\Auth\Factory\AuthorizationServerFactory($this->authServerConfig))->create();
58-
$this->tokenGenerator = (new \Pdsinterop\Solid\Auth\TokenGenerator($this->authServerConfig));
73+
74+
$this->tokenGenerator = new \Pdsinterop\Solid\Auth\TokenGenerator(
75+
$this->authServerConfig,
76+
$this->getDpopValidFor()
77+
);
5978
}
6079

6180
private function getOpenIdEndpoints() {
@@ -239,12 +258,13 @@ public function token() {
239258

240259
$response = new \Laminas\Diactoros\Response();
241260

242-
$DPop = new DPop();
243-
$dpop = $request->getServerParams()['HTTP_DPOP'];
261+
$dpop = $this->getDpop();
262+
$httpDpop = $request->getServerParams()['HTTP_DPOP'];
263+
244264
try {
245-
$dpopKey = $DPop->getDPopKey($dpop, $request);
246-
} catch(\Exception $e) {
247-
$response = $response->withStatus(409, "Invalid token");
265+
$dpopKey = $dpop->getDPopKey($httpDpop, $request);
266+
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
267+
$response = $response->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
248268
return $this->respond($response);
249269
}
250270

solid/lib/Controller/StorageController.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace OCA\Solid\Controller;
33

4+
use OCA\Solid\DpopFactoryTrait;
45
use OCA\Solid\PlainResponse;
56

67
use OCP\AppFramework\Controller;
@@ -17,21 +18,36 @@
1718
use Pdsinterop\Solid\Resources\Server as ResourceServer;
1819

1920
class StorageController extends Controller {
21+
22+
use DpopFactoryTrait;
23+
2024
/* @var IURLGenerator */
2125
private $urlGenerator;
2226

2327
/* @var ISession */
2428
private $session;
25-
26-
public function __construct($AppName, IRootFolder $rootFolder, IRequest $request, ISession $session, IUserManager $userManager, IURLGenerator $urlGenerator, $userId, IConfig $config, \OCA\Solid\Service\UserService $UserService)
27-
{
29+
30+
public function __construct(
31+
$AppName,
32+
IRootFolder $rootFolder,
33+
IRequest $request,
34+
ISession $session,
35+
IUserManager $userManager,
36+
IURLGenerator $urlGenerator,
37+
$userId,
38+
IConfig $config,
39+
\OCA\Solid\Service\UserService $UserService,
40+
IDBConnection $connection,
41+
) {
2842
parent::__construct($AppName, $request);
2943
require_once(__DIR__.'/../../vendor/autoload.php');
3044
$this->config = new \OCA\Solid\ServerConfig($config, $urlGenerator, $userManager);
3145
$this->rootFolder = $rootFolder;
3246
$this->request = $request;
3347
$this->urlGenerator = $urlGenerator;
3448
$this->session = $session;
49+
50+
$this->setJtiStorage($connection);
3551
}
3652

3753
private function getFileSystem() {
@@ -275,7 +291,6 @@ public function handleRequest($userId, $path) {
275291

276292
$this->resourceServer = new ResourceServer($this->filesystem, $this->response);
277293
$this->WAC = new WAC($this->filesystem);
278-
$this->DPop = new DPop();
279294

280295
$request = $this->rawRequest;
281296
$baseUrl = $this->getStorageUrl($userId);
@@ -284,10 +299,13 @@ public function handleRequest($userId, $path) {
284299
$pubsub = getenv('PUBSUB_URL') ?: ("http://pubsub:8080/");
285300
$this->resourceServer->setPubSubUrl($pubsub);
286301

302+
$dpop = $this->getDpop();
303+
287304
try {
288-
$webId = $this->DPop->getWebId($request);
289-
} catch(\Exception $e) {
290-
$response = $this->resourceServer->getResponse()->withStatus(409, "Invalid token");
305+
$webId = $dpop->getWebId($request);
306+
} catch(\Pdsinterop\Solid\Auth\Exception\Exception $e) {
307+
$response = $this->resourceServer->getResponse()
308+
->withStatus(Http::STATUS_CONFLICT, "Invalid token " . $e->getMessage());
291309
return $this->respond($response);
292310
}
293311
$origin = $request->getHeaderLine("Origin");

0 commit comments

Comments
 (0)