diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-08-03 15:57:06 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-11-16 15:24:27 +0100 |
commit | 1afccde16a04f9a91f9c5c46090517a54670f34d (patch) | |
tree | 400495cbb0f40c7054b5fc63539d3546aac1975b /lib/private/Authentication | |
parent | b4e27d35f59e359eb7591a15c7f037968081eb1b (diff) | |
download | nextcloud-server-1afccde16a04f9a91f9c5c46090517a54670f34d.tar.gz nextcloud-server-1afccde16a04f9a91f9c5c46090517a54670f34d.zip |
allow configuring filesystem access
Signed-off-by: Robin Appelman <icewind@owncloud.com>
Diffstat (limited to 'lib/private/Authentication')
-rw-r--r-- | lib/private/Authentication/Token/DefaultToken.php | 15 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenMapper.php | 24 | ||||
-rw-r--r-- | lib/private/Authentication/Token/DefaultTokenProvider.php | 17 | ||||
-rw-r--r-- | lib/private/Authentication/Token/IProvider.php | 11 | ||||
-rw-r--r-- | lib/private/Authentication/Token/IToken.php | 11 |
5 files changed, 71 insertions, 7 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index e938ff92e16..b32f9cc9866 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -124,7 +124,7 @@ class DefaultToken extends Entity implements IToken { 'name' => $this->name, 'lastActivity' => $this->lastActivity, 'type' => $this->type, - 'scope' => $this->getScope() + 'scope' => $this->getScopeAsArray() ]; } @@ -147,7 +147,18 @@ class DefaultToken extends Entity implements IToken { } public function getScope() { - return json_decode(parent::getScope(), true); + return parent::getScope(); + } + + public function getScopeAsArray() { + $scope = json_decode($this->getScope(), true); + if (!$scope) { + return [ + 'filesystem'=> true, + 'apps' => [] + ]; + } + return $scope; } public function setScope($scope) { diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php index bfcb54c66c0..32551a9b37c 100644 --- a/lib/private/Authentication/Token/DefaultTokenMapper.php +++ b/lib/private/Authentication/Token/DefaultTokenMapper.php @@ -88,6 +88,30 @@ class DefaultTokenMapper extends Mapper { } /** + * Get the user UID for the given token + * + * @param string $token + * @throws DoesNotExistException + * @return DefaultToken + */ + public function getTokenById($token) { + /* @var $qb IQueryBuilder */ + $qb = $this->db->getQueryBuilder(); + $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'type', 'token', 'last_activity', 'last_check', 'scope') + ->from('authtoken') + ->where($qb->expr()->eq('id', $qb->createParameter('id'))) + ->setParameter('id', $token) + ->execute(); + + $data = $result->fetch(); + $result->closeCursor(); + if ($data === false) { + throw new DoesNotExistException('token does not exist'); + }; + return DefaultToken::fromRow($data); + } + + /** * Get all token of a user * * The provider may limit the number of result rows in case of an abuse diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index 87f434c684c..0fdbc4a51dd 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -145,7 +145,7 @@ class DefaultTokenProvider implements IProvider { } /** - * Get a token by token id + * Get a token by token * * @param string $tokenId * @throws InvalidTokenException @@ -160,6 +160,21 @@ class DefaultTokenProvider implements IProvider { } /** + * Get a token by token id + * + * @param string $tokenId + * @throws InvalidTokenException + * @return DefaultToken + */ + public function getTokenById($tokenId) { + try { + return $this->mapper->getTokenById($tokenId); + } catch (DoesNotExistException $ex) { + throw new InvalidTokenException(); + } + } + + /** * @param string $oldSessionId * @param string $sessionId * @throws InvalidTokenException diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index ce14a5880c5..9f280263d76 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -50,7 +50,16 @@ interface IProvider { * @throws InvalidTokenException * @return IToken */ - public function getToken($tokenId) ; + public function getToken($tokenId); + + /** + * Get a token by token id + * + * @param string $tokenId + * @throws InvalidTokenException + * @return DefaultToken + */ + public function getTokenById($tokenId); /** * Duplicate an existing session token diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php index a6ba392907d..71f52fd6c03 100644 --- a/lib/private/Authentication/Token/IToken.php +++ b/lib/private/Authentication/Token/IToken.php @@ -76,13 +76,18 @@ interface IToken extends JsonSerializable { /** * Get the authentication scope for this token * - * If the scope is null no limitations exist for the token - * - * @return array|null + * @return string */ public function getScope(); /** + * Get the authentication scope for this token + * + * @return array + */ + public function getScopeAsArray(); + + /** * Set the authentication scope for this token * * @param array|null $scope |