Skip to content

Commit

Permalink
Merge pull request #32587 from owncloud/stable10-bugfix/samaccountnam…
Browse files Browse the repository at this point in the history
…e-as-wnd-username-resend

[stable10] use samaccountname from session for wnd login (resend)
  • Loading branch information
Vincent Petry authored Sep 5, 2018
2 parents 2f1d99a + 45e2bd1 commit 9b05653
Show file tree
Hide file tree
Showing 13 changed files with 394 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ public function manipulateStorageConfig(IStorageConfig &$storage, IUser $user =
}

$credentials = \json_decode($this->crypto->decrypt($encrypted), true);
$storage->setBackendOption('user', $this->session->get('loginname'));
if ($user !== null) {
$storage->setBackendOption('user', $user->getUserName());
} else {
$storage->setBackendOption('user', $this->session->get('loginname'));
}
$storage->setBackendOption('password', $credentials['password']);
}

Expand Down
11 changes: 9 additions & 2 deletions lib/private/Files/External/ConfigAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
use OC\Files\Storage\FailedStorage;
use OCP\Files\StorageNotAvailableException;
use OCP\IConfig;
use OCP\Files\ObjectStore\IObjectStore;
use OCP\ISession;

/**
* Make the old files_external config work with the new public mount config api
Expand All @@ -51,18 +53,23 @@ class ConfigAdapter implements IMountProvider {
/** @var IUserGlobalStoragesService */
private $userGlobalStoragesService;

/** @var ISession */
private $session;

/**
* @param IUserStoragesService $userStoragesService
* @param IUserGlobalStoragesService $userGlobalStoragesService
*/
public function __construct(
IConfig $config,
IUserStoragesService $userStoragesService,
IUserGlobalStoragesService $userGlobalStoragesService
IUserGlobalStoragesService $userGlobalStoragesService,
ISession $session
) {
$this->config = $config;
$this->userStoragesService = $userStoragesService;
$this->userGlobalStoragesService = $userGlobalStoragesService;
$this->session = $session;
}

/**
Expand All @@ -74,7 +81,7 @@ public function __construct(
private function prepareStorageConfig(IStorageConfig &$storage, IUser $user) {
foreach ($storage->getBackendOptions() as $option => $value) {
$storage->setBackendOption($option, $this->setUserVars(
$user->getUID(), $value
$user->getUserName(), $value
));
}

Expand Down
11 changes: 7 additions & 4 deletions lib/private/Files/External/LegacyUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function getAbsoluteMountPoints($uid) {
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
$mountEntry = self::prepareMountPointEntry($storage, false);
foreach ($mountEntry['options'] as &$option) {
$option = self::setUserVars($uid, $option);
$option = self::setUserVars($user->getUserName(), $option);
}
$mountPoints[$mountPoint] = $mountEntry;
}
Expand All @@ -75,7 +75,7 @@ public static function getAbsoluteMountPoints($uid) {
$mountPoint = '/'.$uid.'/files'.$storage->getMountPoint();
$mountEntry = self::prepareMountPointEntry($storage, true);
foreach ($mountEntry['options'] as &$option) {
$option = self::setUserVars($uid, $option);
$option = self::setUserVars($user->getUserName(), $option);
}
$mountPoints[$mountPoint] = $mountEntry;
}
Expand Down Expand Up @@ -190,8 +190,11 @@ public static function getBackendStatus($class, $options, $isPersonal, $testOnly
if (self::$skipTest) {
return StorageNotAvailableException::STATUS_SUCCESS;
}
foreach ($options as $key => $option) {
$options[$key] = self::setUserVars(\OCP\User::getUser(), $option);
$user = \OC::$server->getUserSession()->getUser();
if ($user) {
foreach ($options as $key => $option) {
$options[$key] = self::setUserVars($user->getUserName(), $option);
}
}
if (\class_exists($class)) {
try {
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,8 @@ public function __construct($webRoot, \OC\Config $config) {
$manager->registerProvider(new \OC\Files\External\ConfigAdapter(
$c->query('AllConfig'),
$c->query('UserStoragesService'),
$c->query('UserGlobalStoragesService')
$c->query('UserGlobalStoragesService'),
$c->getSession()
));
}

Expand Down
13 changes: 13 additions & 0 deletions lib/private/User/RemoteUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ public function getUID() {
return $this->userId;
}

/**
* @inheritdoc
*/
public function getUserName() {
return $this->getUID();
}

/**
* @inheritdoc
*/
public function setUserName($userName) {
}

/**
* @inheritdoc
*/
Expand Down
27 changes: 27 additions & 0 deletions lib/private/User/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IConfig;
use OCP\ILogger;
use OCP\PreConditionNotMetException;
use OCP\User\IProvidesDisplayNameBackend;
use OCP\User\IProvidesEMailBackend;
use OCP\User\IProvidesExtendedSearchBackend;
use OCP\User\IProvidesHomeBackend;
use OCP\User\IProvidesQuotaBackend;
use OCP\User\IProvidesUserNameBackend;
use OCP\UserInterface;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;

Expand Down Expand Up @@ -292,6 +294,30 @@ private function syncDisplayName(Account $a, UserInterface $backend) {
}
}

/**
* TODO store username in account table instead of user preferences
*
* @param Account $a
* @param UserInterface $backend
*/
private function syncUserName(Account $a, UserInterface $backend) {
$uid = $a->getUserId();
if ($backend instanceof IProvidesUserNameBackend) {
$userName = $backend->getUserName($uid);
$currentUserName = $this->config->getUserValue($uid, 'core', 'username', null);
if ($userName !== $currentUserName) {
try {
$this->config->setUserValue($uid, 'core', 'username', $userName);
} catch (PreConditionNotMetException $e) {
// ignore, because precondition is empty
}
$this->logger->debug(
"Setting userName for <$uid> from <$currentUserName> to <$userName>", ['app' => self::class]
);
}
}
}

/**
* @param Account $a
* @param UserInterface $backend
Expand Down Expand Up @@ -322,6 +348,7 @@ public function syncAccount(Account $a, UserInterface $backend) {
$this->syncQuota($a, $backend);
$this->syncHome($a, $backend);
$this->syncDisplayName($a, $backend);
$this->syncUserName($a, $backend);
$this->syncSearchTerms($a, $backend);
return $a;
}
Expand Down
30 changes: 30 additions & 0 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCP\IConfig;
use OCP\IUserBackend;
use OCP\IUserSession;
use OCP\PreConditionNotMetException;
use OCP\User\IChangePasswordBackend;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
Expand Down Expand Up @@ -123,6 +124,35 @@ public function getUID() {
return $this->account->getUserId();
}

/**
* get the user name
* TODO move username to account table
*
* @return string
*/
public function getUserName() {
$uid = $this->getUID();
return $this->config->getUserValue($uid, 'core', 'username', $uid);
}

/**
* set the user name
* TODO move username to account table
*
* @param string $userName
*/
public function setUserName($userName) {
$currentUserName = $this->getUserName();
if ($userName !== $currentUserName) {
$uid = $this->getUID();
try {
$this->config->setUserValue($uid, 'core', 'username', $userName);
} catch (PreConditionNotMetException $e) {
// ignore, because precondition is empty
}
}
}

/**
* get the display name for the user, if no specific display name is set it will fallback to the user id
*
Expand Down
16 changes: 16 additions & 0 deletions lib/public/IUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,22 @@ interface IUser {
*/
public function getUID();

/**
* get the user name
*
* @return string
* @since 10.0.10
*/
public function getUserName();

/**
* set the user name
*
* @param string $userName
* @since 10.0.10
*/
public function setUserName($userName);

/**
* get the display name for the user, if no specific display name is set it will fallback to the user id
*
Expand Down
41 changes: 41 additions & 0 deletions lib/public/User/IProvidesUserNameBackend.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
*
* @copyright Copyright (c) 2018, ownCloud GmbH
* @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/>
*
*/

// use OCP namespace for all classes that are considered public.
// This means that they should be used by apps instead of the internal ownCloud classes
namespace OCP\User;

/**
* Interface IProvidesUserNameBackend
*
* @package OCP\User
* @since 10.0
*/
interface IProvidesUserNameBackend {

/**
* get display name of the user
* @param string $uid user ID of the user
* @return string user name
* @since 10.0.10
*/
public function getUserName($uid);
}
Loading

0 comments on commit 9b05653

Please sign in to comment.