Skip to content

Commit b015f8c

Browse files
committed
Remove deprecations, fix up MultiChecker.
1 parent 86b48f2 commit b015f8c

24 files changed

+260
-450
lines changed

src/AuthenticationService.php

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
use Authentication\Authenticator\PersistenceInterface;
2424
use Authentication\Authenticator\ResultInterface;
2525
use Authentication\Authenticator\StatelessInterface;
26-
use Authentication\Identifier\IdentifierCollection;
2726
use Authentication\Identifier\IdentifierInterface;
2827
use Cake\Core\InstanceConfigTrait;
2928
use Cake\Routing\Router;
3029
use InvalidArgumentException;
3130
use Psr\Http\Message\ResponseInterface;
3231
use Psr\Http\Message\ServerRequestInterface;
3332
use RuntimeException;
34-
use function Cake\Core\deprecationWarning;
3533

3634
/**
3735
* Authentication Service
@@ -47,13 +45,6 @@ class AuthenticationService implements AuthenticationServiceInterface, Impersona
4745
*/
4846
protected ?AuthenticatorCollection $_authenticators = null;
4947

50-
/**
51-
* Identifier collection
52-
*
53-
* @var \Authentication\Identifier\IdentifierCollection|null
54-
*/
55-
protected ?IdentifierCollection $_identifiers = null;
56-
5748
/**
5849
* Authenticator that successfully authenticated the identity.
5950
*
@@ -73,10 +64,7 @@ class AuthenticationService implements AuthenticationServiceInterface, Impersona
7364
*
7465
* - `authenticators` - An array of authentication objects to use for authenticating users.
7566
* You can configure multiple adapters and they will be checked sequentially
76-
* when users are identified.
77-
* - `identifiers` - An array of identifiers. The identifiers are constructed by the service
78-
* and then passed to the authenticators that will pass the credentials to them and get the
79-
* user data.
67+
* when users are identified. Each authenticator config can specify its own `identifier`.
8068
* - `identityClass` - The class name of identity or a callable identity builder.
8169
* - `identityAttribute` - The request attribute used to store the identity. Default to `identity`.
8270
* - `unauthenticatedRedirect` - The URL to redirect unauthenticated errors to. See
@@ -100,7 +88,6 @@ class AuthenticationService implements AuthenticationServiceInterface, Impersona
10088
*/
10189
protected array $_defaultConfig = [
10290
'authenticators' => [],
103-
'identifiers' => [],
10491
'identityClass' => Identity::class,
10592
'identityAttribute' => 'identity',
10693
'queryParam' => null,
@@ -117,20 +104,6 @@ public function __construct(array $config = [])
117104
$this->setConfig($config);
118105
}
119106

120-
/**
121-
* Access the identifier collection
122-
*
123-
* @return \Authentication\Identifier\IdentifierCollection
124-
*/
125-
public function identifiers(): IdentifierCollection
126-
{
127-
if ($this->_identifiers === null) {
128-
$this->_identifiers = new IdentifierCollection($this->getConfig('identifiers'));
129-
}
130-
131-
return $this->_identifiers;
132-
}
133-
134107
/**
135108
* Access the authenticator collection
136109
*
@@ -139,9 +112,8 @@ public function identifiers(): IdentifierCollection
139112
public function authenticators(): AuthenticatorCollection
140113
{
141114
if ($this->_authenticators === null) {
142-
$identifiers = $this->identifiers();
143115
$authenticators = $this->getConfig('authenticators');
144-
$this->_authenticators = new AuthenticatorCollection($identifiers, $authenticators);
116+
$this->_authenticators = new AuthenticatorCollection($authenticators);
145117
}
146118

147119
return $this->_authenticators;
@@ -159,24 +131,6 @@ public function loadAuthenticator(string $name, array $config = []): Authenticat
159131
return $this->authenticators()->load($name, $config);
160132
}
161133

162-
/**
163-
* Loads an identifier.
164-
*
165-
* @param string $name Name or class name.
166-
* @param array<string, mixed> $config Identifier configuration.
167-
* @return \Authentication\Identifier\IdentifierInterface Identifier instance
168-
* @deprecated 3.3.0: loadIdentifier() usage is deprecated. Directly pass Identifier to Authenticator.
169-
*/
170-
public function loadIdentifier(string $name, array $config = []): IdentifierInterface
171-
{
172-
deprecationWarning(
173-
'3.3.0',
174-
'loadIdentifier() usage is deprecated. Directly pass `\'identifier\'` config to the Authenticator.',
175-
);
176-
177-
return $this->identifiers()->load($name, $config);
178-
}
179-
180134
/**
181135
* {@inheritDoc}
182136
*
@@ -291,12 +245,7 @@ public function getIdentificationProvider(): ?IdentifierInterface
291245
return null;
292246
}
293247

294-
$identifier = $this->_successfulAuthenticator->getIdentifier();
295-
if ($identifier instanceof IdentifierCollection) {
296-
return $identifier->getIdentificationProvider();
297-
}
298-
299-
return $identifier;
248+
return $this->_successfulAuthenticator->getIdentifier();
300249
}
301250

302251
/**

src/AuthenticationServiceInterface.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use Authentication\Authenticator\AuthenticatorInterface;
2020
use Authentication\Authenticator\PersistenceInterface;
2121
use Authentication\Authenticator\ResultInterface;
22-
use Authentication\Identifier\IdentifierInterface;
2322
use Psr\Http\Message\ServerRequestInterface;
2423

2524
interface AuthenticationServiceInterface extends PersistenceInterface
@@ -33,16 +32,6 @@ interface AuthenticationServiceInterface extends PersistenceInterface
3332
*/
3433
public function loadAuthenticator(string $name, array $config = []): AuthenticatorInterface;
3534

36-
/**
37-
* Loads an identifier.
38-
*
39-
* @param string $name Name or class name.
40-
* @param array<string, mixed> $config Identifier configuration.
41-
* @return \Authentication\Identifier\IdentifierInterface
42-
* @deprecated 3.3.0: loadIdentifier() usage is deprecated. Directly pass Identifier to Authenticator.
43-
*/
44-
public function loadIdentifier(string $name, array $config = []): IdentifierInterface;
45-
4635
/**
4736
* Authenticate the request against the configured authentication adapters.
4837
*

src/Authenticator/AbstractAuthenticator.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
*/
1717
namespace Authentication\Authenticator;
1818

19-
use Authentication\Identifier\AbstractIdentifier;
2019
use Authentication\Identifier\IdentifierInterface;
20+
use Authentication\Identifier\PasswordIdentifier;
2121
use Cake\Core\InstanceConfigTrait;
2222
use Psr\Http\Message\ServerRequestInterface;
2323

@@ -33,25 +33,25 @@ abstract class AbstractAuthenticator implements AuthenticatorInterface
3333
*/
3434
protected array $_defaultConfig = [
3535
'fields' => [
36-
AbstractIdentifier::CREDENTIAL_USERNAME => 'username',
37-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
36+
PasswordIdentifier::CREDENTIAL_USERNAME => 'username',
37+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
3838
],
3939
];
4040

4141
/**
42-
* Identifier or identifiers collection.
42+
* Identifier instance.
4343
*
44-
* @var \Authentication\Identifier\IdentifierInterface
44+
* @var \Authentication\Identifier\IdentifierInterface|null
4545
*/
46-
protected IdentifierInterface $_identifier;
46+
protected ?IdentifierInterface $_identifier = null;
4747

4848
/**
4949
* Constructor
5050
*
51-
* @param \Authentication\Identifier\IdentifierInterface $identifier Identifier or identifiers collection.
51+
* @param \Authentication\Identifier\IdentifierInterface|null $identifier Identifier instance.
5252
* @param array<string, mixed> $config Configuration settings.
5353
*/
54-
public function __construct(IdentifierInterface $identifier, array $config = [])
54+
public function __construct(?IdentifierInterface $identifier, array $config = [])
5555
{
5656
$this->_identifier = $identifier;
5757
$this->setConfig($config);
@@ -60,9 +60,9 @@ public function __construct(IdentifierInterface $identifier, array $config = [])
6060
/**
6161
* Gets the identifier.
6262
*
63-
* @return \Authentication\Identifier\IdentifierInterface
63+
* @return \Authentication\Identifier\IdentifierInterface|null
6464
*/
65-
public function getIdentifier(): IdentifierInterface
65+
public function getIdentifier(): ?IdentifierInterface
6666
{
6767
return $this->_identifier;
6868
}

src/Authenticator/AuthenticatorCollection.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,15 @@
1717
namespace Authentication\Authenticator;
1818

1919
use Authentication\AbstractCollection;
20-
use Authentication\Identifier\IdentifierCollection;
20+
use Authentication\Identifier\IdentifierFactory;
2121
use Cake\Core\App;
2222
use RuntimeException;
23-
use function Cake\Core\deprecationWarning;
2423

2524
/**
2625
* @extends \Authentication\AbstractCollection<\Authentication\Authenticator\AuthenticatorInterface>
2726
*/
2827
class AuthenticatorCollection extends AbstractCollection
2928
{
30-
/**
31-
* Identifier collection.
32-
*
33-
* @var \Authentication\Identifier\IdentifierCollection
34-
*/
35-
protected IdentifierCollection $_identifiers;
36-
37-
/**
38-
* Constructor.
39-
*
40-
* @param \Authentication\Identifier\IdentifierCollection $identifiers Identifiers collection.
41-
* @param array<string, mixed> $config Config array.
42-
*/
43-
public function __construct(IdentifierCollection $identifiers, array $config = [])
44-
{
45-
$this->_identifiers = $identifiers;
46-
if ($identifiers->count() > 0) {
47-
deprecationWarning(
48-
'3.3.0',
49-
'loadIdentifier() usage is deprecated. Directly pass `\'identifier\'` config to the Authenticator.',
50-
);
51-
}
52-
53-
parent::__construct($config);
54-
}
55-
5629
/**
5730
* Creates authenticator instance.
5831
*
@@ -65,11 +38,12 @@ public function __construct(IdentifierCollection $identifiers, array $config = [
6538
protected function _create(object|string $class, string $alias, array $config): AuthenticatorInterface
6639
{
6740
if (is_string($class)) {
41+
$identifier = null;
6842
if (!empty($config['identifier'])) {
69-
$this->_identifiers = new IdentifierCollection((array)$config['identifier']);
43+
$identifier = IdentifierFactory::create($config['identifier']);
7044
}
7145

72-
return new $class($this->_identifiers, $config);
46+
return new $class($identifier, $config);
7347
}
7448

7549
return $class;

src/Authenticator/CookieAuthenticator.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
namespace Authentication\Authenticator;
1818

1919
use ArrayAccess;
20-
use Authentication\Identifier\AbstractIdentifier;
21-
use Authentication\Identifier\IdentifierCollection;
20+
use Authentication\Identifier\IdentifierFactory;
2221
use Authentication\Identifier\IdentifierInterface;
22+
use Authentication\Identifier\PasswordIdentifier;
2323
use Authentication\PasswordHasher\PasswordHasherTrait;
2424
use Authentication\UrlChecker\UrlCheckerTrait;
2525
use Cake\Http\Cookie\Cookie;
@@ -47,8 +47,8 @@ class CookieAuthenticator extends AbstractAuthenticator implements PersistenceIn
4747
'urlChecker' => 'Authentication.Default',
4848
'rememberMeField' => 'remember_me',
4949
'fields' => [
50-
AbstractIdentifier::CREDENTIAL_USERNAME => 'username',
51-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
50+
PasswordIdentifier::CREDENTIAL_USERNAME => 'username',
51+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
5252
],
5353
'cookie' => [
5454
'name' => 'CookieAuth',
@@ -60,21 +60,19 @@ class CookieAuthenticator extends AbstractAuthenticator implements PersistenceIn
6060
/**
6161
* Constructor
6262
*
63-
* @param \Authentication\Identifier\IdentifierInterface $identifier Identifier or identifiers collection.
63+
* @param \Authentication\Identifier\IdentifierInterface|null $identifier Identifier instance.
6464
* @param array<string, mixed> $config Configuration settings.
6565
*/
66-
public function __construct(IdentifierInterface $identifier, array $config = [])
66+
public function __construct(?IdentifierInterface $identifier, array $config = [])
6767
{
6868
// If no identifier is configured, set up a default Password identifier
69-
if ($identifier instanceof IdentifierCollection && $identifier->isEmpty()) {
69+
if ($identifier === null) {
7070
// Pass the authenticator's fields configuration to the identifier
7171
$identifierConfig = [];
7272
if (isset($config['fields'])) {
7373
$identifierConfig['fields'] = $config['fields'];
7474
}
75-
$identifier = new IdentifierCollection([
76-
'Authentication.Password' => $identifierConfig,
77-
]);
75+
$identifier = IdentifierFactory::create('Authentication.Password', $identifierConfig);
7876
}
7977

8078
parent::__construct($identifier, $config);
@@ -107,6 +105,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
107105

108106
[$username, $tokenHash] = $token;
109107

108+
assert($this->_identifier !== null);
110109
$identity = $this->_identifier->identify(compact('username'));
111110

112111
if (!$identity) {

src/Authenticator/EnvironmentAuthenticator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
153153

154154
$data = array_merge($this->_getOptionalData($request), $data);
155155

156+
assert($this->_identifier !== null);
156157
$user = $this->_identifier->identify($data);
157158

158159
if (!$user) {

src/Authenticator/FormAuthenticator.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717
namespace Authentication\Authenticator;
1818

19-
use Authentication\Identifier\AbstractIdentifier;
20-
use Authentication\Identifier\IdentifierCollection;
19+
use Authentication\Identifier\IdentifierFactory;
2120
use Authentication\Identifier\IdentifierInterface;
21+
use Authentication\Identifier\PasswordIdentifier;
2222
use Authentication\UrlChecker\UrlCheckerTrait;
2323
use Cake\Routing\Router;
2424
use Psr\Http\Message\ServerRequestInterface;
@@ -44,29 +44,27 @@ class FormAuthenticator extends AbstractAuthenticator
4444
'loginUrl' => null,
4545
'urlChecker' => 'Authentication.Default',
4646
'fields' => [
47-
AbstractIdentifier::CREDENTIAL_USERNAME => 'username',
48-
AbstractIdentifier::CREDENTIAL_PASSWORD => 'password',
47+
PasswordIdentifier::CREDENTIAL_USERNAME => 'username',
48+
PasswordIdentifier::CREDENTIAL_PASSWORD => 'password',
4949
],
5050
];
5151

5252
/**
5353
* Constructor
5454
*
55-
* @param \Authentication\Identifier\IdentifierInterface $identifier Identifier or identifiers collection.
55+
* @param \Authentication\Identifier\IdentifierInterface|null $identifier Identifier instance.
5656
* @param array<string, mixed> $config Configuration settings.
5757
*/
58-
public function __construct(IdentifierInterface $identifier, array $config = [])
58+
public function __construct(?IdentifierInterface $identifier, array $config = [])
5959
{
6060
// If no identifier is configured, set up a default Password identifier
61-
if ($identifier instanceof IdentifierCollection && $identifier->isEmpty()) {
61+
if ($identifier === null) {
6262
// Pass the authenticator's fields configuration to the identifier
6363
$identifierConfig = [];
6464
if (isset($config['fields'])) {
6565
$identifierConfig['fields'] = $config['fields'];
6666
}
67-
$identifier = new IdentifierCollection([
68-
'Authentication.Password' => $identifierConfig,
69-
]);
67+
$identifier = IdentifierFactory::create('Authentication.Password', $identifierConfig);
7068
}
7169

7270
parent::__construct($identifier, $config);
@@ -161,6 +159,7 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
161159
]);
162160
}
163161

162+
assert($this->_identifier !== null);
164163
$user = $this->_identifier->identify($data);
165164

166165
if (!$user) {

0 commit comments

Comments
 (0)