From 46bdf6ea2b1e10c2f4d2fae214ecc81b188fa981 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 6 May 2016 16:31:40 +0200 Subject: fix PHPDoc and other minor issues --- lib/private/Authentication/Token/DefaultToken.php | 2 +- .../Authentication/Token/DefaultTokenProvider.php | 11 ++++-- lib/private/Authentication/Token/IProvider.php | 2 +- lib/private/Authentication/Token/IToken.php | 2 +- lib/private/Files/Filesystem.php | 2 +- lib/private/Updater.php | 1 + lib/private/User/Session.php | 45 ++++++++++------------ lib/private/legacy/api.php | 2 +- 8 files changed, 35 insertions(+), 32 deletions(-) (limited to 'lib') diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 5dd9dc5b039..25caf675a43 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -74,7 +74,7 @@ class DefaultToken extends Entity implements IToken { return $this->id; } - public function getUid() { + public function getUID() { return $this->uid; } diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index a0d07f9e2e2..53ecb562a8d 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -51,6 +51,7 @@ class DefaultTokenProvider implements IProvider { * @param ICrypto $crypto * @param IConfig $config * @param ILogger $logger + * @param ITimeFactory $time */ public function __construct(DefaultTokenMapper $mapper, ICrypto $crypto, IConfig $config, ILogger $logger, ITimeFactory $time) { $this->mapper = $mapper; @@ -66,6 +67,7 @@ class DefaultTokenProvider implements IProvider { * @param string $token * @param string $uid * @param string $password + * @param string $name * @param int $type token type * @return DefaultToken */ @@ -86,7 +88,8 @@ class DefaultTokenProvider implements IProvider { /** * Update token activity timestamp * - * @param DefaultToken $token + * @throws InvalidTokenException + * @param IToken $token */ public function updateToken(IToken $token) { if (!($token instanceof DefaultToken)) { @@ -101,6 +104,7 @@ class DefaultTokenProvider implements IProvider { /** * @param string $token * @throws InvalidTokenException + * @return DefaultToken */ public function getToken($token) { try { @@ -113,6 +117,7 @@ class DefaultTokenProvider implements IProvider { /** * @param DefaultToken $savedToken * @param string $token session token + * @return string */ public function getPassword(DefaultToken $savedToken, $token) { return $this->decryptPassword($savedToken->getPassword(), $token); @@ -139,13 +144,13 @@ class DefaultTokenProvider implements IProvider { /** * @param string $token * @throws InvalidTokenException - * @return IToken user UID + * @return DefaultToken user UID */ public function validateToken($token) { $this->logger->debug('validating default token <' . $token . '>'); try { $dbToken = $this->mapper->getToken($this->hashToken($token)); - $this->logger->debug('valid token for ' . $dbToken->getUid()); + $this->logger->debug('valid token for ' . $dbToken->getUID()); return $dbToken; } catch (DoesNotExistException $ex) { $this->logger->warning('invalid token'); diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index 5c0b0d140ae..f8a3262ca8b 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -36,7 +36,7 @@ interface IProvider { /** * Update token activity timestamp * - * @param DefaultToken $token + * @param IToken $token */ public function updateToken(IToken $token); } diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index 90feefb4589..9b2bd18f83b 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -42,5 +42,5 @@ interface IToken { * * @return string */ - public function getUid(); + public function getUID(); } diff --git a/lib/private/Files/Filesystem.php b/lib/private/Files/Filesystem.php index 89b8547aa52..99c123ad1a1 100644 --- a/lib/private/Files/Filesystem.php +++ b/lib/private/Files/Filesystem.php @@ -404,7 +404,7 @@ class Filesystem { if (is_null($userObject)) { \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); - throw new \OC\User\NoUserException('Backend provided no user object for ' . $user); + throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); } self::$usersSetup[$user] = true; diff --git a/lib/private/Updater.php b/lib/private/Updater.php index fd082c837e0..dbcaccaad26 100644 --- a/lib/private/Updater.php +++ b/lib/private/Updater.php @@ -216,6 +216,7 @@ class Updater extends BasicEmitter { try { Setup::updateHtaccess(); Setup::protectDataDirectory(); + // TODO: replace with the new repair step mechanism https://github.com/owncloud/core/pull/24378 Setup::installBackgroundJobs(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); diff --git a/lib/private/User/Session.php b/lib/private/User/Session.php index 297ebb2aaf0..0351125b5d9 100644 --- a/lib/private/User/Session.php +++ b/lib/private/User/Session.php @@ -97,11 +97,14 @@ class Session implements IUserSession, Emitter { /** * @var User $activeUser + */ protected $activeUser; /** * @param IUserManager $manager * @param ISession $session + * @param ITimeFactory $timeFacory + * @param IProvider $tokenProvider * @param IProvider[] $tokenProviders */ public function __construct(IUserManager $manager, ISession $session, ITimeFactory $timeFacory, $tokenProvider, @@ -219,7 +222,7 @@ class Session implements IUserSession, Emitter { } catch (InvalidTokenException $ex) { // Session was invalidated $this->logout(); - return false; + return; } // Check whether login credentials are still valid @@ -231,15 +234,13 @@ class Session implements IUserSession, Emitter { if ($this->manager->checkPassword($user->getUID(), $pwd) === false) { // Password has changed -> log user out $this->logout(); - return false; + return; } $this->session->set('last_login_check', $now); } // Session is valid, so the token can be refreshed $this->updateToken($this->tokenProvider, $token); - - return true; } /** @@ -301,9 +302,7 @@ class Session implements IUserSession, Emitter { $this->manager->emit('\OC\User', 'preLogin', array($uid, $password)); $user = $this->manager->checkPassword($uid, $password); if ($user === false) { - // Password auth failed, maybe it's a token - $request = \OC::$server->getRequest(); - if ($this->validateToken($request, $password)) { + if ($this->validateToken($password)) { $user = $this->getUser(); } } @@ -349,9 +348,8 @@ class Session implements IUserSession, Emitter { * @return boolean if the login was successful */ public function tryBasicAuthLogin(IRequest $request) { - // TODO: use $request->server instead of super globals - if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { - $result = $this->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); + if (!empty($request->server['PHP_AUTH_USER']) && !empty($request->server['PHP_AUTH_PW'])) { + $result = $this->login($request->server['PHP_AUTH_USER'], $request->server['PHP_AUTH_PW']); if ($result === true) { /** * Add DAV authenticated. This should in an ideal world not be @@ -363,14 +361,14 @@ class Session implements IUserSession, Emitter { $this->session->set( Auth::DAV_AUTHENTICATED, $this->getUser()->getUID() ); + return true; } - return $result; } return false; } private function loginWithToken($uid) { - //$this->manager->emit('\OC\User', 'preTokenLogin', array($uid)); + // TODO: $this->manager->emit('\OC\User', 'preTokenLogin', array($uid)); $user = $this->manager->get($uid); if (is_null($user)) { // user does not exist @@ -379,7 +377,7 @@ class Session implements IUserSession, Emitter { //login $this->setUser($user); - //$this->manager->emit('\OC\User', 'postTokenLogin', array($user)); + // TODO: $this->manager->emit('\OC\User', 'postTokenLogin', array($user)); return true; } @@ -410,16 +408,15 @@ class Session implements IUserSession, Emitter { } /** - * @param IRequest $request * @param string $token * @return boolean */ - private function validateToken(IRequest $request, $token) { + private function validateToken($token) { foreach ($this->tokenProviders as $provider) { try { $token = $provider->validateToken($token); if (!is_null($token)) { - $result = $this->loginWithToken($token->getUid()); + $result = $this->loginWithToken($token->getUID()); if ($result) { // Login success $this->updateToken($provider, $token); @@ -458,13 +455,13 @@ class Session implements IUserSession, Emitter { // No auth header, let's try session id try { $sessionId = $this->session->getId(); - return $this->validateToken($request, $sessionId); + return $this->validateToken($sessionId); } catch (SessionNotAvailableException $ex) { return false; } } else { $token = substr($authHeader, 6); - return $this->validateToken($request, $token); + return $this->validateToken($token); } } @@ -530,9 +527,9 @@ class Session implements IUserSession, Emitter { public function setMagicInCookie($username, $token) { $secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https'; $expires = time() + OC::$server->getConfig()->getSystemValue('remember_login_cookie_lifetime', 60 * 60 * 24 * 15); - setcookie("oc_username", $username, $expires, OC::$WEBROOT, '', $secureCookie, true); - setcookie("oc_token", $token, $expires, OC::$WEBROOT, '', $secureCookie, true); - setcookie("oc_remember_login", "1", $expires, OC::$WEBROOT, '', $secureCookie, true); + setcookie('oc_username', $username, $expires, OC::$WEBROOT, '', $secureCookie, true); + setcookie('oc_token', $token, $expires, OC::$WEBROOT, '', $secureCookie, true); + setcookie('oc_remember_login', '1', $expires, OC::$WEBROOT, '', $secureCookie, true); } /** @@ -542,9 +539,9 @@ class Session implements IUserSession, Emitter { //TODO: DI for cookies and IRequest $secureCookie = OC::$server->getRequest()->getServerProtocol() === 'https'; - unset($_COOKIE["oc_username"]); //TODO: DI - unset($_COOKIE["oc_token"]); - unset($_COOKIE["oc_remember_login"]); + unset($_COOKIE['oc_username']); //TODO: DI + unset($_COOKIE['oc_token']); + unset($_COOKIE['oc_remember_login']); setcookie('oc_username', '', time() - 3600, OC::$WEBROOT, '', $secureCookie, true); setcookie('oc_token', '', time() - 3600, OC::$WEBROOT, '', $secureCookie, true); setcookie('oc_remember_login', '', time() - 3600, OC::$WEBROOT, '', $secureCookie, true); diff --git a/lib/private/legacy/api.php b/lib/private/legacy/api.php index e3d597fc64e..60300c88b57 100644 --- a/lib/private/legacy/api.php +++ b/lib/private/legacy/api.php @@ -358,7 +358,7 @@ class OC_API { try { $loginSuccess = $userSession->tryTokenLogin($request); if (!$loginSuccess) { - $loginSuccess = $userSession->tryBasicAuthLogin(); + $loginSuccess = $userSession->tryBasicAuthLogin($request); } } catch (\OC\User\LoginException $e) { return false; -- cgit v1.2.3