use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\IConfig;
use OCP\IDBConnection;
/**
* @template-extends QBMapper<DefaultToken>
*/
class DefaultTokenMapper extends QBMapper {
- public function __construct(IDBConnection $db) {
+
+ /** @var IConfig */
+ protected $config;
+
+ public function __construct(IDBConnection $db, IConfig $config) {
+ $this->config = $config;
parent::__construct($db, 'authtoken');
}
* @param string $token
*/
public function invalidate(string $token) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->delete('authtoken')
* @param int $remember
*/
public function invalidateOld(int $olderThan, int $remember = IToken::DO_NOT_REMEMBER) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->delete('authtoken')
* @return DefaultToken
*/
public function getToken(string $token): DefaultToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new DoesNotExistException('Authtoken v1 disabled');
+ }
+
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version')
* @return DefaultToken
*/
public function getTokenById(int $id): DefaultToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new DoesNotExistException('Authtoken v1 disabled');
+ }
+
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$result = $qb->select('id', 'uid', 'login_name', 'password', 'name', 'token', 'type', 'remember', 'last_activity', 'last_check', 'scope', 'expires', 'version')
* @return DefaultToken[]
*/
public function getTokenByUser(string $uid): array {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return [];
+ }
+
/* @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')
}
public function deleteById(string $uid, int $id) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
/* @var $qb IQueryBuilder */
$qb = $this->db->getQueryBuilder();
$qb->delete('authtoken')
* @param string $name
*/
public function deleteByName(string $name) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
$qb = $this->db->getQueryBuilder();
$qb->delete('authtoken')
->where($qb->expr()->eq('name', $qb->createNamedParameter($name), IQueryBuilder::PARAM_STR))
string $name,
int $type = IToken::TEMPORARY_TOKEN,
int $remember = IToken::DO_NOT_REMEMBER): IToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
$dbToken = new DefaultToken();
$dbToken->setUid($uid);
$dbToken->setLoginName($loginName);
* @throws InvalidTokenException
*/
public function updateToken(IToken $token) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
if (!($token instanceof DefaultToken)) {
throw new InvalidTokenException("Invalid token type");
}
* @param IToken $token
*/
public function updateTokenActivity(IToken $token) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
if (!($token instanceof DefaultToken)) {
throw new InvalidTokenException("Invalid token type");
}
}
public function getTokenByUser(string $uid): array {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return [];
+ }
+
return $this->mapper->getTokenByUser($uid);
}
* @return IToken
*/
public function getToken(string $tokenId): IToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
try {
$token = $this->mapper->getToken($this->hashToken($tokenId));
} catch (DoesNotExistException $ex) {
* @return IToken
*/
public function getTokenById(int $tokenId): IToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
try {
$token = $this->mapper->getTokenById($tokenId);
} catch (DoesNotExistException $ex) {
* @return IToken
*/
public function renewSessionToken(string $oldSessionId, string $sessionId): IToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
$token = $this->getToken($oldSessionId);
$newToken = new DefaultToken();
* @return string
*/
public function getPassword(IToken $savedToken, string $tokenId): string {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
$password = $savedToken->getPassword();
if ($password === null || $password === '') {
throw new PasswordlessTokenException();
* @throws InvalidTokenException
*/
public function setPassword(IToken $token, string $tokenId, string $password) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
if (!($token instanceof DefaultToken)) {
throw new InvalidTokenException("Invalid token type");
}
* @param string $token
*/
public function invalidateToken(string $token) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
$this->mapper->invalidate($this->hashToken($token));
}
public function invalidateTokenById(string $uid, int $id) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
$this->mapper->deleteById($uid, $id);
}
* Invalidate (delete) old session tokens
*/
public function invalidateOldTokens() {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ return;
+ }
+
$olderThan = $this->time->getTime() - (int) $this->config->getSystemValue('session_lifetime', 60 * 60 * 24);
$this->logger->debug('Invalidating session tokens older than ' . date('c', $olderThan), ['app' => 'cron']);
$this->mapper->invalidateOld($olderThan, IToken::DO_NOT_REMEMBER);
* @return IToken
*/
public function rotate(IToken $token, string $oldTokenId, string $newTokenId): IToken {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
try {
$password = $this->getPassword($token, $oldTokenId);
$token->setPassword($this->encryptPassword($password, $newTokenId));
}
public function markPasswordInvalid(IToken $token, string $tokenId) {
+ if ($this->config->getSystemValueBool('auth.authtoken.v1.disabled')) {
+ throw new InvalidTokenException('Authtokens v1 disabled');
+ }
+
if (!($token instanceof DefaultToken)) {
throw new InvalidTokenException("Invalid token type");
}