2016-04-25 15:10:55 +03:00
|
|
|
<?php
|
|
|
|
/**
|
2016-07-21 18:07:57 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-04-25 15:10:55 +03:00
|
|
|
* @author Christoph Wurst <christoph@owncloud.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2016-04-25 15:10:55 +03: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 20:58:19 +03:00
|
|
|
/**
|
|
|
|
* @method void setId(int $id)
|
|
|
|
* @method void setUid(string $uid);
|
2016-05-24 11:50:18 +03:00
|
|
|
* @method void setLoginName(string $loginName)
|
2016-05-02 20:58:19 +03:00
|
|
|
* @method void setPassword(string $password)
|
|
|
|
* @method void setName(string $name)
|
|
|
|
* @method string getName()
|
|
|
|
* @method void setToken(string $token)
|
|
|
|
* @method string getToken()
|
|
|
|
* @method void setType(string $type)
|
|
|
|
* @method int getType()
|
2016-09-06 22:41:15 +03:00
|
|
|
* @method void setRemember(int $remember)
|
|
|
|
* @method int getRemember()
|
2016-05-02 20:58:19 +03:00
|
|
|
* @method void setLastActivity(int $lastActivity)
|
|
|
|
* @method int getLastActivity()
|
|
|
|
*/
|
2016-05-19 12:20:22 +03:00
|
|
|
class DefaultToken extends Entity implements IToken {
|
2016-04-25 15:10:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string user UID
|
|
|
|
*/
|
|
|
|
protected $uid;
|
|
|
|
|
2016-05-24 11:50:18 +03:00
|
|
|
/**
|
|
|
|
* @var string login name used for generating the token
|
|
|
|
*/
|
|
|
|
protected $loginName;
|
|
|
|
|
2016-04-25 15:10:55 +03:00
|
|
|
/**
|
|
|
|
* @var string encrypted user password
|
|
|
|
*/
|
|
|
|
protected $password;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string token name (e.g. browser/OS)
|
|
|
|
*/
|
|
|
|
protected $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $token;
|
|
|
|
|
2016-04-26 13:48:19 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $type;
|
|
|
|
|
2016-09-06 22:41:15 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $remember;
|
|
|
|
|
2016-04-25 17:40:41 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $lastActivity;
|
|
|
|
|
2016-06-17 14:59:15 +03:00
|
|
|
/**
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $lastCheck;
|
|
|
|
|
2016-08-01 20:06:54 +03:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $scope;
|
|
|
|
|
2016-10-31 16:38:41 +03:00
|
|
|
public function __construct() {
|
|
|
|
$this->addType('type', 'int');
|
|
|
|
$this->addType('lastActivity', 'int');
|
|
|
|
$this->addType('lastCheck', 'int');
|
|
|
|
}
|
|
|
|
|
2016-04-25 15:10:55 +03:00
|
|
|
public function getId() {
|
2016-04-26 12:32:35 +03:00
|
|
|
return $this->id;
|
2016-04-25 15:10:55 +03:00
|
|
|
}
|
|
|
|
|
2016-05-06 17:31:40 +03:00
|
|
|
public function getUID() {
|
2016-04-27 10:38:30 +03:00
|
|
|
return $this->uid;
|
|
|
|
}
|
2016-05-24 11:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the login name used when generating the token
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLoginName() {
|
|
|
|
return parent::getLoginName();
|
|
|
|
}
|
|
|
|
|
2016-05-17 18:20:54 +03:00
|
|
|
/**
|
|
|
|
* Get the (encrypted) login password
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getPassword() {
|
|
|
|
return parent::getPassword();
|
|
|
|
}
|
2016-04-27 10:38:30 +03:00
|
|
|
|
2016-05-18 13:03:22 +03:00
|
|
|
public function jsonSerialize() {
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'name' => $this->name,
|
2016-10-31 16:38:41 +03:00
|
|
|
'lastActivity' => $this->lastActivity,
|
|
|
|
'type' => $this->type,
|
2016-08-03 16:57:06 +03:00
|
|
|
'scope' => $this->getScopeAsArray()
|
2016-05-18 13:03:22 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-06-17 14:59:15 +03:00
|
|
|
/**
|
|
|
|
* Get the timestamp of the last password check
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getLastCheck() {
|
|
|
|
return parent::getLastCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the timestamp of the last password check
|
|
|
|
*
|
|
|
|
* @param int $time
|
|
|
|
*/
|
|
|
|
public function setLastCheck($time) {
|
|
|
|
return parent::setLastCheck($time);
|
|
|
|
}
|
|
|
|
|
2016-08-01 20:06:54 +03:00
|
|
|
public function getScope() {
|
2016-08-03 16:57:06 +03:00
|
|
|
return parent::getScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getScopeAsArray() {
|
|
|
|
$scope = json_decode($this->getScope(), true);
|
|
|
|
if (!$scope) {
|
|
|
|
return [
|
2016-10-19 16:11:58 +03:00
|
|
|
'filesystem'=> true
|
2016-08-03 16:57:06 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
return $scope;
|
2016-08-01 20:06:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setScope($scope) {
|
2016-10-31 16:38:41 +03:00
|
|
|
if (is_array($scope)) {
|
2016-08-04 13:49:41 +03:00
|
|
|
parent::setScope(json_encode($scope));
|
2016-10-31 16:38:41 +03:00
|
|
|
} else {
|
|
|
|
parent::setScope((string)$scope);
|
2016-08-03 13:03:18 +03:00
|
|
|
}
|
2016-08-01 20:06:54 +03:00
|
|
|
}
|
2016-04-25 15:10:55 +03:00
|
|
|
}
|