diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-05-02 19:58:19 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-05-11 13:36:46 +0200 |
commit | f0f8bdd495ff958ce536e577e42586090b6bcd8f (patch) | |
tree | c13077c866c0561cf158b5de913c1975721172cd /lib/private/Authentication/Token | |
parent | dff108e97bea1d1b6e6a639fabd64d400acd4347 (diff) | |
download | nextcloud-server-f0f8bdd495ff958ce536e577e42586090b6bcd8f.tar.gz nextcloud-server-f0f8bdd495ff958ce536e577e42586090b6bcd8f.zip |
PHPDoc and other minor fixes
Diffstat (limited to 'lib/private/Authentication/Token')
-rw-r--r-- | lib/private/Authentication/Token/DefaultToken.php | 14 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenProvider.php | 18 |
2 files changed, 26 insertions, 6 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 70562502b76..5dd9dc5b039 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -24,6 +24,20 @@ namespace OC\Authentication\Token; use OCP\AppFramework\Db\Entity; +/** + * @method void setId(int $id) + * @method void setUid(string $uid); + * @method void setPassword(string $password) + * @method string getPassword() + * @method void setName(string $name) + * @method string getName() + * @method void setToken(string $token) + * @method string getToken() + * @method void setType(string $type) + * @method int getType() + * @method void setLastActivity(int $lastActivity) + * @method int getLastActivity() + */ class DefaultToken extends Entity implements IToken { /** diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 97567e53cd0..a0d07f9e2e2 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -24,6 +24,7 @@ namespace OC\Authentication\Token; use OC\Authentication\Exceptions\InvalidTokenException; use OCP\AppFramework\Db\DoesNotExistException; +use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; use OCP\ILogger; use OCP\Security\ICrypto; @@ -42,17 +43,21 @@ class DefaultTokenProvider implements IProvider { /** @var ILogger $logger */ private $logger; + /** @var ITimeFactory $time */ + private $time; + /** * @param DefaultTokenMapper $mapper * @param ICrypto $crypto * @param IConfig $config * @param ILogger $logger */ - public function __construct(DefaultTokenMapper $mapper, ICrypto $crypto, IConfig $config, ILogger $logger) { + public function __construct(DefaultTokenMapper $mapper, ICrypto $crypto, IConfig $config, ILogger $logger, ITimeFactory $time) { $this->mapper = $mapper; $this->crypto = $crypto; $this->config = $config; $this->logger = $logger; + $this->time = $time; } /** @@ -61,7 +66,7 @@ class DefaultTokenProvider implements IProvider { * @param string $token * @param string $uid * @param string $password - * @apram int $type token type + * @param int $type token type * @return DefaultToken */ public function generateToken($token, $uid, $password, $name, $type = IToken::TEMPORARY_TOKEN) { @@ -71,7 +76,7 @@ class DefaultTokenProvider implements IProvider { $dbToken->setName($name); $dbToken->setToken($this->hashToken($token)); $dbToken->setType($type); - $dbToken->setLastActivity(time()); + $dbToken->setLastActivity($this->time->getTime()); $this->mapper->insert($dbToken); @@ -88,7 +93,7 @@ class DefaultTokenProvider implements IProvider { throw new InvalidTokenException(); } /** @var DefaultToken $token */ - $token->setLastActivity(time()); + $token->setLastActivity($this->time->getTime()); $this->mapper->update($token); } @@ -126,7 +131,7 @@ class DefaultTokenProvider implements IProvider { * Invalidate (delete) old session tokens */ public function invalidateOldTokens() { - $olderThan = time() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); + $olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24); $this->logger->info('Invalidating tokens older than ' . date('c', $olderThan)); $this->mapper->invalidateOld($olderThan); } @@ -153,7 +158,8 @@ class DefaultTokenProvider implements IProvider { * @return string */ private function hashToken($token) { - return hash('sha512', $token); + $secret = $this->config->getSystemValue('secret'); + return hash('sha512', $token . $secret); } /** |