Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use OCP\ITagManager;
use OCP\IUserSession;
use OCP\L10N\IFactory as IL10nFactory;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\IManager;
use OCP\Share\IShare;
Expand All @@ -50,12 +49,7 @@
Server::get(ISession::class)->close();

// Backends
$authBackend = new LegacyPublicAuth(
Server::get(IRequest::class),
Server::get(\OCP\Share\IManager::class),
Server::get(ISession::class),
Server::get(IThrottler::class)
);
$authBackend = Server::get(LegacyPublicAuth::class);
$bearerAuthBackend = new BearerAuth(
Server::get(IUserSession::class),
Server::get(ISession::class),
Expand Down
11 changes: 1 addition & 10 deletions apps/dav/appinfo/v2/publicremote.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
use OCP\IRequest;
use OCP\ISession;
use OCP\ITagManager;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\L10N\IFactory;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Server;
use OCP\Share\IManager;
use Psr\Log\LoggerInterface;
Expand All @@ -62,14 +60,7 @@
$requestUri = $request->getRequestUri();

// Backends
$authBackend = new PublicAuth(
$request,
Server::get(IManager::class),
$session,
Server::get(IThrottler::class),
Server::get(LoggerInterface::class),
Server::get(IURLGenerator::class),
);
$authBackend = Server::get(PublicAuth::class);
$bearerAuthBackend = new BearerAuth(
Server::get(IUserSession::class),
$session,
Expand Down
4 changes: 3 additions & 1 deletion apps/dav/lib/Connector/LegacyPublicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCP\Defaults;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
Expand All @@ -33,6 +34,7 @@ public function __construct(
private IManager $shareManager,
private ISession $session,
private IThrottler $throttler,
private IUserSession $userSession,
) {
// setup realm
$defaults = new Defaults();
Expand Down Expand Up @@ -64,7 +66,7 @@ protected function validateUserPass($username, $password) {

$this->share = $share;

\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// check if the share is password protected
if ($share->isPasswordProtected()) {
Expand Down
2 changes: 2 additions & 0 deletions apps/dav/lib/Connector/Sabre/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ private function auth(RequestInterface $request, ResponseInterface $response): a
if ($this->twoFactorManager->needsSecondFactor($this->userSession->getUser())) {
throw new \Sabre\DAV\Exception\NotAuthenticated('2FA challenge not passed.');
}
/** @psalm-suppress DeprecatedClass OC_User is deprecated*/
/** @psalm-suppress DeprecatedMethod this call should be removed ideally */
if (
//Fix for broken webdav clients
($this->userSession->isLoggedIn() && is_null($this->session->get(self::DAV_AUTHENTICATED)))
Expand Down
4 changes: 2 additions & 2 deletions apps/dav/lib/Connector/Sabre/BearerAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function validateBearerToken($bearerToken) {
$sharedSecret = $this->resolveOcmSharedSecret($bearerToken);
if ($sharedSecret !== null) {
$this->token = $sharedSecret;
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);
return $this->principalPrefix . $sharedSecret;
}
}
Expand All @@ -69,7 +69,7 @@ public function validateBearerToken($bearerToken) {
// the logged-in user is visible for the rest of the request. If the
// bearer token is invalid and Sabre falls back to one of the public
// auth backends, that backend will re-enable incognito mode itself.
\OC_User::setIncognitoMode(false);
$this->userSession->setIncognitoMode(false);

if ($this->userSession->tryTokenLogin($this->request)) {
return $this->setupUserFs($this->userSession->getUser()->getUID());
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/lib/Connector/Sabre/PublicAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Security\Bruteforce\MaxDelayReached;
use OCP\Share\Exceptions\ShareNotFound;
Expand Down Expand Up @@ -47,6 +48,7 @@ public function __construct(
private IThrottler $throttler,
private LoggerInterface $logger,
private IURLGenerator $urlGenerator,
private IUserSession $userSession,
) {
// setup realm
$defaults = new Defaults();
Expand Down Expand Up @@ -134,7 +136,7 @@ private function checkToken(): array {
}

$this->share = $share;
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// If already authenticated
if ($this->isShareInSession($share)) {
Expand Down Expand Up @@ -173,7 +175,7 @@ protected function validateUserPass($username, $password) {
return false;
}

\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// check if the share is password protected
if ($share->isPasswordProtected()) {
Expand Down
6 changes: 5 additions & 1 deletion apps/dav/tests/unit/Connector/LegacyPublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use OCA\DAV\Connector\LegacyPublicAuth;
use OCP\IRequest;
use OCP\ISession;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
Expand All @@ -26,6 +27,7 @@ class LegacyPublicAuthTest extends TestCase {
private IRequest&MockObject $request;
private IManager&MockObject $shareManager;
private IThrottler&MockObject $throttler;
private IUserSession&MockObject $userSession;
private LegacyPublicAuth $auth;
private string|false $oldUser;

Expand All @@ -36,12 +38,14 @@ protected function setUp(): void {
$this->request = $this->createMock(IRequest::class);
$this->shareManager = $this->createMock(IManager::class);
$this->throttler = $this->createMock(IThrottler::class);
$this->userSession = $this->createMock(IUserSession::class);

$this->auth = new LegacyPublicAuth(
$this->request,
$this->shareManager,
$this->session,
$this->throttler
$this->throttler,
$this->userSession,
);

// Store current user
Expand Down
4 changes: 4 additions & 0 deletions apps/dav/tests/unit/Connector/Sabre/PublicAuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\IRequest;
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserSession;
use OCP\Security\Bruteforce\IThrottler;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Share\IManager;
Expand All @@ -35,6 +36,7 @@ class PublicAuthTest extends \Test\TestCase {
private IThrottler&MockObject $throttler;
private LoggerInterface&MockObject $logger;
private IURLGenerator&MockObject $urlGenerator;
private IUserSession&MockObject $userSession;
private PublicAuth $auth;

private bool|string $oldUser;
Expand All @@ -48,6 +50,7 @@ protected function setUp(): void {
$this->throttler = $this->createMock(IThrottler::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->urlGenerator = $this->createMock(IURLGenerator::class);
$this->userSession = $this->createMock(IUserSession::class);

$this->auth = new PublicAuth(
$this->request,
Expand All @@ -56,6 +59,7 @@ protected function setUp(): void {
$this->throttler,
$this->logger,
$this->urlGenerator,
$this->userSession,
);

// Store current user
Expand Down
3 changes: 2 additions & 1 deletion apps/files_external/lib/Lib/Storage/SFTP.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private function absPath(string $path): string {

private function hostKeysPath(): string|false {
try {
$userId = \OC_User::getUser();
$userId = Server::get(\OCP\IUserSession::class)->getUser()?->getUID() ?? false;
;
if ($userId === false) {
return false;
}
Expand Down
11 changes: 11 additions & 0 deletions apps/files_external/lib/Migration/DummyUserSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class DummyUserSession implements IUserSession {

private ?IUser $user = null;
private bool $incognitoMode = false;

#[\Override]
public function login($uid, $password) {
Expand Down Expand Up @@ -63,4 +64,14 @@ public function getImpersonatingUserID() : ?string {
public function setImpersonatingUserID(bool $useCurrentUser = true): void {
//no OP
}

#[\Override]
public function setIncognitoMode(bool $mode): void {
$this->incognitoMode = $mode;
}

#[\Override]
public function isIncognitoMode(): bool {
return $this->incognitoMode;
}
}
6 changes: 4 additions & 2 deletions apps/files_sharing/lib/Controller/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
use OCP\ISession;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Security\Events\GenerateSecurePasswordEvent;
use OCP\Security\ISecureRandom;
use OCP\Security\PasswordContext;
Expand Down Expand Up @@ -78,6 +79,7 @@ public function __construct(
protected ISecureRandom $secureRandom,
protected Defaults $defaults,
private IPublicShareTemplateFactory $publicShareTemplateFactory,
private IUserSession $userSession,
) {
parent::__construct($appName, $request, $session, $urlGenerator);
}
Expand Down Expand Up @@ -275,7 +277,7 @@ private function validateShare(IShare $share) {
#[PublicPage]
#[NoCSRFRequired]
public function showShare($path = ''): TemplateResponse {
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

// Check whether share exists
try {
Expand Down Expand Up @@ -328,7 +330,7 @@ public function showShare($path = ''): TemplateResponse {
#[NoCSRFRequired]
#[NoSameSiteCookieRequired]
public function downloadShare(string $token, ?string $files = null, string $path = ''): NotFoundResponse|RedirectResponse|DataResponse {
\OC_User::setIncognitoMode(true);
$this->userSession->setIncognitoMode(true);

$share = $this->shareManager->getShareByToken($token);

Expand Down
10 changes: 7 additions & 3 deletions apps/files_sharing/lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,15 @@ private static function moveShareInOrOutOfShare($path): void {
* @param string $newPath new path relative to data/user/files
*/
private static function renameChildren($oldPath, $newPath) {
$absNewPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $newPath);
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files/' . $oldPath);
$userInSession = Server::get(IUserSession::class)->getUser()?->getUID();
if ($userInSession === null) {
return;
}
$absNewPath = Filesystem::normalizePath('/' . $userInSession . '/files/' . $newPath);
$absOldPath = Filesystem::normalizePath('/' . $userInSession . '/files/' . $oldPath);

$mountManager = Filesystem::getMountManager();
$mountedShares = $mountManager->findIn('/' . \OC_User::getUser() . '/files/' . $oldPath);
$mountedShares = $mountManager->findIn('/' . $userInSession . '/files/' . $oldPath);
foreach ($mountedShares as $mount) {
/** @var MountPoint $mount */
if ($mount->getStorage()->instanceOfStorage(ISharedStorage::class)) {
Expand Down
4 changes: 4 additions & 0 deletions apps/files_sharing/tests/Controller/ShareControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\Security\ISecureRandom;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
Expand Down Expand Up @@ -80,6 +81,7 @@ class ShareControllerTest extends \Test\TestCase {
private IEventDispatcher&MockObject $eventDispatcher;
private FederatedShareProvider&MockObject $federatedShareProvider;
private IPublicShareTemplateFactory&MockObject $publicShareTemplateFactory;
private IUserSession&MockObject $userSession;

protected function setUp(): void {
parent::setUp();
Expand All @@ -104,6 +106,7 @@ protected function setUp(): void {
$this->l10n = $this->createMock(IL10N::class);
$this->secureRandom = $this->createMock(ISecureRandom::class);
$this->defaults = $this->createMock(Defaults::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->publicShareTemplateFactory = $this->createMock(IPublicShareTemplateFactory::class);
$this->publicShareTemplateFactory
->expects($this->any())
Expand Down Expand Up @@ -144,6 +147,7 @@ protected function setUp(): void {
$this->secureRandom,
$this->defaults,
$this->publicShareTemplateFactory,
$this->userSession,
);

// Store current user
Expand Down
Loading
Loading