Skip to content

Commit

Permalink
Merge pull request #30421 from owncloud/kill-base.php-handleLogin
Browse files Browse the repository at this point in the history
No need to handle authentication that early aka in here at all
  • Loading branch information
Vincent Petry authored Mar 19, 2018
2 parents 420fd3d + ae97bff commit 580d2fd
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 30 deletions.
1 change: 0 additions & 1 deletion lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,6 @@ public static function handleRequest() {
} else {
// For guests: Load only filesystem and logging
OC_App::loadApps(['filesystem', 'logging']);
self::handleLogin($request);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ public function __construct($appName, $urlParams = []){
$app->getServer()->getNavigationManager(),
$app->getServer()->getURLGenerator(),
$app->getServer()->getLogger(),
$app->getServer()->getUserSession(),
$c['AppName'],
$app->isLoggedIn(),
$app->isAdminUser(),
$app->getServer()->getContentSecurityPolicyManager()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
use OCP\IRequest;
use OCP\ILogger;
use OCP\AppFramework\Controller;
use OCP\IUserSession;
use OCP\Util;
use OC\AppFramework\Middleware\Security\Exceptions\SecurityException;

Expand All @@ -69,20 +70,20 @@ class SecurityMiddleware extends Middleware {
/** @var ILogger */
private $logger;
/** @var bool */
private $isLoggedIn;
/** @var bool */
private $isAdminUser;
/** @var ContentSecurityPolicyManager */
private $contentSecurityPolicyManager;
/** @var IUserSession */
private $session;

/**
* @param IRequest $request
* @param ControllerMethodReflector $reflector
* @param INavigationManager $navigationManager
* @param IURLGenerator $urlGenerator
* @param ILogger $logger
* @param IUserSession $session
* @param string $appName
* @param bool $isLoggedIn
* @param bool $isAdminUser
* @param ContentSecurityPolicyManager $contentSecurityPolicyManager
*/
Expand All @@ -91,8 +92,8 @@ public function __construct(IRequest $request,
INavigationManager $navigationManager,
IURLGenerator $urlGenerator,
ILogger $logger,
IUserSession $session,
$appName,
$isLoggedIn,
$isAdminUser,
ContentSecurityPolicyManager $contentSecurityPolicyManager) {
$this->navigationManager = $navigationManager;
Expand All @@ -101,7 +102,7 @@ public function __construct(IRequest $request,
$this->appName = $appName;
$this->urlGenerator = $urlGenerator;
$this->logger = $logger;
$this->isLoggedIn = $isLoggedIn;
$this->session = $session;
$this->isAdminUser = $isAdminUser;
$this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
}
Expand All @@ -124,7 +125,7 @@ public function beforeController($controller, $methodName) {
// security checks
$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
if(!$isPublicPage) {
if(!$this->isLoggedIn) {
if(!$this->isLoggedIn()) {
throw new NotLoggedInException();
}

Expand Down Expand Up @@ -165,7 +166,7 @@ public function beforeController($controller, $methodName) {
* @return Response
*/
public function afterController($controller, $methodName, Response $response) {
$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
$policy = $response->getContentSecurityPolicy() !== null ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();

$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
Expand Down Expand Up @@ -229,4 +230,13 @@ public function afterException($controller, $methodName, \Exception $exception)
throw $exception;
}

private function isLoggedIn() {
static $loginCalled = false;
if (!$loginCalled && !$this->session->isLoggedIn()) {
\OC::handleLogin($this->request);
$loginCalled = true;
}
return $this->session->isLoggedIn();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public function __construct() {


/**
* @param object $object an object or classname
* @param object|string $object an object or classname
* @param string $method the method which we want to inspect
* @throws \ReflectionException
*/
public function reflect($object, $method){
$reflection = new \ReflectionMethod($object, $method);
Expand Down
6 changes: 6 additions & 0 deletions lib/private/legacy/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ public static function checkAppEnabled($app) {
* @deprecated Use annotation based ACLs from the AppFramework instead
*/
public static function checkLoggedIn() {
static $loginCalled = false;
if (!$loginCalled && !OC_User::isLoggedIn()) {
\OC::handleLogin(\OC::$server->getRequest());
$loginCalled = true;
}

$twoFactorAuthManger = \OC::$server->getTwoFactorAuthManager();
if( !OC_User::isLoggedIn()
|| $twoFactorAuthManger->needsSecondFactor()) {
Expand Down
Loading

0 comments on commit 580d2fd

Please sign in to comment.