Skip to content

Commit

Permalink
Merge pull request #31933 from owncloud/stable10-a23e6e505a685858e2da…
Browse files Browse the repository at this point in the history
…866504d2d457209b2863

[stable10] Move AccountCheckException to public api
  • Loading branch information
Vincent Petry authored Jun 29, 2018
2 parents 497207f + d030017 commit c5b18ed
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@

use Exception;
use OC\AppFramework\Http\Request;
use OC\Authentication\Exceptions\AccountCheckException;
use OC\Authentication\Exceptions\PasswordLoginForbiddenException;
use OC\Authentication\TwoFactorAuth\Manager;
use OC\Authentication\AccountModule\Manager as AccountModuleManager;
use OC\User\LoginException;
use OC\User\Session;
use OCA\DAV\Connector\Sabre\Exception\PasswordLoginForbidden;
use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\IRequest;
use OCP\ISession;
use Sabre\DAV\Auth\Backend\AbstractBasic;
Expand Down
2 changes: 1 addition & 1 deletion core/Middleware/AccountModuleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@

use Exception;
use OC\Authentication\AccountModule\Manager;
use OC\Authentication\Exceptions\AccountCheckException;
use OC\Core\Controller\LoginController;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Middleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\IAccountModuleController;
use OCP\ILogger;
use OCP\IUserSession;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Authentication/AccountModule/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

namespace OC\Authentication\AccountModule;

use OC\Authentication\Exceptions\AccountCheckException;
use OCP\App\IServiceLoader;
use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\IAccountModule;
use OCP\IConfig;
use OCP\ILogger;
Expand Down
18 changes: 11 additions & 7 deletions lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ public function prepareUserLogin($firstTimeLogin = false) {

// trigger any other initialization
$this->eventDispatcher->dispatch(IUser::class . '::firstLogin', new GenericEvent($this->getUser()));
$this->eventDispatcher->dispatch('user.firstlogin', new GenericEvent($this->getUser()));
}
}

Expand Down Expand Up @@ -517,7 +518,6 @@ private function loginWithPassword($login, $password) {

$user = $this->manager->checkPassword($login, $password);
if ($user === false) {
$this->manager->emit('\OC\User', 'failedLogin', [$login]);
$this->emitFailedLogin($login);
return false;
}
Expand Down Expand Up @@ -660,7 +660,6 @@ public function loginWithApache(IApacheBackend $apacheBackend) {

$user = $this->manager->get($uid);
if ($user === null) {
$this->manager->emit('\OC\User', 'failedLogin', [$uid]);
$this->emitFailedLogin($uid);
return false;
}
Expand Down Expand Up @@ -954,9 +953,10 @@ public function tryAuthModuleLogin(IRequest $request) {
* @param IUser $user The user
* @param String $password The user's password
* @return boolean True if the user can be authenticated, false otherwise
* @throws LoginException if an app canceld the login process or the user is not enabled
* @throws LoginException if an app canceled the login process or the user is not enabled
*/
protected function loginUser($user, $password) {
protected function loginUser(IUser $user = null, $password) {
$uid = $user === null ? '' : $user->getUID();
return $this->emittingCall(function () use (&$user, &$password) {
if (is_null($user)) {
//Cannot extract the uid when $user is null, hence pass null
Expand Down Expand Up @@ -985,7 +985,9 @@ protected function loginUser($user, $password) {
}

return true;
}, ['before' => ['uid' => $user, 'password' => $password], 'after' => ['uid' => $user, 'password' => $password]], 'user', 'login');
}, ['before' => ['user' => $user, 'uid' => $uid, 'password' => $password],
'after' => ['user' => $user, 'uid' => $uid, 'password' => $password]],
'user', 'login');
}

/**
Expand Down Expand Up @@ -1168,11 +1170,13 @@ protected function getAuthModules($includeBuiltIn) {
}

/**
* This method triggers symfony event for failed login
*
* This method triggers symfony event for failed login as well as
* emits via the emitter in user manager
* @param string $user
*/
protected function emitFailedLogin($user) {
$this->manager->emit('\OC\User', 'failedLogin', [$user]);

$loginFailedEvent = new GenericEvent(null, ['user' => $user]);
$this->eventDispatcher->dispatch('user.loginfailed', $loginFailedEvent);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
use OCP\API;
use OCP\AppFramework\Http;
use OC\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\Exceptions\AccountCheckException;

/**
* @author Bart Visscher <bartv@thisnet.nl>
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/json.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
*
*/

use OC\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\Exceptions\AccountCheckException;

/**
* Class OC_JSON
Expand Down
2 changes: 1 addition & 1 deletion lib/private/legacy/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@
*
*/

use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\Files\NoReadAccessException;
use OCP\IConfig;
use OCP\IGroupManager;
use OCP\IUser;
use OC\Authentication\Exceptions\AccountCheckException;

class OC_Util {
public static $scripts = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@
*
*/

namespace OC\Authentication\Exceptions;
namespace OCP\Authentication\Exceptions;

use Exception;
use OCP\AppFramework\Http\RedirectResponse;

/**
* Class AccountCheckException
*
* @package OCP\Authentication\Exceptions
* @since 10.0.9
*/
class AccountCheckException extends Exception {

/**
Expand All @@ -38,14 +44,19 @@ class AccountCheckException extends Exception {
* @param string $message
* @param int $code
* @param \Throwable|null $previous
* @since 10.0.9
*/
public function __construct(RedirectResponse $redirectResponse, $message = '', $code = 0, \Throwable $previous = null) {
public function __construct(RedirectResponse $redirectResponse,
$message = '',
$code = 0,
\Throwable $previous = null) {
parent::__construct($message, $code, $previous);
$this->redirectResponse = $redirectResponse;
}

/**
* @return RedirectResponse
* @since 10.0.9
*/
public function getRedirectResponse() {
return $this->redirectResponse;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/Authentication/IAccountModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

namespace OCP\Authentication;

use OC\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\IUser;

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Core/Middleware/AccountModuleMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
namespace Test\Core\Middleware;

use OC\Authentication\AccountModule\Manager;
use OC\Authentication\Exceptions\AccountCheckException;
use OC\Core\Controller\LoginController;
use OC\Core\Middleware\AccountModuleMiddleware;
use OCP\AppFramework\Utility\IControllerMethodReflector;
use OCP\Authentication\Exceptions\AccountCheckException;
use OCP\Authentication\IAccountModuleController;
use OCP\ILogger;
use OCP\IUser;
Expand Down Expand Up @@ -159,7 +159,7 @@ public function testBeforeControllerAccountUpToDate() {
}

/**
* @expectedException \OC\Authentication\Exceptions\AccountCheckException
* @expectedException \OCP\Authentication\Exceptions\AccountCheckException
*/
public function testBeforeControllerAccountNeedsUpdate() {
$this->reflector->expects($this->once())
Expand Down
2 changes: 1 addition & 1 deletion tests/lib/User/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1528,7 +1528,7 @@ function (GenericEvent $event) use (&$calledFailedLoginEvent) {
$iUser->expects($this->once())
->method('isEnabled')
->willReturn(false);
$iUser->expects($this->once())
$iUser->expects($this->exactly(2))
->method('getUID')
->willReturn('foo');

Expand Down

0 comments on commit c5b18ed

Please sign in to comment.