summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/Token
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-05-29 09:29:29 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-06-18 22:11:54 +0200
commit4c0d7104792cb89b8bc013c08b9c9fcb63dcf0da (patch)
tree2f23ee511ab06b17128ab123765bac93c9b82ef1 /lib/private/Authentication/Token
parent1f17010e0b4099b41cc72f53e18f4d162ce2e3da (diff)
downloadnextcloud-server-4c0d7104792cb89b8bc013c08b9c9fcb63dcf0da.tar.gz
nextcloud-server-4c0d7104792cb89b8bc013c08b9c9fcb63dcf0da.zip
Just pass uid to the Token stuff
We don't have user objects in the code everywhere Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/Authentication/Token')
-rw-r--r--lib/private/Authentication/Token/DefaultTokenMapper.php15
-rw-r--r--lib/private/Authentication/Token/DefaultTokenProvider.php23
-rw-r--r--lib/private/Authentication/Token/IProvider.php9
-rw-r--r--lib/private/Authentication/Token/Manager.php8
-rw-r--r--lib/private/Authentication/Token/PublicKeyTokenMapper.php15
-rw-r--r--lib/private/Authentication/Token/PublicKeyTokenProvider.php8
6 files changed, 26 insertions, 52 deletions
diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php
index 0a3f32ffb46..02964e3f59c 100644
--- a/lib/private/Authentication/Token/DefaultTokenMapper.php
+++ b/lib/private/Authentication/Token/DefaultTokenMapper.php
@@ -33,7 +33,6 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
-use OCP\IUser;
class DefaultTokenMapper extends QBMapper {
@@ -124,15 +123,15 @@ class DefaultTokenMapper extends QBMapper {
* The provider may limit the number of result rows in case of an abuse
* where a high number of (session) tokens is generated
*
- * @param IUser $user
+ * @param string $uid
* @return DefaultToken[]
*/
- public function getTokenByUser(IUser $user): array {
+ public function getTokenByUser(string $uid): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version')
->from('authtoken')
- ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
+ ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)))
->setMaxResults(1000);
$result = $qb->execute();
@@ -146,16 +145,12 @@ class DefaultTokenMapper extends QBMapper {
return $entities;
}
- /**
- * @param IUser $user
- * @param int $id
- */
- public function deleteById(IUser $user, int $id) {
+ public function deleteById(string $uid, int $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())))
+ ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT)));
$qb->execute();
}
diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php
index 7a43dbb23e1..ed3c14c1745 100644
--- a/lib/private/Authentication/Token/DefaultTokenProvider.php
+++ b/lib/private/Authentication/Token/DefaultTokenProvider.php
@@ -143,17 +143,8 @@ class DefaultTokenProvider implements IProvider {
}
}
- /**
- * Get all tokens of a user
- *
- * The provider may limit the number of result rows in case of an abuse
- * where a high number of (session) tokens is generated
- *
- * @param IUser $user
- * @return IToken[]
- */
- public function getTokenByUser(IUser $user): array {
- return $this->mapper->getTokenByUser($user);
+ public function getTokenByUser(string $uid): array {
+ return $this->mapper->getTokenByUser($uid);
}
/**
@@ -265,14 +256,8 @@ class DefaultTokenProvider implements IProvider {
$this->mapper->invalidate($this->hashToken($token));
}
- /**
- * Invalidate (delete) the given token
- *
- * @param IUser $user
- * @param int $id
- */
- public function invalidateTokenById(IUser $user, int $id) {
- $this->mapper->deleteById($user, $id);
+ public function invalidateTokenById(string $uid, int $id) {
+ $this->mapper->deleteById($uid, $id);
}
/**
diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php
index 0efffefac68..ab46bd12126 100644
--- a/lib/private/Authentication/Token/IProvider.php
+++ b/lib/private/Authentication/Token/IProvider.php
@@ -28,7 +28,6 @@ namespace OC\Authentication\Token;
use OC\Authentication\Exceptions\InvalidTokenException;
use OC\Authentication\Exceptions\PasswordlessTokenException;
-use OCP\IUser;
interface IProvider {
@@ -92,10 +91,10 @@ interface IProvider {
/**
* Invalidate (delete) the given token
*
- * @param IUser $user
+ * @param string $uid
* @param int $id
*/
- public function invalidateTokenById(IUser $user, int $id);
+ public function invalidateTokenById(string $uid, int $id);
/**
* Invalidate (delete) old session tokens
@@ -122,10 +121,10 @@ interface IProvider {
* The provider may limit the number of result rows in case of an abuse
* where a high number of (session) tokens is generated
*
- * @param IUser $user
+ * @param string $uid
* @return IToken[]
*/
- public function getTokenByUser(IUser $user): array;
+ public function getTokenByUser(string $uid): array;
/**
* Get the (unencrypted) password of the given token
diff --git a/lib/private/Authentication/Token/Manager.php b/lib/private/Authentication/Token/Manager.php
index 85fe91cdf14..7ec90e92ed0 100644
--- a/lib/private/Authentication/Token/Manager.php
+++ b/lib/private/Authentication/Token/Manager.php
@@ -104,8 +104,8 @@ class Manager implements IProvider {
* @param IUser $user
* @return IToken[]
*/
- public function getTokenByUser(IUser $user): array {
- return $this->defaultTokenProvider->getTokenByUser($user);
+ public function getTokenByUser(string $uid): array {
+ return $this->defaultTokenProvider->getTokenByUser($uid);
}
/**
@@ -188,9 +188,9 @@ class Manager implements IProvider {
* @param IUser $user
* @param int $id
*/
- public function invalidateTokenById(IUser $user, int $id) {
+ public function invalidateTokenById(string $uid, int $id) {
//TODO find way to distinguis between tokens
- $this->defaultTokenProvider->invalidateTokenById($user, $id);
+ $this->defaultTokenProvider->invalidateTokenById($uid, $id);
}
/**
diff --git a/lib/private/Authentication/Token/PublicKeyTokenMapper.php b/lib/private/Authentication/Token/PublicKeyTokenMapper.php
index 0d5657cb582..6feb176fb68 100644
--- a/lib/private/Authentication/Token/PublicKeyTokenMapper.php
+++ b/lib/private/Authentication/Token/PublicKeyTokenMapper.php
@@ -28,7 +28,6 @@ use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
-use OCP\IUser;
class PublicKeyTokenMapper extends QBMapper {
@@ -115,15 +114,15 @@ class PublicKeyTokenMapper extends QBMapper {
* The provider may limit the number of result rows in case of an abuse
* where a high number of (session) tokens is generated
*
- * @param IUser $user
+ * @param string $uid
* @return DefaultToken[]
*/
- public function getTokenByUser(IUser $user): array {
+ public function getTokenByUser(string $uid): array {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from('authtoken')
- ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
+ ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT)))
->setMaxResults(1000);
$result = $qb->execute();
@@ -137,16 +136,12 @@ class PublicKeyTokenMapper extends QBMapper {
return $entities;
}
- /**
- * @param IUser $user
- * @param int $id
- */
- public function deleteById(IUser $user, int $id) {
+ public function deleteById(string $uid, int $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())))
+ ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($uid)))
->andWhere($qb->expr()->eq('version', $qb->createNamedParameter(2, IQueryBuilder::PARAM_INT)));
$qb->execute();
}
diff --git a/lib/private/Authentication/Token/PublicKeyTokenProvider.php b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
index 1c5f3da147f..926e3c678d4 100644
--- a/lib/private/Authentication/Token/PublicKeyTokenProvider.php
+++ b/lib/private/Authentication/Token/PublicKeyTokenProvider.php
@@ -161,8 +161,8 @@ class PublicKeyTokenProvider implements IProvider {
$this->mapper->invalidate($this->hashToken($token));
}
- public function invalidateTokenById(IUser $user, int $id) {
- $this->mapper->deleteById($user, $id);
+ public function invalidateTokenById(string $uid, int $id) {
+ $this->mapper->deleteById($uid, $id);
}
public function invalidateOldTokens() {
@@ -194,8 +194,8 @@ class PublicKeyTokenProvider implements IProvider {
}
}
- public function getTokenByUser(IUser $user): array {
- return $this->mapper->getTokenByUser($user);
+ public function getTokenByUser(string $uid): array {
+ return $this->mapper->getTokenByUser($uid);
}
public function getPassword(IToken $token, string $tokenId): string {