use discovered end-point for trusted servers

Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
pull/3614/head
Bjoern Schiessle 8 years ago committed by Roeland Jago Douma
parent 45aee2e479
commit 930c507d89
No known key found for this signature in database
GPG Key ID: F941078878347C0C
  1. 21
      apps/federation/lib/BackgroundJob/GetSharedSecret.php
  2. 21
      apps/federation/lib/BackgroundJob/RequestSharedSecret.php

@ -37,6 +37,7 @@ use OCP\Http\Client\IClient;
use OCP\Http\Client\IResponse;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
/**
* Class GetSharedSecret
@ -62,13 +63,18 @@ class GetSharedSecret extends Job{
/** @var DbHandler */
private $dbHandler;
/** @var IDiscoveryService */
private $ocsDiscoveryService;
/** @var ILogger */
private $logger;
/** @var bool */
protected $retainJob = false;
private $endPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret?format=json';
private $format = '?format=json';
private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/shared-secret';
/**
* RequestSharedSecret constructor.
@ -79,6 +85,7 @@ class GetSharedSecret extends Job{
* @param TrustedServers $trustedServers
* @param ILogger $logger
* @param DbHandler $dbHandler
* @param IDiscoveryService $ocsDiscoveryService
*/
public function __construct(
IClient $httpClient = null,
@ -86,13 +93,15 @@ class GetSharedSecret extends Job{
IJobList $jobList = null,
TrustedServers $trustedServers = null,
ILogger $logger = null,
DbHandler $dbHandler = null
DbHandler $dbHandler = null,
IDiscoveryService $ocsDiscoveryService
) {
$this->logger = $logger ? $logger : \OC::$server->getLogger();
$this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient();
$this->jobList = $jobList ? $jobList : \OC::$server->getJobList();
$this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator();
$this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation'));
$this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService();
if ($trustedServers) {
$this->trustedServers = $trustedServers;
} else {
@ -142,10 +151,16 @@ class GetSharedSecret extends Job{
$source = rtrim($source, '/');
$token = $argument['token'];
$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
// make sure that we have a well formated url
$url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format;
$result = null;
try {
$result = $this->httpClient->get(
$target . $this->endPoint,
$url,
[
'query' =>
[

@ -37,6 +37,7 @@ use OCP\BackgroundJob\IJobList;
use OCP\Http\Client\IClient;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\OCS\IDiscoveryService;
/**
* Class RequestSharedSecret
@ -62,7 +63,8 @@ class RequestSharedSecret extends Job {
/** @var TrustedServers */
private $trustedServers;
private $endPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret?format=json';
/** @var IDiscoveryService */
private $ocsDiscoveryService;
/** @var ILogger */
private $logger;
@ -70,6 +72,10 @@ class RequestSharedSecret extends Job {
/** @var bool */
protected $retainJob = false;
private $format = '?format=json';
private $defaultEndPoint = '/ocs/v2.php/apps/federation/api/v1/request-shared-secret';
/**
* RequestSharedSecret constructor.
*
@ -78,19 +84,22 @@ class RequestSharedSecret extends Job {
* @param IJobList $jobList
* @param TrustedServers $trustedServers
* @param DbHandler $dbHandler
* @param IDiscoveryService $ocsDiscoveryService
*/
public function __construct(
IClient $httpClient = null,
IURLGenerator $urlGenerator = null,
IJobList $jobList = null,
TrustedServers $trustedServers = null,
DbHandler $dbHandler = null
DbHandler $dbHandler = null,
IDiscoveryService $ocsDiscoveryService
) {
$this->httpClient = $httpClient ? $httpClient : \OC::$server->getHTTPClientService()->newClient();
$this->jobList = $jobList ? $jobList : \OC::$server->getJobList();
$this->urlGenerator = $urlGenerator ? $urlGenerator : \OC::$server->getURLGenerator();
$this->dbHandler = $dbHandler ? $dbHandler : new DbHandler(\OC::$server->getDatabaseConnection(), \OC::$server->getL10N('federation'));
$this->logger = \OC::$server->getLogger();
$this->ocsDiscoveryService = $ocsDiscoveryService ? $ocsDiscoveryService : \OC::$server->getOCSDiscoveryService();
if ($trustedServers) {
$this->trustedServers = $trustedServers;
} else {
@ -142,9 +151,15 @@ class RequestSharedSecret extends Job {
$source = rtrim($source, '/');
$token = $argument['token'];
$endPoints = $this->ocsDiscoveryService->discover($target, 'FEDERATED_SHARING');
$endPoint = isset($endPoints['shared-secret']) ? $endPoints['shared-secret'] : $this->defaultEndPoint;
// make sure that we have a well formated url
$url = rtrim($target, '/') . '/' . trim($endPoint, '/') . $this->format;
try {
$result = $this->httpClient->post(
$target . $this->endPoint,
$url,
[
'body' => [
'url' => $source,

Loading…
Cancel
Save