mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
refactor: Update Wopi::checkFileInfo()
so it can authenticate users from access token.
This commit is contained in:
parent
a2df3c8144
commit
fb8b8b354f
@ -14,6 +14,8 @@ use ChampsLibres\WopiLib\Contract\Service\WopiInterface;
|
|||||||
use loophp\psr17\Psr17Interface;
|
use loophp\psr17\Psr17Interface;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
|
||||||
|
use Symfony\Component\Security\Core\User\UserProviderInterface;
|
||||||
|
|
||||||
final class ChillWopi implements WopiInterface
|
final class ChillWopi implements WopiInterface
|
||||||
{
|
{
|
||||||
@ -21,15 +23,19 @@ final class ChillWopi implements WopiInterface
|
|||||||
|
|
||||||
private Psr17Interface $psr17;
|
private Psr17Interface $psr17;
|
||||||
|
|
||||||
|
private UserProviderInterface $userProvider;
|
||||||
|
|
||||||
private WopiInterface $wopi;
|
private WopiInterface $wopi;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DocumentManagerInterface $documentManager,
|
DocumentManagerInterface $documentManager,
|
||||||
Psr17Interface $psr17,
|
Psr17Interface $psr17,
|
||||||
|
UserProviderInterface $userProvider,
|
||||||
WopiInterface $wopi
|
WopiInterface $wopi
|
||||||
) {
|
) {
|
||||||
$this->documentManager = $documentManager;
|
$this->documentManager = $documentManager;
|
||||||
$this->psr17 = $psr17;
|
$this->psr17 = $psr17;
|
||||||
|
$this->userProvider = $userProvider;
|
||||||
$this->wopi = $wopi;
|
$this->wopi = $wopi;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +44,52 @@ final class ChillWopi implements WopiInterface
|
|||||||
?string $accessToken,
|
?string $accessToken,
|
||||||
RequestInterface $request
|
RequestInterface $request
|
||||||
): ResponseInterface {
|
): ResponseInterface {
|
||||||
|
try {
|
||||||
|
$user = $this->userProvider->loadUserByUsername($accessToken);
|
||||||
|
} catch (UsernameNotFoundException $e) {
|
||||||
|
return $this
|
||||||
|
->psr17
|
||||||
|
->createResponse(401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @ TODO : Replace this with a call to decorated object once authentication is done.
|
||||||
|
$document = $this->documentManager->findByDocumentId($fileId);
|
||||||
|
$userIdentifier = $user->getUsername();
|
||||||
|
$userCacheKey = sprintf('wopi_putUserInfo_%s', $userIdentifier);
|
||||||
|
|
||||||
|
return $this
|
||||||
|
->psr17
|
||||||
|
->createResponse()
|
||||||
|
->withHeader('Content-Type', 'application/json')
|
||||||
|
->withBody($this->psr17->createStream((string) json_encode(
|
||||||
|
[
|
||||||
|
'BaseFileName' => $this->documentManager->getBasename($document),
|
||||||
|
'OwnerId' => 'Symfony',
|
||||||
|
'Size' => $this->documentManager->getSize($document),
|
||||||
|
'UserId' => $userIdentifier,
|
||||||
|
'ReadOnly' => false,
|
||||||
|
'UserCanAttend' => true,
|
||||||
|
'UserCanPresent' => true,
|
||||||
|
'UserCanRename' => true,
|
||||||
|
'UserCanWrite' => true,
|
||||||
|
'UserCanNotWriteRelative' => false,
|
||||||
|
'SupportsUserInfo' => true,
|
||||||
|
'SupportsDeleteFile' => true,
|
||||||
|
'SupportsLocks' => true,
|
||||||
|
'SupportsGetLock' => true,
|
||||||
|
'SupportsExtendedLockLength' => true,
|
||||||
|
'UserFriendlyName' => $userIdentifier,
|
||||||
|
'SupportsUpdate' => true,
|
||||||
|
'SupportsRename' => true,
|
||||||
|
'DisablePrint' => false,
|
||||||
|
'AllowExternalMarketplace' => true,
|
||||||
|
'SupportedShareUrlTypes' => [
|
||||||
|
'ReadOnly',
|
||||||
|
],
|
||||||
|
'SHA256' => $this->documentManager->getSha256($document),
|
||||||
|
'UserInfo' => (string) $this->cache->getItem($userCacheKey)->get(),
|
||||||
|
]
|
||||||
|
)));
|
||||||
$response = $this->wopi->checkFileInfo($fileId, $accessToken, $request);
|
$response = $this->wopi->checkFileInfo($fileId, $accessToken, $request);
|
||||||
$document = $this->documentManager->findByDocumentId($fileId);
|
$document = $this->documentManager->findByDocumentId($fileId);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user