Skip to content

Commit 91d6bd3

Browse files
committed
SimpleAuthenticator implements Autheticator
1 parent 4306360 commit 91d6bd3

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

src/Security/SimpleAuthenticator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414

1515
/**
16-
* Trivial implementation of IAuthenticator.
16+
* Trivial implementation of Authenticator.
1717
*/
18-
class SimpleAuthenticator implements IAuthenticator
18+
class SimpleAuthenticator implements Authenticator
1919
{
2020
use Nette\SmartObject;
2121

@@ -47,9 +47,13 @@ public function __construct(array $userlist, array $usersRoles = [], array $user
4747
* and returns IIdentity on success or throws AuthenticationException
4848
* @throws AuthenticationException
4949
*/
50-
public function authenticate(array $credentials): IIdentity
50+
public function authenticate(/*string*/ $username, string $password = null): IIdentity
5151
{
52-
[$username, $password] = $credentials;
52+
if (is_array($username)) {
53+
[$username, $password] = $username; // back compatibility
54+
trigger_error(__METHOD__ . '() now accepts arguments (string $username, string $password).', E_USER_DEPRECATED);
55+
}
56+
5357
foreach ($this->userlist as $name => $pass) {
5458
if (strcasecmp($name, $username) === 0) {
5559
if ((string) $pass === (string) $password) {

tests/Security.DI/SecurityExtension.authenticator.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ $expectedRoles = [
5252
];
5353

5454
foreach ($userList as $username => $password) {
55-
$identity = $authenticator->authenticate([$username, $password]);
55+
$identity = $authenticator->authenticate($username, $password);
5656
Assert::equal($username, $identity->getId());
5757
Assert::equal($expectedRoles[$username], $identity->getRoles());
5858
}

tests/Security/SimpleAuthenticator.Data.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $expectedData = [
3131
$authenticator = new SimpleAuthenticator($users, [], $usersData);
3232

3333
foreach ($users as $username => $password) {
34-
$identity = $authenticator->authenticate([$username, $password]);
34+
$identity = $authenticator->authenticate($username, $password);
3535
Assert::equal($username, $identity->getId());
3636
Assert::equal($expectedData[$username], $identity->getData());
3737
}

tests/Security/SimpleAuthenticator.Roles.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ $expectedRoles = [
3131
$authenticator = new SimpleAuthenticator($users, $usersRoles);
3232

3333
foreach ($users as $username => $password) {
34-
$identity = $authenticator->authenticate([$username, $password]);
34+
$identity = $authenticator->authenticate($username, $password);
3535
Assert::equal($username, $identity->getId());
3636
Assert::equal($expectedRoles[$username], $identity->getRoles());
3737
}

tests/Security/SimpleAuthenticator.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ $users = [
2020

2121
$authenticator = new SimpleAuthenticator($users);
2222

23-
$identity = $authenticator->authenticate(['john', 'password123!']);
23+
$identity = $authenticator->authenticate('john', 'password123!');
2424
Assert::type(Nette\Security\IIdentity::class, $identity);
2525
Assert::equal('john', $identity->getId());
2626

27-
$identity = $authenticator->authenticate(['admin', 'admin']);
27+
$identity = $authenticator->authenticate('admin', 'admin');
2828
Assert::type(Nette\Security\IIdentity::class, $identity);
2929
Assert::equal('admin', $identity->getId());
3030

3131
Assert::exception(function () use ($authenticator) {
32-
$authenticator->authenticate(['admin', 'wrong password']);
32+
$authenticator->authenticate('admin', 'wrong password');
3333
}, Nette\Security\AuthenticationException::class, 'Invalid password.');
3434

3535
Assert::exception(function () use ($authenticator) {
36-
$authenticator->authenticate(['nobody', 'password']);
36+
$authenticator->authenticate('nobody', 'password');
3737
}, Nette\Security\AuthenticationException::class, "User 'nobody' not found.");

0 commit comments

Comments
 (0)