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

Return correct loginname in credentials #21288

Merged
merged 2 commits into from
Aug 28, 2020
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 lib/private/Authentication/LoginCredentials/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function getLoginCredentials(): ICredentials {

if ($trySession && $this->session->exists('login_credentials')) {
$creds = json_decode($this->session->get('login_credentials'));
return new Credentials($creds->uid, $creds->uid, $creds->password);
return new Credentials($creds->uid, $creds->loginName, $creds->password);
}

// If we reach this line, an exception was thrown.
Expand Down
4 changes: 2 additions & 2 deletions lib/private/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ public function __construct($webRoot, \OC\Config $config) {
$dispatcher = $this->query(IEventDispatcher::class);
$dispatcher->dispatchTyped(new BeforeUserLoggedInEvent($uid, $password));
});
$userSession->listen('\OC\User', 'postLogin', function ($user, $password, $isTokenLogin) {
$userSession->listen('\OC\User', 'postLogin', function ($user, $loginName, $password, $isTokenLogin) {
/** @var \OC\User\User $user */
\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'password' => $password, 'isTokenLogin' => $isTokenLogin]);
\OC_Hook::emit('OC_User', 'post_login', ['run' => true, 'uid' => $user->getUID(), 'loginName' => $loginName, 'password' => $password, 'isTokenLogin' => $isTokenLogin]);

/** @var IEventDispatcher $dispatcher */
$dispatcher = $this->query(IEventDispatcher::class);
Expand Down
4 changes: 3 additions & 1 deletion lib/private/User/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* - preUnassignedUserId(string $uid)
* - postUnassignedUserId(string $uid)
* - preLogin(string $user, string $password)
* - postLogin(\OC\User\User $user, string $password)
* - postLogin(\OC\User\User $user, string $loginName, string $password, boolean $isTokenLogin)
* - preRememberedLogin(string $uid)
* - postRememberedLogin(\OC\User\User $user)
* - logout()
Expand Down Expand Up @@ -400,11 +400,13 @@ public function completeLogin(IUser $user, array $loginDetails, $regenerateSessi

$this->dispatcher->dispatchTyped(new PostLoginEvent(
$user,
$loginDetails['loginName'],
$loginDetails['password'],
$isToken
));
$this->manager->emit('\OC\User', 'postLogin', [
$user,
$loginDetails['loginName'],
$loginDetails['password'],
$isToken,
]);
Expand Down
16 changes: 15 additions & 1 deletion lib/public/User/Events/PostLoginEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ class PostLoginEvent extends Event {
/** @var IUser */
private $user;

/**
* @since 20.0.0
* @var string
*/
private $loginName;

/** @var string */
private $password;

Expand All @@ -47,9 +53,10 @@ class PostLoginEvent extends Event {
/**
* @since 18.0.0
*/
public function __construct(IUser $user, string $password, bool $isTokenLogin) {
public function __construct(IUser $user, string $loginName, string $password, bool $isTokenLogin) {
Copy link
Member

Choose a reason for hiding this comment

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

FYI, we cannot backport this as it breaks public API.

parent::__construct();
$this->user = $user;
$this->loginName = $loginName;
$this->password = $password;
$this->isTokenLogin = $isTokenLogin;
}
Expand All @@ -61,6 +68,13 @@ public function getUser(): IUser {
return $this->user;
}

/**
* @since 20.0.0
*/
public function getLoginName(): string {
return $this->loginName;
}

/**
* @since 18.0.0
*/
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/Authentication/LoginCredentials/StoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public function testGetLoginCredentialsInvalidToken() {
}

public function testGetLoginCredentialsInvalidTokenLoginCredentials() {
$uid = 'user987';
$uid = 'id987';
$user = 'user987';
$password = '7389374';

$this->session->expects($this->once())
Expand All @@ -158,8 +159,8 @@ public function testGetLoginCredentialsInvalidTokenLoginCredentials() {
$this->session->expects($this->once())
->method('get')
->with($this->equalTo('login_credentials'))
->willReturn('{"run":true,"uid":"user987","password":"7389374"}');
$expected = new Credentials('user987', 'user987', '7389374');
->willReturn('{"run":true,"uid":"id987","loginName":"user987","password":"7389374"}');
$expected = new Credentials($uid, $user, $password);

$actual = $this->store->getLoginCredentials();

Expand Down