diff options
author | Christoph Wurst <christoph@owncloud.com> | 2016-05-31 10:48:14 +0200 |
---|---|---|
committer | Christoph Wurst <christoph@owncloud.com> | 2016-05-31 17:07:49 +0200 |
commit | c58d8159d7bdee93a67a917e16b750fe99df9f99 (patch) | |
tree | 568acfd8c2f26bd675a151bb42130a626468633b /lib/private/Authentication | |
parent | 9a9c1b9439055fc6ad9f8372b354e4fc7ce3bc02 (diff) | |
download | nextcloud-server-c58d8159d7bdee93a67a917e16b750fe99df9f99.tar.gz nextcloud-server-c58d8159d7bdee93a67a917e16b750fe99df9f99.zip |
Create session tokens for apache auth users
Diffstat (limited to 'lib/private/Authentication')
4 files changed, 43 insertions, 5 deletions
diff --git a/lib/private/Authentication/Exceptions/PasswordlessTokenException.php b/lib/private/Authentication/Exceptions/PasswordlessTokenException.php new file mode 100644 index 00000000000..dbe0ee8fbca --- /dev/null +++ b/lib/private/Authentication/Exceptions/PasswordlessTokenException.php @@ -0,0 +1,29 @@ +<?php + +/** + * @author Christoph Wurst <christoph@owncloud.com> + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @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\Exceptions; + +use Exception; + +class PasswordlessTokenException extends Exception { + +} diff --git a/lib/private/Authentication/Token/DefaultToken.php b/lib/private/Authentication/Token/DefaultToken.php index 4be43fada0d..299291e34af 100644 --- a/lib/private/Authentication/Token/DefaultToken.php +++ b/lib/private/Authentication/Token/DefaultToken.php @@ -27,7 +27,6 @@ use OCP\AppFramework\Db\Entity; * @method void setId(int $id) * @method void setUid(string $uid); * @method void setLoginName(string $loginName) - * @method string getLoginName() * @method void setPassword(string $password) * @method void setName(string $name) * @method string getName() diff --git a/lib/private/Authentication/Token/DefaultTokenProvider.php b/lib/private/Authentication/Token/DefaultTokenProvider.php index dd6e264ed3d..84effc5f875 100644 --- a/lib/private/Authentication/Token/DefaultTokenProvider.php +++ b/lib/private/Authentication/Token/DefaultTokenProvider.php @@ -23,6 +23,7 @@ namespace OC\Authentication\Token; use Exception; use OC\Authentication\Exceptions\InvalidTokenException; +use OC\Authentication\Exceptions\PasswordlessTokenException; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IConfig; @@ -68,7 +69,7 @@ class DefaultTokenProvider implements IProvider { * @param string $token * @param string $uid * @param string $loginName - * @param string $password + * @param string|null $password * @param string $name * @param int $type token type * @return IToken @@ -77,7 +78,9 @@ class DefaultTokenProvider implements IProvider { $dbToken = new DefaultToken(); $dbToken->setUid($uid); $dbToken->setLoginName($loginName); - $dbToken->setPassword($this->encryptPassword($password, $token)); + if (!is_null($password)) { + $dbToken->setPassword($this->encryptPassword($password, $token)); + } $dbToken->setName($name); $dbToken->setToken($this->hashToken($token)); $dbToken->setType($type); @@ -136,10 +139,15 @@ class DefaultTokenProvider implements IProvider { * @param IToken $savedToken * @param string $tokenId session token * @throws InvalidTokenException + * @throws PasswordlessTokenException * @return string */ public function getPassword(IToken $savedToken, $tokenId) { - return $this->decryptPassword($savedToken->getPassword(), $tokenId); + $password = $savedToken->getPassword(); + if (is_null($password)) { + throw new PasswordlessTokenException(); + } + return $this->decryptPassword($password, $tokenId); } /** diff --git a/lib/private/Authentication/Token/IProvider.php b/lib/private/Authentication/Token/IProvider.php index bdfde62d320..fece7dcb567 100644 --- a/lib/private/Authentication/Token/IProvider.php +++ b/lib/private/Authentication/Token/IProvider.php @@ -22,6 +22,7 @@ namespace OC\Authentication\Token; use OC\Authentication\Exceptions\InvalidTokenException; +use OC\Authentication\Exceptions\PasswordlessTokenException; use OCP\IUser; interface IProvider { @@ -32,7 +33,7 @@ interface IProvider { * @param string $token * @param string $uid * @param string $loginName - * @param string $password + * @param string|null $password * @param string $name * @param int $type token type * @return IToken @@ -94,6 +95,7 @@ interface IProvider { * @param IToken $token * @param string $tokenId * @throws InvalidTokenException + * @throws PasswordlessTokenException * @return string */ public function getPassword(IToken $token, $tokenId); |