@@ -50,324 +50,324 @@  | 
                                                    ||
| 50 | 50 | use Symfony\Component\EventDispatcher\GenericEvent;  | 
                                                        
| 51 | 51 | |
| 52 | 52 |  class ClientFlowLoginController extends Controller { | 
                                                        
| 53 | - /** @var IUserSession */  | 
                                                        |
| 54 | - private $userSession;  | 
                                                        |
| 55 | - /** @var IL10N */  | 
                                                        |
| 56 | - private $l10n;  | 
                                                        |
| 57 | - /** @var Defaults */  | 
                                                        |
| 58 | - private $defaults;  | 
                                                        |
| 59 | - /** @var ISession */  | 
                                                        |
| 60 | - private $session;  | 
                                                        |
| 61 | - /** @var IProvider */  | 
                                                        |
| 62 | - private $tokenProvider;  | 
                                                        |
| 63 | - /** @var ISecureRandom */  | 
                                                        |
| 64 | - private $random;  | 
                                                        |
| 65 | - /** @var IURLGenerator */  | 
                                                        |
| 66 | - private $urlGenerator;  | 
                                                        |
| 67 | - /** @var ClientMapper */  | 
                                                        |
| 68 | - private $clientMapper;  | 
                                                        |
| 69 | - /** @var AccessTokenMapper */  | 
                                                        |
| 70 | - private $accessTokenMapper;  | 
                                                        |
| 71 | - /** @var ICrypto */  | 
                                                        |
| 72 | - private $crypto;  | 
                                                        |
| 73 | - /** @var EventDispatcherInterface */  | 
                                                        |
| 74 | - private $eventDispatcher;  | 
                                                        |
| 75 | -  | 
                                                        |
| 76 | - const stateName = 'client.flow.state.token';  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - /**  | 
                                                        |
| 79 | - * @param string $appName  | 
                                                        |
| 80 | - * @param IRequest $request  | 
                                                        |
| 81 | - * @param IUserSession $userSession  | 
                                                        |
| 82 | - * @param IL10N $l10n  | 
                                                        |
| 83 | - * @param Defaults $defaults  | 
                                                        |
| 84 | - * @param ISession $session  | 
                                                        |
| 85 | - * @param IProvider $tokenProvider  | 
                                                        |
| 86 | - * @param ISecureRandom $random  | 
                                                        |
| 87 | - * @param IURLGenerator $urlGenerator  | 
                                                        |
| 88 | - * @param ClientMapper $clientMapper  | 
                                                        |
| 89 | - * @param AccessTokenMapper $accessTokenMapper  | 
                                                        |
| 90 | - * @param ICrypto $crypto  | 
                                                        |
| 91 | - * @param EventDispatcherInterface $eventDispatcher  | 
                                                        |
| 92 | - */  | 
                                                        |
| 93 | - public function __construct($appName,  | 
                                                        |
| 94 | - IRequest $request,  | 
                                                        |
| 95 | - IUserSession $userSession,  | 
                                                        |
| 96 | - IL10N $l10n,  | 
                                                        |
| 97 | - Defaults $defaults,  | 
                                                        |
| 98 | - ISession $session,  | 
                                                        |
| 99 | - IProvider $tokenProvider,  | 
                                                        |
| 100 | - ISecureRandom $random,  | 
                                                        |
| 101 | - IURLGenerator $urlGenerator,  | 
                                                        |
| 102 | - ClientMapper $clientMapper,  | 
                                                        |
| 103 | - AccessTokenMapper $accessTokenMapper,  | 
                                                        |
| 104 | - ICrypto $crypto,  | 
                                                        |
| 105 | -								EventDispatcherInterface $eventDispatcher) { | 
                                                        |
| 106 | - parent::__construct($appName, $request);  | 
                                                        |
| 107 | - $this->userSession = $userSession;  | 
                                                        |
| 108 | - $this->l10n = $l10n;  | 
                                                        |
| 109 | - $this->defaults = $defaults;  | 
                                                        |
| 110 | - $this->session = $session;  | 
                                                        |
| 111 | - $this->tokenProvider = $tokenProvider;  | 
                                                        |
| 112 | - $this->random = $random;  | 
                                                        |
| 113 | - $this->urlGenerator = $urlGenerator;  | 
                                                        |
| 114 | - $this->clientMapper = $clientMapper;  | 
                                                        |
| 115 | - $this->accessTokenMapper = $accessTokenMapper;  | 
                                                        |
| 116 | - $this->crypto = $crypto;  | 
                                                        |
| 117 | - $this->eventDispatcher = $eventDispatcher;  | 
                                                        |
| 118 | - }  | 
                                                        |
| 119 | -  | 
                                                        |
| 120 | - /**  | 
                                                        |
| 121 | - * @return string  | 
                                                        |
| 122 | - */  | 
                                                        |
| 123 | -	private function getClientName() { | 
                                                        |
| 124 | -		$userAgent = $this->request->getHeader('USER_AGENT'); | 
                                                        |
| 125 | - return $userAgent !== '' ? $userAgent : 'unknown';  | 
                                                        |
| 126 | - }  | 
                                                        |
| 127 | -  | 
                                                        |
| 128 | - /**  | 
                                                        |
| 129 | - * @param string $stateToken  | 
                                                        |
| 130 | - * @return bool  | 
                                                        |
| 131 | - */  | 
                                                        |
| 132 | -	private function isValidToken($stateToken) { | 
                                                        |
| 133 | - $currentToken = $this->session->get(self::stateName);  | 
                                                        |
| 134 | -		if(!is_string($stateToken) || !is_string($currentToken)) { | 
                                                        |
| 135 | - return false;  | 
                                                        |
| 136 | - }  | 
                                                        |
| 137 | - return hash_equals($currentToken, $stateToken);  | 
                                                        |
| 138 | - }  | 
                                                        |
| 139 | -  | 
                                                        |
| 140 | - /**  | 
                                                        |
| 141 | - * @return StandaloneTemplateResponse  | 
                                                        |
| 142 | - */  | 
                                                        |
| 143 | -	private function stateTokenForbiddenResponse() { | 
                                                        |
| 144 | - $response = new StandaloneTemplateResponse(  | 
                                                        |
| 145 | - $this->appName,  | 
                                                        |
| 146 | - '403',  | 
                                                        |
| 147 | - [  | 
                                                        |
| 148 | -				'message' => $this->l10n->t('State token does not match'), | 
                                                        |
| 149 | - ],  | 
                                                        |
| 150 | - 'guest'  | 
                                                        |
| 151 | - );  | 
                                                        |
| 152 | - $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 153 | - return $response;  | 
                                                        |
| 154 | - }  | 
                                                        |
| 155 | -  | 
                                                        |
| 156 | - /**  | 
                                                        |
| 157 | - * @PublicPage  | 
                                                        |
| 158 | - * @NoCSRFRequired  | 
                                                        |
| 159 | - * @UseSession  | 
                                                        |
| 160 | - *  | 
                                                        |
| 161 | - * @param string $clientIdentifier  | 
                                                        |
| 162 | - *  | 
                                                        |
| 163 | - * @return StandaloneTemplateResponse  | 
                                                        |
| 164 | - */  | 
                                                        |
| 165 | -	public function showAuthPickerPage($clientIdentifier = '') { | 
                                                        |
| 166 | - $clientName = $this->getClientName();  | 
                                                        |
| 167 | - $client = null;  | 
                                                        |
| 168 | -		if($clientIdentifier !== '') { | 
                                                        |
| 169 | - $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 170 | - $clientName = $client->getName();  | 
                                                        |
| 171 | - }  | 
                                                        |
| 172 | -  | 
                                                        |
| 173 | - // No valid clientIdentifier given and no valid API Request (APIRequest header not set)  | 
                                                        |
| 174 | -		$clientRequest = $this->request->getHeader('OCS-APIREQUEST'); | 
                                                        |
| 175 | -		if ($clientRequest !== 'true' && $client === null) { | 
                                                        |
| 176 | - return new StandaloneTemplateResponse(  | 
                                                        |
| 177 | - $this->appName,  | 
                                                        |
| 178 | - 'error',  | 
                                                        |
| 179 | - [  | 
                                                        |
| 180 | - 'errors' =>  | 
                                                        |
| 181 | - [  | 
                                                        |
| 182 | - [  | 
                                                        |
| 183 | - 'error' => 'Access Forbidden',  | 
                                                        |
| 184 | - 'hint' => 'Invalid request',  | 
                                                        |
| 185 | - ],  | 
                                                        |
| 186 | - ],  | 
                                                        |
| 187 | - ],  | 
                                                        |
| 188 | - 'guest'  | 
                                                        |
| 189 | - );  | 
                                                        |
| 190 | - }  | 
                                                        |
| 191 | -  | 
                                                        |
| 192 | - $stateToken = $this->random->generate(  | 
                                                        |
| 193 | - 64,  | 
                                                        |
| 194 | - ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS  | 
                                                        |
| 195 | - );  | 
                                                        |
| 196 | - $this->session->set(self::stateName, $stateToken);  | 
                                                        |
| 197 | -  | 
                                                        |
| 198 | - return new StandaloneTemplateResponse(  | 
                                                        |
| 199 | - $this->appName,  | 
                                                        |
| 200 | - 'loginflow/authpicker',  | 
                                                        |
| 201 | - [  | 
                                                        |
| 202 | - 'client' => $clientName,  | 
                                                        |
| 203 | - 'clientIdentifier' => $clientIdentifier,  | 
                                                        |
| 204 | - 'instanceName' => $this->defaults->getName(),  | 
                                                        |
| 205 | - 'urlGenerator' => $this->urlGenerator,  | 
                                                        |
| 206 | - 'stateToken' => $stateToken,  | 
                                                        |
| 207 | - 'serverHost' => $this->getServerPath(),  | 
                                                        |
| 208 | -				'oauthState' => $this->session->get('oauth.state'), | 
                                                        |
| 209 | - ],  | 
                                                        |
| 210 | - 'guest'  | 
                                                        |
| 211 | - );  | 
                                                        |
| 212 | - }  | 
                                                        |
| 213 | -  | 
                                                        |
| 214 | - /**  | 
                                                        |
| 215 | - * @NoAdminRequired  | 
                                                        |
| 216 | - * @NoCSRFRequired  | 
                                                        |
| 217 | - * @NoSameSiteCookieRequired  | 
                                                        |
| 218 | - * @UseSession  | 
                                                        |
| 219 | - *  | 
                                                        |
| 220 | - * @param string $stateToken  | 
                                                        |
| 221 | - * @param string $clientIdentifier  | 
                                                        |
| 222 | - * @return StandaloneTemplateResponse  | 
                                                        |
| 223 | - */  | 
                                                        |
| 224 | - public function grantPage($stateToken = '',  | 
                                                        |
| 225 | -								 $clientIdentifier = '') { | 
                                                        |
| 226 | -		if(!$this->isValidToken($stateToken)) { | 
                                                        |
| 227 | - return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 228 | - }  | 
                                                        |
| 229 | -  | 
                                                        |
| 230 | - $clientName = $this->getClientName();  | 
                                                        |
| 231 | - $client = null;  | 
                                                        |
| 232 | -		if($clientIdentifier !== '') { | 
                                                        |
| 233 | - $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 234 | - $clientName = $client->getName();  | 
                                                        |
| 235 | - }  | 
                                                        |
| 236 | -  | 
                                                        |
| 237 | - return new StandaloneTemplateResponse(  | 
                                                        |
| 238 | - $this->appName,  | 
                                                        |
| 239 | - 'loginflow/grant',  | 
                                                        |
| 240 | - [  | 
                                                        |
| 241 | - 'client' => $clientName,  | 
                                                        |
| 242 | - 'clientIdentifier' => $clientIdentifier,  | 
                                                        |
| 243 | - 'instanceName' => $this->defaults->getName(),  | 
                                                        |
| 244 | - 'urlGenerator' => $this->urlGenerator,  | 
                                                        |
| 245 | - 'stateToken' => $stateToken,  | 
                                                        |
| 246 | - 'serverHost' => $this->getServerPath(),  | 
                                                        |
| 247 | -				'oauthState' => $this->session->get('oauth.state'), | 
                                                        |
| 248 | - ],  | 
                                                        |
| 249 | - 'guest'  | 
                                                        |
| 250 | - );  | 
                                                        |
| 251 | - }  | 
                                                        |
| 252 | -  | 
                                                        |
| 253 | - /**  | 
                                                        |
| 254 | - * @NoAdminRequired  | 
                                                        |
| 255 | - * @UseSession  | 
                                                        |
| 256 | - *  | 
                                                        |
| 257 | - * @param string $stateToken  | 
                                                        |
| 258 | - * @param string $clientIdentifier  | 
                                                        |
| 259 | - * @return Http\RedirectResponse|Response  | 
                                                        |
| 260 | - */  | 
                                                        |
| 261 | - public function generateAppPassword($stateToken,  | 
                                                        |
| 262 | -										$clientIdentifier = '') { | 
                                                        |
| 263 | -		if(!$this->isValidToken($stateToken)) { | 
                                                        |
| 264 | - $this->session->remove(self::stateName);  | 
                                                        |
| 265 | - return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 266 | - }  | 
                                                        |
| 267 | -  | 
                                                        |
| 268 | - $this->session->remove(self::stateName);  | 
                                                        |
| 269 | -  | 
                                                        |
| 270 | -		try { | 
                                                        |
| 271 | - $sessionId = $this->session->getId();  | 
                                                        |
| 272 | -		} catch (SessionNotAvailableException $ex) { | 
                                                        |
| 273 | - $response = new Response();  | 
                                                        |
| 274 | - $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 275 | - return $response;  | 
                                                        |
| 276 | - }  | 
                                                        |
| 277 | -  | 
                                                        |
| 278 | -		try { | 
                                                        |
| 279 | - $sessionToken = $this->tokenProvider->getToken($sessionId);  | 
                                                        |
| 280 | - $loginName = $sessionToken->getLoginName();  | 
                                                        |
| 281 | -			try { | 
                                                        |
| 282 | - $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);  | 
                                                        |
| 283 | -			} catch (PasswordlessTokenException $ex) { | 
                                                        |
| 284 | - $password = null;  | 
                                                        |
| 285 | - }  | 
                                                        |
| 286 | -		} catch (InvalidTokenException $ex) { | 
                                                        |
| 287 | - $response = new Response();  | 
                                                        |
| 288 | - $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 289 | - return $response;  | 
                                                        |
| 290 | - }  | 
                                                        |
| 291 | -  | 
                                                        |
| 292 | - $clientName = $this->getClientName();  | 
                                                        |
| 293 | - $client = false;  | 
                                                        |
| 294 | -		if($clientIdentifier !== '') { | 
                                                        |
| 295 | - $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 296 | - $clientName = $client->getName();  | 
                                                        |
| 297 | - }  | 
                                                        |
| 298 | -  | 
                                                        |
| 299 | - $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 300 | - $uid = $this->userSession->getUser()->getUID();  | 
                                                        |
| 301 | - $generatedToken = $this->tokenProvider->generateToken(  | 
                                                        |
| 302 | - $token,  | 
                                                        |
| 303 | - $uid,  | 
                                                        |
| 304 | - $loginName,  | 
                                                        |
| 305 | - $password,  | 
                                                        |
| 306 | - $clientName,  | 
                                                        |
| 307 | - IToken::PERMANENT_TOKEN,  | 
                                                        |
| 308 | - IToken::DO_NOT_REMEMBER  | 
                                                        |
| 309 | - );  | 
                                                        |
| 310 | -  | 
                                                        |
| 311 | -		if($client) { | 
                                                        |
| 312 | - $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 313 | - $accessToken = new AccessToken();  | 
                                                        |
| 314 | - $accessToken->setClientId($client->getId());  | 
                                                        |
| 315 | - $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));  | 
                                                        |
| 316 | -			$accessToken->setHashedCode(hash('sha512', $code)); | 
                                                        |
| 317 | - $accessToken->setTokenId($generatedToken->getId());  | 
                                                        |
| 318 | - $this->accessTokenMapper->insert($accessToken);  | 
                                                        |
| 319 | -  | 
                                                        |
| 320 | - $redirectUri = sprintf(  | 
                                                        |
| 321 | - '%s?state=%s&code=%s',  | 
                                                        |
| 322 | - $client->getRedirectUri(),  | 
                                                        |
| 323 | -				urlencode($this->session->get('oauth.state')), | 
                                                        |
| 324 | - urlencode($code)  | 
                                                        |
| 325 | - );  | 
                                                        |
| 326 | -			$this->session->remove('oauth.state'); | 
                                                        |
| 327 | -		} else { | 
                                                        |
| 328 | - $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);  | 
                                                        |
| 329 | -  | 
                                                        |
| 330 | - // Clear the token from the login here  | 
                                                        |
| 331 | - $this->tokenProvider->invalidateToken($sessionId);  | 
                                                        |
| 332 | - }  | 
                                                        |
| 333 | -  | 
                                                        |
| 334 | - $event = new GenericEvent($generatedToken);  | 
                                                        |
| 335 | -		$this->eventDispatcher->dispatch('app_password_created', $event); | 
                                                        |
| 336 | -  | 
                                                        |
| 337 | - return new Http\RedirectResponse($redirectUri);  | 
                                                        |
| 338 | - }  | 
                                                        |
| 339 | -  | 
                                                        |
| 340 | - /**  | 
                                                        |
| 341 | - * @PublicPage  | 
                                                        |
| 342 | - */  | 
                                                        |
| 343 | -	public function apptokenRedirect(string $stateToken, string $user, string $password) { | 
                                                        |
| 344 | -		if (!$this->isValidToken($stateToken)) { | 
                                                        |
| 345 | - return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 346 | - }  | 
                                                        |
| 347 | -  | 
                                                        |
| 348 | - $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);  | 
                                                        |
| 349 | - return new Http\RedirectResponse($redirectUri);  | 
                                                        |
| 350 | - }  | 
                                                        |
| 351 | -  | 
                                                        |
| 352 | -	private function getServerPath(): string { | 
                                                        |
| 353 | - $serverPostfix = '';  | 
                                                        |
| 354 | -  | 
                                                        |
| 355 | -		if (strpos($this->request->getRequestUri(), '/index.php') !== false) { | 
                                                        |
| 356 | - $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));  | 
                                                        |
| 357 | -		} else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) { | 
                                                        |
| 358 | - $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));  | 
                                                        |
| 359 | - }  | 
                                                        |
| 360 | -  | 
                                                        |
| 361 | - $protocol = $this->request->getServerProtocol();  | 
                                                        |
| 362 | -  | 
                                                        |
| 363 | -		if ($protocol !== "https") { | 
                                                        |
| 364 | -			$xForwardedProto = $this->request->getHeader('X-Forwarded-Proto'); | 
                                                        |
| 365 | -			$xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl'); | 
                                                        |
| 366 | -			if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') { | 
                                                        |
| 367 | - $protocol = 'https';  | 
                                                        |
| 368 | - }  | 
                                                        |
| 369 | - }  | 
                                                        |
| 370 | -  | 
                                                        |
| 371 | - return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;  | 
                                                        |
| 372 | - }  | 
                                                        |
| 53 | + /** @var IUserSession */  | 
                                                        |
| 54 | + private $userSession;  | 
                                                        |
| 55 | + /** @var IL10N */  | 
                                                        |
| 56 | + private $l10n;  | 
                                                        |
| 57 | + /** @var Defaults */  | 
                                                        |
| 58 | + private $defaults;  | 
                                                        |
| 59 | + /** @var ISession */  | 
                                                        |
| 60 | + private $session;  | 
                                                        |
| 61 | + /** @var IProvider */  | 
                                                        |
| 62 | + private $tokenProvider;  | 
                                                        |
| 63 | + /** @var ISecureRandom */  | 
                                                        |
| 64 | + private $random;  | 
                                                        |
| 65 | + /** @var IURLGenerator */  | 
                                                        |
| 66 | + private $urlGenerator;  | 
                                                        |
| 67 | + /** @var ClientMapper */  | 
                                                        |
| 68 | + private $clientMapper;  | 
                                                        |
| 69 | + /** @var AccessTokenMapper */  | 
                                                        |
| 70 | + private $accessTokenMapper;  | 
                                                        |
| 71 | + /** @var ICrypto */  | 
                                                        |
| 72 | + private $crypto;  | 
                                                        |
| 73 | + /** @var EventDispatcherInterface */  | 
                                                        |
| 74 | + private $eventDispatcher;  | 
                                                        |
| 75 | +  | 
                                                        |
| 76 | + const stateName = 'client.flow.state.token';  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + /**  | 
                                                        |
| 79 | + * @param string $appName  | 
                                                        |
| 80 | + * @param IRequest $request  | 
                                                        |
| 81 | + * @param IUserSession $userSession  | 
                                                        |
| 82 | + * @param IL10N $l10n  | 
                                                        |
| 83 | + * @param Defaults $defaults  | 
                                                        |
| 84 | + * @param ISession $session  | 
                                                        |
| 85 | + * @param IProvider $tokenProvider  | 
                                                        |
| 86 | + * @param ISecureRandom $random  | 
                                                        |
| 87 | + * @param IURLGenerator $urlGenerator  | 
                                                        |
| 88 | + * @param ClientMapper $clientMapper  | 
                                                        |
| 89 | + * @param AccessTokenMapper $accessTokenMapper  | 
                                                        |
| 90 | + * @param ICrypto $crypto  | 
                                                        |
| 91 | + * @param EventDispatcherInterface $eventDispatcher  | 
                                                        |
| 92 | + */  | 
                                                        |
| 93 | + public function __construct($appName,  | 
                                                        |
| 94 | + IRequest $request,  | 
                                                        |
| 95 | + IUserSession $userSession,  | 
                                                        |
| 96 | + IL10N $l10n,  | 
                                                        |
| 97 | + Defaults $defaults,  | 
                                                        |
| 98 | + ISession $session,  | 
                                                        |
| 99 | + IProvider $tokenProvider,  | 
                                                        |
| 100 | + ISecureRandom $random,  | 
                                                        |
| 101 | + IURLGenerator $urlGenerator,  | 
                                                        |
| 102 | + ClientMapper $clientMapper,  | 
                                                        |
| 103 | + AccessTokenMapper $accessTokenMapper,  | 
                                                        |
| 104 | + ICrypto $crypto,  | 
                                                        |
| 105 | +                                EventDispatcherInterface $eventDispatcher) { | 
                                                        |
| 106 | + parent::__construct($appName, $request);  | 
                                                        |
| 107 | + $this->userSession = $userSession;  | 
                                                        |
| 108 | + $this->l10n = $l10n;  | 
                                                        |
| 109 | + $this->defaults = $defaults;  | 
                                                        |
| 110 | + $this->session = $session;  | 
                                                        |
| 111 | + $this->tokenProvider = $tokenProvider;  | 
                                                        |
| 112 | + $this->random = $random;  | 
                                                        |
| 113 | + $this->urlGenerator = $urlGenerator;  | 
                                                        |
| 114 | + $this->clientMapper = $clientMapper;  | 
                                                        |
| 115 | + $this->accessTokenMapper = $accessTokenMapper;  | 
                                                        |
| 116 | + $this->crypto = $crypto;  | 
                                                        |
| 117 | + $this->eventDispatcher = $eventDispatcher;  | 
                                                        |
| 118 | + }  | 
                                                        |
| 119 | +  | 
                                                        |
| 120 | + /**  | 
                                                        |
| 121 | + * @return string  | 
                                                        |
| 122 | + */  | 
                                                        |
| 123 | +    private function getClientName() { | 
                                                        |
| 124 | +        $userAgent = $this->request->getHeader('USER_AGENT'); | 
                                                        |
| 125 | + return $userAgent !== '' ? $userAgent : 'unknown';  | 
                                                        |
| 126 | + }  | 
                                                        |
| 127 | +  | 
                                                        |
| 128 | + /**  | 
                                                        |
| 129 | + * @param string $stateToken  | 
                                                        |
| 130 | + * @return bool  | 
                                                        |
| 131 | + */  | 
                                                        |
| 132 | +    private function isValidToken($stateToken) { | 
                                                        |
| 133 | + $currentToken = $this->session->get(self::stateName);  | 
                                                        |
| 134 | +        if(!is_string($stateToken) || !is_string($currentToken)) { | 
                                                        |
| 135 | + return false;  | 
                                                        |
| 136 | + }  | 
                                                        |
| 137 | + return hash_equals($currentToken, $stateToken);  | 
                                                        |
| 138 | + }  | 
                                                        |
| 139 | +  | 
                                                        |
| 140 | + /**  | 
                                                        |
| 141 | + * @return StandaloneTemplateResponse  | 
                                                        |
| 142 | + */  | 
                                                        |
| 143 | +    private function stateTokenForbiddenResponse() { | 
                                                        |
| 144 | + $response = new StandaloneTemplateResponse(  | 
                                                        |
| 145 | + $this->appName,  | 
                                                        |
| 146 | + '403',  | 
                                                        |
| 147 | + [  | 
                                                        |
| 148 | +                'message' => $this->l10n->t('State token does not match'), | 
                                                        |
| 149 | + ],  | 
                                                        |
| 150 | + 'guest'  | 
                                                        |
| 151 | + );  | 
                                                        |
| 152 | + $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 153 | + return $response;  | 
                                                        |
| 154 | + }  | 
                                                        |
| 155 | +  | 
                                                        |
| 156 | + /**  | 
                                                        |
| 157 | + * @PublicPage  | 
                                                        |
| 158 | + * @NoCSRFRequired  | 
                                                        |
| 159 | + * @UseSession  | 
                                                        |
| 160 | + *  | 
                                                        |
| 161 | + * @param string $clientIdentifier  | 
                                                        |
| 162 | + *  | 
                                                        |
| 163 | + * @return StandaloneTemplateResponse  | 
                                                        |
| 164 | + */  | 
                                                        |
| 165 | +    public function showAuthPickerPage($clientIdentifier = '') { | 
                                                        |
| 166 | + $clientName = $this->getClientName();  | 
                                                        |
| 167 | + $client = null;  | 
                                                        |
| 168 | +        if($clientIdentifier !== '') { | 
                                                        |
| 169 | + $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 170 | + $clientName = $client->getName();  | 
                                                        |
| 171 | + }  | 
                                                        |
| 172 | +  | 
                                                        |
| 173 | + // No valid clientIdentifier given and no valid API Request (APIRequest header not set)  | 
                                                        |
| 174 | +        $clientRequest = $this->request->getHeader('OCS-APIREQUEST'); | 
                                                        |
| 175 | +        if ($clientRequest !== 'true' && $client === null) { | 
                                                        |
| 176 | + return new StandaloneTemplateResponse(  | 
                                                        |
| 177 | + $this->appName,  | 
                                                        |
| 178 | + 'error',  | 
                                                        |
| 179 | + [  | 
                                                        |
| 180 | + 'errors' =>  | 
                                                        |
| 181 | + [  | 
                                                        |
| 182 | + [  | 
                                                        |
| 183 | + 'error' => 'Access Forbidden',  | 
                                                        |
| 184 | + 'hint' => 'Invalid request',  | 
                                                        |
| 185 | + ],  | 
                                                        |
| 186 | + ],  | 
                                                        |
| 187 | + ],  | 
                                                        |
| 188 | + 'guest'  | 
                                                        |
| 189 | + );  | 
                                                        |
| 190 | + }  | 
                                                        |
| 191 | +  | 
                                                        |
| 192 | + $stateToken = $this->random->generate(  | 
                                                        |
| 193 | + 64,  | 
                                                        |
| 194 | + ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_DIGITS  | 
                                                        |
| 195 | + );  | 
                                                        |
| 196 | + $this->session->set(self::stateName, $stateToken);  | 
                                                        |
| 197 | +  | 
                                                        |
| 198 | + return new StandaloneTemplateResponse(  | 
                                                        |
| 199 | + $this->appName,  | 
                                                        |
| 200 | + 'loginflow/authpicker',  | 
                                                        |
| 201 | + [  | 
                                                        |
| 202 | + 'client' => $clientName,  | 
                                                        |
| 203 | + 'clientIdentifier' => $clientIdentifier,  | 
                                                        |
| 204 | + 'instanceName' => $this->defaults->getName(),  | 
                                                        |
| 205 | + 'urlGenerator' => $this->urlGenerator,  | 
                                                        |
| 206 | + 'stateToken' => $stateToken,  | 
                                                        |
| 207 | + 'serverHost' => $this->getServerPath(),  | 
                                                        |
| 208 | +                'oauthState' => $this->session->get('oauth.state'), | 
                                                        |
| 209 | + ],  | 
                                                        |
| 210 | + 'guest'  | 
                                                        |
| 211 | + );  | 
                                                        |
| 212 | + }  | 
                                                        |
| 213 | +  | 
                                                        |
| 214 | + /**  | 
                                                        |
| 215 | + * @NoAdminRequired  | 
                                                        |
| 216 | + * @NoCSRFRequired  | 
                                                        |
| 217 | + * @NoSameSiteCookieRequired  | 
                                                        |
| 218 | + * @UseSession  | 
                                                        |
| 219 | + *  | 
                                                        |
| 220 | + * @param string $stateToken  | 
                                                        |
| 221 | + * @param string $clientIdentifier  | 
                                                        |
| 222 | + * @return StandaloneTemplateResponse  | 
                                                        |
| 223 | + */  | 
                                                        |
| 224 | + public function grantPage($stateToken = '',  | 
                                                        |
| 225 | +                                    $clientIdentifier = '') { | 
                                                        |
| 226 | +        if(!$this->isValidToken($stateToken)) { | 
                                                        |
| 227 | + return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 228 | + }  | 
                                                        |
| 229 | +  | 
                                                        |
| 230 | + $clientName = $this->getClientName();  | 
                                                        |
| 231 | + $client = null;  | 
                                                        |
| 232 | +        if($clientIdentifier !== '') { | 
                                                        |
| 233 | + $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 234 | + $clientName = $client->getName();  | 
                                                        |
| 235 | + }  | 
                                                        |
| 236 | +  | 
                                                        |
| 237 | + return new StandaloneTemplateResponse(  | 
                                                        |
| 238 | + $this->appName,  | 
                                                        |
| 239 | + 'loginflow/grant',  | 
                                                        |
| 240 | + [  | 
                                                        |
| 241 | + 'client' => $clientName,  | 
                                                        |
| 242 | + 'clientIdentifier' => $clientIdentifier,  | 
                                                        |
| 243 | + 'instanceName' => $this->defaults->getName(),  | 
                                                        |
| 244 | + 'urlGenerator' => $this->urlGenerator,  | 
                                                        |
| 245 | + 'stateToken' => $stateToken,  | 
                                                        |
| 246 | + 'serverHost' => $this->getServerPath(),  | 
                                                        |
| 247 | +                'oauthState' => $this->session->get('oauth.state'), | 
                                                        |
| 248 | + ],  | 
                                                        |
| 249 | + 'guest'  | 
                                                        |
| 250 | + );  | 
                                                        |
| 251 | + }  | 
                                                        |
| 252 | +  | 
                                                        |
| 253 | + /**  | 
                                                        |
| 254 | + * @NoAdminRequired  | 
                                                        |
| 255 | + * @UseSession  | 
                                                        |
| 256 | + *  | 
                                                        |
| 257 | + * @param string $stateToken  | 
                                                        |
| 258 | + * @param string $clientIdentifier  | 
                                                        |
| 259 | + * @return Http\RedirectResponse|Response  | 
                                                        |
| 260 | + */  | 
                                                        |
| 261 | + public function generateAppPassword($stateToken,  | 
                                                        |
| 262 | +                                        $clientIdentifier = '') { | 
                                                        |
| 263 | +        if(!$this->isValidToken($stateToken)) { | 
                                                        |
| 264 | + $this->session->remove(self::stateName);  | 
                                                        |
| 265 | + return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 266 | + }  | 
                                                        |
| 267 | +  | 
                                                        |
| 268 | + $this->session->remove(self::stateName);  | 
                                                        |
| 269 | +  | 
                                                        |
| 270 | +        try { | 
                                                        |
| 271 | + $sessionId = $this->session->getId();  | 
                                                        |
| 272 | +        } catch (SessionNotAvailableException $ex) { | 
                                                        |
| 273 | + $response = new Response();  | 
                                                        |
| 274 | + $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 275 | + return $response;  | 
                                                        |
| 276 | + }  | 
                                                        |
| 277 | +  | 
                                                        |
| 278 | +        try { | 
                                                        |
| 279 | + $sessionToken = $this->tokenProvider->getToken($sessionId);  | 
                                                        |
| 280 | + $loginName = $sessionToken->getLoginName();  | 
                                                        |
| 281 | +            try { | 
                                                        |
| 282 | + $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);  | 
                                                        |
| 283 | +            } catch (PasswordlessTokenException $ex) { | 
                                                        |
| 284 | + $password = null;  | 
                                                        |
| 285 | + }  | 
                                                        |
| 286 | +        } catch (InvalidTokenException $ex) { | 
                                                        |
| 287 | + $response = new Response();  | 
                                                        |
| 288 | + $response->setStatus(Http::STATUS_FORBIDDEN);  | 
                                                        |
| 289 | + return $response;  | 
                                                        |
| 290 | + }  | 
                                                        |
| 291 | +  | 
                                                        |
| 292 | + $clientName = $this->getClientName();  | 
                                                        |
| 293 | + $client = false;  | 
                                                        |
| 294 | +        if($clientIdentifier !== '') { | 
                                                        |
| 295 | + $client = $this->clientMapper->getByIdentifier($clientIdentifier);  | 
                                                        |
| 296 | + $clientName = $client->getName();  | 
                                                        |
| 297 | + }  | 
                                                        |
| 298 | +  | 
                                                        |
| 299 | + $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 300 | + $uid = $this->userSession->getUser()->getUID();  | 
                                                        |
| 301 | + $generatedToken = $this->tokenProvider->generateToken(  | 
                                                        |
| 302 | + $token,  | 
                                                        |
| 303 | + $uid,  | 
                                                        |
| 304 | + $loginName,  | 
                                                        |
| 305 | + $password,  | 
                                                        |
| 306 | + $clientName,  | 
                                                        |
| 307 | + IToken::PERMANENT_TOKEN,  | 
                                                        |
| 308 | + IToken::DO_NOT_REMEMBER  | 
                                                        |
| 309 | + );  | 
                                                        |
| 310 | +  | 
                                                        |
| 311 | +        if($client) { | 
                                                        |
| 312 | + $code = $this->random->generate(128, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 313 | + $accessToken = new AccessToken();  | 
                                                        |
| 314 | + $accessToken->setClientId($client->getId());  | 
                                                        |
| 315 | + $accessToken->setEncryptedToken($this->crypto->encrypt($token, $code));  | 
                                                        |
| 316 | +            $accessToken->setHashedCode(hash('sha512', $code)); | 
                                                        |
| 317 | + $accessToken->setTokenId($generatedToken->getId());  | 
                                                        |
| 318 | + $this->accessTokenMapper->insert($accessToken);  | 
                                                        |
| 319 | +  | 
                                                        |
| 320 | + $redirectUri = sprintf(  | 
                                                        |
| 321 | + '%s?state=%s&code=%s',  | 
                                                        |
| 322 | + $client->getRedirectUri(),  | 
                                                        |
| 323 | +                urlencode($this->session->get('oauth.state')), | 
                                                        |
| 324 | + urlencode($code)  | 
                                                        |
| 325 | + );  | 
                                                        |
| 326 | +            $this->session->remove('oauth.state'); | 
                                                        |
| 327 | +        } else { | 
                                                        |
| 328 | + $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($loginName) . '&password:' . urlencode($token);  | 
                                                        |
| 329 | +  | 
                                                        |
| 330 | + // Clear the token from the login here  | 
                                                        |
| 331 | + $this->tokenProvider->invalidateToken($sessionId);  | 
                                                        |
| 332 | + }  | 
                                                        |
| 333 | +  | 
                                                        |
| 334 | + $event = new GenericEvent($generatedToken);  | 
                                                        |
| 335 | +        $this->eventDispatcher->dispatch('app_password_created', $event); | 
                                                        |
| 336 | +  | 
                                                        |
| 337 | + return new Http\RedirectResponse($redirectUri);  | 
                                                        |
| 338 | + }  | 
                                                        |
| 339 | +  | 
                                                        |
| 340 | + /**  | 
                                                        |
| 341 | + * @PublicPage  | 
                                                        |
| 342 | + */  | 
                                                        |
| 343 | +    public function apptokenRedirect(string $stateToken, string $user, string $password) { | 
                                                        |
| 344 | +        if (!$this->isValidToken($stateToken)) { | 
                                                        |
| 345 | + return $this->stateTokenForbiddenResponse();  | 
                                                        |
| 346 | + }  | 
                                                        |
| 347 | +  | 
                                                        |
| 348 | + $redirectUri = 'nc://login/server:' . $this->getServerPath() . '&user:' . urlencode($user) . '&password:' . urlencode($password);  | 
                                                        |
| 349 | + return new Http\RedirectResponse($redirectUri);  | 
                                                        |
| 350 | + }  | 
                                                        |
| 351 | +  | 
                                                        |
| 352 | +    private function getServerPath(): string { | 
                                                        |
| 353 | + $serverPostfix = '';  | 
                                                        |
| 354 | +  | 
                                                        |
| 355 | +        if (strpos($this->request->getRequestUri(), '/index.php') !== false) { | 
                                                        |
| 356 | + $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/index.php'));  | 
                                                        |
| 357 | +        } else if (strpos($this->request->getRequestUri(), '/login/flow') !== false) { | 
                                                        |
| 358 | + $serverPostfix = substr($this->request->getRequestUri(), 0, strpos($this->request->getRequestUri(), '/login/flow'));  | 
                                                        |
| 359 | + }  | 
                                                        |
| 360 | +  | 
                                                        |
| 361 | + $protocol = $this->request->getServerProtocol();  | 
                                                        |
| 362 | +  | 
                                                        |
| 363 | +        if ($protocol !== "https") { | 
                                                        |
| 364 | +            $xForwardedProto = $this->request->getHeader('X-Forwarded-Proto'); | 
                                                        |
| 365 | +            $xForwardedSSL = $this->request->getHeader('X-Forwarded-Ssl'); | 
                                                        |
| 366 | +            if ($xForwardedProto === 'https' || $xForwardedSSL === 'on') { | 
                                                        |
| 367 | + $protocol = 'https';  | 
                                                        |
| 368 | + }  | 
                                                        |
| 369 | + }  | 
                                                        |
| 370 | +  | 
                                                        |
| 371 | + return $protocol . "://" . $this->request->getServerHost() . $serverPostfix;  | 
                                                        |
| 372 | + }  | 
                                                        |
| 373 | 373 | }  | 
                                                        
@@ -39,80 +39,80 @@  | 
                                                    ||
| 39 | 39 | |
| 40 | 40 |  class AppPasswordController extends \OCP\AppFramework\OCSController { | 
                                                        
| 41 | 41 | |
| 42 | - /** @var ISession */  | 
                                                        |
| 43 | - private $session;  | 
                                                        |
| 44 | -  | 
                                                        |
| 45 | - /** @var ISecureRandom */  | 
                                                        |
| 46 | - private $random;  | 
                                                        |
| 47 | -  | 
                                                        |
| 48 | - /** @var IProvider */  | 
                                                        |
| 49 | - private $tokenProvider;  | 
                                                        |
| 50 | -  | 
                                                        |
| 51 | - /** @var IStore */  | 
                                                        |
| 52 | - private $credentialStore;  | 
                                                        |
| 53 | -  | 
                                                        |
| 54 | - /** @var EventDispatcherInterface */  | 
                                                        |
| 55 | - private $eventDispatcher;  | 
                                                        |
| 56 | -  | 
                                                        |
| 57 | - public function __construct(string $appName,  | 
                                                        |
| 58 | - IRequest $request,  | 
                                                        |
| 59 | - ISession $session,  | 
                                                        |
| 60 | - ISecureRandom $random,  | 
                                                        |
| 61 | - IProvider $tokenProvider,  | 
                                                        |
| 62 | - IStore $credentialStore,  | 
                                                        |
| 63 | -								EventDispatcherInterface $eventDispatcher) { | 
                                                        |
| 64 | - parent::__construct($appName, $request);  | 
                                                        |
| 65 | -  | 
                                                        |
| 66 | - $this->session = $session;  | 
                                                        |
| 67 | - $this->random = $random;  | 
                                                        |
| 68 | - $this->tokenProvider = $tokenProvider;  | 
                                                        |
| 69 | - $this->credentialStore = $credentialStore;  | 
                                                        |
| 70 | - $this->eventDispatcher = $eventDispatcher;  | 
                                                        |
| 71 | - }  | 
                                                        |
| 72 | -  | 
                                                        |
| 73 | - /**  | 
                                                        |
| 74 | - * @NoAdminRequired  | 
                                                        |
| 75 | - *  | 
                                                        |
| 76 | - * @return DataResponse  | 
                                                        |
| 77 | - * @throws OCSForbiddenException  | 
                                                        |
| 78 | - */  | 
                                                        |
| 79 | -	public function getAppPassword(): DataResponse { | 
                                                        |
| 80 | - // We do not allow the creation of new tokens if this is an app password  | 
                                                        |
| 81 | -		if ($this->session->exists('app_password')) { | 
                                                        |
| 82 | -			throw new OCSForbiddenException('You cannot request an new apppassword with an apppassword'); | 
                                                        |
| 83 | - }  | 
                                                        |
| 84 | -  | 
                                                        |
| 85 | -		try { | 
                                                        |
| 86 | - $credentials = $this->credentialStore->getLoginCredentials();  | 
                                                        |
| 87 | -		} catch (CredentialsUnavailableException $e) { | 
                                                        |
| 88 | - throw new OCSForbiddenException();  | 
                                                        |
| 89 | - }  | 
                                                        |
| 90 | -  | 
                                                        |
| 91 | -		try { | 
                                                        |
| 92 | - $password = $credentials->getPassword();  | 
                                                        |
| 93 | -		} catch (PasswordUnavailableException $e) { | 
                                                        |
| 94 | - $password = null;  | 
                                                        |
| 95 | - }  | 
                                                        |
| 96 | -  | 
                                                        |
| 97 | -		$userAgent = $this->request->getHeader('USER_AGENT'); | 
                                                        |
| 98 | -  | 
                                                        |
| 99 | - $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 100 | -  | 
                                                        |
| 101 | - $generatedToken = $this->tokenProvider->generateToken(  | 
                                                        |
| 102 | - $token,  | 
                                                        |
| 103 | - $credentials->getUID(),  | 
                                                        |
| 104 | - $credentials->getLoginName(),  | 
                                                        |
| 105 | - $password,  | 
                                                        |
| 106 | - $userAgent,  | 
                                                        |
| 107 | - IToken::PERMANENT_TOKEN,  | 
                                                        |
| 108 | - IToken::DO_NOT_REMEMBER  | 
                                                        |
| 109 | - );  | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | - $event = new GenericEvent($generatedToken);  | 
                                                        |
| 112 | -		$this->eventDispatcher->dispatch('app_password_created', $event); | 
                                                        |
| 113 | -  | 
                                                        |
| 114 | - return new DataResponse([  | 
                                                        |
| 115 | - 'apppassword' => $token  | 
                                                        |
| 116 | - ]);  | 
                                                        |
| 117 | - }  | 
                                                        |
| 42 | + /** @var ISession */  | 
                                                        |
| 43 | + private $session;  | 
                                                        |
| 44 | +  | 
                                                        |
| 45 | + /** @var ISecureRandom */  | 
                                                        |
| 46 | + private $random;  | 
                                                        |
| 47 | +  | 
                                                        |
| 48 | + /** @var IProvider */  | 
                                                        |
| 49 | + private $tokenProvider;  | 
                                                        |
| 50 | +  | 
                                                        |
| 51 | + /** @var IStore */  | 
                                                        |
| 52 | + private $credentialStore;  | 
                                                        |
| 53 | +  | 
                                                        |
| 54 | + /** @var EventDispatcherInterface */  | 
                                                        |
| 55 | + private $eventDispatcher;  | 
                                                        |
| 56 | +  | 
                                                        |
| 57 | + public function __construct(string $appName,  | 
                                                        |
| 58 | + IRequest $request,  | 
                                                        |
| 59 | + ISession $session,  | 
                                                        |
| 60 | + ISecureRandom $random,  | 
                                                        |
| 61 | + IProvider $tokenProvider,  | 
                                                        |
| 62 | + IStore $credentialStore,  | 
                                                        |
| 63 | +                                EventDispatcherInterface $eventDispatcher) { | 
                                                        |
| 64 | + parent::__construct($appName, $request);  | 
                                                        |
| 65 | +  | 
                                                        |
| 66 | + $this->session = $session;  | 
                                                        |
| 67 | + $this->random = $random;  | 
                                                        |
| 68 | + $this->tokenProvider = $tokenProvider;  | 
                                                        |
| 69 | + $this->credentialStore = $credentialStore;  | 
                                                        |
| 70 | + $this->eventDispatcher = $eventDispatcher;  | 
                                                        |
| 71 | + }  | 
                                                        |
| 72 | +  | 
                                                        |
| 73 | + /**  | 
                                                        |
| 74 | + * @NoAdminRequired  | 
                                                        |
| 75 | + *  | 
                                                        |
| 76 | + * @return DataResponse  | 
                                                        |
| 77 | + * @throws OCSForbiddenException  | 
                                                        |
| 78 | + */  | 
                                                        |
| 79 | +    public function getAppPassword(): DataResponse { | 
                                                        |
| 80 | + // We do not allow the creation of new tokens if this is an app password  | 
                                                        |
| 81 | +        if ($this->session->exists('app_password')) { | 
                                                        |
| 82 | +            throw new OCSForbiddenException('You cannot request an new apppassword with an apppassword'); | 
                                                        |
| 83 | + }  | 
                                                        |
| 84 | +  | 
                                                        |
| 85 | +        try { | 
                                                        |
| 86 | + $credentials = $this->credentialStore->getLoginCredentials();  | 
                                                        |
| 87 | +        } catch (CredentialsUnavailableException $e) { | 
                                                        |
| 88 | + throw new OCSForbiddenException();  | 
                                                        |
| 89 | + }  | 
                                                        |
| 90 | +  | 
                                                        |
| 91 | +        try { | 
                                                        |
| 92 | + $password = $credentials->getPassword();  | 
                                                        |
| 93 | +        } catch (PasswordUnavailableException $e) { | 
                                                        |
| 94 | + $password = null;  | 
                                                        |
| 95 | + }  | 
                                                        |
| 96 | +  | 
                                                        |
| 97 | +        $userAgent = $this->request->getHeader('USER_AGENT'); | 
                                                        |
| 98 | +  | 
                                                        |
| 99 | + $token = $this->random->generate(72, ISecureRandom::CHAR_UPPER.ISecureRandom::CHAR_LOWER.ISecureRandom::CHAR_DIGITS);  | 
                                                        |
| 100 | +  | 
                                                        |
| 101 | + $generatedToken = $this->tokenProvider->generateToken(  | 
                                                        |
| 102 | + $token,  | 
                                                        |
| 103 | + $credentials->getUID(),  | 
                                                        |
| 104 | + $credentials->getLoginName(),  | 
                                                        |
| 105 | + $password,  | 
                                                        |
| 106 | + $userAgent,  | 
                                                        |
| 107 | + IToken::PERMANENT_TOKEN,  | 
                                                        |
| 108 | + IToken::DO_NOT_REMEMBER  | 
                                                        |
| 109 | + );  | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | + $event = new GenericEvent($generatedToken);  | 
                                                        |
| 112 | +        $this->eventDispatcher->dispatch('app_password_created', $event); | 
                                                        |
| 113 | +  | 
                                                        |
| 114 | + return new DataResponse([  | 
                                                        |
| 115 | + 'apppassword' => $token  | 
                                                        |
| 116 | + ]);  | 
                                                        |
| 117 | + }  | 
                                                        |
| 118 | 118 | }  | 
                                                        
@@ -56,147 +56,147 @@  | 
                                                    ||
| 56 | 56 |  class Application extends App { | 
                                                        
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /**  | 
                                                        |
| 60 | - * @param array $urlParams  | 
                                                        |
| 61 | - */  | 
                                                        |
| 62 | -	public function __construct(array $urlParams=[]){ | 
                                                        |
| 63 | -		parent::__construct('settings', $urlParams); | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - $container = $this->getContainer();  | 
                                                        |
| 66 | -  | 
                                                        |
| 67 | - // Register Middleware  | 
                                                        |
| 68 | -		$container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); | 
                                                        |
| 69 | -		$container->registerMiddleWare('SubadminMiddleware'); | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | - /**  | 
                                                        |
| 72 | - * Core class wrappers  | 
                                                        |
| 73 | - */  | 
                                                        |
| 74 | - /** FIXME: Remove once OC_User is non-static and mockable */  | 
                                                        |
| 75 | -		$container->registerService('isAdmin', function() { | 
                                                        |
| 76 | - return \OC_User::isAdminUser(\OC_User::getUser());  | 
                                                        |
| 77 | - });  | 
                                                        |
| 78 | - /** FIXME: Remove once OC_SubAdmin is non-static and mockable */  | 
                                                        |
| 79 | -		$container->registerService('isSubAdmin', function(IContainer $c) { | 
                                                        |
| 80 | - $userObject = \OC::$server->getUserSession()->getUser();  | 
                                                        |
| 81 | - $isSubAdmin = false;  | 
                                                        |
| 82 | -			if($userObject !== null) { | 
                                                        |
| 83 | - $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);  | 
                                                        |
| 84 | - }  | 
                                                        |
| 85 | - return $isSubAdmin;  | 
                                                        |
| 86 | - });  | 
                                                        |
| 87 | -		$container->registerService('userCertificateManager', function(IContainer $c) { | 
                                                        |
| 88 | -			return $c->query('ServerContainer')->getCertificateManager(); | 
                                                        |
| 89 | - }, false);  | 
                                                        |
| 90 | -		$container->registerService('systemCertificateManager', function (IContainer $c) { | 
                                                        |
| 91 | -			return $c->query('ServerContainer')->getCertificateManager(null); | 
                                                        |
| 92 | - }, false);  | 
                                                        |
| 93 | -		$container->registerService(IProvider::class, function (IContainer $c) { | 
                                                        |
| 94 | -			return $c->query('ServerContainer')->query(IProvider::class); | 
                                                        |
| 95 | - });  | 
                                                        |
| 96 | -		$container->registerService(IManager::class, function (IContainer $c) { | 
                                                        |
| 97 | -			return $c->query('ServerContainer')->getSettingsManager(); | 
                                                        |
| 98 | - });  | 
                                                        |
| 99 | -  | 
                                                        |
| 100 | -		$container->registerService(NewUserMailHelper::class, function (IContainer $c) { | 
                                                        |
| 101 | - /** @var Server $server */  | 
                                                        |
| 102 | -			$server = $c->query('ServerContainer'); | 
                                                        |
| 103 | - /** @var Defaults $defaults */  | 
                                                        |
| 104 | - $defaults = $server->query(Defaults::class);  | 
                                                        |
| 105 | -  | 
                                                        |
| 106 | - return new NewUserMailHelper(  | 
                                                        |
| 107 | - $defaults,  | 
                                                        |
| 108 | - $server->getURLGenerator(),  | 
                                                        |
| 109 | - $server->getL10NFactory(),  | 
                                                        |
| 110 | - $server->getMailer(),  | 
                                                        |
| 111 | - $server->getSecureRandom(),  | 
                                                        |
| 112 | - new TimeFactory(),  | 
                                                        |
| 113 | - $server->getConfig(),  | 
                                                        |
| 114 | - $server->getCrypto(),  | 
                                                        |
| 115 | -				Util::getDefaultEmailAddress('no-reply') | 
                                                        |
| 116 | - );  | 
                                                        |
| 117 | - });  | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | - /** @var EventDispatcherInterface $eventDispatcher */  | 
                                                        |
| 120 | - $eventDispatcher = $container->getServer()->getEventDispatcher();  | 
                                                        |
| 121 | -		$eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { | 
                                                        |
| 122 | -			if (($token = $event->getSubject()) instanceof IToken) { | 
                                                        |
| 123 | - /** @var IActivityManager $activityManager */  | 
                                                        |
| 124 | - $activityManager = $container->query(IActivityManager::class);  | 
                                                        |
| 125 | - /** @var ILogger $logger */  | 
                                                        |
| 126 | - $logger = $container->query(ILogger::class);  | 
                                                        |
| 127 | -  | 
                                                        |
| 128 | - $activity = $activityManager->generateEvent();  | 
                                                        |
| 129 | -				$activity->setApp('settings') | 
                                                        |
| 130 | -					->setType('security') | 
                                                        |
| 131 | - ->setAffectedUser($token->getUID())  | 
                                                        |
| 132 | - ->setAuthor($token->getUID())  | 
                                                        |
| 133 | - ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()])  | 
                                                        |
| 134 | -					->setObject('app_token', $token->getId()); | 
                                                        |
| 135 | -  | 
                                                        |
| 136 | -				try { | 
                                                        |
| 137 | - $activityManager->publish($activity);  | 
                                                        |
| 138 | -				} catch (BadMethodCallException $e) { | 
                                                        |
| 139 | - $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]);  | 
                                                        |
| 140 | - }  | 
                                                        |
| 141 | - }  | 
                                                        |
| 142 | - });  | 
                                                        |
| 143 | - }  | 
                                                        |
| 144 | -  | 
                                                        |
| 145 | -	public function register() { | 
                                                        |
| 146 | - $activityManager = $this->getContainer()->getServer()->getActivityManager();  | 
                                                        |
| 147 | - $activityManager->registerSetting(Setting::class); // FIXME move to info.xml  | 
                                                        |
| 148 | - $activityManager->registerProvider(Provider::class); // FIXME move to info.xml  | 
                                                        |
| 149 | - $activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml  | 
                                                        |
| 150 | - $activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml  | 
                                                        |
| 151 | - $activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml  | 
                                                        |
| 152 | -  | 
                                                        |
| 153 | -		Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); | 
                                                        |
| 154 | -		Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); | 
                                                        |
| 155 | -  | 
                                                        |
| 156 | -		Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); | 
                                                        |
| 157 | - }  | 
                                                        |
| 158 | -  | 
                                                        |
| 159 | - /**  | 
                                                        |
| 160 | - * @param array $parameters  | 
                                                        |
| 161 | - * @throws \InvalidArgumentException  | 
                                                        |
| 162 | - * @throws \BadMethodCallException  | 
                                                        |
| 163 | - * @throws \Exception  | 
                                                        |
| 164 | - * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 165 | - */  | 
                                                        |
| 166 | -	public function onChangePassword(array $parameters) { | 
                                                        |
| 167 | - /** @var Hooks $hooks */  | 
                                                        |
| 168 | - $hooks = $this->getContainer()->query(Hooks::class);  | 
                                                        |
| 169 | - $hooks->onChangePassword($parameters['uid']);  | 
                                                        |
| 170 | - }  | 
                                                        |
| 171 | -  | 
                                                        |
| 172 | - /**  | 
                                                        |
| 173 | - * @param array $parameters  | 
                                                        |
| 174 | - * @throws \InvalidArgumentException  | 
                                                        |
| 175 | - * @throws \BadMethodCallException  | 
                                                        |
| 176 | - * @throws \Exception  | 
                                                        |
| 177 | - * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 178 | - */  | 
                                                        |
| 179 | -	public function onChangeInfo(array $parameters) { | 
                                                        |
| 180 | -		if ($parameters['feature'] !== 'eMailAddress') { | 
                                                        |
| 181 | - return;  | 
                                                        |
| 182 | - }  | 
                                                        |
| 183 | -  | 
                                                        |
| 184 | - /** @var Hooks $hooks */  | 
                                                        |
| 185 | - $hooks = $this->getContainer()->query(Hooks::class);  | 
                                                        |
| 186 | - $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);  | 
                                                        |
| 187 | - }  | 
                                                        |
| 188 | -  | 
                                                        |
| 189 | - /**  | 
                                                        |
| 190 | - * @param array $settings  | 
                                                        |
| 191 | - */  | 
                                                        |
| 192 | -	public function extendJsConfig(array $settings) { | 
                                                        |
| 193 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true);  | 
                                                        |
| 194 | -  | 
                                                        |
| 195 | -		$publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); | 
                                                        |
| 196 | -		if (!empty($publicWebFinger)) { | 
                                                        |
| 197 | - $appConfig['core']['public_webfinger'] = $publicWebFinger;  | 
                                                        |
| 198 | - }  | 
                                                        |
| 199 | -  | 
                                                        |
| 200 | - $settings['array']['oc_appconfig'] = json_encode($appConfig);  | 
                                                        |
| 201 | - }  | 
                                                        |
| 59 | + /**  | 
                                                        |
| 60 | + * @param array $urlParams  | 
                                                        |
| 61 | + */  | 
                                                        |
| 62 | +    public function __construct(array $urlParams=[]){ | 
                                                        |
| 63 | +        parent::__construct('settings', $urlParams); | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + $container = $this->getContainer();  | 
                                                        |
| 66 | +  | 
                                                        |
| 67 | + // Register Middleware  | 
                                                        |
| 68 | +        $container->registerAlias('SubadminMiddleware', SubadminMiddleware::class); | 
                                                        |
| 69 | +        $container->registerMiddleWare('SubadminMiddleware'); | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | + /**  | 
                                                        |
| 72 | + * Core class wrappers  | 
                                                        |
| 73 | + */  | 
                                                        |
| 74 | + /** FIXME: Remove once OC_User is non-static and mockable */  | 
                                                        |
| 75 | +        $container->registerService('isAdmin', function() { | 
                                                        |
| 76 | + return \OC_User::isAdminUser(\OC_User::getUser());  | 
                                                        |
| 77 | + });  | 
                                                        |
| 78 | + /** FIXME: Remove once OC_SubAdmin is non-static and mockable */  | 
                                                        |
| 79 | +        $container->registerService('isSubAdmin', function(IContainer $c) { | 
                                                        |
| 80 | + $userObject = \OC::$server->getUserSession()->getUser();  | 
                                                        |
| 81 | + $isSubAdmin = false;  | 
                                                        |
| 82 | +            if($userObject !== null) { | 
                                                        |
| 83 | + $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);  | 
                                                        |
| 84 | + }  | 
                                                        |
| 85 | + return $isSubAdmin;  | 
                                                        |
| 86 | + });  | 
                                                        |
| 87 | +        $container->registerService('userCertificateManager', function(IContainer $c) { | 
                                                        |
| 88 | +            return $c->query('ServerContainer')->getCertificateManager(); | 
                                                        |
| 89 | + }, false);  | 
                                                        |
| 90 | +        $container->registerService('systemCertificateManager', function (IContainer $c) { | 
                                                        |
| 91 | +            return $c->query('ServerContainer')->getCertificateManager(null); | 
                                                        |
| 92 | + }, false);  | 
                                                        |
| 93 | +        $container->registerService(IProvider::class, function (IContainer $c) { | 
                                                        |
| 94 | +            return $c->query('ServerContainer')->query(IProvider::class); | 
                                                        |
| 95 | + });  | 
                                                        |
| 96 | +        $container->registerService(IManager::class, function (IContainer $c) { | 
                                                        |
| 97 | +            return $c->query('ServerContainer')->getSettingsManager(); | 
                                                        |
| 98 | + });  | 
                                                        |
| 99 | +  | 
                                                        |
| 100 | +        $container->registerService(NewUserMailHelper::class, function (IContainer $c) { | 
                                                        |
| 101 | + /** @var Server $server */  | 
                                                        |
| 102 | +            $server = $c->query('ServerContainer'); | 
                                                        |
| 103 | + /** @var Defaults $defaults */  | 
                                                        |
| 104 | + $defaults = $server->query(Defaults::class);  | 
                                                        |
| 105 | +  | 
                                                        |
| 106 | + return new NewUserMailHelper(  | 
                                                        |
| 107 | + $defaults,  | 
                                                        |
| 108 | + $server->getURLGenerator(),  | 
                                                        |
| 109 | + $server->getL10NFactory(),  | 
                                                        |
| 110 | + $server->getMailer(),  | 
                                                        |
| 111 | + $server->getSecureRandom(),  | 
                                                        |
| 112 | + new TimeFactory(),  | 
                                                        |
| 113 | + $server->getConfig(),  | 
                                                        |
| 114 | + $server->getCrypto(),  | 
                                                        |
| 115 | +                Util::getDefaultEmailAddress('no-reply') | 
                                                        |
| 116 | + );  | 
                                                        |
| 117 | + });  | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | + /** @var EventDispatcherInterface $eventDispatcher */  | 
                                                        |
| 120 | + $eventDispatcher = $container->getServer()->getEventDispatcher();  | 
                                                        |
| 121 | +        $eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { | 
                                                        |
| 122 | +            if (($token = $event->getSubject()) instanceof IToken) { | 
                                                        |
| 123 | + /** @var IActivityManager $activityManager */  | 
                                                        |
| 124 | + $activityManager = $container->query(IActivityManager::class);  | 
                                                        |
| 125 | + /** @var ILogger $logger */  | 
                                                        |
| 126 | + $logger = $container->query(ILogger::class);  | 
                                                        |
| 127 | +  | 
                                                        |
| 128 | + $activity = $activityManager->generateEvent();  | 
                                                        |
| 129 | +                $activity->setApp('settings') | 
                                                        |
| 130 | +                    ->setType('security') | 
                                                        |
| 131 | + ->setAffectedUser($token->getUID())  | 
                                                        |
| 132 | + ->setAuthor($token->getUID())  | 
                                                        |
| 133 | + ->setSubject(Provider::APP_TOKEN_CREATED, ['name' => $token->getName()])  | 
                                                        |
| 134 | +                    ->setObject('app_token', $token->getId()); | 
                                                        |
| 135 | +  | 
                                                        |
| 136 | +                try { | 
                                                        |
| 137 | + $activityManager->publish($activity);  | 
                                                        |
| 138 | +                } catch (BadMethodCallException $e) { | 
                                                        |
| 139 | + $logger->logException($e, ['message' => 'could not publish activity', 'level' => ILogger::WARN]);  | 
                                                        |
| 140 | + }  | 
                                                        |
| 141 | + }  | 
                                                        |
| 142 | + });  | 
                                                        |
| 143 | + }  | 
                                                        |
| 144 | +  | 
                                                        |
| 145 | +    public function register() { | 
                                                        |
| 146 | + $activityManager = $this->getContainer()->getServer()->getActivityManager();  | 
                                                        |
| 147 | + $activityManager->registerSetting(Setting::class); // FIXME move to info.xml  | 
                                                        |
| 148 | + $activityManager->registerProvider(Provider::class); // FIXME move to info.xml  | 
                                                        |
| 149 | + $activityManager->registerFilter(SecurityFilter::class); // FIXME move to info.xml  | 
                                                        |
| 150 | + $activityManager->registerSetting(SecuritySetting::class); // FIXME move to info.xml  | 
                                                        |
| 151 | + $activityManager->registerProvider(SecurityProvider::class); // FIXME move to info.xml  | 
                                                        |
| 152 | +  | 
                                                        |
| 153 | +        Util::connectHook('OC_User', 'post_setPassword', $this, 'onChangePassword'); | 
                                                        |
| 154 | +        Util::connectHook('OC_User', 'changeUser', $this, 'onChangeInfo'); | 
                                                        |
| 155 | +  | 
                                                        |
| 156 | +        Util::connectHook('\OCP\Config', 'js', $this, 'extendJsConfig'); | 
                                                        |
| 157 | + }  | 
                                                        |
| 158 | +  | 
                                                        |
| 159 | + /**  | 
                                                        |
| 160 | + * @param array $parameters  | 
                                                        |
| 161 | + * @throws \InvalidArgumentException  | 
                                                        |
| 162 | + * @throws \BadMethodCallException  | 
                                                        |
| 163 | + * @throws \Exception  | 
                                                        |
| 164 | + * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 165 | + */  | 
                                                        |
| 166 | +    public function onChangePassword(array $parameters) { | 
                                                        |
| 167 | + /** @var Hooks $hooks */  | 
                                                        |
| 168 | + $hooks = $this->getContainer()->query(Hooks::class);  | 
                                                        |
| 169 | + $hooks->onChangePassword($parameters['uid']);  | 
                                                        |
| 170 | + }  | 
                                                        |
| 171 | +  | 
                                                        |
| 172 | + /**  | 
                                                        |
| 173 | + * @param array $parameters  | 
                                                        |
| 174 | + * @throws \InvalidArgumentException  | 
                                                        |
| 175 | + * @throws \BadMethodCallException  | 
                                                        |
| 176 | + * @throws \Exception  | 
                                                        |
| 177 | + * @throws \OCP\AppFramework\QueryException  | 
                                                        |
| 178 | + */  | 
                                                        |
| 179 | +    public function onChangeInfo(array $parameters) { | 
                                                        |
| 180 | +        if ($parameters['feature'] !== 'eMailAddress') { | 
                                                        |
| 181 | + return;  | 
                                                        |
| 182 | + }  | 
                                                        |
| 183 | +  | 
                                                        |
| 184 | + /** @var Hooks $hooks */  | 
                                                        |
| 185 | + $hooks = $this->getContainer()->query(Hooks::class);  | 
                                                        |
| 186 | + $hooks->onChangeEmail($parameters['user'], $parameters['old_value']);  | 
                                                        |
| 187 | + }  | 
                                                        |
| 188 | +  | 
                                                        |
| 189 | + /**  | 
                                                        |
| 190 | + * @param array $settings  | 
                                                        |
| 191 | + */  | 
                                                        |
| 192 | +    public function extendJsConfig(array $settings) { | 
                                                        |
| 193 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true);  | 
                                                        |
| 194 | +  | 
                                                        |
| 195 | +        $publicWebFinger = \OC::$server->getConfig()->getAppValue('core', 'public_webfinger', ''); | 
                                                        |
| 196 | +        if (!empty($publicWebFinger)) { | 
                                                        |
| 197 | + $appConfig['core']['public_webfinger'] = $publicWebFinger;  | 
                                                        |
| 198 | + }  | 
                                                        |
| 199 | +  | 
                                                        |
| 200 | + $settings['array']['oc_appconfig'] = json_encode($appConfig);  | 
                                                        |
| 201 | + }  | 
                                                        |
| 202 | 202 | }  | 
                                                        
@@ -59,7 +59,7 @@ discard block  | 
                                                    ||
| 59 | 59 | /**  | 
                                                        
| 60 | 60 | * @param array $urlParams  | 
                                                        
| 61 | 61 | */  | 
                                                        
| 62 | -	public function __construct(array $urlParams=[]){ | 
                                                        |
| 62 | +	public function __construct(array $urlParams = []) { | 
                                                        |
| 63 | 63 |  		parent::__construct('settings', $urlParams); | 
                                                        
| 64 | 64 | |
| 65 | 65 | $container = $this->getContainer();  | 
                                                        
@@ -79,7 +79,7 @@ discard block  | 
                                                    ||
| 79 | 79 |  		$container->registerService('isSubAdmin', function(IContainer $c) { | 
                                                        
| 80 | 80 | $userObject = \OC::$server->getUserSession()->getUser();  | 
                                                        
| 81 | 81 | $isSubAdmin = false;  | 
                                                        
| 82 | -			if($userObject !== null) { | 
                                                        |
| 82 | +			if ($userObject !== null) { | 
                                                        |
| 83 | 83 | $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);  | 
                                                        
| 84 | 84 | }  | 
                                                        
| 85 | 85 | return $isSubAdmin;  | 
                                                        
@@ -87,17 +87,17 @@ discard block  | 
                                                    ||
| 87 | 87 |  		$container->registerService('userCertificateManager', function(IContainer $c) { | 
                                                        
| 88 | 88 |  			return $c->query('ServerContainer')->getCertificateManager(); | 
                                                        
| 89 | 89 | }, false);  | 
                                                        
| 90 | -		$container->registerService('systemCertificateManager', function (IContainer $c) { | 
                                                        |
| 90 | +		$container->registerService('systemCertificateManager', function(IContainer $c) { | 
                                                        |
| 91 | 91 |  			return $c->query('ServerContainer')->getCertificateManager(null); | 
                                                        
| 92 | 92 | }, false);  | 
                                                        
| 93 | -		$container->registerService(IProvider::class, function (IContainer $c) { | 
                                                        |
| 93 | +		$container->registerService(IProvider::class, function(IContainer $c) { | 
                                                        |
| 94 | 94 |  			return $c->query('ServerContainer')->query(IProvider::class); | 
                                                        
| 95 | 95 | });  | 
                                                        
| 96 | -		$container->registerService(IManager::class, function (IContainer $c) { | 
                                                        |
| 96 | +		$container->registerService(IManager::class, function(IContainer $c) { | 
                                                        |
| 97 | 97 |  			return $c->query('ServerContainer')->getSettingsManager(); | 
                                                        
| 98 | 98 | });  | 
                                                        
| 99 | 99 | |
| 100 | -		$container->registerService(NewUserMailHelper::class, function (IContainer $c) { | 
                                                        |
| 100 | +		$container->registerService(NewUserMailHelper::class, function(IContainer $c) { | 
                                                        |
| 101 | 101 | /** @var Server $server */  | 
                                                        
| 102 | 102 |  			$server = $c->query('ServerContainer'); | 
                                                        
| 103 | 103 | /** @var Defaults $defaults */  | 
                                                        
@@ -118,7 +118,7 @@ discard block  | 
                                                    ||
| 118 | 118 | |
| 119 | 119 | /** @var EventDispatcherInterface $eventDispatcher */  | 
                                                        
| 120 | 120 | $eventDispatcher = $container->getServer()->getEventDispatcher();  | 
                                                        
| 121 | -		$eventDispatcher->addListener('app_password_created', function (GenericEvent $event) use ($container) { | 
                                                        |
| 121 | +		$eventDispatcher->addListener('app_password_created', function(GenericEvent $event) use ($container) { | 
                                                        |
| 122 | 122 |  			if (($token = $event->getSubject()) instanceof IToken) { | 
                                                        
| 123 | 123 | /** @var IActivityManager $activityManager */  | 
                                                        
| 124 | 124 | $activityManager = $container->query(IActivityManager::class);  |