summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication/Token
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Authentication/Token')
-rw-r--r--lib/private/Authentication/Token/DefaultToken.php16
-rw-r--r--lib/private/Authentication/Token/DefaultTokenMapper.php6
-rw-r--r--lib/private/Authentication/Token/DefaultTokenProvider.php19
-rw-r--r--lib/private/Authentication/Token/IProvider.php2
-rw-r--r--lib/private/Authentication/Token/IToken.php7
5 files changed, 45 insertions, 5 deletions
diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php
index 52dd6644d2e..f41d0b8b7c4 100644
--- a/lib/private/Authentication/Token/DefaultToken.php
+++ b/lib/private/Authentication/Token/DefaultToken.php
@@ -91,10 +91,15 @@ class DefaultToken extends Entity implements IToken {
*/
protected $scope;
+ /** @var int */
+ protected $expires;
+
public function __construct() {
$this->addType('type', 'int');
$this->addType('lastActivity', 'int');
$this->addType('lastCheck', 'int');
+ $this->addType('scope', 'string');
+ $this->addType('expires', 'int');
}
public function getId() {
@@ -180,4 +185,15 @@ class DefaultToken extends Entity implements IToken {
public function setPassword($password = null) {
parent::setPassword($password);
}
+
+ public function setExpires($expires) {
+ parent::setExpires($expires);
+ }
+
+ /**
+ * @return int|null
+ */
+ public function getExpires() {
+ return parent::getExpires();
+ }
}
diff --git a/lib/private/Authentication/Token/DefaultTokenMapper.php b/lib/private/Authentication/Token/DefaultTokenMapper.php
index 41d1b9f203d..70a450602da 100644
--- a/lib/private/Authentication/Token/DefaultTokenMapper.php
+++ b/lib/private/Authentication/Token/DefaultTokenMapper.php
@@ -78,7 +78,7 @@ class DefaultTokenMapper extends Mapper {
public function getToken($token) {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
- $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'type', 'remember', 'token', 'last_activity', 'last_check', 'scope')
+ $result = $qb->select('*')
->from('authtoken')
->where($qb->expr()->eq('token', $qb->createNamedParameter($token)))
->execute();
@@ -101,7 +101,7 @@ class DefaultTokenMapper extends Mapper {
public function getTokenById($id) {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
- $result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'type', 'token', 'last_activity', 'last_check', 'scope')
+ $result = $qb->select('*')
->from('authtoken')
->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
->execute();
@@ -126,7 +126,7 @@ class DefaultTokenMapper extends Mapper {
public function getTokenByUser(IUser $user) {
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
- $qb->select('id', 'uid', 'login_name', 'password', 'name', 'type', 'remember', 'token', 'last_activity', 'last_check', 'scope')
+ $qb->select('*')
->from('authtoken')
->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
->setMaxResults(1000);
diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php
index 13407a688d3..4e87424e55c 100644
--- a/lib/private/Authentication/Token/DefaultTokenProvider.php
+++ b/lib/private/Authentication/Token/DefaultTokenProvider.php
@@ -155,13 +155,20 @@ class DefaultTokenProvider implements IProvider {
* @param string $tokenId
* @throws InvalidTokenException
* @return DefaultToken
+ * @throws ExpiredTokenException
*/
public function getToken($tokenId) {
try {
- return $this->mapper->getToken($this->hashToken($tokenId));
+ $token = $this->mapper->getToken($this->hashToken($tokenId));
} catch (DoesNotExistException $ex) {
throw new InvalidTokenException();
}
+
+ if ($token->getExpires() !== null && $token->getExpires() < $this->time->getTime()) {
+ throw new ExpiredTokenException($token);
+ }
+
+ return $token;
}
/**
@@ -170,13 +177,21 @@ class DefaultTokenProvider implements IProvider {
* @param string $tokenId
* @throws InvalidTokenException
* @return DefaultToken
+ * @throws ExpiredTokenException
+ * @return IToken
*/
public function getTokenById($tokenId) {
try {
- return $this->mapper->getTokenById($tokenId);
+ $token = $this->mapper->getTokenById($tokenId);
} catch (DoesNotExistException $ex) {
throw new InvalidTokenException();
}
+
+ if ($token->getExpires() !== null && $token->getExpires() < $this->time->getTime()) {
+ throw new ExpiredTokenException($token);
+ }
+
+ return $token;
}
/**
diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php
index 707645a09e9..8b812a9533c 100644
--- a/lib/private/Authentication/Token/IProvider.php
+++ b/lib/private/Authentication/Token/IProvider.php
@@ -51,6 +51,7 @@ interface IProvider {
*
* @param string $tokenId
* @throws InvalidTokenException
+ * @throws ExpiredTokenException
* @return IToken
*/
public function getToken($tokenId);
@@ -61,6 +62,7 @@ interface IProvider {
* @param string $tokenId
* @throws InvalidTokenException
* @return DefaultToken
+ * @throws ExpiredTokenException
*/
public function getTokenById($tokenId);
diff --git a/lib/private/Authentication/Token/IToken.php b/lib/private/Authentication/Token/IToken.php
index 0e32e3adfd6..6586a5b2fd7 100644
--- a/lib/private/Authentication/Token/IToken.php
+++ b/lib/private/Authentication/Token/IToken.php
@@ -108,4 +108,11 @@ interface IToken extends JsonSerializable {
* @param string $password
*/
public function setPassword($password);
+
+ /**
+ * Set the expiration time of the token
+ *
+ * @param int|null $expires
+ */
+ public function setExpires($expires);
}