diff --git a/lib/Federation/CloudFederationProviderTalk.php b/lib/Federation/CloudFederationProviderTalk.php index f36722f1adc..256a11b6902 100644 --- a/lib/Federation/CloudFederationProviderTalk.php +++ b/lib/Federation/CloudFederationProviderTalk.php @@ -9,6 +9,7 @@ namespace OCA\Talk\Federation; use Exception; +use NCU\Federation\ISignedCloudFederationProvider; use OCA\FederatedFileSharing\AddressHandler; use OCA\Talk\AppInfo\Application; use OCA\Talk\CachePrefix; @@ -36,6 +37,7 @@ use OCA\Talk\Service\ProxyCacheMessageService; use OCA\Talk\Service\RoomService; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Http; use OCP\AppFramework\Services\IAppConfig; use OCP\AppFramework\Utility\ITimeFactory; @@ -59,7 +61,7 @@ use Psr\Log\LoggerInterface; use SensitiveParameter; -class CloudFederationProviderTalk implements ICloudFederationProvider { +class CloudFederationProviderTalk implements ICloudFederationProvider, ISignedCloudFederationProvider { protected ?ICache $proxyCacheMessages; public function __construct( @@ -639,8 +641,25 @@ public function getSupportedShareTypes(): array { * @param string $token * @return string|array */ - public function getFederationIdFromToken(string $token): string|array { - $invite = $this->invitationMapper->getByAccessToken($token); - return [$invite->getLocalCloudId(), $invite->getInviterCloudId()]; + public function getFederationIdsFromSharedSecret( + #[SensitiveParameter] + string $sharedSecret, + array $payload, + ): array { + try { + $invite = $this->invitationMapper->getByRemoteServerOnlyWithAccessToken($payload['remoteServerUrl'], $sharedSecret); + return [$invite->getLocalCloudId(), $invite->getInviterCloudId()]; + } catch (DoesNotExistException) { + } + + try { + $attendee = $this->attendeeMapper->getByAccessToken($sharedSecret); + if (str_ends_with($attendee->getActorId(), $payload['remoteServerUrl'])) { + return [$attendee->getActorId()]; + } + } catch (DoesNotExistException|MultipleObjectsReturnedException) { + } + + return []; } } diff --git a/lib/Model/AttendeeMapper.php b/lib/Model/AttendeeMapper.php index b3e73c5c582..4d46e928007 100644 --- a/lib/Model/AttendeeMapper.php +++ b/lib/Model/AttendeeMapper.php @@ -53,6 +53,19 @@ public function getById(int $id): Attendee { return $this->findEntity($query); } + /** + * @throws DoesNotExistException + * @throws MultipleObjectsReturnedException + */ + public function getByAccessToken(string $accessToken): Attendee { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->from($this->getTableName()) + ->where($query->expr()->eq('access_token', $query->createNamedParameter($accessToken))); + + return $this->findEntity($query); + } + /** * @throws DoesNotExistException * @throws MultipleObjectsReturnedException diff --git a/lib/Model/InvitationMapper.php b/lib/Model/InvitationMapper.php index 130ddd9d32b..7221a8842de 100644 --- a/lib/Model/InvitationMapper.php +++ b/lib/Model/InvitationMapper.php @@ -10,6 +10,7 @@ use OCA\Talk\Room; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\QBMapper; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; @@ -48,7 +49,8 @@ public function getInvitationById(int $id): Invitation { * @throws DoesNotExistException * @internal Does not check user relation */ - public function getByAccessToken( + public function getByRemoteServerOnlyWithAccessToken( + string $remoteServerUrl, #[SensitiveParameter] string $accessToken, ): Invitation { @@ -56,7 +58,8 @@ public function getByAccessToken( $qb->select('*') ->from($this->getTableName()) - ->where($qb->expr()->eq('access_token', $qb->createNamedParameter($accessToken))); + ->where($qb->expr()->eq('remote_server_url', $qb->createNamedParameter($remoteServerUrl))) + ->andWhere($qb->expr()->eq('access_token', $qb->createNamedParameter($accessToken))); return $this->findEntity($qb); } diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index b3031a6c16a..eaba79ac968 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -1,6 +1,9 @@ - + + + + @@ -26,6 +29,17 @@ request->server]]> + + + + + + + + talkProvider]]> + + +