Skip to content

Commit 3c1906a

Browse files
petrparolekf3l1x
authored andcommitted
require nette/security 3.1 (BC break)
1 parent a28fdfc commit 3c1906a

File tree

5 files changed

+21
-25
lines changed

5 files changed

+21
-25
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
],
2121
"require": {
2222
"php": ">=7.2",
23-
"nette/security": "^3.0.0"
23+
"nette/security": "^3.1"
2424
},
2525
"require-dev": {
2626
"ninjify/nunjuck": "^0.4",

src/Auth/DebugAuthenticator.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
namespace Contributte\Security\Auth;
44

55
use Nette\Security\AuthenticationException;
6-
use Nette\Security\IAuthenticator;
7-
use Nette\Security\Identity;
6+
use Nette\Security\Authenticator;
87
use Nette\Security\IIdentity;
8+
use Nette\Security\SimpleIdentity;
99

10-
class DebugAuthenticator implements IAuthenticator
10+
class DebugAuthenticator implements Authenticator
1111
{
1212

1313
/** @var bool */
@@ -27,20 +27,19 @@ public function setIdentity(IIdentity $identity): void
2727
}
2828

2929
/**
30-
* @param string[] $credentials
3130
* @throws AuthenticationException
3231
*/
33-
public function authenticate(array $credentials): IIdentity
32+
public function authenticate(string $username, string $password): IIdentity
3433
{
3534
if ($this->pass === false) {
36-
throw new AuthenticationException('Cannot login', IAuthenticator::FAILURE);
35+
throw new AuthenticationException('Cannot login', Authenticator::FAILURE);
3736
}
3837

3938
if ($this->identity !== null) {
4039
return $this->identity;
4140
}
4241

43-
return new Identity(1, null, null);
42+
return new SimpleIdentity(1, null, null);
4443
}
4544

4645
}

src/Auth/StaticAuthenticator.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use InvalidArgumentException;
66
use Nette\Security\AuthenticationException;
7-
use Nette\Security\IAuthenticator;
8-
use Nette\Security\Identity;
7+
use Nette\Security\Authenticator;
98
use Nette\Security\IIdentity;
109
use Nette\Security\Passwords;
10+
use Nette\Security\SimpleIdentity;
1111

12-
class StaticAuthenticator implements IAuthenticator
12+
class StaticAuthenticator implements Authenticator
1313
{
1414

1515
/** @var mixed[][] */
@@ -40,15 +40,12 @@ public function __construct(array $list, Passwords $passwords)
4040
}
4141

4242
/**
43-
* @param string[] $credentials
4443
* @throws AuthenticationException
4544
*/
46-
public function authenticate(array $credentials): IIdentity
45+
public function authenticate(string $username, string $password): IIdentity
4746
{
48-
[$username, $password] = $credentials;
49-
5047
if (!isset($this->list[$username])) {
51-
throw new AuthenticationException(sprintf('User `%s` not found', $username), IAuthenticator::IDENTITY_NOT_FOUND);
48+
throw new AuthenticationException(sprintf('User `%s` not found', $username), Authenticator::IDENTITY_NOT_FOUND);
5249
}
5350

5451
$user = $this->list[$username];
@@ -57,7 +54,7 @@ public function authenticate(array $credentials): IIdentity
5754
($user['unsecured'] === true && !hash_equals($password, $user['password'])) ||
5855
($user['unsecured'] === false && !$this->passwords->verify($password, $user['password']))
5956
) {
60-
throw new AuthenticationException('Invalid password', IAuthenticator::INVALID_CREDENTIAL);
57+
throw new AuthenticationException('Invalid password', Authenticator::INVALID_CREDENTIAL);
6158
}
6259

6360
return $user['identity'];
@@ -69,7 +66,7 @@ public function authenticate(array $credentials): IIdentity
6966
private function createIdentity(string $username, array $values): IIdentity
7067
{
7168
if (!isset($values['identity'])) {
72-
return new Identity($username);
69+
return new SimpleIdentity($username);
7370
}
7471

7572
$identity = $values['identity'];
@@ -79,7 +76,7 @@ private function createIdentity(string $username, array $values): IIdentity
7976
}
8077

8178
if (is_array($values['identity'])) {
82-
return new Identity(
79+
return new SimpleIdentity(
8380
$identity['id'] ?? $username,
8481
$identity['roles'] ?? null,
8582
$identity['date'] ?? null

tests/cases/Auth/DebugAuthenticator.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use Tester\Assert;
1414
// Optimistic
1515
test(function (): void {
1616
$auth = new DebugAuthenticator(true);
17-
Assert::type(IIdentity::class, $auth->authenticate(['foo', 'bar']));
17+
Assert::type(IIdentity::class, $auth->authenticate('foo', 'bar'));
1818
});
1919

2020
// Pessimistic
2121
test(function (): void {
2222
Assert::exception(function (): void {
2323
$auth = new DebugAuthenticator(false);
24-
$auth->authenticate([]);
24+
$auth->authenticate('', '');
2525
}, AuthenticationException::class);
2626
});

tests/cases/Auth/StaticAuthenticator.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ test(function (): void {
2121
],
2222
], (new Passwords(PASSWORD_BCRYPT)));
2323

24-
Assert::type(IIdentity::class, $auth->authenticate(['[email protected]', 'foobar']));
24+
Assert::type(IIdentity::class, $auth->authenticate('[email protected]', 'foobar'));
2525
});
2626

2727
// Success - plain password
@@ -33,7 +33,7 @@ test(function (): void {
3333
],
3434
], (new Passwords(PASSWORD_BCRYPT)));
3535

36-
Assert::type(IIdentity::class, $auth->authenticate(['[email protected]', 'foobar']));
36+
Assert::type(IIdentity::class, $auth->authenticate('[email protected]', 'foobar'));
3737
});
3838

3939
// User not found
@@ -46,7 +46,7 @@ test(function (): void {
4646
], (new Passwords(PASSWORD_BCRYPT)));
4747

4848
Assert::exception(function () use ($auth): void {
49-
$auth->authenticate(['foo', 'bar']);
49+
$auth->authenticate('foo', 'bar');
5050
}, AuthenticationException::class, 'User `foo` not found');
5151
});
5252

@@ -60,6 +60,6 @@ test(function (): void {
6060
], (new Passwords(PASSWORD_BCRYPT)));
6161

6262
Assert::exception(function () use ($auth): void {
63-
$auth->authenticate(['[email protected]', 'bar']);
63+
$auth->authenticate('[email protected]', 'bar');
6464
}, AuthenticationException::class, 'Invalid password');
6565
});

0 commit comments

Comments
 (0)