Passed
Push — master ( 1dce30...f6efd5 )
by Joas
15:03 queued 13s
created
apps/settings/lib/Settings/Personal/Security/WebAuthn.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -33,48 +33,48 @@
 block discarded – undo
33 33
 
34 34
 class WebAuthn implements ISettings {
35 35
 
36
-	/** @var PublicKeyCredentialMapper */
37
-	private $mapper;
36
+    /** @var PublicKeyCredentialMapper */
37
+    private $mapper;
38 38
 
39
-	/** @var string */
40
-	private $uid;
39
+    /** @var string */
40
+    private $uid;
41 41
 
42
-	/** @var IInitialStateService */
43
-	private $initialStateService;
42
+    /** @var IInitialStateService */
43
+    private $initialStateService;
44 44
 
45
-	/** @var Manager */
46
-	private $manager;
45
+    /** @var Manager */
46
+    private $manager;
47 47
 
48
-	public function __construct(PublicKeyCredentialMapper $mapper,
49
-								string $UserId,
50
-								IInitialStateService $initialStateService,
51
-								Manager $manager) {
52
-		$this->mapper = $mapper;
53
-		$this->uid = $UserId;
54
-		$this->initialStateService = $initialStateService;
55
-		$this->manager = $manager;
56
-	}
48
+    public function __construct(PublicKeyCredentialMapper $mapper,
49
+                                string $UserId,
50
+                                IInitialStateService $initialStateService,
51
+                                Manager $manager) {
52
+        $this->mapper = $mapper;
53
+        $this->uid = $UserId;
54
+        $this->initialStateService = $initialStateService;
55
+        $this->manager = $manager;
56
+    }
57 57
 
58
-	public function getForm() {
59
-		$this->initialStateService->provideInitialState(
60
-			Application::APP_ID,
61
-			'webauthn-devices',
62
-			$this->mapper->findAllForUid($this->uid)
63
-		);
58
+    public function getForm() {
59
+        $this->initialStateService->provideInitialState(
60
+            Application::APP_ID,
61
+            'webauthn-devices',
62
+            $this->mapper->findAllForUid($this->uid)
63
+        );
64 64
 
65
-		return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
66
-		]);
67
-	}
65
+        return new TemplateResponse('settings', 'settings/personal/security/webauthn', [
66
+        ]);
67
+    }
68 68
 
69
-	public function getSection(): ?string {
70
-		if (!$this->manager->isWebAuthnAvailable()) {
71
-			return null;
72
-		}
69
+    public function getSection(): ?string {
70
+        if (!$this->manager->isWebAuthnAvailable()) {
71
+            return null;
72
+        }
73 73
 
74
-		return 'security';
75
-	}
74
+        return 'security';
75
+    }
76 76
 
77
-	public function getPriority(): int {
78
-		return 20;
79
-	}
77
+    public function getPriority(): int {
78
+        return 20;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
lib/private/Authentication/WebAuthn/CredentialRepository.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
 		$uid = $publicKeyCredentialUserEntity->getId();
57 57
 		$entities = $this->credentialMapper->findAllForUid($uid);
58 58
 
59
-		return array_map(function (PublicKeyCredentialEntity $entity) {
59
+		return array_map(function(PublicKeyCredentialEntity $entity) {
60 60
 			return $entity->toPublicKeyCredentialSource();
61 61
 		}, $entities);
62 62
 	}
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -35,61 +35,61 @@
 block discarded – undo
35 35
 
36 36
 class CredentialRepository implements PublicKeyCredentialSourceRepository {
37 37
 
38
-	/** @var PublicKeyCredentialMapper */
39
-	private $credentialMapper;
40
-
41
-	public function __construct(PublicKeyCredentialMapper $credentialMapper) {
42
-		$this->credentialMapper = $credentialMapper;
43
-	}
44
-
45
-	public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource {
46
-		try {
47
-			$entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId);
48
-			return $entity->toPublicKeyCredentialSource();
49
-		} catch (IMapperException $e) {
50
-			return  null;
51
-		}
52
-	}
53
-
54
-	/**
55
-	 * @return PublicKeyCredentialSource[]
56
-	 */
57
-	public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array {
58
-		$uid = $publicKeyCredentialUserEntity->getId();
59
-		$entities = $this->credentialMapper->findAllForUid($uid);
60
-
61
-		return array_map(function (PublicKeyCredentialEntity $entity) {
62
-			return $entity->toPublicKeyCredentialSource();
63
-		}, $entities);
64
-	}
65
-
66
-	public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity {
67
-		$oldEntity = null;
68
-
69
-		try {
70
-			$oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId());
71
-		} catch (IMapperException $e) {
72
-		}
73
-
74
-		$defaultName = false;
75
-		if ($name === null) {
76
-			$defaultName = true;
77
-			$name = 'default';
78
-		}
79
-
80
-		$entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource);
81
-
82
-		if ($oldEntity) {
83
-			$entity->setId($oldEntity->getId());
84
-			if ($defaultName) {
85
-				$entity->setName($oldEntity->getName());
86
-			}
87
-		}
88
-
89
-		return $this->credentialMapper->insertOrUpdate($entity);
90
-	}
91
-
92
-	public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void {
93
-		$this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name);
94
-	}
38
+    /** @var PublicKeyCredentialMapper */
39
+    private $credentialMapper;
40
+
41
+    public function __construct(PublicKeyCredentialMapper $credentialMapper) {
42
+        $this->credentialMapper = $credentialMapper;
43
+    }
44
+
45
+    public function findOneByCredentialId(string $publicKeyCredentialId): ?PublicKeyCredentialSource {
46
+        try {
47
+            $entity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialId);
48
+            return $entity->toPublicKeyCredentialSource();
49
+        } catch (IMapperException $e) {
50
+            return  null;
51
+        }
52
+    }
53
+
54
+    /**
55
+     * @return PublicKeyCredentialSource[]
56
+     */
57
+    public function findAllForUserEntity(PublicKeyCredentialUserEntity $publicKeyCredentialUserEntity): array {
58
+        $uid = $publicKeyCredentialUserEntity->getId();
59
+        $entities = $this->credentialMapper->findAllForUid($uid);
60
+
61
+        return array_map(function (PublicKeyCredentialEntity $entity) {
62
+            return $entity->toPublicKeyCredentialSource();
63
+        }, $entities);
64
+    }
65
+
66
+    public function saveAndReturnCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): PublicKeyCredentialEntity {
67
+        $oldEntity = null;
68
+
69
+        try {
70
+            $oldEntity = $this->credentialMapper->findOneByCredentialId($publicKeyCredentialSource->getPublicKeyCredentialId());
71
+        } catch (IMapperException $e) {
72
+        }
73
+
74
+        $defaultName = false;
75
+        if ($name === null) {
76
+            $defaultName = true;
77
+            $name = 'default';
78
+        }
79
+
80
+        $entity = PublicKeyCredentialEntity::fromPublicKeyCrendentialSource($name, $publicKeyCredentialSource);
81
+
82
+        if ($oldEntity) {
83
+            $entity->setId($oldEntity->getId());
84
+            if ($defaultName) {
85
+                $entity->setName($oldEntity->getName());
86
+            }
87
+        }
88
+
89
+        return $this->credentialMapper->insertOrUpdate($entity);
90
+    }
91
+
92
+    public function saveCredentialSource(PublicKeyCredentialSource $publicKeyCredentialSource, string $name = null): void {
93
+        $this->saveAndReturnCredentialSource($publicKeyCredentialSource, $name);
94
+    }
95 95
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Login/WebAuthnChain.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -25,72 +25,72 @@
 block discarded – undo
25 25
 namespace OC\Authentication\Login;
26 26
 
27 27
 class WebAuthnChain {
28
-	/** @var UserDisabledCheckCommand */
29
-	private $userDisabledCheckCommand;
28
+    /** @var UserDisabledCheckCommand */
29
+    private $userDisabledCheckCommand;
30 30
 
31
-	/** @var LoggedInCheckCommand */
32
-	private $loggedInCheckCommand;
31
+    /** @var LoggedInCheckCommand */
32
+    private $loggedInCheckCommand;
33 33
 
34
-	/** @var CompleteLoginCommand */
35
-	private $completeLoginCommand;
34
+    /** @var CompleteLoginCommand */
35
+    private $completeLoginCommand;
36 36
 
37
-	/** @var CreateSessionTokenCommand */
38
-	private $createSessionTokenCommand;
37
+    /** @var CreateSessionTokenCommand */
38
+    private $createSessionTokenCommand;
39 39
 
40
-	/** @var ClearLostPasswordTokensCommand */
41
-	private $clearLostPasswordTokensCommand;
40
+    /** @var ClearLostPasswordTokensCommand */
41
+    private $clearLostPasswordTokensCommand;
42 42
 
43
-	/** @var UpdateLastPasswordConfirmCommand */
44
-	private $updateLastPasswordConfirmCommand;
43
+    /** @var UpdateLastPasswordConfirmCommand */
44
+    private $updateLastPasswordConfirmCommand;
45 45
 
46
-	/** @var SetUserTimezoneCommand */
47
-	private $setUserTimezoneCommand;
46
+    /** @var SetUserTimezoneCommand */
47
+    private $setUserTimezoneCommand;
48 48
 
49
-	/** @var TwoFactorCommand */
50
-	private $twoFactorCommand;
49
+    /** @var TwoFactorCommand */
50
+    private $twoFactorCommand;
51 51
 
52
-	/** @var FinishRememberedLoginCommand */
53
-	private $finishRememberedLoginCommand;
52
+    /** @var FinishRememberedLoginCommand */
53
+    private $finishRememberedLoginCommand;
54 54
 
55
-	/** @var WebAuthnLoginCommand */
56
-	private $webAuthnLoginCommand;
55
+    /** @var WebAuthnLoginCommand */
56
+    private $webAuthnLoginCommand;
57 57
 
58
-	public function __construct(UserDisabledCheckCommand $userDisabledCheckCommand,
59
-								WebAuthnLoginCommand $webAuthnLoginCommand,
60
-								LoggedInCheckCommand $loggedInCheckCommand,
61
-								CompleteLoginCommand $completeLoginCommand,
62
-								CreateSessionTokenCommand $createSessionTokenCommand,
63
-								ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
64
-								UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
65
-								SetUserTimezoneCommand $setUserTimezoneCommand,
66
-								TwoFactorCommand $twoFactorCommand,
67
-								FinishRememberedLoginCommand $finishRememberedLoginCommand
68
-	) {
69
-		$this->userDisabledCheckCommand = $userDisabledCheckCommand;
70
-		$this->webAuthnLoginCommand = $webAuthnLoginCommand;
71
-		$this->loggedInCheckCommand = $loggedInCheckCommand;
72
-		$this->completeLoginCommand = $completeLoginCommand;
73
-		$this->createSessionTokenCommand = $createSessionTokenCommand;
74
-		$this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
75
-		$this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
76
-		$this->setUserTimezoneCommand = $setUserTimezoneCommand;
77
-		$this->twoFactorCommand = $twoFactorCommand;
78
-		$this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
79
-	}
58
+    public function __construct(UserDisabledCheckCommand $userDisabledCheckCommand,
59
+                                WebAuthnLoginCommand $webAuthnLoginCommand,
60
+                                LoggedInCheckCommand $loggedInCheckCommand,
61
+                                CompleteLoginCommand $completeLoginCommand,
62
+                                CreateSessionTokenCommand $createSessionTokenCommand,
63
+                                ClearLostPasswordTokensCommand $clearLostPasswordTokensCommand,
64
+                                UpdateLastPasswordConfirmCommand $updateLastPasswordConfirmCommand,
65
+                                SetUserTimezoneCommand $setUserTimezoneCommand,
66
+                                TwoFactorCommand $twoFactorCommand,
67
+                                FinishRememberedLoginCommand $finishRememberedLoginCommand
68
+    ) {
69
+        $this->userDisabledCheckCommand = $userDisabledCheckCommand;
70
+        $this->webAuthnLoginCommand = $webAuthnLoginCommand;
71
+        $this->loggedInCheckCommand = $loggedInCheckCommand;
72
+        $this->completeLoginCommand = $completeLoginCommand;
73
+        $this->createSessionTokenCommand = $createSessionTokenCommand;
74
+        $this->clearLostPasswordTokensCommand = $clearLostPasswordTokensCommand;
75
+        $this->updateLastPasswordConfirmCommand = $updateLastPasswordConfirmCommand;
76
+        $this->setUserTimezoneCommand = $setUserTimezoneCommand;
77
+        $this->twoFactorCommand = $twoFactorCommand;
78
+        $this->finishRememberedLoginCommand = $finishRememberedLoginCommand;
79
+    }
80 80
 
81
-	public function process(LoginData $loginData): LoginResult {
82
-		$chain = $this->userDisabledCheckCommand;
83
-		$chain
84
-			->setNext($this->webAuthnLoginCommand)
85
-			->setNext($this->loggedInCheckCommand)
86
-			->setNext($this->completeLoginCommand)
87
-			->setNext($this->createSessionTokenCommand)
88
-			->setNext($this->clearLostPasswordTokensCommand)
89
-			->setNext($this->updateLastPasswordConfirmCommand)
90
-			->setNext($this->setUserTimezoneCommand)
91
-			->setNext($this->twoFactorCommand)
92
-			->setNext($this->finishRememberedLoginCommand);
81
+    public function process(LoginData $loginData): LoginResult {
82
+        $chain = $this->userDisabledCheckCommand;
83
+        $chain
84
+            ->setNext($this->webAuthnLoginCommand)
85
+            ->setNext($this->loggedInCheckCommand)
86
+            ->setNext($this->completeLoginCommand)
87
+            ->setNext($this->createSessionTokenCommand)
88
+            ->setNext($this->clearLostPasswordTokensCommand)
89
+            ->setNext($this->updateLastPasswordConfirmCommand)
90
+            ->setNext($this->setUserTimezoneCommand)
91
+            ->setNext($this->twoFactorCommand)
92
+            ->setNext($this->finishRememberedLoginCommand);
93 93
 
94
-		return $chain->process($loginData);
95
-	}
94
+        return $chain->process($loginData);
95
+    }
96 96
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Login/WebAuthnLoginCommand.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -28,21 +28,21 @@
 block discarded – undo
28 28
 
29 29
 class WebAuthnLoginCommand extends ALoginCommand {
30 30
 
31
-	/** @var IUserManager */
32
-	private $userManager;
33
-
34
-	public function __construct(IUserManager $userManager) {
35
-		$this->userManager = $userManager;
36
-	}
37
-
38
-	public function process(LoginData $loginData): LoginResult {
39
-		$user = $this->userManager->get($loginData->getUsername());
40
-		$loginData->setUser($user);
41
-		if ($user === null) {
42
-			$loginData->setUser(false);
43
-		}
44
-
45
-		return $this->processNextOrFinishSuccessfully($loginData);
46
-	}
31
+    /** @var IUserManager */
32
+    private $userManager;
33
+
34
+    public function __construct(IUserManager $userManager) {
35
+        $this->userManager = $userManager;
36
+    }
37
+
38
+    public function process(LoginData $loginData): LoginResult {
39
+        $user = $this->userManager->get($loginData->getUsername());
40
+        $loginData->setUser($user);
41
+        if ($user === null) {
42
+            $loginData->setUser(false);
43
+        }
44
+
45
+        return $this->processNextOrFinishSuccessfully($loginData);
46
+    }
47 47
 
48 48
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Login/LoginData.php 1 patch
Indentation   +87 added lines, -87 removed lines patch added patch discarded remove patch
@@ -30,92 +30,92 @@
 block discarded – undo
30 30
 
31 31
 class LoginData {
32 32
 
33
-	/** @var IRequest */
34
-	private $request;
35
-
36
-	/** @var string */
37
-	private $username;
38
-
39
-	/** @var string */
40
-	private $password;
41
-
42
-	/** @var string */
43
-	private $redirectUrl;
44
-
45
-	/** @var string */
46
-	private $timeZone;
47
-
48
-	/** @var string */
49
-	private $timeZoneOffset;
50
-
51
-	/** @var IUser|false|null */
52
-	private $user = null;
53
-
54
-	/** @var bool */
55
-	private $rememberLogin = true;
56
-
57
-	public function __construct(IRequest $request,
58
-								string $username,
59
-								?string $password,
60
-								string $redirectUrl = null,
61
-								string $timeZone = '',
62
-								string $timeZoneOffset = '') {
63
-		$this->request = $request;
64
-		$this->username = $username;
65
-		$this->password = $password;
66
-		$this->redirectUrl = $redirectUrl;
67
-		$this->timeZone = $timeZone;
68
-		$this->timeZoneOffset = $timeZoneOffset;
69
-	}
70
-
71
-	public function getRequest(): IRequest {
72
-		return $this->request;
73
-	}
74
-
75
-	public function setUsername(string $username): void {
76
-		$this->username = $username;
77
-	}
78
-
79
-	public function getUsername(): string {
80
-		return $this->username;
81
-	}
82
-
83
-	public function getPassword(): ?string {
84
-		return $this->password;
85
-	}
86
-
87
-	public function getRedirectUrl(): ?string {
88
-		return $this->redirectUrl;
89
-	}
90
-
91
-	public function getTimeZone(): string {
92
-		return $this->timeZone;
93
-	}
94
-
95
-	public function getTimeZoneOffset(): string {
96
-		return $this->timeZoneOffset;
97
-	}
98
-
99
-	/**
100
-	 * @param IUser|false|null $user
101
-	 */
102
-	public function setUser($user) {
103
-		$this->user = $user;
104
-	}
105
-
106
-	/**
107
-	 * @return false|IUser|null
108
-	 */
109
-	public function getUser() {
110
-		return $this->user;
111
-	}
112
-
113
-	public function setRememberLogin(bool $rememberLogin): void {
114
-		$this->rememberLogin = $rememberLogin;
115
-	}
116
-
117
-	public function isRememberLogin(): bool {
118
-		return $this->rememberLogin;
119
-	}
33
+    /** @var IRequest */
34
+    private $request;
35
+
36
+    /** @var string */
37
+    private $username;
38
+
39
+    /** @var string */
40
+    private $password;
41
+
42
+    /** @var string */
43
+    private $redirectUrl;
44
+
45
+    /** @var string */
46
+    private $timeZone;
47
+
48
+    /** @var string */
49
+    private $timeZoneOffset;
50
+
51
+    /** @var IUser|false|null */
52
+    private $user = null;
53
+
54
+    /** @var bool */
55
+    private $rememberLogin = true;
56
+
57
+    public function __construct(IRequest $request,
58
+                                string $username,
59
+                                ?string $password,
60
+                                string $redirectUrl = null,
61
+                                string $timeZone = '',
62
+                                string $timeZoneOffset = '') {
63
+        $this->request = $request;
64
+        $this->username = $username;
65
+        $this->password = $password;
66
+        $this->redirectUrl = $redirectUrl;
67
+        $this->timeZone = $timeZone;
68
+        $this->timeZoneOffset = $timeZoneOffset;
69
+    }
70
+
71
+    public function getRequest(): IRequest {
72
+        return $this->request;
73
+    }
74
+
75
+    public function setUsername(string $username): void {
76
+        $this->username = $username;
77
+    }
78
+
79
+    public function getUsername(): string {
80
+        return $this->username;
81
+    }
82
+
83
+    public function getPassword(): ?string {
84
+        return $this->password;
85
+    }
86
+
87
+    public function getRedirectUrl(): ?string {
88
+        return $this->redirectUrl;
89
+    }
90
+
91
+    public function getTimeZone(): string {
92
+        return $this->timeZone;
93
+    }
94
+
95
+    public function getTimeZoneOffset(): string {
96
+        return $this->timeZoneOffset;
97
+    }
98
+
99
+    /**
100
+     * @param IUser|false|null $user
101
+     */
102
+    public function setUser($user) {
103
+        $this->user = $user;
104
+    }
105
+
106
+    /**
107
+     * @return false|IUser|null
108
+     */
109
+    public function getUser() {
110
+        return $this->user;
111
+    }
112
+
113
+    public function setRememberLogin(bool $rememberLogin): void {
114
+        $this->rememberLogin = $rememberLogin;
115
+    }
116
+
117
+    public function isRememberLogin(): bool {
118
+        return $this->rememberLogin;
119
+    }
120 120
 
121 121
 }
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/Integration/IAddressBookProvider.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,43 +31,43 @@
 block discarded – undo
31 31
  */
32 32
 interface IAddressBookProvider {
33 33
 
34
-	/**
35
-	 * Provides the appId of the plugin
36
-	 *
37
-	 * @since 19.0.0
38
-	 * @return string AppId
39
-	 */
40
-	public function getAppId(): string;
34
+    /**
35
+     * Provides the appId of the plugin
36
+     *
37
+     * @since 19.0.0
38
+     * @return string AppId
39
+     */
40
+    public function getAppId(): string;
41 41
 
42
-	/**
43
-	 * Fetches all address books for a given principal uri
44
-	 *
45
-	 * @since 19.0.0
46
-	 * @param string $principalUri E.g. principals/users/user1
47
-	 * @return ExternalAddressBook[] Array of all address books
48
-	 */
49
-	public function fetchAllForAddressBookHome(string $principalUri): array;
42
+    /**
43
+     * Fetches all address books for a given principal uri
44
+     *
45
+     * @since 19.0.0
46
+     * @param string $principalUri E.g. principals/users/user1
47
+     * @return ExternalAddressBook[] Array of all address books
48
+     */
49
+    public function fetchAllForAddressBookHome(string $principalUri): array;
50 50
 
51
-	/**
52
-	 * Checks whether plugin has an address book for a given principalUri and URI
53
-	 *
54
-	 * @since 19.0.0
55
-	 * @param string $principalUri E.g. principals/users/user1
56
-	 * @param string $uri E.g. personal
57
-	 * @return bool True if address book for principalUri and URI exists, false otherwise
58
-	 */
59
-	public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool;
51
+    /**
52
+     * Checks whether plugin has an address book for a given principalUri and URI
53
+     *
54
+     * @since 19.0.0
55
+     * @param string $principalUri E.g. principals/users/user1
56
+     * @param string $uri E.g. personal
57
+     * @return bool True if address book for principalUri and URI exists, false otherwise
58
+     */
59
+    public function hasAddressBookInAddressBookHome(string $principalUri, string $uri): bool;
60 60
 
61
-	/**
62
-	 * Fetches an address book for a given principalUri and URI
63
-	 * Returns null if address book does not exist
64
-	 *
65
-	 * @param string $principalUri E.g. principals/users/user1
66
-	 * @param string $uri E.g. personal
67
-	 *
68
-	 * @return ExternalAddressBook|null address book if it exists, null otherwise
69
-	 *@since 19.0.0
70
-	 */
71
-	public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook;
61
+    /**
62
+     * Fetches an address book for a given principalUri and URI
63
+     * Returns null if address book does not exist
64
+     *
65
+     * @param string $principalUri E.g. principals/users/user1
66
+     * @param string $uri E.g. personal
67
+     *
68
+     * @return ExternalAddressBook|null address book if it exists, null otherwise
69
+     *@since 19.0.0
70
+     */
71
+    public function getAddressBookInAddressBookHome(string $principalUri, string $uri): ?ExternalAddressBook;
72 72
 
73 73
 }
Please login to merge, or discard this patch.
lib/public/User/Events/BeforeUserLoggedInEvent.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -34,35 +34,35 @@
 block discarded – undo
34 34
  */
35 35
 class BeforeUserLoggedInEvent extends Event {
36 36
 
37
-	/** @var string */
38
-	private $username;
37
+    /** @var string */
38
+    private $username;
39 39
 
40
-	/** @var string */
41
-	private $password;
40
+    /** @var string */
41
+    private $password;
42 42
 
43
-	/**
44
-	 * @since 18.0.0
45
-	 */
46
-	public function __construct(string $username, string $password) {
47
-		parent::__construct();
48
-		$this->username = $username;
49
-		$this->password = $password;
50
-	}
43
+    /**
44
+     * @since 18.0.0
45
+     */
46
+    public function __construct(string $username, string $password) {
47
+        parent::__construct();
48
+        $this->username = $username;
49
+        $this->password = $password;
50
+    }
51 51
 
52
-	/**
53
-	 * returns the login name, which must not necessarily match to a user ID
54
-	 *
55
-	 * @since 18.0.0
56
-	 */
57
-	public function getUsername(): string {
58
-		return $this->username;
59
-	}
52
+    /**
53
+     * returns the login name, which must not necessarily match to a user ID
54
+     *
55
+     * @since 18.0.0
56
+     */
57
+    public function getUsername(): string {
58
+        return $this->username;
59
+    }
60 60
 
61
-	/**
62
-	 * @since 18.0.0
63
-	 */
64
-	public function getPassword(): string {
65
-		return $this->password;
66
-	}
61
+    /**
62
+     * @since 18.0.0
63
+     */
64
+    public function getPassword(): string {
65
+        return $this->password;
66
+    }
67 67
 
68 68
 }
Please login to merge, or discard this patch.
lib/private/legacy/OC_User.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 				case 'database':
92 92
 				case 'mysql':
93 93
 				case 'sqlite':
94
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
94
+					\OCP\Util::writeLog('core', 'Adding user backend '.$backend.'.', ILogger::DEBUG);
95 95
 					self::$_usedBackends[$backend] = new \OC\User\Database();
96 96
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
97 97
 					break;
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
101 101
 					break;
102 102
 				default:
103
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
104
-					$className = 'OC_USER_' . strtoupper($backend);
103
+					\OCP\Util::writeLog('core', 'Adding default user backend '.$backend.'.', ILogger::DEBUG);
104
+					$className = 'OC_USER_'.strtoupper($backend);
105 105
 					self::$_usedBackends[$backend] = new $className();
106 106
 					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
107 107
 					break;
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
 					self::useBackend($backend);
146 146
 					self::$_setupedBackends[] = $i;
147 147
 				} else {
148
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
148
+					\OCP\Util::writeLog('core', 'User backend '.$class.' already initialized.', ILogger::DEBUG);
149 149
 				}
150 150
 			} else {
151
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
151
+				\OCP\Util::writeLog('core', 'User backend '.$class.' not found.', ILogger::ERROR);
152 152
 			}
153 153
 		}
154 154
 	}
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
 		}
271 271
 
272 272
 		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
273
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
273
+		$logoutUrl .= '?requesttoken='.urlencode(\OCP\Util::callRegister());
274 274
 
275 275
 		return $logoutUrl;
276 276
 	}
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
 		if ($user) {
363 363
 			return $user->getHome();
364 364
 		} else {
365
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
365
+			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT.'/data').'/'.$uid;
366 366
 		}
367 367
 	}
368 368
 
Please login to merge, or discard this patch.
Indentation   +349 added lines, -349 removed lines patch added patch discarded remove patch
@@ -61,353 +61,353 @@
 block discarded – undo
61 61
  *   logout()
62 62
  */
63 63
 class OC_User {
64
-	private static $_usedBackends = [];
65
-
66
-	private static $_setupedBackends = [];
67
-
68
-	// bool, stores if a user want to access a resource anonymously, e.g if they open a public link
69
-	private static $incognitoMode = false;
70
-
71
-	/**
72
-	 * Adds the backend to the list of used backends
73
-	 *
74
-	 * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
75
-	 * @return bool
76
-	 *
77
-	 * Set the User Authentication Module
78
-	 * @suppress PhanDeprecatedFunction
79
-	 */
80
-	public static function useBackend($backend = 'database') {
81
-		if ($backend instanceof \OCP\UserInterface) {
82
-			self::$_usedBackends[get_class($backend)] = $backend;
83
-			\OC::$server->getUserManager()->registerBackend($backend);
84
-		} else {
85
-			// You'll never know what happens
86
-			if (null === $backend or !is_string($backend)) {
87
-				$backend = 'database';
88
-			}
89
-
90
-			// Load backend
91
-			switch ($backend) {
92
-				case 'database':
93
-				case 'mysql':
94
-				case 'sqlite':
95
-					\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
96
-					self::$_usedBackends[$backend] = new \OC\User\Database();
97
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
98
-					break;
99
-				case 'dummy':
100
-					self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
101
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
102
-					break;
103
-				default:
104
-					\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
105
-					$className = 'OC_USER_' . strtoupper($backend);
106
-					self::$_usedBackends[$backend] = new $className();
107
-					\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
108
-					break;
109
-			}
110
-		}
111
-		return true;
112
-	}
113
-
114
-	/**
115
-	 * remove all used backends
116
-	 */
117
-	public static function clearBackends() {
118
-		self::$_usedBackends = [];
119
-		\OC::$server->getUserManager()->clearBackends();
120
-	}
121
-
122
-	/**
123
-	 * setup the configured backends in config.php
124
-	 * @suppress PhanDeprecatedFunction
125
-	 */
126
-	public static function setupBackends() {
127
-		OC_App::loadApps(['prelogin']);
128
-		$backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
129
-		if (isset($backends['default']) && !$backends['default']) {
130
-			// clear default backends
131
-			self::clearBackends();
132
-		}
133
-		foreach ($backends as $i => $config) {
134
-			if (!is_array($config)) {
135
-				continue;
136
-			}
137
-			$class = $config['class'];
138
-			$arguments = $config['arguments'];
139
-			if (class_exists($class)) {
140
-				if (array_search($i, self::$_setupedBackends) === false) {
141
-					// make a reflection object
142
-					$reflectionObj = new ReflectionClass($class);
143
-
144
-					// use Reflection to create a new instance, using the $args
145
-					$backend = $reflectionObj->newInstanceArgs($arguments);
146
-					self::useBackend($backend);
147
-					self::$_setupedBackends[] = $i;
148
-				} else {
149
-					\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
150
-				}
151
-			} else {
152
-				\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
153
-			}
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * Try to login a user, assuming authentication
159
-	 * has already happened (e.g. via Single Sign On).
160
-	 *
161
-	 * Log in a user and regenerate a new session.
162
-	 *
163
-	 * @param \OCP\Authentication\IApacheBackend $backend
164
-	 * @return bool
165
-	 */
166
-	public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
167
-		$uid = $backend->getCurrentUserId();
168
-		$run = true;
169
-		OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170
-
171
-		if ($uid) {
172
-			if (self::getUser() !== $uid) {
173
-				self::setUserId($uid);
174
-				$userSession = \OC::$server->getUserSession();
175
-				if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
176
-					$message = \OC::$server->getL10N('lib')->t('User disabled');
177
-					throw new LoginException($message);
178
-				}
179
-				$userSession->setLoginName($uid);
180
-				$request = OC::$server->getRequest();
181
-				$password = null;
182
-				if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
183
-					$password = $backend->getCurrentUserSecret();
184
-				}
185
-				$userSession->createSessionToken($request, $uid, $uid, $password);
186
-				$userSession->createRememberMeToken($userSession->getUser());
187
-				// setup the filesystem
188
-				OC_Util::setupFS($uid);
189
-				// first call the post_login hooks, the login-process needs to be
190
-				// completed before we can safely create the users folder.
191
-				// For example encryption needs to initialize the users keys first
192
-				// before we can create the user folder with the skeleton files
193
-				OC_Hook::emit(
194
-					'OC_User',
195
-					'post_login',
196
-					[
197
-						'uid' => $uid,
198
-						'password' => $password,
199
-						'isTokenLogin' => false,
200
-					]
201
-				);
202
-				/** @var IEventDispatcher $dispatcher */
203
-				$dispatcher = \OC::$server->get(IEventDispatcher::class);
204
-				$dispatcher->dispatchTyped(new UserLoggedInEvent(
205
-						\OC::$server->get(IUserManager::class)->get($uid),
206
-						$uid,
207
-						null,
208
-						false)
209
-				);
210
-
211
-				//trigger creation of user home and /files folder
212
-				\OC::$server->getUserFolder($uid);
213
-			}
214
-			return true;
215
-		}
216
-		return false;
217
-	}
218
-
219
-	/**
220
-	 * Verify with Apache whether user is authenticated.
221
-	 *
222
-	 * @return boolean|null
223
-	 *          true: authenticated
224
-	 *          false: not authenticated
225
-	 *          null: not handled / no backend available
226
-	 */
227
-	public static function handleApacheAuth() {
228
-		$backend = self::findFirstActiveUsedBackend();
229
-		if ($backend) {
230
-			OC_App::loadApps();
231
-
232
-			//setup extra user backends
233
-			self::setupBackends();
234
-			\OC::$server->getUserSession()->unsetMagicInCookie();
235
-
236
-			return self::loginWithApache($backend);
237
-		}
238
-
239
-		return null;
240
-	}
241
-
242
-
243
-	/**
244
-	 * Sets user id for session and triggers emit
245
-	 *
246
-	 * @param string $uid
247
-	 */
248
-	public static function setUserId($uid) {
249
-		$userSession = \OC::$server->getUserSession();
250
-		$userManager = \OC::$server->getUserManager();
251
-		if ($user = $userManager->get($uid)) {
252
-			$userSession->setUser($user);
253
-		} else {
254
-			\OC::$server->getSession()->set('user_id', $uid);
255
-		}
256
-	}
257
-
258
-	/**
259
-	 * Check if the user is logged in, considers also the HTTP basic credentials
260
-	 *
261
-	 * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
262
-	 * @return bool
263
-	 */
264
-	public static function isLoggedIn() {
265
-		return \OC::$server->getUserSession()->isLoggedIn();
266
-	}
267
-
268
-	/**
269
-	 * set incognito mode, e.g. if a user wants to open a public link
270
-	 *
271
-	 * @param bool $status
272
-	 */
273
-	public static function setIncognitoMode($status) {
274
-		self::$incognitoMode = $status;
275
-	}
276
-
277
-	/**
278
-	 * get incognito mode status
279
-	 *
280
-	 * @return bool
281
-	 */
282
-	public static function isIncognitoMode() {
283
-		return self::$incognitoMode;
284
-	}
285
-
286
-	/**
287
-	 * Returns the current logout URL valid for the currently logged-in user
288
-	 *
289
-	 * @param \OCP\IURLGenerator $urlGenerator
290
-	 * @return string
291
-	 */
292
-	public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
293
-		$backend = self::findFirstActiveUsedBackend();
294
-		if ($backend) {
295
-			return $backend->getLogoutUrl();
296
-		}
297
-
298
-		$user = \OC::$server->getUserSession()->getUser();
299
-		if ($user instanceof \OCP\IUser) {
300
-			$backend = $user->getBackend();
301
-			if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
302
-				return $backend->getLogoutUrl();
303
-			}
304
-		}
305
-
306
-		$logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
307
-		$logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
308
-
309
-		return $logoutUrl;
310
-	}
311
-
312
-	/**
313
-	 * Check if the user is an admin user
314
-	 *
315
-	 * @param string $uid uid of the admin
316
-	 * @return bool
317
-	 */
318
-	public static function isAdminUser($uid) {
319
-		$group = \OC::$server->getGroupManager()->get('admin');
320
-		$user = \OC::$server->getUserManager()->get($uid);
321
-		if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
322
-			return true;
323
-		}
324
-		return false;
325
-	}
326
-
327
-
328
-	/**
329
-	 * get the user id of the user currently logged in.
330
-	 *
331
-	 * @return string|false uid or false
332
-	 */
333
-	public static function getUser() {
334
-		$uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
335
-		if (!is_null($uid) && self::$incognitoMode === false) {
336
-			return $uid;
337
-		} else {
338
-			return false;
339
-		}
340
-	}
341
-
342
-	/**
343
-	 * Set password
344
-	 *
345
-	 * @param string $uid The username
346
-	 * @param string $password The new password
347
-	 * @param string $recoveryPassword for the encryption app to reset encryption keys
348
-	 * @return bool
349
-	 *
350
-	 * Change the password of a user
351
-	 */
352
-	public static function setPassword($uid, $password, $recoveryPassword = null) {
353
-		$user = \OC::$server->getUserManager()->get($uid);
354
-		if ($user) {
355
-			return $user->setPassword($password, $recoveryPassword);
356
-		} else {
357
-			return false;
358
-		}
359
-	}
360
-
361
-	/**
362
-	 * @param string $uid The username
363
-	 * @return string
364
-	 *
365
-	 * returns the path to the users home directory
366
-	 * @deprecated Use \OC::$server->getUserManager->getHome()
367
-	 */
368
-	public static function getHome($uid) {
369
-		$user = \OC::$server->getUserManager()->get($uid);
370
-		if ($user) {
371
-			return $user->getHome();
372
-		} else {
373
-			return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
374
-		}
375
-	}
376
-
377
-	/**
378
-	 * Get a list of all users display name
379
-	 *
380
-	 * @param string $search
381
-	 * @param int $limit
382
-	 * @param int $offset
383
-	 * @return array associative array with all display names (value) and corresponding uids (key)
384
-	 *
385
-	 * Get a list of all display names and user ids.
386
-	 * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
387
-	 */
388
-	public static function getDisplayNames($search = '', $limit = null, $offset = null) {
389
-		$displayNames = [];
390
-		$users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
391
-		foreach ($users as $user) {
392
-			$displayNames[$user->getUID()] = $user->getDisplayName();
393
-		}
394
-		return $displayNames;
395
-	}
396
-
397
-	/**
398
-	 * Returns the first active backend from self::$_usedBackends.
399
-	 *
400
-	 * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
401
-	 */
402
-	private static function findFirstActiveUsedBackend() {
403
-		foreach (self::$_usedBackends as $backend) {
404
-			if ($backend instanceof OCP\Authentication\IApacheBackend) {
405
-				if ($backend->isSessionActive()) {
406
-					return $backend;
407
-				}
408
-			}
409
-		}
410
-
411
-		return null;
412
-	}
64
+    private static $_usedBackends = [];
65
+
66
+    private static $_setupedBackends = [];
67
+
68
+    // bool, stores if a user want to access a resource anonymously, e.g if they open a public link
69
+    private static $incognitoMode = false;
70
+
71
+    /**
72
+     * Adds the backend to the list of used backends
73
+     *
74
+     * @param string|\OCP\UserInterface $backend default: database The backend to use for user management
75
+     * @return bool
76
+     *
77
+     * Set the User Authentication Module
78
+     * @suppress PhanDeprecatedFunction
79
+     */
80
+    public static function useBackend($backend = 'database') {
81
+        if ($backend instanceof \OCP\UserInterface) {
82
+            self::$_usedBackends[get_class($backend)] = $backend;
83
+            \OC::$server->getUserManager()->registerBackend($backend);
84
+        } else {
85
+            // You'll never know what happens
86
+            if (null === $backend or !is_string($backend)) {
87
+                $backend = 'database';
88
+            }
89
+
90
+            // Load backend
91
+            switch ($backend) {
92
+                case 'database':
93
+                case 'mysql':
94
+                case 'sqlite':
95
+                    \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
96
+                    self::$_usedBackends[$backend] = new \OC\User\Database();
97
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
98
+                    break;
99
+                case 'dummy':
100
+                    self::$_usedBackends[$backend] = new \Test\Util\User\Dummy();
101
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
102
+                    break;
103
+                default:
104
+                    \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
105
+                    $className = 'OC_USER_' . strtoupper($backend);
106
+                    self::$_usedBackends[$backend] = new $className();
107
+                    \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
108
+                    break;
109
+            }
110
+        }
111
+        return true;
112
+    }
113
+
114
+    /**
115
+     * remove all used backends
116
+     */
117
+    public static function clearBackends() {
118
+        self::$_usedBackends = [];
119
+        \OC::$server->getUserManager()->clearBackends();
120
+    }
121
+
122
+    /**
123
+     * setup the configured backends in config.php
124
+     * @suppress PhanDeprecatedFunction
125
+     */
126
+    public static function setupBackends() {
127
+        OC_App::loadApps(['prelogin']);
128
+        $backends = \OC::$server->getSystemConfig()->getValue('user_backends', []);
129
+        if (isset($backends['default']) && !$backends['default']) {
130
+            // clear default backends
131
+            self::clearBackends();
132
+        }
133
+        foreach ($backends as $i => $config) {
134
+            if (!is_array($config)) {
135
+                continue;
136
+            }
137
+            $class = $config['class'];
138
+            $arguments = $config['arguments'];
139
+            if (class_exists($class)) {
140
+                if (array_search($i, self::$_setupedBackends) === false) {
141
+                    // make a reflection object
142
+                    $reflectionObj = new ReflectionClass($class);
143
+
144
+                    // use Reflection to create a new instance, using the $args
145
+                    $backend = $reflectionObj->newInstanceArgs($arguments);
146
+                    self::useBackend($backend);
147
+                    self::$_setupedBackends[] = $i;
148
+                } else {
149
+                    \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
150
+                }
151
+            } else {
152
+                \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
153
+            }
154
+        }
155
+    }
156
+
157
+    /**
158
+     * Try to login a user, assuming authentication
159
+     * has already happened (e.g. via Single Sign On).
160
+     *
161
+     * Log in a user and regenerate a new session.
162
+     *
163
+     * @param \OCP\Authentication\IApacheBackend $backend
164
+     * @return bool
165
+     */
166
+    public static function loginWithApache(\OCP\Authentication\IApacheBackend $backend) {
167
+        $uid = $backend->getCurrentUserId();
168
+        $run = true;
169
+        OC_Hook::emit("OC_User", "pre_login", ["run" => &$run, "uid" => $uid, 'backend' => $backend]);
170
+
171
+        if ($uid) {
172
+            if (self::getUser() !== $uid) {
173
+                self::setUserId($uid);
174
+                $userSession = \OC::$server->getUserSession();
175
+                if ($userSession->getUser() && !$userSession->getUser()->isEnabled()) {
176
+                    $message = \OC::$server->getL10N('lib')->t('User disabled');
177
+                    throw new LoginException($message);
178
+                }
179
+                $userSession->setLoginName($uid);
180
+                $request = OC::$server->getRequest();
181
+                $password = null;
182
+                if ($backend instanceof \OCP\Authentication\IProvideUserSecretBackend) {
183
+                    $password = $backend->getCurrentUserSecret();
184
+                }
185
+                $userSession->createSessionToken($request, $uid, $uid, $password);
186
+                $userSession->createRememberMeToken($userSession->getUser());
187
+                // setup the filesystem
188
+                OC_Util::setupFS($uid);
189
+                // first call the post_login hooks, the login-process needs to be
190
+                // completed before we can safely create the users folder.
191
+                // For example encryption needs to initialize the users keys first
192
+                // before we can create the user folder with the skeleton files
193
+                OC_Hook::emit(
194
+                    'OC_User',
195
+                    'post_login',
196
+                    [
197
+                        'uid' => $uid,
198
+                        'password' => $password,
199
+                        'isTokenLogin' => false,
200
+                    ]
201
+                );
202
+                /** @var IEventDispatcher $dispatcher */
203
+                $dispatcher = \OC::$server->get(IEventDispatcher::class);
204
+                $dispatcher->dispatchTyped(new UserLoggedInEvent(
205
+                        \OC::$server->get(IUserManager::class)->get($uid),
206
+                        $uid,
207
+                        null,
208
+                        false)
209
+                );
210
+
211
+                //trigger creation of user home and /files folder
212
+                \OC::$server->getUserFolder($uid);
213
+            }
214
+            return true;
215
+        }
216
+        return false;
217
+    }
218
+
219
+    /**
220
+     * Verify with Apache whether user is authenticated.
221
+     *
222
+     * @return boolean|null
223
+     *          true: authenticated
224
+     *          false: not authenticated
225
+     *          null: not handled / no backend available
226
+     */
227
+    public static function handleApacheAuth() {
228
+        $backend = self::findFirstActiveUsedBackend();
229
+        if ($backend) {
230
+            OC_App::loadApps();
231
+
232
+            //setup extra user backends
233
+            self::setupBackends();
234
+            \OC::$server->getUserSession()->unsetMagicInCookie();
235
+
236
+            return self::loginWithApache($backend);
237
+        }
238
+
239
+        return null;
240
+    }
241
+
242
+
243
+    /**
244
+     * Sets user id for session and triggers emit
245
+     *
246
+     * @param string $uid
247
+     */
248
+    public static function setUserId($uid) {
249
+        $userSession = \OC::$server->getUserSession();
250
+        $userManager = \OC::$server->getUserManager();
251
+        if ($user = $userManager->get($uid)) {
252
+            $userSession->setUser($user);
253
+        } else {
254
+            \OC::$server->getSession()->set('user_id', $uid);
255
+        }
256
+    }
257
+
258
+    /**
259
+     * Check if the user is logged in, considers also the HTTP basic credentials
260
+     *
261
+     * @deprecated use \OC::$server->getUserSession()->isLoggedIn()
262
+     * @return bool
263
+     */
264
+    public static function isLoggedIn() {
265
+        return \OC::$server->getUserSession()->isLoggedIn();
266
+    }
267
+
268
+    /**
269
+     * set incognito mode, e.g. if a user wants to open a public link
270
+     *
271
+     * @param bool $status
272
+     */
273
+    public static function setIncognitoMode($status) {
274
+        self::$incognitoMode = $status;
275
+    }
276
+
277
+    /**
278
+     * get incognito mode status
279
+     *
280
+     * @return bool
281
+     */
282
+    public static function isIncognitoMode() {
283
+        return self::$incognitoMode;
284
+    }
285
+
286
+    /**
287
+     * Returns the current logout URL valid for the currently logged-in user
288
+     *
289
+     * @param \OCP\IURLGenerator $urlGenerator
290
+     * @return string
291
+     */
292
+    public static function getLogoutUrl(\OCP\IURLGenerator $urlGenerator) {
293
+        $backend = self::findFirstActiveUsedBackend();
294
+        if ($backend) {
295
+            return $backend->getLogoutUrl();
296
+        }
297
+
298
+        $user = \OC::$server->getUserSession()->getUser();
299
+        if ($user instanceof \OCP\IUser) {
300
+            $backend = $user->getBackend();
301
+            if ($backend instanceof \OCP\User\Backend\ICustomLogout) {
302
+                return $backend->getLogoutUrl();
303
+            }
304
+        }
305
+
306
+        $logoutUrl = $urlGenerator->linkToRoute('core.login.logout');
307
+        $logoutUrl .= '?requesttoken=' . urlencode(\OCP\Util::callRegister());
308
+
309
+        return $logoutUrl;
310
+    }
311
+
312
+    /**
313
+     * Check if the user is an admin user
314
+     *
315
+     * @param string $uid uid of the admin
316
+     * @return bool
317
+     */
318
+    public static function isAdminUser($uid) {
319
+        $group = \OC::$server->getGroupManager()->get('admin');
320
+        $user = \OC::$server->getUserManager()->get($uid);
321
+        if ($group && $user && $group->inGroup($user) && self::$incognitoMode === false) {
322
+            return true;
323
+        }
324
+        return false;
325
+    }
326
+
327
+
328
+    /**
329
+     * get the user id of the user currently logged in.
330
+     *
331
+     * @return string|false uid or false
332
+     */
333
+    public static function getUser() {
334
+        $uid = \OC::$server->getSession() ? \OC::$server->getSession()->get('user_id') : null;
335
+        if (!is_null($uid) && self::$incognitoMode === false) {
336
+            return $uid;
337
+        } else {
338
+            return false;
339
+        }
340
+    }
341
+
342
+    /**
343
+     * Set password
344
+     *
345
+     * @param string $uid The username
346
+     * @param string $password The new password
347
+     * @param string $recoveryPassword for the encryption app to reset encryption keys
348
+     * @return bool
349
+     *
350
+     * Change the password of a user
351
+     */
352
+    public static function setPassword($uid, $password, $recoveryPassword = null) {
353
+        $user = \OC::$server->getUserManager()->get($uid);
354
+        if ($user) {
355
+            return $user->setPassword($password, $recoveryPassword);
356
+        } else {
357
+            return false;
358
+        }
359
+    }
360
+
361
+    /**
362
+     * @param string $uid The username
363
+     * @return string
364
+     *
365
+     * returns the path to the users home directory
366
+     * @deprecated Use \OC::$server->getUserManager->getHome()
367
+     */
368
+    public static function getHome($uid) {
369
+        $user = \OC::$server->getUserManager()->get($uid);
370
+        if ($user) {
371
+            return $user->getHome();
372
+        } else {
373
+            return \OC::$server->getSystemConfig()->getValue('datadirectory', OC::$SERVERROOT . '/data') . '/' . $uid;
374
+        }
375
+    }
376
+
377
+    /**
378
+     * Get a list of all users display name
379
+     *
380
+     * @param string $search
381
+     * @param int $limit
382
+     * @param int $offset
383
+     * @return array associative array with all display names (value) and corresponding uids (key)
384
+     *
385
+     * Get a list of all display names and user ids.
386
+     * @deprecated Use \OC::$server->getUserManager->searchDisplayName($search, $limit, $offset) instead.
387
+     */
388
+    public static function getDisplayNames($search = '', $limit = null, $offset = null) {
389
+        $displayNames = [];
390
+        $users = \OC::$server->getUserManager()->searchDisplayName($search, $limit, $offset);
391
+        foreach ($users as $user) {
392
+            $displayNames[$user->getUID()] = $user->getDisplayName();
393
+        }
394
+        return $displayNames;
395
+    }
396
+
397
+    /**
398
+     * Returns the first active backend from self::$_usedBackends.
399
+     *
400
+     * @return OCP\Authentication\IApacheBackend|null if no backend active, otherwise OCP\Authentication\IApacheBackend
401
+     */
402
+    private static function findFirstActiveUsedBackend() {
403
+        foreach (self::$_usedBackends as $backend) {
404
+            if ($backend instanceof OCP\Authentication\IApacheBackend) {
405
+                if ($backend->isSessionActive()) {
406
+                    return $backend;
407
+                }
408
+            }
409
+        }
410
+
411
+        return null;
412
+    }
413 413
 }
Please login to merge, or discard this patch.
core/Controller/WebAuthnController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@
 block discarded – undo
77 77
 			'preLoginNameUsedAsUserName',
78 78
 			['uid' => &$uid]
79 79
 		);
80
-		$this->logger->debug('Got UID: ' . $uid);
80
+		$this->logger->debug('Got UID: '.$uid);
81 81
 
82 82
 		$publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
83 83
 		$this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
Please login to merge, or discard this patch.
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -39,73 +39,73 @@
 block discarded – undo
39 39
 use Webauthn\PublicKeyCredentialRequestOptions;
40 40
 
41 41
 class WebAuthnController extends Controller {
42
-	private const WEBAUTHN_LOGIN = 'webauthn_login';
43
-	private const WEBAUTHN_LOGIN_UID = 'webauthn_login_uid';
44
-
45
-	private Manager $webAuthnManger;
46
-	private ISession $session;
47
-	private LoggerInterface $logger;
48
-	private WebAuthnChain $webAuthnChain;
49
-
50
-	public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain) {
51
-		parent::__construct($appName, $request);
52
-
53
-		$this->webAuthnManger = $webAuthnManger;
54
-		$this->session = $session;
55
-		$this->logger = $logger;
56
-		$this->webAuthnChain = $webAuthnChain;
57
-	}
58
-
59
-	/**
60
-	 * @NoAdminRequired
61
-	 * @PublicPage
62
-	 * @UseSession
63
-	 */
64
-	public function startAuthentication(string $loginName): JSONResponse {
65
-		$this->logger->debug('Starting WebAuthn login');
66
-
67
-		$this->logger->debug('Converting login name to UID');
68
-		$uid = $loginName;
69
-		Util::emitHook(
70
-			'\OCA\Files_Sharing\API\Server2Server',
71
-			'preLoginNameUsedAsUserName',
72
-			['uid' => &$uid]
73
-		);
74
-		$this->logger->debug('Got UID: ' . $uid);
75
-
76
-		$publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
77
-		$this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
78
-		$this->session->set(self::WEBAUTHN_LOGIN_UID, $uid);
79
-
80
-		return new JSONResponse($publicKeyCredentialRequestOptions);
81
-	}
82
-
83
-	/**
84
-	 * @NoAdminRequired
85
-	 * @PublicPage
86
-	 * @UseSession
87
-	 */
88
-	public function finishAuthentication(string $data): JSONResponse {
89
-		$this->logger->debug('Validating WebAuthn login');
90
-
91
-		if (!$this->session->exists(self::WEBAUTHN_LOGIN) || !$this->session->exists(self::WEBAUTHN_LOGIN_UID)) {
92
-			$this->logger->debug('Trying to finish WebAuthn login without session data');
93
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
94
-		}
95
-
96
-		// Obtain the publicKeyCredentialOptions from when we started the registration
97
-		$publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($this->session->get(self::WEBAUTHN_LOGIN));
98
-		$uid = $this->session->get(self::WEBAUTHN_LOGIN_UID);
99
-		$this->webAuthnManger->finishAuthentication($publicKeyCredentialRequestOptions, $data, $uid);
100
-
101
-		//TODO: add other parameters
102
-		$loginData = new LoginData(
103
-			$this->request,
104
-			$uid,
105
-			''
106
-		);
107
-		$this->webAuthnChain->process($loginData);
108
-
109
-		return new JSONResponse([]);
110
-	}
42
+    private const WEBAUTHN_LOGIN = 'webauthn_login';
43
+    private const WEBAUTHN_LOGIN_UID = 'webauthn_login_uid';
44
+
45
+    private Manager $webAuthnManger;
46
+    private ISession $session;
47
+    private LoggerInterface $logger;
48
+    private WebAuthnChain $webAuthnChain;
49
+
50
+    public function __construct($appName, IRequest $request, Manager $webAuthnManger, ISession $session, LoggerInterface $logger, WebAuthnChain $webAuthnChain) {
51
+        parent::__construct($appName, $request);
52
+
53
+        $this->webAuthnManger = $webAuthnManger;
54
+        $this->session = $session;
55
+        $this->logger = $logger;
56
+        $this->webAuthnChain = $webAuthnChain;
57
+    }
58
+
59
+    /**
60
+     * @NoAdminRequired
61
+     * @PublicPage
62
+     * @UseSession
63
+     */
64
+    public function startAuthentication(string $loginName): JSONResponse {
65
+        $this->logger->debug('Starting WebAuthn login');
66
+
67
+        $this->logger->debug('Converting login name to UID');
68
+        $uid = $loginName;
69
+        Util::emitHook(
70
+            '\OCA\Files_Sharing\API\Server2Server',
71
+            'preLoginNameUsedAsUserName',
72
+            ['uid' => &$uid]
73
+        );
74
+        $this->logger->debug('Got UID: ' . $uid);
75
+
76
+        $publicKeyCredentialRequestOptions = $this->webAuthnManger->startAuthentication($uid, $this->request->getServerHost());
77
+        $this->session->set(self::WEBAUTHN_LOGIN, json_encode($publicKeyCredentialRequestOptions));
78
+        $this->session->set(self::WEBAUTHN_LOGIN_UID, $uid);
79
+
80
+        return new JSONResponse($publicKeyCredentialRequestOptions);
81
+    }
82
+
83
+    /**
84
+     * @NoAdminRequired
85
+     * @PublicPage
86
+     * @UseSession
87
+     */
88
+    public function finishAuthentication(string $data): JSONResponse {
89
+        $this->logger->debug('Validating WebAuthn login');
90
+
91
+        if (!$this->session->exists(self::WEBAUTHN_LOGIN) || !$this->session->exists(self::WEBAUTHN_LOGIN_UID)) {
92
+            $this->logger->debug('Trying to finish WebAuthn login without session data');
93
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
94
+        }
95
+
96
+        // Obtain the publicKeyCredentialOptions from when we started the registration
97
+        $publicKeyCredentialRequestOptions = PublicKeyCredentialRequestOptions::createFromString($this->session->get(self::WEBAUTHN_LOGIN));
98
+        $uid = $this->session->get(self::WEBAUTHN_LOGIN_UID);
99
+        $this->webAuthnManger->finishAuthentication($publicKeyCredentialRequestOptions, $data, $uid);
100
+
101
+        //TODO: add other parameters
102
+        $loginData = new LoginData(
103
+            $this->request,
104
+            $uid,
105
+            ''
106
+        );
107
+        $this->webAuthnChain->process($loginData);
108
+
109
+        return new JSONResponse([]);
110
+    }
111 111
 }
Please login to merge, or discard this patch.