Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Move AccountCheckException to public api #31933

Merged
merged 4 commits into from
Jun 29, 2018
Merged
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
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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why needing another event ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to fix the naming convention

}
}

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]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happened to these ? obsolete ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the emit call is within emitFailedLogin

$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]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PVince81 see here


$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 <[email protected]>
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