diff options
author | Vincent Petry <pvince81@owncloud.com> | 2016-05-23 14:17:01 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2016-05-23 14:17:01 +0200 |
commit | 57525a02f8e0153dcb8c83e0e8b7bafe34a3f820 (patch) | |
tree | d6aaafba86dbe9df75fabe369ad6b53ef62234cf /lib | |
parent | bd87f6747376063b05ad5f1f7ce12446dddd5697 (diff) | |
parent | 74277c25be2f3231e52a73a684bd14452a9ff2aa (diff) | |
download | nextcloud-server-57525a02f8e0153dcb8c83e0e8b7bafe34a3f820.tar.gz nextcloud-server-57525a02f8e0153dcb8c83e0e8b7bafe34a3f820.zip |
Merge pull request #24703 from owncloud/personal-settings-auth-tokens
Personal settings auth tokens
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Authentication/Token/DefaultToken.php | 10 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenMapper.php | 13 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenProvider.php | 12 | ||||
-rw-r--r-- | lib/private/Authentication/Token/IProvider.php | 13 | ||||
-rw-r--r-- | lib/private/Authentication/Token/IToken.php | 6 | ||||
-rw-r--r-- | lib/private/Server.php | 3 |
6 files changed, 51 insertions, 6 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 08451a46151..4a64eacb247 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -28,7 +28,6 @@ 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) @@ -87,4 +86,13 @@ class DefaultToken extends Entity implements IToken { return parent::getPassword(); } + public function jsonSerialize() { + return [ + 'id' => $this->id, + 'name' => $this->name, + 'lastActivity' => $this->lastActivity, + 'type' => $this->type, + ]; + } + } diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php index 9f173571270..970c2242dbe 100644 --- a/lib/private/Authentication/Token/DefaultTokenMapper.php +++ b/lib/private/Authentication/Token/DefaultTokenMapper.php @@ -111,4 +111,17 @@ class DefaultTokenMapper extends Mapper { return $entities; } + /** + * @param IUser $user + * @param int $id + */ + public function deleteById(IUser $user, $id) { + /* @var $qb IQueryBuilder */ + $qb = $this->db->getQueryBuilder(); + $qb->delete('authtoken') + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id))) + ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID()))); + $qb->execute(); + } + } diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 6c69d852d7b..0f7c54dab57 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -134,6 +134,7 @@ class DefaultTokenProvider implements IProvider { /** * @param IToken $savedToken * @param string $tokenId session token + * @throws InvalidTokenException * @return string */ public function getPassword(IToken $savedToken, $tokenId) { @@ -150,6 +151,16 @@ class DefaultTokenProvider implements IProvider { } /** + * Invalidate (delete) the given token + * + * @param IUser $user + * @param int $id + */ + public function invalidateTokenById(IUser $user, $id) { + $this->mapper->deleteById($user, $id); + } + + /** * Invalidate (delete) old session tokens */ public function invalidateOldTokens() { @@ -203,6 +214,7 @@ class DefaultTokenProvider implements IProvider { * * @param string $password * @param string $token + * @throws InvalidTokenException * @return string the decrypted key */ private function decryptPassword($password, $token) { diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index a5c5faa5639..e4e4581e738 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -35,7 +35,7 @@ interface IProvider { * @param string $password * @param string $name * @param int $type token type - * @return DefaultToken + * @return IToken */ public function generateToken($token, $uid, $password, $name, $type = IToken::TEMPORARY_TOKEN); @@ -47,7 +47,7 @@ interface IProvider { * @return IToken */ public function getToken($tokenId) ; - + /** * @param string $token * @throws InvalidTokenException @@ -63,6 +63,14 @@ interface IProvider { public function invalidateToken($token); /** + * Invalidate (delete) the given token + * + * @param IUser $user + * @param int $id + */ + public function invalidateTokenById(IUser $user, $id); + + /** * Update token activity timestamp * * @param IToken $token @@ -85,6 +93,7 @@ interface IProvider { * * @param IToken $token * @param string $tokenId + * @throws InvalidTokenException * @return string */ public function getPassword(IToken $token, $tokenId); diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index 2a01ea75ea9..b741cd4ac22 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -22,7 +22,9 @@ namespace OC\Authentication\Token; -interface IToken { +use JsonSerializable; + +interface IToken extends JsonSerializable { const TEMPORARY_TOKEN = 0; const PERMANENT_TOKEN = 1; @@ -30,7 +32,7 @@ interface IToken { /** * Get the token ID * - * @return string + * @return int */ public function getId(); diff --git a/lib/private/Server.php b/lib/private/Server.php index 0b7b8f9e403..ea0c436d84b 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -223,6 +223,7 @@ class Server extends ServerContainer implements IServerContainer { $timeFactory = new TimeFactory(); return new \OC\Authentication\Token\DefaultTokenProvider($mapper, $crypto, $config, $logger, $timeFactory); }); + $this->registerAlias('OC\Authentication\Token\IProvider', 'OC\Authentication\Token\DefaultTokenProvider'); $this->registerService('UserSession', function (Server $c) { $manager = $c->getUserManager(); $session = new \OC\Session\Memory(''); @@ -230,7 +231,7 @@ class Server extends ServerContainer implements IServerContainer { // Token providers might require a working database. This code // might however be called when ownCloud is not yet setup. if (\OC::$server->getSystemConfig()->getValue('installed', false)) { - $defaultTokenProvider = $c->query('OC\Authentication\Token\DefaultTokenProvider'); + $defaultTokenProvider = $c->query('OC\Authentication\Token\IProvider'); } else { $defaultTokenProvider = null; } |