summaryrefslogtreecommitdiffstats
path: root/lib/private/Authentication
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2016-11-08 09:15:02 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2017-01-11 19:20:09 +0100
commita6dca9e7a0c344f0914ce53982e1c6f926e620ac (patch)
tree4cad81fd7692543f873972601f8794a84abb9532 /lib/private/Authentication
parentfab82e9780ad06e20808b9bd2d9c9612eb45e8d0 (diff)
downloadnextcloud-server-a6dca9e7a0c344f0914ce53982e1c6f926e620ac.tar.gz
nextcloud-server-a6dca9e7a0c344f0914ce53982e1c6f926e620ac.zip
add login credential store
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'lib/private/Authentication')
-rw-r--r--lib/private/Authentication/LoginCredentials/Credentials.php72
-rw-r--r--lib/private/Authentication/LoginCredentials/Store.php86
2 files changed, 158 insertions, 0 deletions
diff --git a/lib/private/Authentication/LoginCredentials/Credentials.php b/lib/private/Authentication/LoginCredentials/Credentials.php
new file mode 100644
index 00000000000..9314b7489db
--- /dev/null
+++ b/lib/private/Authentication/LoginCredentials/Credentials.php
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * @copyright 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Authentication\LoginCredentials;
+
+use OCP\Authentication\LoginCredentials\ICredentials;
+
+class Credentials implements ICredentials {
+
+ /** @var string */
+ private $uid;
+
+ /** @var string */
+ private $loginName;
+
+ /** @var string */
+ private $password;
+
+ /**
+ * @param string $uid
+ * @param string $loginName
+ * @param string $password
+ */
+ public function __construct($uid, $loginName, $password) {
+ $this->uid = $uid;
+ $this->loginName = $loginName;
+ $this->password = $password;
+ }
+
+ /**
+ * @return string
+ */
+ public function getUID() {
+ return $this->uid;
+ }
+
+ /**
+ * @return string
+ */
+ public function getLoginName() {
+ return $this->loginName;
+ }
+
+ /**
+ * @return string
+ */
+ public function getPassword() {
+ return $this->password;
+ }
+
+}
diff --git a/lib/private/Authentication/LoginCredentials/Store.php b/lib/private/Authentication/LoginCredentials/Store.php
new file mode 100644
index 00000000000..ea4c9fdd0c5
--- /dev/null
+++ b/lib/private/Authentication/LoginCredentials/Store.php
@@ -0,0 +1,86 @@
+<?php
+
+/**
+ * @copyright 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @author 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * 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
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Authentication\LoginCredentials;
+
+use OC\Authentication\Exceptions\InvalidTokenException;
+use OC\Authentication\Exceptions\PasswordlessTokenException;
+use OC\Authentication\Token\IProvider;
+use OCP\Authentication\Exceptions\CredentialsUnavailableException;
+use OCP\Authentication\LoginCredentials\ICredentials;
+use OCP\Authentication\LoginCredentials\IStore;
+use OCP\ILogger;
+use OCP\ISession;
+use OCP\Session\Exceptions\SessionNotAvailableException;
+
+class Store implements IStore {
+
+ /** @var ISession */
+ private $session;
+
+ /** @var IProvider */
+ private $tokenProvider;
+
+ /** @var ILogger */
+ private $logger;
+
+ /**
+ * @param ISession $session
+ * @param IProvider $tokenProvider
+ * @param ILogger $logger
+ */
+ public function __construct(ISession $session, IProvider $tokenProvider, ILogger $logger) {
+ $this->session = $session;
+ $this->tokenProvider = $tokenProvider;
+ $this->logger = $logger;
+ }
+
+ /**
+ * @since 9.2
+ *
+ * @return ICredentials the login credentials of the current user
+ * @throws CredentialsUnavailableException
+ */
+ public function getLoginCredentials() {
+ try {
+ $sessionId = $this->session->getId();
+ $token = $this->tokenProvider->getToken($sessionId);
+
+ $uid = $token->getUID();
+ $user = $token->getLoginName();
+ $password = $this->tokenProvider->getPassword($token, $sessionId);
+
+ return new Credentials($uid, $user, $password);
+ } catch (SessionNotAvailableException $ex) {
+ $this->logger->debug('could not get login credentials because session is unavailable', ['app' => 'core']);
+ } catch (InvalidTokenException $ex) {
+ $this->logger->debug('could not get login credentials because the token is invalid', ['app' => 'core']);
+ } catch (PasswordlessTokenException $ex) {
+ $this->logger->debug('could not get login credentials because the token has no password', ['app' => 'core']);
+ }
+ // If we reach this line, an exception was thrown.
+ throw new CredentialsUnavailableException();
+ }
+
+}