Completed
Pull Request — master (#3829)
by Maxence
12:57
created
apps/federatedfilesharing/lib/BackgroundJob/RetryJob.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -42,107 +42,107 @@
 block discarded – undo
42 42
  */
43 43
 class RetryJob extends Job {
44 44
 
45
-	/** @var  bool */
46
-	private $retainJob = true;
47
-
48
-	/** @var Notifications */
49
-	private $notifications;
50
-
51
-	/** @var int max number of attempts to send the request */
52
-	private $maxTry = 20;
53
-
54
-	/** @var int how much time should be between two tries (10 minutes) */
55
-	private $interval = 600;
56
-
57
-	/**
58
-	 * UnShare constructor.
59
-	 *
60
-	 * @param Notifications $notifications
61
-	 */
62
-	public function __construct(Notifications $notifications = null) {
63
-		if ($notifications) {
64
-			$this->notifications = $notifications;
65
-		} else {
66
-			$addressHandler = new AddressHandler(
67
-				\OC::$server->getURLGenerator(),
68
-				\OC::$server->getL10N('federatedfilesharing'),
69
-				\OC::$server->getCloudIdManager()
70
-			);
71
-			$discoveryManager = new DiscoveryManager(
72
-				\OC::$server->getMemCacheFactory(),
73
-				\OC::$server->getHTTPClientService()
74
-			);
75
-			$this->notifications = new Notifications(
76
-				$addressHandler,
77
-				\OC::$server->getHTTPClientService(),
78
-				$discoveryManager,
79
-				\OC::$server->getJobList()
80
-			);
81
-		}
82
-
83
-	}
84
-
85
-	/**
86
-	 * run the job, then remove it from the jobList
87
-	 *
88
-	 * @param JobList $jobList
89
-	 * @param ILogger $logger
90
-	 */
91
-	public function execute($jobList, ILogger $logger = null) {
92
-
93
-		if ($this->shouldRun($this->argument)) {
94
-			parent::execute($jobList, $logger);
95
-			$jobList->remove($this, $this->argument);
96
-			if ($this->retainJob) {
97
-				$this->reAddJob($jobList, $this->argument);
98
-			}
99
-		}
100
-	}
101
-
102
-	protected function run($argument) {
103
-		$remote = $argument['remote'];
104
-		$remoteId = $argument['remoteId'];
105
-		$token = $argument['token'];
106
-		$action = $argument['action'];
107
-		$data = json_decode($argument['data'], true);
108
-		$try = (int)$argument['try'] + 1;
109
-
110
-		$result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try);
45
+    /** @var  bool */
46
+    private $retainJob = true;
47
+
48
+    /** @var Notifications */
49
+    private $notifications;
50
+
51
+    /** @var int max number of attempts to send the request */
52
+    private $maxTry = 20;
53
+
54
+    /** @var int how much time should be between two tries (10 minutes) */
55
+    private $interval = 600;
56
+
57
+    /**
58
+     * UnShare constructor.
59
+     *
60
+     * @param Notifications $notifications
61
+     */
62
+    public function __construct(Notifications $notifications = null) {
63
+        if ($notifications) {
64
+            $this->notifications = $notifications;
65
+        } else {
66
+            $addressHandler = new AddressHandler(
67
+                \OC::$server->getURLGenerator(),
68
+                \OC::$server->getL10N('federatedfilesharing'),
69
+                \OC::$server->getCloudIdManager()
70
+            );
71
+            $discoveryManager = new DiscoveryManager(
72
+                \OC::$server->getMemCacheFactory(),
73
+                \OC::$server->getHTTPClientService()
74
+            );
75
+            $this->notifications = new Notifications(
76
+                $addressHandler,
77
+                \OC::$server->getHTTPClientService(),
78
+                $discoveryManager,
79
+                \OC::$server->getJobList()
80
+            );
81
+        }
82
+
83
+    }
84
+
85
+    /**
86
+     * run the job, then remove it from the jobList
87
+     *
88
+     * @param JobList $jobList
89
+     * @param ILogger $logger
90
+     */
91
+    public function execute($jobList, ILogger $logger = null) {
92
+
93
+        if ($this->shouldRun($this->argument)) {
94
+            parent::execute($jobList, $logger);
95
+            $jobList->remove($this, $this->argument);
96
+            if ($this->retainJob) {
97
+                $this->reAddJob($jobList, $this->argument);
98
+            }
99
+        }
100
+    }
101
+
102
+    protected function run($argument) {
103
+        $remote = $argument['remote'];
104
+        $remoteId = $argument['remoteId'];
105
+        $token = $argument['token'];
106
+        $action = $argument['action'];
107
+        $data = json_decode($argument['data'], true);
108
+        $try = (int)$argument['try'] + 1;
109
+
110
+        $result = $this->notifications->sendUpdateToRemote($remote, $remoteId, $token, $action, $data, $try);
111 111
 		
112
-		if ($result === true || $try > $this->maxTry) {
113
-			$this->retainJob = false;
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * re-add background job with new arguments
119
-	 *
120
-	 * @param IJobList $jobList
121
-	 * @param array $argument
122
-	 */
123
-	protected function reAddJob(IJobList $jobList, array $argument) {
124
-		$jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
125
-			[
126
-				'remote' => $argument['remote'],
127
-				'remoteId' => $argument['remoteId'],
128
-				'token' => $argument['token'],
129
-				'data' => $argument['data'],
130
-				'action' => $argument['action'],
131
-				'try' => (int)$argument['try'] + 1,
132
-				'lastRun' => time()
133
-			]
134
-		);
135
-	}
136
-
137
-	/**
138
-	 * test if it is time for the next run
139
-	 *
140
-	 * @param array $argument
141
-	 * @return bool
142
-	 */
143
-	protected function shouldRun(array $argument) {
144
-		$lastRun = (int)$argument['lastRun'];
145
-		return ((time() - $lastRun) > $this->interval);
146
-	}
112
+        if ($result === true || $try > $this->maxTry) {
113
+            $this->retainJob = false;
114
+        }
115
+    }
116
+
117
+    /**
118
+     * re-add background job with new arguments
119
+     *
120
+     * @param IJobList $jobList
121
+     * @param array $argument
122
+     */
123
+    protected function reAddJob(IJobList $jobList, array $argument) {
124
+        $jobList->add('OCA\FederatedFileSharing\BackgroundJob\RetryJob',
125
+            [
126
+                'remote' => $argument['remote'],
127
+                'remoteId' => $argument['remoteId'],
128
+                'token' => $argument['token'],
129
+                'data' => $argument['data'],
130
+                'action' => $argument['action'],
131
+                'try' => (int)$argument['try'] + 1,
132
+                'lastRun' => time()
133
+            ]
134
+        );
135
+    }
136
+
137
+    /**
138
+     * test if it is time for the next run
139
+     *
140
+     * @param array $argument
141
+     * @return bool
142
+     */
143
+    protected function shouldRun(array $argument) {
144
+        $lastRun = (int)$argument['lastRun'];
145
+        return ((time() - $lastRun) > $this->interval);
146
+    }
147 147
 
148 148
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/Settings/Admin.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,42 +29,42 @@
 block discarded – undo
29 29
 
30 30
 class Admin implements ISettings {
31 31
 
32
-	/** @var FederatedShareProvider */
33
-	private $fedShareProvider;
32
+    /** @var FederatedShareProvider */
33
+    private $fedShareProvider;
34 34
 
35
-	public function __construct(FederatedShareProvider $fedShareProvider) {
36
-		$this->fedShareProvider = $fedShareProvider;
37
-	}
35
+    public function __construct(FederatedShareProvider $fedShareProvider) {
36
+        $this->fedShareProvider = $fedShareProvider;
37
+    }
38 38
 
39
-	/**
40
-	 * @return TemplateResponse
41
-	 */
42
-	public function getForm() {
43
-		$parameters = [
44
-			'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
45
-			'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
46
-			'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
47
-		];
39
+    /**
40
+     * @return TemplateResponse
41
+     */
42
+    public function getForm() {
43
+        $parameters = [
44
+            'outgoingServer2serverShareEnabled' => $this->fedShareProvider->isOutgoingServer2serverShareEnabled(),
45
+            'incomingServer2serverShareEnabled' => $this->fedShareProvider->isIncomingServer2serverShareEnabled(),
46
+            'lookupServerEnabled' => $this->fedShareProvider->isLookupServerQueriesEnabled(),
47
+        ];
48 48
 
49
-		return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
50
-	}
49
+        return new TemplateResponse('federatedfilesharing', 'settings-admin', $parameters, '');
50
+    }
51 51
 
52
-	/**
53
-	 * @return string the section ID, e.g. 'sharing'
54
-	 */
55
-	public function getSection() {
56
-		return 'sharing';
57
-	}
52
+    /**
53
+     * @return string the section ID, e.g. 'sharing'
54
+     */
55
+    public function getSection() {
56
+        return 'sharing';
57
+    }
58 58
 
59
-	/**
60
-	 * @return int whether the form should be rather on the top or bottom of
61
-	 * the admin section. The forms are arranged in ascending order of the
62
-	 * priority values. It is required to return a value between 0 and 100.
63
-	 *
64
-	 * E.g.: 70
65
-	 */
66
-	public function getPriority() {
67
-		return 20;
68
-	}
59
+    /**
60
+     * @return int whether the form should be rather on the top or bottom of
61
+     * the admin section. The forms are arranged in ascending order of the
62
+     * priority values. It is required to return a value between 0 and 100.
63
+     *
64
+     * E.g.: 70
65
+     */
66
+    public function getPriority() {
67
+        return 20;
68
+    }
69 69
 
70 70
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/TokenHandler.php 1 patch
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -33,30 +33,30 @@
 block discarded – undo
33 33
  */
34 34
 class TokenHandler {
35 35
 
36
-	const TOKEN_LENGTH = 15;
37
-
38
-	/** @var ISecureRandom */
39
-	private $secureRandom;
40
-
41
-	/**
42
-	 * TokenHandler constructor.
43
-	 *
44
-	 * @param ISecureRandom $secureRandom
45
-	 */
46
-	public function __construct(ISecureRandom $secureRandom) {
47
-		$this->secureRandom = $secureRandom;
48
-	}
49
-
50
-	/**
51
-	 * generate to token used to authenticate federated shares
52
-	 *
53
-	 * @return string
54
-	 */
55
-	public function generateToken() {
56
-		$token = $this->secureRandom->generate(
57
-			self::TOKEN_LENGTH,
58
-			ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
59
-		return $token;
60
-	}
36
+    const TOKEN_LENGTH = 15;
37
+
38
+    /** @var ISecureRandom */
39
+    private $secureRandom;
40
+
41
+    /**
42
+     * TokenHandler constructor.
43
+     *
44
+     * @param ISecureRandom $secureRandom
45
+     */
46
+    public function __construct(ISecureRandom $secureRandom) {
47
+        $this->secureRandom = $secureRandom;
48
+    }
49
+
50
+    /**
51
+     * generate to token used to authenticate federated shares
52
+     *
53
+     * @return string
54
+     */
55
+    public function generateToken() {
56
+        $token = $this->secureRandom->generate(
57
+            self::TOKEN_LENGTH,
58
+            ISecureRandom::CHAR_LOWER . ISecureRandom::CHAR_UPPER . ISecureRandom::CHAR_DIGITS);
59
+        return $token;
60
+    }
61 61
 
62 62
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/lib/AddressHandler.php 1 patch
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -33,122 +33,122 @@
 block discarded – undo
33 33
  */
34 34
 class AddressHandler {
35 35
 
36
-	/** @var IL10N */
37
-	private $l;
38
-
39
-	/** @var IURLGenerator */
40
-	private $urlGenerator;
41
-
42
-	/** @var ICloudIdManager */
43
-	private $cloudIdManager;
44
-
45
-	/**
46
-	 * AddressHandler constructor.
47
-	 *
48
-	 * @param IURLGenerator $urlGenerator
49
-	 * @param IL10N $il10n
50
-	 * @param ICloudIdManager $cloudIdManager
51
-	 */
52
-	public function __construct(
53
-		IURLGenerator $urlGenerator,
54
-		IL10N $il10n,
55
-		ICloudIdManager $cloudIdManager
56
-	) {
57
-		$this->l = $il10n;
58
-		$this->urlGenerator = $urlGenerator;
59
-		$this->cloudIdManager = $cloudIdManager;
60
-	}
61
-
62
-	/**
63
-	 * split user and remote from federated cloud id
64
-	 *
65
-	 * @param string $address federated share address
66
-	 * @return array [user, remoteURL]
67
-	 * @throws HintException
68
-	 */
69
-	public function splitUserRemote($address) {
70
-		try {
71
-			$cloudId = $this->cloudIdManager->resolveCloudId($address);
72
-			return [$cloudId->getUser(), $cloudId->getRemote()];
73
-		} catch (\InvalidArgumentException $e) {
74
-			$hint = $this->l->t('Invalid Federated Cloud ID');
75
-			throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e);
76
-		}
77
-	}
78
-
79
-	/**
80
-	 * generate remote URL part of federated ID
81
-	 *
82
-	 * @return string url of the current server
83
-	 */
84
-	public function generateRemoteURL() {
85
-		$url = $this->urlGenerator->getAbsoluteURL('/');
86
-		return $url;
87
-	}
88
-
89
-	/**
90
-	 * check if two federated cloud IDs refer to the same user
91
-	 *
92
-	 * @param string $user1
93
-	 * @param string $server1
94
-	 * @param string $user2
95
-	 * @param string $server2
96
-	 * @return bool true if both users and servers are the same
97
-	 */
98
-	public function compareAddresses($user1, $server1, $user2, $server2) {
99
-		$normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1));
100
-		$normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2));
101
-
102
-		if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) {
103
-			// FIXME this should be a method in the user management instead
104
-			\OCP\Util::emitHook(
105
-				'\OCA\Files_Sharing\API\Server2Server',
106
-				'preLoginNameUsedAsUserName',
107
-				array('uid' => &$user1)
108
-			);
109
-			\OCP\Util::emitHook(
110
-				'\OCA\Files_Sharing\API\Server2Server',
111
-				'preLoginNameUsedAsUserName',
112
-				array('uid' => &$user2)
113
-			);
114
-
115
-			if ($user1 === $user2) {
116
-				return true;
117
-			}
118
-		}
119
-
120
-		return false;
121
-	}
122
-
123
-	/**
124
-	 * remove protocol from URL
125
-	 *
126
-	 * @param string $url
127
-	 * @return string
128
-	 */
129
-	public function removeProtocolFromUrl($url) {
130
-		if (strpos($url, 'https://') === 0) {
131
-			return substr($url, strlen('https://'));
132
-		} else if (strpos($url, 'http://') === 0) {
133
-			return substr($url, strlen('http://'));
134
-		}
135
-
136
-		return $url;
137
-	}
138
-
139
-	/**
140
-	 * check if the url contain the protocol (http or https)
141
-	 *
142
-	 * @param string $url
143
-	 * @return bool
144
-	 */
145
-	public function urlContainProtocol($url) {
146
-		if (strpos($url, 'https://') === 0 ||
147
-			strpos($url, 'http://') === 0) {
148
-
149
-			return true;
150
-		}
151
-
152
-		return false;
153
-	}
36
+    /** @var IL10N */
37
+    private $l;
38
+
39
+    /** @var IURLGenerator */
40
+    private $urlGenerator;
41
+
42
+    /** @var ICloudIdManager */
43
+    private $cloudIdManager;
44
+
45
+    /**
46
+     * AddressHandler constructor.
47
+     *
48
+     * @param IURLGenerator $urlGenerator
49
+     * @param IL10N $il10n
50
+     * @param ICloudIdManager $cloudIdManager
51
+     */
52
+    public function __construct(
53
+        IURLGenerator $urlGenerator,
54
+        IL10N $il10n,
55
+        ICloudIdManager $cloudIdManager
56
+    ) {
57
+        $this->l = $il10n;
58
+        $this->urlGenerator = $urlGenerator;
59
+        $this->cloudIdManager = $cloudIdManager;
60
+    }
61
+
62
+    /**
63
+     * split user and remote from federated cloud id
64
+     *
65
+     * @param string $address federated share address
66
+     * @return array [user, remoteURL]
67
+     * @throws HintException
68
+     */
69
+    public function splitUserRemote($address) {
70
+        try {
71
+            $cloudId = $this->cloudIdManager->resolveCloudId($address);
72
+            return [$cloudId->getUser(), $cloudId->getRemote()];
73
+        } catch (\InvalidArgumentException $e) {
74
+            $hint = $this->l->t('Invalid Federated Cloud ID');
75
+            throw new HintException('Invalid Federated Cloud ID', $hint, 0, $e);
76
+        }
77
+    }
78
+
79
+    /**
80
+     * generate remote URL part of federated ID
81
+     *
82
+     * @return string url of the current server
83
+     */
84
+    public function generateRemoteURL() {
85
+        $url = $this->urlGenerator->getAbsoluteURL('/');
86
+        return $url;
87
+    }
88
+
89
+    /**
90
+     * check if two federated cloud IDs refer to the same user
91
+     *
92
+     * @param string $user1
93
+     * @param string $server1
94
+     * @param string $user2
95
+     * @param string $server2
96
+     * @return bool true if both users and servers are the same
97
+     */
98
+    public function compareAddresses($user1, $server1, $user2, $server2) {
99
+        $normalizedServer1 = strtolower($this->removeProtocolFromUrl($server1));
100
+        $normalizedServer2 = strtolower($this->removeProtocolFromUrl($server2));
101
+
102
+        if (rtrim($normalizedServer1, '/') === rtrim($normalizedServer2, '/')) {
103
+            // FIXME this should be a method in the user management instead
104
+            \OCP\Util::emitHook(
105
+                '\OCA\Files_Sharing\API\Server2Server',
106
+                'preLoginNameUsedAsUserName',
107
+                array('uid' => &$user1)
108
+            );
109
+            \OCP\Util::emitHook(
110
+                '\OCA\Files_Sharing\API\Server2Server',
111
+                'preLoginNameUsedAsUserName',
112
+                array('uid' => &$user2)
113
+            );
114
+
115
+            if ($user1 === $user2) {
116
+                return true;
117
+            }
118
+        }
119
+
120
+        return false;
121
+    }
122
+
123
+    /**
124
+     * remove protocol from URL
125
+     *
126
+     * @param string $url
127
+     * @return string
128
+     */
129
+    public function removeProtocolFromUrl($url) {
130
+        if (strpos($url, 'https://') === 0) {
131
+            return substr($url, strlen('https://'));
132
+        } else if (strpos($url, 'http://') === 0) {
133
+            return substr($url, strlen('http://'));
134
+        }
135
+
136
+        return $url;
137
+    }
138
+
139
+    /**
140
+     * check if the url contain the protocol (http or https)
141
+     *
142
+     * @param string $url
143
+     * @return bool
144
+     */
145
+    public function urlContainProtocol($url) {
146
+        if (strpos($url, 'https://') === 0 ||
147
+            strpos($url, 'http://') === 0) {
148
+
149
+            return true;
150
+        }
151
+
152
+        return false;
153
+    }
154 154
 }
Please login to merge, or discard this patch.
apps/federatedfilesharing/appinfo/routes.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -23,17 +23,17 @@
 block discarded – undo
23 23
  */
24 24
 
25 25
 return [
26
-	'routes' => [
27
-		['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
-		['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
-	],
30
-	'ocs' => [
31
-		['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
-		['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
-		['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
-		['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
-		['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
-		['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
-		['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
-	],
26
+    'routes' => [
27
+        ['name' => 'MountPublicLink#createFederatedShare', 'url' => '/createFederatedShare', 'verb' => 'POST'],
28
+        ['name' => 'MountPublicLink#askForFederatedShare', 'url' => '/askForFederatedShare', 'verb' => 'POST'],
29
+    ],
30
+    'ocs' => [
31
+        ['root' => '/cloud', 'name' => 'RequestHandler#createShare', 'url' => '/shares', 'verb' => 'POST'],
32
+        ['root' => '/cloud', 'name' => 'RequestHandler#reShare', 'url' => '/shares/{id}/reshare', 'verb' => 'POST'],
33
+        ['root' => '/cloud', 'name' => 'RequestHandler#updatePermissions', 'url' => '/shares/{id}/permissions', 'verb' => 'POST'],
34
+        ['root' => '/cloud', 'name' => 'RequestHandler#acceptShare', 'url' => '/shares/{id}/accept', 'verb' => 'POST'],
35
+        ['root' => '/cloud', 'name' => 'RequestHandler#declineShare', 'url' => '/shares/{id}/decline', 'verb' => 'POST'],
36
+        ['root' => '/cloud', 'name' => 'RequestHandler#unshare', 'url' => '/shares/{id}/unshare', 'verb' => 'POST'],
37
+        ['root' => '/cloud', 'name' => 'RequestHandler#revoke', 'url' => '/shares/{id}/revoke', 'verb' => 'POST'],
38
+    ],
39 39
 ];
Please login to merge, or discard this patch.
apps/federation/templates/settings-admin.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,10 +28,10 @@
 block discarded – undo
28 28
 				<?php if((int)$trustedServer['status'] === TrustedServers::STATUS_OK) { ?>
29 29
 					<span class="status success"></span>
30 30
 				<?php
31
-				} elseif(
32
-					(int)$trustedServer['status'] === TrustedServers::STATUS_PENDING ||
33
-					(int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED
34
-				) { ?>
31
+                } elseif(
32
+                    (int)$trustedServer['status'] === TrustedServers::STATUS_PENDING ||
33
+                    (int)$trustedServer['status'] === TrustedServers::STATUS_ACCESS_REVOKED
34
+                ) { ?>
35 35
 					<span class="status indeterminate"></span>
36 36
 				<?php } else {?>
37 37
 					<span class="status error"></span>
Please login to merge, or discard this patch.
apps/federation/lib/DAV/FedAuth.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
 
30 30
 class FedAuth extends AbstractBasic {
31 31
 
32
-	/** @var DbHandler */
33
-	private $db;
32
+    /** @var DbHandler */
33
+    private $db;
34 34
 
35
-	/**
36
-	 * FedAuth constructor.
37
-	 *
38
-	 * @param DbHandler $db
39
-	 */
40
-	public function __construct(DbHandler $db) {
41
-		$this->db = $db;
42
-		$this->principalPrefix = 'principals/system/';
35
+    /**
36
+     * FedAuth constructor.
37
+     *
38
+     * @param DbHandler $db
39
+     */
40
+    public function __construct(DbHandler $db) {
41
+        $this->db = $db;
42
+        $this->principalPrefix = 'principals/system/';
43 43
 
44
-		// setup realm
45
-		$defaults = new \OCP\Defaults();
46
-		$this->realm = $defaults->getName();
47
-	}
44
+        // setup realm
45
+        $defaults = new \OCP\Defaults();
46
+        $this->realm = $defaults->getName();
47
+    }
48 48
 
49
-	/**
50
-	 * Validates a username and password
51
-	 *
52
-	 * This method should return true or false depending on if login
53
-	 * succeeded.
54
-	 *
55
-	 * @param string $username
56
-	 * @param string $password
57
-	 * @return bool
58
-	 */
59
-	protected function validateUserPass($username, $password) {
60
-		return $this->db->auth($username, $password);
61
-	}
49
+    /**
50
+     * Validates a username and password
51
+     *
52
+     * This method should return true or false depending on if login
53
+     * succeeded.
54
+     *
55
+     * @param string $username
56
+     * @param string $password
57
+     * @return bool
58
+     */
59
+    protected function validateUserPass($username, $password) {
60
+        return $this->db->auth($username, $password);
61
+    }
62 62
 
63
-	/**
64
-	 * @inheritdoc
65
-	 */
66
-	function challenge(RequestInterface $request, ResponseInterface $response) {
67
-	}
63
+    /**
64
+     * @inheritdoc
65
+     */
66
+    function challenge(RequestInterface $request, ResponseInterface $response) {
67
+    }
68 68
 }
Please login to merge, or discard this patch.
apps/federation/lib/Controller/SettingsController.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -34,91 +34,91 @@
 block discarded – undo
34 34
 
35 35
 class SettingsController extends Controller {
36 36
 
37
-	/** @var IL10N */
38
-	private $l;
39
-
40
-	/** @var  TrustedServers */
41
-	private $trustedServers;
42
-
43
-	/**
44
-	 * @param string $AppName
45
-	 * @param IRequest $request
46
-	 * @param IL10N $l10n
47
-	 * @param TrustedServers $trustedServers
48
-	 */
49
-	public function __construct($AppName,
50
-								IRequest $request,
51
-								IL10N $l10n,
52
-								TrustedServers $trustedServers
53
-	) {
54
-		parent::__construct($AppName, $request);
55
-		$this->l = $l10n;
56
-		$this->trustedServers = $trustedServers;
57
-	}
58
-
59
-
60
-	/**
61
-	 * add server to the list of trusted ownClouds
62
-	 *
63
-	 * @param string $url
64
-	 * @return DataResponse
65
-	 * @throws HintException
66
-	 */
67
-	public function addServer($url) {
68
-		$this->checkServer($url);
69
-		$id = $this->trustedServers->addServer($url);
70
-
71
-		return new DataResponse(
72
-			[
73
-				'url' => $url,
74
-				'id' => $id,
75
-				'message' => (string) $this->l->t('Added to the list of trusted servers')
76
-			]
77
-		);
78
-	}
79
-
80
-	/**
81
-	 * add server to the list of trusted ownClouds
82
-	 *
83
-	 * @param int $id
84
-	 * @return DataResponse
85
-	 */
86
-	public function removeServer($id) {
87
-		$this->trustedServers->removeServer($id);
88
-		return new DataResponse();
89
-	}
90
-
91
-	/**
92
-	 * enable/disable to automatically add servers to the list of trusted servers
93
-	 * once a federated share was created and accepted successfully
94
-	 *
95
-	 * @param bool $autoAddServers
96
-	 */
97
-	public function autoAddServers($autoAddServers) {
98
-		$this->trustedServers->setAutoAddServers($autoAddServers);
99
-	}
100
-
101
-	/**
102
-	 * check if the server should be added to the list of trusted servers or not
103
-	 *
104
-	 * @param string $url
105
-	 * @return bool
106
-	 * @throws HintException
107
-	 */
108
-	protected function checkServer($url) {
109
-		if ($this->trustedServers->isTrustedServer($url) === true) {
110
-			$message = 'Server is already in the list of trusted servers.';
111
-			$hint = $this->l->t('Server is already in the list of trusted servers.');
112
-			throw new HintException($message, $hint);
113
-		}
114
-
115
-		if ($this->trustedServers->isOwnCloudServer($url) === false) {
116
-			$message = 'No server to federate with found';
117
-			$hint = $this->l->t('No server to federate with found');
118
-			throw new HintException($message, $hint);
119
-		}
120
-
121
-		return true;
122
-	}
37
+    /** @var IL10N */
38
+    private $l;
39
+
40
+    /** @var  TrustedServers */
41
+    private $trustedServers;
42
+
43
+    /**
44
+     * @param string $AppName
45
+     * @param IRequest $request
46
+     * @param IL10N $l10n
47
+     * @param TrustedServers $trustedServers
48
+     */
49
+    public function __construct($AppName,
50
+                                IRequest $request,
51
+                                IL10N $l10n,
52
+                                TrustedServers $trustedServers
53
+    ) {
54
+        parent::__construct($AppName, $request);
55
+        $this->l = $l10n;
56
+        $this->trustedServers = $trustedServers;
57
+    }
58
+
59
+
60
+    /**
61
+     * add server to the list of trusted ownClouds
62
+     *
63
+     * @param string $url
64
+     * @return DataResponse
65
+     * @throws HintException
66
+     */
67
+    public function addServer($url) {
68
+        $this->checkServer($url);
69
+        $id = $this->trustedServers->addServer($url);
70
+
71
+        return new DataResponse(
72
+            [
73
+                'url' => $url,
74
+                'id' => $id,
75
+                'message' => (string) $this->l->t('Added to the list of trusted servers')
76
+            ]
77
+        );
78
+    }
79
+
80
+    /**
81
+     * add server to the list of trusted ownClouds
82
+     *
83
+     * @param int $id
84
+     * @return DataResponse
85
+     */
86
+    public function removeServer($id) {
87
+        $this->trustedServers->removeServer($id);
88
+        return new DataResponse();
89
+    }
90
+
91
+    /**
92
+     * enable/disable to automatically add servers to the list of trusted servers
93
+     * once a federated share was created and accepted successfully
94
+     *
95
+     * @param bool $autoAddServers
96
+     */
97
+    public function autoAddServers($autoAddServers) {
98
+        $this->trustedServers->setAutoAddServers($autoAddServers);
99
+    }
100
+
101
+    /**
102
+     * check if the server should be added to the list of trusted servers or not
103
+     *
104
+     * @param string $url
105
+     * @return bool
106
+     * @throws HintException
107
+     */
108
+    protected function checkServer($url) {
109
+        if ($this->trustedServers->isTrustedServer($url) === true) {
110
+            $message = 'Server is already in the list of trusted servers.';
111
+            $hint = $this->l->t('Server is already in the list of trusted servers.');
112
+            throw new HintException($message, $hint);
113
+        }
114
+
115
+        if ($this->trustedServers->isOwnCloudServer($url) === false) {
116
+            $message = 'No server to federate with found';
117
+            $hint = $this->l->t('No server to federate with found');
118
+            throw new HintException($message, $hint);
119
+        }
120
+
121
+        return true;
122
+    }
123 123
 
124 124
 }
Please login to merge, or discard this patch.
apps/federation/lib/Controller/OCSAuthAPIController.php 1 patch
Indentation   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -46,138 +46,138 @@
 block discarded – undo
46 46
  */
47 47
 class OCSAuthAPIController extends OCSController{
48 48
 
49
-	/** @var ISecureRandom  */
50
-	private $secureRandom;
51
-
52
-	/** @var IJobList */
53
-	private $jobList;
54
-
55
-	/** @var TrustedServers */
56
-	private $trustedServers;
57
-
58
-	/** @var DbHandler */
59
-	private $dbHandler;
60
-
61
-	/** @var ILogger */
62
-	private $logger;
63
-
64
-	/**
65
-	 * OCSAuthAPI constructor.
66
-	 *
67
-	 * @param string $appName
68
-	 * @param IRequest $request
69
-	 * @param ISecureRandom $secureRandom
70
-	 * @param IJobList $jobList
71
-	 * @param TrustedServers $trustedServers
72
-	 * @param DbHandler $dbHandler
73
-	 * @param ILogger $logger
74
-	 */
75
-	public function __construct(
76
-		$appName,
77
-		IRequest $request,
78
-		ISecureRandom $secureRandom,
79
-		IJobList $jobList,
80
-		TrustedServers $trustedServers,
81
-		DbHandler $dbHandler,
82
-		ILogger $logger
83
-	) {
84
-		parent::__construct($appName, $request);
85
-
86
-		$this->secureRandom = $secureRandom;
87
-		$this->jobList = $jobList;
88
-		$this->trustedServers = $trustedServers;
89
-		$this->dbHandler = $dbHandler;
90
-		$this->logger = $logger;
91
-	}
92
-
93
-	/**
94
-	 * @NoCSRFRequired
95
-	 * @PublicPage
96
-	 *
97
-	 * request received to ask remote server for a shared secret
98
-	 *
99
-	 * @param string $url
100
-	 * @param string $token
101
-	 * @return Http\DataResponse
102
-	 * @throws OCSForbiddenException
103
-	 */
104
-	public function requestSharedSecret($url, $token) {
105
-		if ($this->trustedServers->isTrustedServer($url) === false) {
106
-			$this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
107
-			throw new OCSForbiddenException();
108
-		}
109
-
110
-		// if both server initiated the exchange of the shared secret the greater
111
-		// token wins
112
-		$localToken = $this->dbHandler->getToken($url);
113
-		if (strcmp($localToken, $token) > 0) {
114
-			$this->logger->info(
115
-				'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.',
116
-				['app' => 'federation']
117
-			);
118
-			throw new OCSForbiddenException();
119
-		}
120
-
121
-		// we ask for the shared secret so we no longer have to ask the other server
122
-		// to request the shared secret
123
-		$this->jobList->remove('OCA\Federation\BackgroundJob\RequestSharedSecret',
124
-			[
125
-				'url' => $url,
126
-				'token' => $localToken
127
-			]
128
-		);
129
-
130
-		$this->jobList->add(
131
-			'OCA\Federation\BackgroundJob\GetSharedSecret',
132
-			[
133
-				'url' => $url,
134
-				'token' => $token,
135
-			]
136
-		);
137
-
138
-		return new Http\DataResponse();
139
-	}
140
-
141
-	/**
142
-	 * @NoCSRFRequired
143
-	 * @PublicPage
144
-	 *
145
-	 * create shared secret and return it
146
-	 *
147
-	 * @param string $url
148
-	 * @param string $token
149
-	 * @return Http\DataResponse
150
-	 * @throws OCSForbiddenException
151
-	 */
152
-	public function getSharedSecret($url, $token) {
153
-		if ($this->trustedServers->isTrustedServer($url) === false) {
154
-			$this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']);
155
-			throw new OCSForbiddenException();
156
-		}
157
-
158
-		if ($this->isValidToken($url, $token) === false) {
159
-			$expectedToken = $this->dbHandler->getToken($url);
160
-			$this->logger->error(
161
-				'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret',
162
-				['app' => 'federation']
163
-			);
164
-			throw new OCSForbiddenException();
165
-		}
166
-
167
-		$sharedSecret = $this->secureRandom->generate(32);
168
-
169
-		$this->trustedServers->addSharedSecret($url, $sharedSecret);
170
-		// reset token after the exchange of the shared secret was successful
171
-		$this->dbHandler->addToken($url, '');
172
-
173
-		return new Http\DataResponse([
174
-			'sharedSecret' => $sharedSecret
175
-		]);
176
-	}
177
-
178
-	protected function isValidToken($url, $token) {
179
-		$storedToken = $this->dbHandler->getToken($url);
180
-		return hash_equals($storedToken, $token);
181
-	}
49
+    /** @var ISecureRandom  */
50
+    private $secureRandom;
51
+
52
+    /** @var IJobList */
53
+    private $jobList;
54
+
55
+    /** @var TrustedServers */
56
+    private $trustedServers;
57
+
58
+    /** @var DbHandler */
59
+    private $dbHandler;
60
+
61
+    /** @var ILogger */
62
+    private $logger;
63
+
64
+    /**
65
+     * OCSAuthAPI constructor.
66
+     *
67
+     * @param string $appName
68
+     * @param IRequest $request
69
+     * @param ISecureRandom $secureRandom
70
+     * @param IJobList $jobList
71
+     * @param TrustedServers $trustedServers
72
+     * @param DbHandler $dbHandler
73
+     * @param ILogger $logger
74
+     */
75
+    public function __construct(
76
+        $appName,
77
+        IRequest $request,
78
+        ISecureRandom $secureRandom,
79
+        IJobList $jobList,
80
+        TrustedServers $trustedServers,
81
+        DbHandler $dbHandler,
82
+        ILogger $logger
83
+    ) {
84
+        parent::__construct($appName, $request);
85
+
86
+        $this->secureRandom = $secureRandom;
87
+        $this->jobList = $jobList;
88
+        $this->trustedServers = $trustedServers;
89
+        $this->dbHandler = $dbHandler;
90
+        $this->logger = $logger;
91
+    }
92
+
93
+    /**
94
+     * @NoCSRFRequired
95
+     * @PublicPage
96
+     *
97
+     * request received to ask remote server for a shared secret
98
+     *
99
+     * @param string $url
100
+     * @param string $token
101
+     * @return Http\DataResponse
102
+     * @throws OCSForbiddenException
103
+     */
104
+    public function requestSharedSecret($url, $token) {
105
+        if ($this->trustedServers->isTrustedServer($url) === false) {
106
+            $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
107
+            throw new OCSForbiddenException();
108
+        }
109
+
110
+        // if both server initiated the exchange of the shared secret the greater
111
+        // token wins
112
+        $localToken = $this->dbHandler->getToken($url);
113
+        if (strcmp($localToken, $token) > 0) {
114
+            $this->logger->info(
115
+                'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.',
116
+                ['app' => 'federation']
117
+            );
118
+            throw new OCSForbiddenException();
119
+        }
120
+
121
+        // we ask for the shared secret so we no longer have to ask the other server
122
+        // to request the shared secret
123
+        $this->jobList->remove('OCA\Federation\BackgroundJob\RequestSharedSecret',
124
+            [
125
+                'url' => $url,
126
+                'token' => $localToken
127
+            ]
128
+        );
129
+
130
+        $this->jobList->add(
131
+            'OCA\Federation\BackgroundJob\GetSharedSecret',
132
+            [
133
+                'url' => $url,
134
+                'token' => $token,
135
+            ]
136
+        );
137
+
138
+        return new Http\DataResponse();
139
+    }
140
+
141
+    /**
142
+     * @NoCSRFRequired
143
+     * @PublicPage
144
+     *
145
+     * create shared secret and return it
146
+     *
147
+     * @param string $url
148
+     * @param string $token
149
+     * @return Http\DataResponse
150
+     * @throws OCSForbiddenException
151
+     */
152
+    public function getSharedSecret($url, $token) {
153
+        if ($this->trustedServers->isTrustedServer($url) === false) {
154
+            $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']);
155
+            throw new OCSForbiddenException();
156
+        }
157
+
158
+        if ($this->isValidToken($url, $token) === false) {
159
+            $expectedToken = $this->dbHandler->getToken($url);
160
+            $this->logger->error(
161
+                'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret',
162
+                ['app' => 'federation']
163
+            );
164
+            throw new OCSForbiddenException();
165
+        }
166
+
167
+        $sharedSecret = $this->secureRandom->generate(32);
168
+
169
+        $this->trustedServers->addSharedSecret($url, $sharedSecret);
170
+        // reset token after the exchange of the shared secret was successful
171
+        $this->dbHandler->addToken($url, '');
172
+
173
+        return new Http\DataResponse([
174
+            'sharedSecret' => $sharedSecret
175
+        ]);
176
+    }
177
+
178
+    protected function isValidToken($url, $token) {
179
+        $storedToken = $this->dbHandler->getToken($url);
180
+        return hash_equals($storedToken, $token);
181
+    }
182 182
 
183 183
 }
Please login to merge, or discard this patch.