Passed
Push — master ( 873501...d2df81 )
by Maxence
14:59 queued 12s
created
apps/dav/lib/Storage/PublicOwnerWrapper.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -29,27 +29,27 @@
 block discarded – undo
29 29
 
30 30
 class PublicOwnerWrapper extends Wrapper {
31 31
 
32
-	/** @var string */
33
-	private $owner;
34
-
35
-	/**
36
-	 * @param array $arguments ['storage' => $storage, 'owner' => $owner]
37
-	 *
38
-	 * $storage: The storage the permissions mask should be applied on
39
-	 * $owner: The owner to use in case no owner is found
40
-	 */
41
-	public function __construct($arguments) {
42
-		parent::__construct($arguments);
43
-		$this->owner = $arguments['owner'];
44
-	}
45
-
46
-	public function getOwner($path) {
47
-		$owner = parent::getOwner($path);
48
-
49
-		if ($owner === null || $owner === false) {
50
-			return $this->owner;
51
-		}
52
-
53
-		return $owner;
54
-	}
32
+    /** @var string */
33
+    private $owner;
34
+
35
+    /**
36
+     * @param array $arguments ['storage' => $storage, 'owner' => $owner]
37
+     *
38
+     * $storage: The storage the permissions mask should be applied on
39
+     * $owner: The owner to use in case no owner is found
40
+     */
41
+    public function __construct($arguments) {
42
+        parent::__construct($arguments);
43
+        $this->owner = $arguments['owner'];
44
+    }
45
+
46
+    public function getOwner($path) {
47
+        $owner = parent::getOwner($path);
48
+
49
+        if ($owner === null || $owner === false) {
50
+            return $this->owner;
51
+        }
52
+
53
+        return $owner;
54
+    }
55 55
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Services/IAppConfig.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -31,81 +31,81 @@
 block discarded – undo
31 31
  * @since 20.0.0
32 32
  */
33 33
 interface IAppConfig {
34
-	/**
35
-	 * Get all keys stored for this app
36
-	 *
37
-	 * @return string[] the keys stored for the app
38
-	 * @since 20.0.0
39
-	 */
40
-	public function getAppKeys(): array ;
34
+    /**
35
+     * Get all keys stored for this app
36
+     *
37
+     * @return string[] the keys stored for the app
38
+     * @since 20.0.0
39
+     */
40
+    public function getAppKeys(): array ;
41 41
 
42
-	/**
43
-	 * Writes a new app wide value
44
-	 *
45
-	 * @param string $key the key of the value, under which will be saved
46
-	 * @param string $value the value that should be stored
47
-	 * @return void
48
-	 * @since 20.0.0
49
-	 */
50
-	public function setAppValue(string $key, string $value): void;
42
+    /**
43
+     * Writes a new app wide value
44
+     *
45
+     * @param string $key the key of the value, under which will be saved
46
+     * @param string $value the value that should be stored
47
+     * @return void
48
+     * @since 20.0.0
49
+     */
50
+    public function setAppValue(string $key, string $value): void;
51 51
 
52
-	/**
53
-	 * Looks up an app wide defined value
54
-	 *
55
-	 * @param string $key the key of the value, under which it was saved
56
-	 * @param string $default the default value to be returned if the value isn't set
57
-	 * @return string the saved value
58
-	 * @since 20.0.0
59
-	 */
60
-	public function getAppValue(string $key, string $default = ''): string;
52
+    /**
53
+     * Looks up an app wide defined value
54
+     *
55
+     * @param string $key the key of the value, under which it was saved
56
+     * @param string $default the default value to be returned if the value isn't set
57
+     * @return string the saved value
58
+     * @since 20.0.0
59
+     */
60
+    public function getAppValue(string $key, string $default = ''): string;
61 61
 
62
-	/**
63
-	 * Delete an app wide defined value
64
-	 *
65
-	 * @param string $key the key of the value, under which it was saved
66
-	 * @return void
67
-	 * @since 20.0.0
68
-	 */
69
-	public function deleteAppValue(string $key): void;
62
+    /**
63
+     * Delete an app wide defined value
64
+     *
65
+     * @param string $key the key of the value, under which it was saved
66
+     * @return void
67
+     * @since 20.0.0
68
+     */
69
+    public function deleteAppValue(string $key): void;
70 70
 
71
-	/**
72
-	 * Removes all keys in appconfig belonging to the app
73
-	 *
74
-	 * @return void
75
-	 * @since 20.0.0
76
-	 */
77
-	public function deleteAppValues(): void;
71
+    /**
72
+     * Removes all keys in appconfig belonging to the app
73
+     *
74
+     * @return void
75
+     * @since 20.0.0
76
+     */
77
+    public function deleteAppValues(): void;
78 78
 
79
-	/**
80
-	 * Set a user defined value
81
-	 *
82
-	 * @param string $userId the userId of the user that we want to store the value under
83
-	 * @param string $key the key under which the value is being stored
84
-	 * @param string $value the value that you want to store
85
-	 * @param string $preCondition only update if the config value was previously the value passed as $preCondition
86
-	 * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
87
-	 * @throws \UnexpectedValueException when trying to store an unexpected value
88
-	 * @since 20.0.0
89
-	 */
90
-	public function setUserValue(string $userId, string $key, string $value, ?string $preCondition = null): void;
79
+    /**
80
+     * Set a user defined value
81
+     *
82
+     * @param string $userId the userId of the user that we want to store the value under
83
+     * @param string $key the key under which the value is being stored
84
+     * @param string $value the value that you want to store
85
+     * @param string $preCondition only update if the config value was previously the value passed as $preCondition
86
+     * @throws \OCP\PreConditionNotMetException if a precondition is specified and is not met
87
+     * @throws \UnexpectedValueException when trying to store an unexpected value
88
+     * @since 20.0.0
89
+     */
90
+    public function setUserValue(string $userId, string $key, string $value, ?string $preCondition = null): void;
91 91
 
92
-	/**
93
-	 * Shortcut for getting a user defined value
94
-	 *
95
-	 * @param string $userId the userId of the user that we want to store the value under
96
-	 * @param string $key the key under which the value is being stored
97
-	 * @param mixed $default the default value to be returned if the value isn't set
98
-	 * @return string
99
-	 * @since 20.0.0
100
-	 */
101
-	public function getUserValue(string $userId, string $key, string $default = ''): string;
92
+    /**
93
+     * Shortcut for getting a user defined value
94
+     *
95
+     * @param string $userId the userId of the user that we want to store the value under
96
+     * @param string $key the key under which the value is being stored
97
+     * @param mixed $default the default value to be returned if the value isn't set
98
+     * @return string
99
+     * @since 20.0.0
100
+     */
101
+    public function getUserValue(string $userId, string $key, string $default = ''): string;
102 102
 
103
-	/**
104
-	 * Delete a user value
105
-	 *
106
-	 * @param string $userId the userId of the user that we want to store the value under
107
-	 * @param string $key the key under which the value is being stored
108
-	 * @since 20.0.0
109
-	 */
110
-	public function deleteUserValue(string $userId, string $key): void;
103
+    /**
104
+     * Delete a user value
105
+     *
106
+     * @param string $userId the userId of the user that we want to store the value under
107
+     * @param string $key the key under which the value is being stored
108
+     * @since 20.0.0
109
+     */
110
+    public function deleteUserValue(string $userId, string $key): void;
111 111
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
 	 * @return string[] the keys stored for the app
38 38
 	 * @since 20.0.0
39 39
 	 */
40
-	public function getAppKeys(): array ;
40
+	public function getAppKeys(): array;
41 41
 
42 42
 	/**
43 43
 	 * Writes a new app wide value
Please login to merge, or discard this patch.
core/Controller/ClientFlowLoginController.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 			);
358 358
 			$this->session->remove('oauth.state');
359 359
 		} else {
360
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
360
+			$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($loginName).'&password:'.urlencode($token);
361 361
 
362 362
 			// Clear the token from the login here
363 363
 			$this->tokenProvider->invalidateToken($sessionId);
@@ -395,7 +395,7 @@  discard block
 block discarded – undo
395 395
 			return $response;
396 396
 		}
397 397
 
398
-		$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
398
+		$redirectUri = 'nc://login/server:'.$this->getServerPath().'&user:'.urlencode($user).'&password:'.urlencode($password);
399 399
 		return new Http\RedirectResponse($redirectUri);
400 400
 	}
401 401
 
@@ -418,6 +418,6 @@  discard block
 block discarded – undo
418 418
 			}
419 419
 		}
420 420
 
421
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
421
+		return $protocol."://".$this->request->getServerHost().$serverPostfix;
422 422
 	}
423 423
 }
Please login to merge, or discard this patch.
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -57,333 +57,333 @@
 block discarded – undo
57 57
 use OCP\Session\Exceptions\SessionNotAvailableException;
58 58
 
59 59
 class ClientFlowLoginController extends Controller {
60
-	private IUserSession $userSession;
61
-	private IL10N $l10n;
62
-	private Defaults $defaults;
63
-	private ISession $session;
64
-	private IProvider $tokenProvider;
65
-	private ISecureRandom $random;
66
-	private IURLGenerator $urlGenerator;
67
-	private ClientMapper $clientMapper;
68
-	private AccessTokenMapper $accessTokenMapper;
69
-	private ICrypto $crypto;
70
-	private IEventDispatcher $eventDispatcher;
71
-
72
-	public const STATE_NAME = 'client.flow.state.token';
73
-
74
-	public function __construct(string $appName,
75
-								IRequest $request,
76
-								IUserSession $userSession,
77
-								IL10N $l10n,
78
-								Defaults $defaults,
79
-								ISession $session,
80
-								IProvider $tokenProvider,
81
-								ISecureRandom $random,
82
-								IURLGenerator $urlGenerator,
83
-								ClientMapper $clientMapper,
84
-								AccessTokenMapper $accessTokenMapper,
85
-								ICrypto $crypto,
86
-								IEventDispatcher $eventDispatcher) {
87
-		parent::__construct($appName, $request);
88
-		$this->userSession = $userSession;
89
-		$this->l10n = $l10n;
90
-		$this->defaults = $defaults;
91
-		$this->session = $session;
92
-		$this->tokenProvider = $tokenProvider;
93
-		$this->random = $random;
94
-		$this->urlGenerator = $urlGenerator;
95
-		$this->clientMapper = $clientMapper;
96
-		$this->accessTokenMapper = $accessTokenMapper;
97
-		$this->crypto = $crypto;
98
-		$this->eventDispatcher = $eventDispatcher;
99
-	}
100
-
101
-	private function getClientName(): string {
102
-		$userAgent = $this->request->getHeader('USER_AGENT');
103
-		return $userAgent !== '' ? $userAgent : 'unknown';
104
-	}
105
-
106
-	private function isValidToken(string $stateToken): bool {
107
-		$currentToken = $this->session->get(self::STATE_NAME);
108
-		if (!is_string($currentToken)) {
109
-			return false;
110
-		}
111
-		return hash_equals($currentToken, $stateToken);
112
-	}
113
-
114
-	private function stateTokenForbiddenResponse(): StandaloneTemplateResponse {
115
-		$response = new StandaloneTemplateResponse(
116
-			$this->appName,
117
-			'403',
118
-			[
119
-				'message' => $this->l10n->t('State token does not match'),
120
-			],
121
-			'guest'
122
-		);
123
-		$response->setStatus(Http::STATUS_FORBIDDEN);
124
-		return $response;
125
-	}
126
-
127
-	/**
128
-	 * @PublicPage
129
-	 * @NoCSRFRequired
130
-	 */
131
-	#[UseSession]
132
-	public function showAuthPickerPage(string $clientIdentifier = '', string $user = '', int $direct = 0): StandaloneTemplateResponse {
133
-		$clientName = $this->getClientName();
134
-		$client = null;
135
-		if ($clientIdentifier !== '') {
136
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
137
-			$clientName = $client->getName();
138
-		}
139
-
140
-		// No valid clientIdentifier given and no valid API Request (APIRequest header not set)
141
-		$clientRequest = $this->request->getHeader('OCS-APIREQUEST');
142
-		if ($clientRequest !== 'true' && $client === null) {
143
-			return new StandaloneTemplateResponse(
144
-				$this->appName,
145
-				'error',
146
-				[
147
-					'errors' =>
148
-					[
149
-						[
150
-							'error' => 'Access Forbidden',
151
-							'hint' => 'Invalid request',
152
-						],
153
-					],
154
-				],
155
-				'guest'
156
-			);
157
-		}
158
-
159
-		$stateToken = $this->random->generate(
160
-			64,
161
-			ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
162
-		);
163
-		$this->session->set(self::STATE_NAME, $stateToken);
164
-
165
-		$csp = new Http\ContentSecurityPolicy();
166
-		if ($client) {
167
-			$csp->addAllowedFormActionDomain($client->getRedirectUri());
168
-		} else {
169
-			$csp->addAllowedFormActionDomain('nc://*');
170
-		}
171
-
172
-		$response = new StandaloneTemplateResponse(
173
-			$this->appName,
174
-			'loginflow/authpicker',
175
-			[
176
-				'client' => $clientName,
177
-				'clientIdentifier' => $clientIdentifier,
178
-				'instanceName' => $this->defaults->getName(),
179
-				'urlGenerator' => $this->urlGenerator,
180
-				'stateToken' => $stateToken,
181
-				'serverHost' => $this->getServerPath(),
182
-				'oauthState' => $this->session->get('oauth.state'),
183
-				'user' => $user,
184
-				'direct' => $direct,
185
-			],
186
-			'guest'
187
-		);
188
-
189
-		$response->setContentSecurityPolicy($csp);
190
-		return $response;
191
-	}
192
-
193
-	/**
194
-	 * @NoAdminRequired
195
-	 * @NoCSRFRequired
196
-	 * @NoSameSiteCookieRequired
197
-	 */
198
-	#[UseSession]
199
-	public function grantPage(string $stateToken = '',
200
-				  string $clientIdentifier = '',
201
-				  int $direct = 0): StandaloneTemplateResponse {
202
-		if (!$this->isValidToken($stateToken)) {
203
-			return $this->stateTokenForbiddenResponse();
204
-		}
205
-
206
-		$clientName = $this->getClientName();
207
-		$client = null;
208
-		if ($clientIdentifier !== '') {
209
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
210
-			$clientName = $client->getName();
211
-		}
212
-
213
-		$csp = new Http\ContentSecurityPolicy();
214
-		if ($client) {
215
-			$csp->addAllowedFormActionDomain($client->getRedirectUri());
216
-		} else {
217
-			$csp->addAllowedFormActionDomain('nc://*');
218
-		}
219
-
220
-		/** @var IUser $user */
221
-		$user = $this->userSession->getUser();
222
-
223
-		$response = new StandaloneTemplateResponse(
224
-			$this->appName,
225
-			'loginflow/grant',
226
-			[
227
-				'userId' => $user->getUID(),
228
-				'userDisplayName' => $user->getDisplayName(),
229
-				'client' => $clientName,
230
-				'clientIdentifier' => $clientIdentifier,
231
-				'instanceName' => $this->defaults->getName(),
232
-				'urlGenerator' => $this->urlGenerator,
233
-				'stateToken' => $stateToken,
234
-				'serverHost' => $this->getServerPath(),
235
-				'oauthState' => $this->session->get('oauth.state'),
236
-				'direct' => $direct,
237
-			],
238
-			'guest'
239
-		);
240
-
241
-		$response->setContentSecurityPolicy($csp);
242
-		return $response;
243
-	}
244
-
245
-	/**
246
-	 * @NoAdminRequired
247
-	 *
248
-	 * @return Http\RedirectResponse|Response
249
-	 */
250
-	#[UseSession]
251
-	public function generateAppPassword(string $stateToken,
252
-										string $clientIdentifier = '') {
253
-		if (!$this->isValidToken($stateToken)) {
254
-			$this->session->remove(self::STATE_NAME);
255
-			return $this->stateTokenForbiddenResponse();
256
-		}
257
-
258
-		$this->session->remove(self::STATE_NAME);
259
-
260
-		try {
261
-			$sessionId = $this->session->getId();
262
-		} catch (SessionNotAvailableException $ex) {
263
-			$response = new Response();
264
-			$response->setStatus(Http::STATUS_FORBIDDEN);
265
-			return $response;
266
-		}
267
-
268
-		try {
269
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
270
-			$loginName = $sessionToken->getLoginName();
271
-			try {
272
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
273
-			} catch (PasswordlessTokenException $ex) {
274
-				$password = null;
275
-			}
276
-		} catch (InvalidTokenException $ex) {
277
-			$response = new Response();
278
-			$response->setStatus(Http::STATUS_FORBIDDEN);
279
-			return $response;
280
-		}
281
-
282
-		$clientName = $this->getClientName();
283
-		$client = false;
284
-		if ($clientIdentifier !== '') {
285
-			$client = $this->clientMapper->getByIdentifier($clientIdentifier);
286
-			$clientName = $client->getName();
287
-		}
288
-
289
-		$token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
290
-		$uid = $this->userSession->getUser()->getUID();
291
-		$generatedToken = $this->tokenProvider->generateToken(
292
-			$token,
293
-			$uid,
294
-			$loginName,
295
-			$password,
296
-			$clientName,
297
-			IToken::PERMANENT_TOKEN,
298
-			IToken::DO_NOT_REMEMBER
299
-		);
300
-
301
-		if ($client) {
302
-			$code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
303
-			$accessToken = new AccessToken();
304
-			$accessToken->setClientId($client->getId());
305
-			$accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
306
-			$accessToken->setHashedCode(hash('sha512', $code));
307
-			$accessToken->setTokenId($generatedToken->getId());
308
-			$this->accessTokenMapper->insert($accessToken);
309
-
310
-			$redirectUri = $client->getRedirectUri();
311
-
312
-			if (parse_url($redirectUri, PHP_URL_QUERY)) {
313
-				$redirectUri .= '&';
314
-			} else {
315
-				$redirectUri .= '?';
316
-			}
317
-
318
-			$redirectUri .= sprintf(
319
-				'state=%s&code=%s',
320
-				urlencode($this->session->get('oauth.state')),
321
-				urlencode($code)
322
-			);
323
-			$this->session->remove('oauth.state');
324
-		} else {
325
-			$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
326
-
327
-			// Clear the token from the login here
328
-			$this->tokenProvider->invalidateToken($sessionId);
329
-		}
330
-
331
-		$this->eventDispatcher->dispatchTyped(
332
-			new AppPasswordCreatedEvent($generatedToken)
333
-		);
334
-
335
-		return new Http\RedirectResponse($redirectUri);
336
-	}
337
-
338
-	/**
339
-	 * @PublicPage
340
-	 */
341
-	public function apptokenRedirect(string $stateToken, string $user, string $password): Response {
342
-		if (!$this->isValidToken($stateToken)) {
343
-			return $this->stateTokenForbiddenResponse();
344
-		}
345
-
346
-		try {
347
-			$token = $this->tokenProvider->getToken($password);
348
-			if ($token->getLoginName() !== $user) {
349
-				throw new InvalidTokenException('login name does not match');
350
-			}
351
-		} catch (InvalidTokenException $e) {
352
-			$response = new StandaloneTemplateResponse(
353
-				$this->appName,
354
-				'403',
355
-				[
356
-					'message' => $this->l10n->t('Invalid app password'),
357
-				],
358
-				'guest'
359
-			);
360
-			$response->setStatus(Http::STATUS_FORBIDDEN);
361
-			return $response;
362
-		}
363
-
364
-		$redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
365
-		return new Http\RedirectResponse($redirectUri);
366
-	}
367
-
368
-	private function getServerPath(): string {
369
-		$serverPostfix = '';
370
-
371
-		if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
372
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
373
-		} elseif (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
374
-			$serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
375
-		}
376
-
377
-		$protocol = $this->request->getServerProtocol();
378
-
379
-		if ($protocol !== "https") {
380
-			$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
381
-			$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
382
-			if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
383
-				$protocol = 'https';
384
-			}
385
-		}
386
-
387
-		return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
388
-	}
60
+    private IUserSession $userSession;
61
+    private IL10N $l10n;
62
+    private Defaults $defaults;
63
+    private ISession $session;
64
+    private IProvider $tokenProvider;
65
+    private ISecureRandom $random;
66
+    private IURLGenerator $urlGenerator;
67
+    private ClientMapper $clientMapper;
68
+    private AccessTokenMapper $accessTokenMapper;
69
+    private ICrypto $crypto;
70
+    private IEventDispatcher $eventDispatcher;
71
+
72
+    public const STATE_NAME = 'client.flow.state.token';
73
+
74
+    public function __construct(string $appName,
75
+                                IRequest $request,
76
+                                IUserSession $userSession,
77
+                                IL10N $l10n,
78
+                                Defaults $defaults,
79
+                                ISession $session,
80
+                                IProvider $tokenProvider,
81
+                                ISecureRandom $random,
82
+                                IURLGenerator $urlGenerator,
83
+                                ClientMapper $clientMapper,
84
+                                AccessTokenMapper $accessTokenMapper,
85
+                                ICrypto $crypto,
86
+                                IEventDispatcher $eventDispatcher) {
87
+        parent::__construct($appName, $request);
88
+        $this->userSession = $userSession;
89
+        $this->l10n = $l10n;
90
+        $this->defaults = $defaults;
91
+        $this->session = $session;
92
+        $this->tokenProvider = $tokenProvider;
93
+        $this->random = $random;
94
+        $this->urlGenerator = $urlGenerator;
95
+        $this->clientMapper = $clientMapper;
96
+        $this->accessTokenMapper = $accessTokenMapper;
97
+        $this->crypto = $crypto;
98
+        $this->eventDispatcher = $eventDispatcher;
99
+    }
100
+
101
+    private function getClientName(): string {
102
+        $userAgent = $this->request->getHeader('USER_AGENT');
103
+        return $userAgent !== '' ? $userAgent : 'unknown';
104
+    }
105
+
106
+    private function isValidToken(string $stateToken): bool {
107
+        $currentToken = $this->session->get(self::STATE_NAME);
108
+        if (!is_string($currentToken)) {
109
+            return false;
110
+        }
111
+        return hash_equals($currentToken, $stateToken);
112
+    }
113
+
114
+    private function stateTokenForbiddenResponse(): StandaloneTemplateResponse {
115
+        $response = new StandaloneTemplateResponse(
116
+            $this->appName,
117
+            '403',
118
+            [
119
+                'message' => $this->l10n->t('State token does not match'),
120
+            ],
121
+            'guest'
122
+        );
123
+        $response->setStatus(Http::STATUS_FORBIDDEN);
124
+        return $response;
125
+    }
126
+
127
+    /**
128
+     * @PublicPage
129
+     * @NoCSRFRequired
130
+     */
131
+    #[UseSession]
132
+    public function showAuthPickerPage(string $clientIdentifier = '', string $user = '', int $direct = 0): StandaloneTemplateResponse {
133
+        $clientName = $this->getClientName();
134
+        $client = null;
135
+        if ($clientIdentifier !== '') {
136
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
137
+            $clientName = $client->getName();
138
+        }
139
+
140
+        // No valid clientIdentifier given and no valid API Request (APIRequest header not set)
141
+        $clientRequest = $this->request->getHeader('OCS-APIREQUEST');
142
+        if ($clientRequest !== 'true' && $client === null) {
143
+            return new StandaloneTemplateResponse(
144
+                $this->appName,
145
+                'error',
146
+                [
147
+                    'errors' =>
148
+                    [
149
+                        [
150
+                            'error' => 'Access Forbidden',
151
+                            'hint' => 'Invalid request',
152
+                        ],
153
+                    ],
154
+                ],
155
+                'guest'
156
+            );
157
+        }
158
+
159
+        $stateToken = $this->random->generate(
160
+            64,
161
+            ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS
162
+        );
163
+        $this->session->set(self::STATE_NAME, $stateToken);
164
+
165
+        $csp = new Http\ContentSecurityPolicy();
166
+        if ($client) {
167
+            $csp->addAllowedFormActionDomain($client->getRedirectUri());
168
+        } else {
169
+            $csp->addAllowedFormActionDomain('nc://*');
170
+        }
171
+
172
+        $response = new StandaloneTemplateResponse(
173
+            $this->appName,
174
+            'loginflow/authpicker',
175
+            [
176
+                'client' => $clientName,
177
+                'clientIdentifier' => $clientIdentifier,
178
+                'instanceName' => $this->defaults->getName(),
179
+                'urlGenerator' => $this->urlGenerator,
180
+                'stateToken' => $stateToken,
181
+                'serverHost' => $this->getServerPath(),
182
+                'oauthState' => $this->session->get('oauth.state'),
183
+                'user' => $user,
184
+                'direct' => $direct,
185
+            ],
186
+            'guest'
187
+        );
188
+
189
+        $response->setContentSecurityPolicy($csp);
190
+        return $response;
191
+    }
192
+
193
+    /**
194
+     * @NoAdminRequired
195
+     * @NoCSRFRequired
196
+     * @NoSameSiteCookieRequired
197
+     */
198
+    #[UseSession]
199
+    public function grantPage(string $stateToken = '',
200
+                    string $clientIdentifier = '',
201
+                    int $direct = 0): StandaloneTemplateResponse {
202
+        if (!$this->isValidToken($stateToken)) {
203
+            return $this->stateTokenForbiddenResponse();
204
+        }
205
+
206
+        $clientName = $this->getClientName();
207
+        $client = null;
208
+        if ($clientIdentifier !== '') {
209
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
210
+            $clientName = $client->getName();
211
+        }
212
+
213
+        $csp = new Http\ContentSecurityPolicy();
214
+        if ($client) {
215
+            $csp->addAllowedFormActionDomain($client->getRedirectUri());
216
+        } else {
217
+            $csp->addAllowedFormActionDomain('nc://*');
218
+        }
219
+
220
+        /** @var IUser $user */
221
+        $user = $this->userSession->getUser();
222
+
223
+        $response = new StandaloneTemplateResponse(
224
+            $this->appName,
225
+            'loginflow/grant',
226
+            [
227
+                'userId' => $user->getUID(),
228
+                'userDisplayName' => $user->getDisplayName(),
229
+                'client' => $clientName,
230
+                'clientIdentifier' => $clientIdentifier,
231
+                'instanceName' => $this->defaults->getName(),
232
+                'urlGenerator' => $this->urlGenerator,
233
+                'stateToken' => $stateToken,
234
+                'serverHost' => $this->getServerPath(),
235
+                'oauthState' => $this->session->get('oauth.state'),
236
+                'direct' => $direct,
237
+            ],
238
+            'guest'
239
+        );
240
+
241
+        $response->setContentSecurityPolicy($csp);
242
+        return $response;
243
+    }
244
+
245
+    /**
246
+     * @NoAdminRequired
247
+     *
248
+     * @return Http\RedirectResponse|Response
249
+     */
250
+    #[UseSession]
251
+    public function generateAppPassword(string $stateToken,
252
+                                        string $clientIdentifier = '') {
253
+        if (!$this->isValidToken($stateToken)) {
254
+            $this->session->remove(self::STATE_NAME);
255
+            return $this->stateTokenForbiddenResponse();
256
+        }
257
+
258
+        $this->session->remove(self::STATE_NAME);
259
+
260
+        try {
261
+            $sessionId = $this->session->getId();
262
+        } catch (SessionNotAvailableException $ex) {
263
+            $response = new Response();
264
+            $response->setStatus(Http::STATUS_FORBIDDEN);
265
+            return $response;
266
+        }
267
+
268
+        try {
269
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
270
+            $loginName = $sessionToken->getLoginName();
271
+            try {
272
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
273
+            } catch (PasswordlessTokenException $ex) {
274
+                $password = null;
275
+            }
276
+        } catch (InvalidTokenException $ex) {
277
+            $response = new Response();
278
+            $response->setStatus(Http::STATUS_FORBIDDEN);
279
+            return $response;
280
+        }
281
+
282
+        $clientName = $this->getClientName();
283
+        $client = false;
284
+        if ($clientIdentifier !== '') {
285
+            $client = $this->clientMapper->getByIdentifier($clientIdentifier);
286
+            $clientName = $client->getName();
287
+        }
288
+
289
+        $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
290
+        $uid = $this->userSession->getUser()->getUID();
291
+        $generatedToken = $this->tokenProvider->generateToken(
292
+            $token,
293
+            $uid,
294
+            $loginName,
295
+            $password,
296
+            $clientName,
297
+            IToken::PERMANENT_TOKEN,
298
+            IToken::DO_NOT_REMEMBER
299
+        );
300
+
301
+        if ($client) {
302
+            $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);
303
+            $accessToken = new AccessToken();
304
+            $accessToken->setClientId($client->getId());
305
+            $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));
306
+            $accessToken->setHashedCode(hash('sha512', $code));
307
+            $accessToken->setTokenId($generatedToken->getId());
308
+            $this->accessTokenMapper->insert($accessToken);
309
+
310
+            $redirectUri = $client->getRedirectUri();
311
+
312
+            if (parse_url($redirectUri, PHP_URL_QUERY)) {
313
+                $redirectUri .= '&';
314
+            } else {
315
+                $redirectUri .= '?';
316
+            }
317
+
318
+            $redirectUri .= sprintf(
319
+                'state=%s&code=%s',
320
+                urlencode($this->session->get('oauth.state')),
321
+                urlencode($code)
322
+            );
323
+            $this->session->remove('oauth.state');
324
+        } else {
325
+            $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);
326
+
327
+            // Clear the token from the login here
328
+            $this->tokenProvider->invalidateToken($sessionId);
329
+        }
330
+
331
+        $this->eventDispatcher->dispatchTyped(
332
+            new AppPasswordCreatedEvent($generatedToken)
333
+        );
334
+
335
+        return new Http\RedirectResponse($redirectUri);
336
+    }
337
+
338
+    /**
339
+     * @PublicPage
340
+     */
341
+    public function apptokenRedirect(string $stateToken, string $user, string $password): Response {
342
+        if (!$this->isValidToken($stateToken)) {
343
+            return $this->stateTokenForbiddenResponse();
344
+        }
345
+
346
+        try {
347
+            $token = $this->tokenProvider->getToken($password);
348
+            if ($token->getLoginName() !== $user) {
349
+                throw new InvalidTokenException('login name does not match');
350
+            }
351
+        } catch (InvalidTokenException $e) {
352
+            $response = new StandaloneTemplateResponse(
353
+                $this->appName,
354
+                '403',
355
+                [
356
+                    'message' => $this->l10n->t('Invalid app password'),
357
+                ],
358
+                'guest'
359
+            );
360
+            $response->setStatus(Http::STATUS_FORBIDDEN);
361
+            return $response;
362
+        }
363
+
364
+        $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);
365
+        return new Http\RedirectResponse($redirectUri);
366
+    }
367
+
368
+    private function getServerPath(): string {
369
+        $serverPostfix = '';
370
+
371
+        if (strpos($this->request->getRequestUri(), '/index.php') !== false) {
372
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));
373
+        } elseif (strpos($this->request->getRequestUri(), '/login/flow') !== false) {
374
+            $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));
375
+        }
376
+
377
+        $protocol = $this->request->getServerProtocol();
378
+
379
+        if ($protocol !== "https") {
380
+            $xForwardedProto = $this->request->getHeader('X-Forwarded-Proto');
381
+            $xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl');
382
+            if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') {
383
+                $protocol = 'https';
384
+            }
385
+        }
386
+
387
+        return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;
388
+    }
389 389
 }
Please login to merge, or discard this patch.
apps/contactsinteraction/lib/AddressBook.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
 			return new Card(
86 86
 				$this->mapper->find(
87 87
 					$this->getUid(),
88
-					(int)$name
88
+					(int) $name
89 89
 				),
90 90
 				$this->principalUri,
91 91
 				$this->getACL()
92 92
 			);
93 93
 		} catch (DoesNotExistException $ex) {
94
-			throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex);
94
+			throw new NotFound("Contact does not exist: ".$ex->getMessage(), 0, $ex);
95 95
 		}
96 96
 	}
97 97
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 	 */
101 101
 	public function getChildren(): array {
102 102
 		return array_map(
103
-			function (RecentContact $contact) {
103
+			function(RecentContact $contact) {
104 104
 				return new Card(
105 105
 					$contact,
106 106
 					$this->principalUri,
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		try {
119 119
 			$this->mapper->find(
120 120
 				$this->getUid(),
121
-				(int)$name
121
+				(int) $name
122 122
 			);
123 123
 			return true;
124 124
 		} catch (DoesNotExistException $e) {
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
 		return [
148 148
 			'principaluri' => $this->principalUri,
149 149
 			'{DAV:}displayname' => $this->l10n->t('Recently contacted'),
150
-			'{' . Plugin::NS_OWNCLOUD . '}read-only' => true,
151
-			'{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0),
150
+			'{'.Plugin::NS_OWNCLOUD.'}read-only' => true,
151
+			'{'.\OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($this->getLastModified() ?? 0),
152 152
 		];
153 153
 	}
154 154
 
Please login to merge, or discard this patch.
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -40,133 +40,133 @@
 block discarded – undo
40 40
 use Sabre\DAVACL\IACL;
41 41
 
42 42
 class AddressBook extends ExternalAddressBook implements IACL {
43
-	use ACLTrait;
44
-
45
-	public const URI = 'recent';
46
-
47
-	private RecentContactMapper $mapper;
48
-	private IL10N $l10n;
49
-	private string $principalUri;
50
-
51
-	public function __construct(RecentContactMapper $mapper,
52
-								IL10N $l10n,
53
-								string $principalUri) {
54
-		parent::__construct(Application::APP_ID, self::URI);
55
-
56
-		$this->mapper = $mapper;
57
-		$this->l10n = $l10n;
58
-		$this->principalUri = $principalUri;
59
-	}
60
-
61
-	/**
62
-	 * @inheritDoc
63
-	 */
64
-	public function delete(): void {
65
-		throw new Exception("This addressbook is immutable");
66
-	}
67
-
68
-	/**
69
-	 * @inheritDoc
70
-	 */
71
-	public function createFile($name, $data = null) {
72
-		throw new Exception("This addressbook is immutable");
73
-	}
74
-
75
-	/**
76
-	 * @inheritDoc
77
-	 * @throws NotFound
78
-	 */
79
-	public function getChild($name): Card {
80
-		try {
81
-			return new Card(
82
-				$this->mapper->find(
83
-					$this->getUid(),
84
-					(int)$name
85
-				),
86
-				$this->principalUri,
87
-				$this->getACL()
88
-			);
89
-		} catch (DoesNotExistException $ex) {
90
-			throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex);
91
-		}
92
-	}
93
-
94
-	/**
95
-	 * @inheritDoc
96
-	 */
97
-	public function getChildren(): array {
98
-		return array_map(
99
-			function (RecentContact $contact) {
100
-				return new Card(
101
-					$contact,
102
-					$this->principalUri,
103
-					$this->getACL()
104
-				);
105
-			},
106
-			$this->mapper->findAll($this->getUid())
107
-		);
108
-	}
109
-
110
-	/**
111
-	 * @inheritDoc
112
-	 */
113
-	public function childExists($name): bool {
114
-		try {
115
-			$this->mapper->find(
116
-				$this->getUid(),
117
-				(int)$name
118
-			);
119
-			return true;
120
-		} catch (DoesNotExistException $e) {
121
-			return false;
122
-		}
123
-	}
124
-
125
-	/**
126
-	 * @inheritDoc
127
-	 */
128
-	public function getLastModified(): ?int {
129
-		return $this->mapper->findLastUpdatedForUserId($this->getUid());
130
-	}
131
-
132
-	/**
133
-	 * @inheritDoc
134
-	 */
135
-	public function propPatch(PropPatch $propPatch) {
136
-		throw new Exception("This addressbook is immutable");
137
-	}
138
-
139
-	/**
140
-	 * @inheritDoc
141
-	 */
142
-	public function getProperties($properties) {
143
-		return [
144
-			'principaluri' => $this->principalUri,
145
-			'{DAV:}displayname' => $this->l10n->t('Recently contacted'),
146
-			'{' . Plugin::NS_OWNCLOUD . '}read-only' => true,
147
-			'{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0),
148
-		];
149
-	}
150
-
151
-	public function getOwner(): string {
152
-		return $this->principalUri;
153
-	}
154
-
155
-	/**
156
-	 * @inheritDoc
157
-	 */
158
-	public function getACL(): array {
159
-		return [
160
-			[
161
-				'privilege' => '{DAV:}read',
162
-				'principal' => $this->getOwner(),
163
-				'protected' => true,
164
-			],
165
-		];
166
-	}
167
-
168
-	private function getUid(): string {
169
-		[, $uid] = \Sabre\Uri\split($this->principalUri);
170
-		return $uid;
171
-	}
43
+    use ACLTrait;
44
+
45
+    public const URI = 'recent';
46
+
47
+    private RecentContactMapper $mapper;
48
+    private IL10N $l10n;
49
+    private string $principalUri;
50
+
51
+    public function __construct(RecentContactMapper $mapper,
52
+                                IL10N $l10n,
53
+                                string $principalUri) {
54
+        parent::__construct(Application::APP_ID, self::URI);
55
+
56
+        $this->mapper = $mapper;
57
+        $this->l10n = $l10n;
58
+        $this->principalUri = $principalUri;
59
+    }
60
+
61
+    /**
62
+     * @inheritDoc
63
+     */
64
+    public function delete(): void {
65
+        throw new Exception("This addressbook is immutable");
66
+    }
67
+
68
+    /**
69
+     * @inheritDoc
70
+     */
71
+    public function createFile($name, $data = null) {
72
+        throw new Exception("This addressbook is immutable");
73
+    }
74
+
75
+    /**
76
+     * @inheritDoc
77
+     * @throws NotFound
78
+     */
79
+    public function getChild($name): Card {
80
+        try {
81
+            return new Card(
82
+                $this->mapper->find(
83
+                    $this->getUid(),
84
+                    (int)$name
85
+                ),
86
+                $this->principalUri,
87
+                $this->getACL()
88
+            );
89
+        } catch (DoesNotExistException $ex) {
90
+            throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex);
91
+        }
92
+    }
93
+
94
+    /**
95
+     * @inheritDoc
96
+     */
97
+    public function getChildren(): array {
98
+        return array_map(
99
+            function (RecentContact $contact) {
100
+                return new Card(
101
+                    $contact,
102
+                    $this->principalUri,
103
+                    $this->getACL()
104
+                );
105
+            },
106
+            $this->mapper->findAll($this->getUid())
107
+        );
108
+    }
109
+
110
+    /**
111
+     * @inheritDoc
112
+     */
113
+    public function childExists($name): bool {
114
+        try {
115
+            $this->mapper->find(
116
+                $this->getUid(),
117
+                (int)$name
118
+            );
119
+            return true;
120
+        } catch (DoesNotExistException $e) {
121
+            return false;
122
+        }
123
+    }
124
+
125
+    /**
126
+     * @inheritDoc
127
+     */
128
+    public function getLastModified(): ?int {
129
+        return $this->mapper->findLastUpdatedForUserId($this->getUid());
130
+    }
131
+
132
+    /**
133
+     * @inheritDoc
134
+     */
135
+    public function propPatch(PropPatch $propPatch) {
136
+        throw new Exception("This addressbook is immutable");
137
+    }
138
+
139
+    /**
140
+     * @inheritDoc
141
+     */
142
+    public function getProperties($properties) {
143
+        return [
144
+            'principaluri' => $this->principalUri,
145
+            '{DAV:}displayname' => $this->l10n->t('Recently contacted'),
146
+            '{' . Plugin::NS_OWNCLOUD . '}read-only' => true,
147
+            '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0),
148
+        ];
149
+    }
150
+
151
+    public function getOwner(): string {
152
+        return $this->principalUri;
153
+    }
154
+
155
+    /**
156
+     * @inheritDoc
157
+     */
158
+    public function getACL(): array {
159
+        return [
160
+            [
161
+                'privilege' => '{DAV:}read',
162
+                'principal' => $this->getOwner(),
163
+                'protected' => true,
164
+            ],
165
+        ];
166
+    }
167
+
168
+    private function getUid(): string {
169
+        [, $uid] = \Sabre\Uri\split($this->principalUri);
170
+        return $uid;
171
+    }
172 172
 }
Please login to merge, or discard this patch.
apps/contactsinteraction/lib/Card.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -95,7 +95,7 @@
 block discarded – undo
95 95
 	 * @inheritDoc
96 96
 	 */
97 97
 	public function getETag(): ?string {
98
-		return '"' . md5((string) $this->getLastModified()) . '"';
98
+		return '"'.md5((string) $this->getLastModified()).'"';
99 99
 	}
100 100
 
101 101
 	/**
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -34,99 +34,99 @@
 block discarded – undo
34 34
 use Sabre\DAVACL\IACL;
35 35
 
36 36
 class Card implements ICard, IACL {
37
-	use ACLTrait;
38
-
39
-	private RecentContact $contact;
40
-	private string $principal;
41
-	private array $acls;
42
-
43
-	public function __construct(RecentContact $contact, string $principal, array $acls) {
44
-		$this->contact = $contact;
45
-		$this->principal = $principal;
46
-		$this->acls = $acls;
47
-	}
48
-
49
-	/**
50
-	 * @inheritDoc
51
-	 */
52
-	public function getOwner(): ?string {
53
-		return $this->principal;
54
-	}
55
-
56
-	/**
57
-	 * @inheritDoc
58
-	 */
59
-	public function getACL(): array {
60
-		return $this->acls;
61
-	}
62
-
63
-	/**
64
-	 * @inheritDoc
65
-	 */
66
-	public function setAcls(array $acls): void {
67
-		throw new NotImplemented();
68
-	}
69
-
70
-	/**
71
-	 * @inheritDoc
72
-	 */
73
-	public function put($data): ?string {
74
-		throw new NotImplemented();
75
-	}
76
-
77
-	/**
78
-	 * @inheritDoc
79
-	 */
80
-	public function get() {
81
-		return $this->contact->getCard();
82
-	}
83
-
84
-	/**
85
-	 * @inheritDoc
86
-	 */
87
-	public function getContentType(): ?string {
88
-		return 'text/vcard; charset=utf-8';
89
-	}
90
-
91
-	/**
92
-	 * @inheritDoc
93
-	 */
94
-	public function getETag(): ?string {
95
-		return '"' . md5((string) $this->getLastModified()) . '"';
96
-	}
97
-
98
-	/**
99
-	 * @inheritDoc
100
-	 */
101
-	public function getSize(): int {
102
-		throw new NotImplemented();
103
-	}
104
-
105
-	/**
106
-	 * @inheritDoc
107
-	 */
108
-	public function delete(): void {
109
-		throw new NotImplemented();
110
-	}
111
-
112
-	/**
113
-	 * @inheritDoc
114
-	 */
115
-	public function getName(): string {
116
-		return (string) $this->contact->getId();
117
-	}
118
-
119
-	/**
120
-	 * @inheritDoc
121
-	 */
122
-	public function setName($name): void {
123
-		throw new NotImplemented();
124
-	}
125
-
126
-	/**
127
-	 * @inheritDoc
128
-	 */
129
-	public function getLastModified(): ?int {
130
-		return $this->contact->getLastContact();
131
-	}
37
+    use ACLTrait;
38
+
39
+    private RecentContact $contact;
40
+    private string $principal;
41
+    private array $acls;
42
+
43
+    public function __construct(RecentContact $contact, string $principal, array $acls) {
44
+        $this->contact = $contact;
45
+        $this->principal = $principal;
46
+        $this->acls = $acls;
47
+    }
48
+
49
+    /**
50
+     * @inheritDoc
51
+     */
52
+    public function getOwner(): ?string {
53
+        return $this->principal;
54
+    }
55
+
56
+    /**
57
+     * @inheritDoc
58
+     */
59
+    public function getACL(): array {
60
+        return $this->acls;
61
+    }
62
+
63
+    /**
64
+     * @inheritDoc
65
+     */
66
+    public function setAcls(array $acls): void {
67
+        throw new NotImplemented();
68
+    }
69
+
70
+    /**
71
+     * @inheritDoc
72
+     */
73
+    public function put($data): ?string {
74
+        throw new NotImplemented();
75
+    }
76
+
77
+    /**
78
+     * @inheritDoc
79
+     */
80
+    public function get() {
81
+        return $this->contact->getCard();
82
+    }
83
+
84
+    /**
85
+     * @inheritDoc
86
+     */
87
+    public function getContentType(): ?string {
88
+        return 'text/vcard; charset=utf-8';
89
+    }
90
+
91
+    /**
92
+     * @inheritDoc
93
+     */
94
+    public function getETag(): ?string {
95
+        return '"' . md5((string) $this->getLastModified()) . '"';
96
+    }
97
+
98
+    /**
99
+     * @inheritDoc
100
+     */
101
+    public function getSize(): int {
102
+        throw new NotImplemented();
103
+    }
104
+
105
+    /**
106
+     * @inheritDoc
107
+     */
108
+    public function delete(): void {
109
+        throw new NotImplemented();
110
+    }
111
+
112
+    /**
113
+     * @inheritDoc
114
+     */
115
+    public function getName(): string {
116
+        return (string) $this->contact->getId();
117
+    }
118
+
119
+    /**
120
+     * @inheritDoc
121
+     */
122
+    public function setName($name): void {
123
+        throw new NotImplemented();
124
+    }
125
+
126
+    /**
127
+     * @inheritDoc
128
+     */
129
+    public function getLastModified(): ?int {
130
+        return $this->contact->getLastContact();
131
+    }
132 132
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Services/InitialState.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -29,22 +29,22 @@
 block discarded – undo
29 29
 use OCP\IInitialStateService;
30 30
 
31 31
 class InitialState implements IInitialState {
32
-	/** @var IInitialStateService */
33
-	private $state;
32
+    /** @var IInitialStateService */
33
+    private $state;
34 34
 
35
-	/** @var string */
36
-	private $appName;
35
+    /** @var string */
36
+    private $appName;
37 37
 
38
-	public function __construct(IInitialStateService $state, string $appName) {
39
-		$this->state = $state;
40
-		$this->appName = $appName;
41
-	}
38
+    public function __construct(IInitialStateService $state, string $appName) {
39
+        $this->state = $state;
40
+        $this->appName = $appName;
41
+    }
42 42
 
43
-	public function provideInitialState(string $key, $data): void {
44
-		$this->state->provideInitialState($this->appName, $key, $data);
45
-	}
43
+    public function provideInitialState(string $key, $data): void {
44
+        $this->state->provideInitialState($this->appName, $key, $data);
45
+    }
46 46
 
47
-	public function provideLazyInitialState(string $key, \Closure $closure): void {
48
-		$this->state->provideLazyInitialState($this->appName, $key, $closure);
49
-	}
47
+    public function provideLazyInitialState(string $key, \Closure $closure): void {
48
+        $this->state->provideLazyInitialState($this->appName, $key, $closure);
49
+    }
50 50
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/NotModifiedMiddleware.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
 
41 41
 	public function afterController($controller, $methodName, Response $response) {
42 42
 		$etagHeader = $this->request->getHeader('IF_NONE_MATCH');
43
-		if ($etagHeader !== '' && $response->getETag() !== null && trim($etagHeader) === '"' . $response->getETag() . '"') {
43
+		if ($etagHeader !== '' && $response->getETag() !== null && trim($etagHeader) === '"'.$response->getETag().'"') {
44 44
 			$response->setStatus(Http::STATUS_NOT_MODIFIED);
45 45
 			return $response;
46 46
 		}
Please login to merge, or discard this patch.
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -31,26 +31,26 @@
 block discarded – undo
31 31
 use OCP\IRequest;
32 32
 
33 33
 class NotModifiedMiddleware extends Middleware {
34
-	/** @var IRequest */
35
-	private $request;
36
-
37
-	public function __construct(IRequest $request) {
38
-		$this->request = $request;
39
-	}
40
-
41
-	public function afterController($controller, $methodName, Response $response) {
42
-		$etagHeader = $this->request->getHeader('IF_NONE_MATCH');
43
-		if ($etagHeader !== '' && $response->getETag() !== null && trim($etagHeader) === '"' . $response->getETag() . '"') {
44
-			$response->setStatus(Http::STATUS_NOT_MODIFIED);
45
-			return $response;
46
-		}
47
-
48
-		$modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE');
49
-		if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC2822)) {
50
-			$response->setStatus(Http::STATUS_NOT_MODIFIED);
51
-			return $response;
52
-		}
53
-
54
-		return $response;
55
-	}
34
+    /** @var IRequest */
35
+    private $request;
36
+
37
+    public function __construct(IRequest $request) {
38
+        $this->request = $request;
39
+    }
40
+
41
+    public function afterController($controller, $methodName, Response $response) {
42
+        $etagHeader = $this->request->getHeader('IF_NONE_MATCH');
43
+        if ($etagHeader !== '' && $response->getETag() !== null && trim($etagHeader) === '"' . $response->getETag() . '"') {
44
+            $response->setStatus(Http::STATUS_NOT_MODIFIED);
45
+            return $response;
46
+        }
47
+
48
+        $modifiedSinceHeader = $this->request->getHeader('IF_MODIFIED_SINCE');
49
+        if ($modifiedSinceHeader !== '' && $response->getLastModified() !== null && trim($modifiedSinceHeader) === $response->getLastModified()->format(\DateTimeInterface::RFC2822)) {
50
+            $response->setStatus(Http::STATUS_NOT_MODIFIED);
51
+            return $response;
52
+        }
53
+
54
+        return $response;
55
+    }
56 56
 }
Please login to merge, or discard this patch.
resources/update-locales.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,28 +25,28 @@
 block discarded – undo
25 25
  */
26 26
 
27 27
 if (!extension_loaded('intl')) {
28
-	echo 'Intl extension is required to run this script.';
29
-	exit(1);
28
+    echo 'Intl extension is required to run this script.';
29
+    exit(1);
30 30
 }
31 31
 
32 32
 require '../3rdparty/autoload.php';
33 33
 
34 34
 $locales = array_map(static function (string $localeCode) {
35
-	return [
36
-		'code' => $localeCode,
37
-		'name' => Locale::getDisplayName($localeCode, 'en')
38
-	];
35
+    return [
36
+        'code' => $localeCode,
37
+        'name' => Locale::getDisplayName($localeCode, 'en')
38
+    ];
39 39
 }, ResourceBundle::getLocales(''));
40 40
 
41 41
 $locales = array_filter($locales, static function (array $locale) {
42
-	return is_array(Punic\Data::explodeLocale($locale['code']));
42
+    return is_array(Punic\Data::explodeLocale($locale['code']));
43 43
 });
44 44
 
45 45
 $locales = array_values($locales);
46 46
 
47 47
 if (file_put_contents(__DIR__ . '/locales.json', json_encode($locales, JSON_PRETTY_PRINT)) === false) {
48
-	echo 'Failed to update locales.json';
49
-	exit(1);
48
+    echo 'Failed to update locales.json';
49
+    exit(1);
50 50
 }
51 51
 
52 52
 echo 'Updated locales.json. Don\'t forget to commit the result.';
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -31,20 +31,20 @@
 block discarded – undo
31 31
 
32 32
 require '../3rdparty/autoload.php';
33 33
 
34
-$locales = array_map(static function (string $localeCode) {
34
+$locales = array_map(static function(string $localeCode) {
35 35
 	return [
36 36
 		'code' => $localeCode,
37 37
 		'name' => Locale::getDisplayName($localeCode, 'en')
38 38
 	];
39 39
 }, ResourceBundle::getLocales(''));
40 40
 
41
-$locales = array_filter($locales, static function (array $locale) {
41
+$locales = array_filter($locales, static function(array $locale) {
42 42
 	return is_array(Punic\Data::explodeLocale($locale['code']));
43 43
 });
44 44
 
45 45
 $locales = array_values($locales);
46 46
 
47
-if (file_put_contents(__DIR__ . '/locales.json', json_encode($locales, JSON_PRETTY_PRINT)) === false) {
47
+if (file_put_contents(__DIR__.'/locales.json', json_encode($locales, JSON_PRETTY_PRINT)) === false) {
48 48
 	echo 'Failed to update locales.json';
49 49
 	exit(1);
50 50
 }
Please login to merge, or discard this patch.
core/Command/Security/ResetBruteforceAttempts.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 		$ip = $input->getArgument('ipaddress');
54 54
 
55 55
 		if (!filter_var($ip, FILTER_VALIDATE_IP)) {
56
-			$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
56
+			$output->writeln('<error>"'.$ip.'" is not a valid IP address</error>');
57 57
 			return 1;
58 58
 		}
59 59
 
Please login to merge, or discard this patch.
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -30,33 +30,33 @@
 block discarded – undo
30 30
 use Symfony\Component\Console\Output\OutputInterface;
31 31
 
32 32
 class ResetBruteforceAttempts extends Base {
33
-	protected Throttler $throttler;
33
+    protected Throttler $throttler;
34 34
 
35
-	public function __construct(Throttler $throttler) {
36
-		$this->throttler = $throttler;
37
-		parent::__construct();
38
-	}
35
+    public function __construct(Throttler $throttler) {
36
+        $this->throttler = $throttler;
37
+        parent::__construct();
38
+    }
39 39
 
40
-	protected function configure() {
41
-		$this
42
-			->setName('security:bruteforce:reset')
43
-			->setDescription('resets bruteforce attemps for given IP address')
44
-			->addArgument(
45
-				'ipaddress',
46
-				InputArgument::REQUIRED,
47
-				'IP address for which the attempts are to be reset'
48
-			);
49
-	}
40
+    protected function configure() {
41
+        $this
42
+            ->setName('security:bruteforce:reset')
43
+            ->setDescription('resets bruteforce attemps for given IP address')
44
+            ->addArgument(
45
+                'ipaddress',
46
+                InputArgument::REQUIRED,
47
+                'IP address for which the attempts are to be reset'
48
+            );
49
+    }
50 50
 
51
-	protected function execute(InputInterface $input, OutputInterface $output): int {
52
-		$ip = $input->getArgument('ipaddress');
51
+    protected function execute(InputInterface $input, OutputInterface $output): int {
52
+        $ip = $input->getArgument('ipaddress');
53 53
 
54
-		if (!filter_var($ip, FILTER_VALIDATE_IP)) {
55
-			$output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
56
-			return 1;
57
-		}
54
+        if (!filter_var($ip, FILTER_VALIDATE_IP)) {
55
+            $output->writeln('<error>"' . $ip . '" is not a valid IP address</error>');
56
+            return 1;
57
+        }
58 58
 
59
-		$this->throttler->resetDelayForIP($ip);
60
-		return 0;
61
-	}
59
+        $this->throttler->resetDelayForIP($ip);
60
+        return 0;
61
+    }
62 62
 }
Please login to merge, or discard this patch.