2016-04-25 12:10:55 +00:00
|
|
|
<?php
|
2018-05-15 08:24:46 +00:00
|
|
|
declare(strict_types=1);
|
2016-04-25 12:10:55 +00:00
|
|
|
/**
|
2016-07-21 15:07:57 +00:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-04-25 12:10:55 +00:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2017-11-06 14:56:42 +00:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-04-25 12:10:55 +00:00
|
|
|
*
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License, version 3,
|
|
|
|
* as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License, version 3,
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Authentication\Token;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Db\Entity;
|
|
|
|
|
2016-05-02 17:58:19 +00:00
|
|
|
/**
|
|
|
|
* @method void setId(int $id)
|
|
|
|
* @method void setUid(string $uid);
|
2018-05-15 08:24:46 +00:00
|
|
|
* @method void setLoginName(string $loginname)
|
2016-05-02 17:58:19 +00:00
|
|
|
* @method string getToken()
|
2018-05-15 08:24:46 +00:00
|
|
|
* @method void setType(int $type)
|
2016-05-02 17:58:19 +00:00
|
|
|
* @method int getType()
|
2016-09-06 19:41:15 +00:00
|
|
|
* @method void setRemember(int $remember)
|
2018-05-15 08:24:46 +00:00
|
|
|
* @method void setLastActivity(int $lastactivity)
|
2016-05-02 17:58:19 +00:00
|
|
|
* @method int getLastActivity()
|
2018-05-18 17:48:08 +00:00
|
|
|
* @method void setVersion(int $version)
|
2016-05-02 17:58:19 +00:00
|
|
|
*/
|
2019-01-21 19:45:27 +00:00
|
|
|
class DefaultToken extends Entity implements INamedToken {
|
2016-04-25 12:10:55 +00:00
|
|
|
|
2018-06-04 07:51:13 +00:00
|
|
|
const VERSION = 1;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string user UID */
|
2016-04-25 12:10:55 +00:00
|
|
|
protected $uid;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string login name used for generating the token */
|
2016-05-24 08:50:18 +00:00
|
|
|
protected $loginName;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string encrypted user password */
|
2016-04-25 12:10:55 +00:00
|
|
|
protected $password;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string token name (e.g. browser/OS) */
|
2016-04-25 12:10:55 +00:00
|
|
|
protected $name;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string */
|
2016-04-25 12:10:55 +00:00
|
|
|
protected $token;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var int */
|
2016-04-26 10:48:19 +00:00
|
|
|
protected $type;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var int */
|
2016-09-06 19:41:15 +00:00
|
|
|
protected $remember;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var int */
|
2016-04-25 14:40:41 +00:00
|
|
|
protected $lastActivity;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var int */
|
2016-06-17 11:59:15 +00:00
|
|
|
protected $lastCheck;
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
/** @var string */
|
2016-08-01 17:06:54 +00:00
|
|
|
protected $scope;
|
|
|
|
|
2018-05-16 10:39:00 +00:00
|
|
|
/** @var int */
|
|
|
|
protected $expires;
|
|
|
|
|
2018-05-18 17:48:08 +00:00
|
|
|
/** @var int */
|
|
|
|
protected $version;
|
|
|
|
|
2016-10-31 13:38:41 +00:00
|
|
|
public function __construct() {
|
2018-05-15 08:24:46 +00:00
|
|
|
$this->addType('uid', 'string');
|
|
|
|
$this->addType('loginName', 'string');
|
|
|
|
$this->addType('password', 'string');
|
|
|
|
$this->addType('name', 'string');
|
|
|
|
$this->addType('token', 'string');
|
2016-10-31 13:38:41 +00:00
|
|
|
$this->addType('type', 'int');
|
2018-05-15 08:24:46 +00:00
|
|
|
$this->addType('remember', 'int');
|
2016-10-31 13:38:41 +00:00
|
|
|
$this->addType('lastActivity', 'int');
|
|
|
|
$this->addType('lastCheck', 'int');
|
2018-05-15 08:24:46 +00:00
|
|
|
$this->addType('scope', 'string');
|
2018-05-16 10:39:00 +00:00
|
|
|
$this->addType('expires', 'int');
|
2018-05-18 17:48:08 +00:00
|
|
|
$this->addType('version', 'int');
|
2016-10-31 13:38:41 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getId(): int {
|
2016-04-26 09:32:35 +00:00
|
|
|
return $this->id;
|
2016-04-25 12:10:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getUID(): string {
|
2016-04-27 07:38:30 +00:00
|
|
|
return $this->uid;
|
|
|
|
}
|
2016-05-24 08:50:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the login name used when generating the token
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getLoginName(): string {
|
2016-05-24 08:50:18 +00:00
|
|
|
return parent::getLoginName();
|
|
|
|
}
|
|
|
|
|
2016-05-17 15:20:54 +00:00
|
|
|
/**
|
|
|
|
* Get the (encrypted) login password
|
|
|
|
*
|
2018-05-15 08:56:40 +00:00
|
|
|
* @return string|null
|
2016-05-17 15:20:54 +00:00
|
|
|
*/
|
2018-05-15 08:56:40 +00:00
|
|
|
public function getPassword() {
|
2016-05-17 15:20:54 +00:00
|
|
|
return parent::getPassword();
|
|
|
|
}
|
2016-04-27 07:38:30 +00:00
|
|
|
|
2016-05-18 10:03:22 +00:00
|
|
|
public function jsonSerialize() {
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'name' => $this->name,
|
2016-10-31 13:38:41 +00:00
|
|
|
'lastActivity' => $this->lastActivity,
|
|
|
|
'type' => $this->type,
|
2016-08-03 13:57:06 +00:00
|
|
|
'scope' => $this->getScopeAsArray()
|
2016-05-18 10:03:22 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-06-17 11:59:15 +00:00
|
|
|
/**
|
|
|
|
* Get the timestamp of the last password check
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getLastCheck(): int {
|
2016-06-17 11:59:15 +00:00
|
|
|
return parent::getLastCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the timestamp of the last password check
|
|
|
|
*
|
|
|
|
* @param int $time
|
|
|
|
*/
|
2018-05-15 08:56:40 +00:00
|
|
|
public function setLastCheck(int $time) {
|
|
|
|
parent::setLastCheck($time);
|
2016-06-17 11:59:15 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getScope(): string {
|
2018-05-15 08:56:40 +00:00
|
|
|
$scope = parent::getScope();
|
|
|
|
if ($scope === null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $scope;
|
2016-08-03 13:57:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 08:24:46 +00:00
|
|
|
public function getScopeAsArray(): array {
|
2016-08-03 13:57:06 +00:00
|
|
|
$scope = json_decode($this->getScope(), true);
|
|
|
|
if (!$scope) {
|
|
|
|
return [
|
2016-10-19 13:11:58 +00:00
|
|
|
'filesystem'=> true
|
2016-08-03 13:57:06 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
return $scope;
|
2016-08-01 17:06:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-15 09:41:27 +00:00
|
|
|
public function setScope($scope) {
|
|
|
|
if (\is_array($scope)) {
|
2018-05-15 08:56:40 +00:00
|
|
|
parent::setScope(json_encode($scope));
|
2018-05-15 09:41:27 +00:00
|
|
|
} else {
|
|
|
|
parent::setScope((string)$scope);
|
2018-05-15 08:56:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName(): string {
|
|
|
|
return parent::getName();
|
|
|
|
}
|
|
|
|
|
2019-01-21 19:45:27 +00:00
|
|
|
public function setName(string $name): void {
|
|
|
|
parent::setName($name);
|
|
|
|
}
|
|
|
|
|
2018-05-15 08:56:40 +00:00
|
|
|
public function getRemember(): int {
|
|
|
|
return parent::getRemember();
|
2016-08-01 17:06:54 +00:00
|
|
|
}
|
2018-05-15 19:10:43 +00:00
|
|
|
|
|
|
|
public function setToken(string $token) {
|
|
|
|
parent::setToken($token);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPassword(string $password = null) {
|
|
|
|
parent::setPassword($password);
|
|
|
|
}
|
2018-05-16 10:39:00 +00:00
|
|
|
|
|
|
|
public function setExpires($expires) {
|
|
|
|
parent::setExpires($expires);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getExpires() {
|
|
|
|
return parent::getExpires();
|
|
|
|
}
|
2016-04-25 12:10:55 +00:00
|
|
|
}
|