Skip to content

Commit 18afbf8

Browse files
committed
Remove deprecated identify option from SessionAuthenticator
The identify option was deprecated in 3.x in favor of PrimaryKeySessionAuthenticator. Remove it for the 4.x major.
1 parent e5f710c commit 18afbf8

File tree

9 files changed

+35
-157
lines changed

9 files changed

+35
-157
lines changed

docs/en/authenticators.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ Configuration options:
1818

1919
- **sessionKey**: The session key for the user data, default is
2020
``Auth``
21-
- **identify**: Set this key with a value of bool ``true`` to enable checking
22-
the session credentials against the identifiers. When ``true``, the configured
23-
:doc:`/identifiers` are used to identify the user using data
24-
stored in the session on each request. Default value is ``false``.
2521
- **fields**: Allows you to map the ``username`` field to the unique
26-
identifier in your user storage. Defaults to ``username``. This option is
27-
used when the ``identify`` option is set to true.
22+
identifier in your user storage. Defaults to ``username``.
2823

2924
PrimaryKeySession
3025
=================

docs/en/upgrade-3-to-4.rst

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,28 @@ For LDAP authentication:
105105
LdapIdentifier::CREDENTIAL_PASSWORD => 'password',
106106
];
107107
108+
SessionAuthenticator ``identify`` Option Removed
109+
-------------------------------------------------
110+
111+
The deprecated ``identify`` option has been removed from ``SessionAuthenticator``.
112+
Use ``PrimaryKeySessionAuthenticator`` instead if you need to fetch fresh user
113+
data from the database on each request.
114+
115+
**Before (3.x):**
116+
117+
.. code-block:: php
118+
119+
$service->loadAuthenticator('Authentication.Session', [
120+
'identify' => true,
121+
'identifier' => 'Authentication.Password',
122+
]);
123+
124+
**After (4.x):**
125+
126+
.. code-block:: php
127+
128+
$service->loadAuthenticator('Authentication.PrimaryKeySession');
129+
108130
URL Checker Renamed and Restructured
109131
-------------------------------------
110132

@@ -278,15 +300,20 @@ New dedicated checker for multiple login URLs:
278300
Migration Tips
279301
==============
280302

281-
1. **Search and Replace**:
303+
1. **Session Identify**:
304+
305+
If you used ``'identify' => true`` on ``SessionAuthenticator``, switch to
306+
``PrimaryKeySessionAuthenticator`` which always fetches fresh data.
307+
308+
2. **Search and Replace**:
282309

283310
- ``AbstractIdentifier::CREDENTIAL_`` → ``PasswordIdentifier::CREDENTIAL_``
284311
- ``IdentifierCollection`` → ``IdentifierFactory``
285312
- ``'Authentication.CakeRouter'`` → Remove (no longer needed, default is now CakePHP-based)
286313
- ``CakeRouterUrlChecker`` → ``DefaultUrlChecker``
287314
- Old 3.x ``DefaultUrlChecker`` → ``StringUrlChecker``
288315

289-
2. **String URL Checking**:
316+
3. **String URL Checking**:
290317

291318
If you want to use string-only URL checking, explicitly configure
292319
``StringUrlChecker``:
@@ -298,17 +325,17 @@ Migration Tips
298325
'loginUrl' => '/users/login',
299326
]);
300327
301-
3. **Multiple Login URLs**:
328+
4. **Multiple Login URLs**:
302329

303330
If you have multiple login URLs, add ``'urlChecker' => 'Authentication.Multi'``
304331
to your authenticator configuration.
305332

306-
4. **Custom Identifier Setup**:
333+
5. **Custom Identifier Setup**:
307334

308335
If you were passing ``IdentifierCollection`` to authenticators, switch to
309336
either passing a single identifier or null (to use defaults).
310337

311-
5. **Test Thoroughly**:
338+
6. **Test Thoroughly**:
312339

313340
The changes to identifier management and URL checking are significant.
314341
Test all authentication flows after upgrading.

docs/es/authenticators.rst

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@ Opciones de configuración:
1818

1919
- **sessionKey**: Key para los datos de usuario, por defecto es
2020
``Auth``
21-
- **identify**: Establezca esta key con un valor ``true`` para permitir la verificación de las
22-
credenciales de sesión con los identificadores. Cuando es ``true``, los
23-
:doc:`/identifiers` configurados se utilizan para identificar al usuario utilizando los datos
24-
almacenados en la sesión en cada request. El valor predeterminado es ``false``.
2521
- **fields**: Permite mapear el campo ``username`` al identificador único
26-
en su almacenamiento de usuario. Por defecto es ``username``. Esta opción se utiliza cuando
27-
la opción ``identify`` se establece en verdadero.
22+
en su almacenamiento de usuario. Por defecto es ``username``.
2823

2924
Form
3025
====

docs/fr/authenticators.rst

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,9 @@ Les options de configuration:
1919

2020
- **sessionKey**: La clé de session pour les données de l'utilisateur, par
2121
défaut ``Auth``.
22-
- **identify**: Définissez cette clé avec la valeur booléenne ``true`` pour
23-
activer la confrontation des identifiants utilisateur contenus dans la
24-
session avec les identificateurs (*identifiers*). Lorsque que la valeur est
25-
``true``, les :doc:`/identifiers` configurés sont utilisés à chaque requête
26-
pour identifier l'utilisateur à partir des informations stockées en session.
27-
La valeur par défaut est ``false``.
2822
- **fields**: Vous permet de mapper le champ ``username`` à l'identifiant
2923
unique dans votre système de stockage des utilisateurs. Vaut ``username`` par
30-
défaut. Cette option est utilisée quand l'option ``identify`` est définie à
31-
*true*.
24+
défaut.
3225

3326
Form
3427
====

docs/ja/authenticators.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,8 @@ Authenticatorは、リクエストを認証操作に変換する処理を行い
1414
設定オプション:
1515

1616
- **sessionKey**: ユーザーのセッションキー, デフォルトは ``Auth``
17-
- **identify**: bool ``true`` の値を指定してこのキーを設定すると、
18-
セッションの認証情報を識別子と照合できるようになります。
19-
``true`` の場合、設定された :doc:`/identifiers` はリクエストのたびにセッションに
20-
保存されたデータを使ってユーザを識別するために使われます。デフォルト値は ``false``.
2117
- **fields**: ``username`` フィールドをユーザストレージ内の一意の識別しに写像することができます。
2218
デフォルトは ``username`` です。
23-
このオプションは ``identify`` オプションが true に設定されている場合に使用されます.
2419

2520
`Form`
2621
=========

src/Authenticator/PrimaryKeySessionAuthenticator.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class PrimaryKeySessionAuthenticator extends SessionAuthenticator
5353
'fields' => [],
5454
'sessionKey' => 'Auth',
5555
'impersonateSessionKey' => 'AuthImpersonate',
56-
'identify' => false,
5756
'identityAttribute' => 'identity',
5857
'identifierKey' => 'key',
5958
'idField' => 'id',
@@ -167,7 +166,6 @@ public function impersonate(
167166
}
168167
$session->write($impersonateSessionKey, $impersonator[$this->getConfig('idField')]);
169168
$session->write($sessionKey, $impersonated[$this->getConfig('idField')]);
170-
$this->setConfig('identify', true);
171169

172170
return [
173171
'request' => $request,

src/Authenticator/SessionAuthenticator.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class SessionAuthenticator extends AbstractAuthenticator implements PersistenceI
3333
* Default config for this object.
3434
* - `fields` The fields to use to verify a user by.
3535
* - `sessionKey` Session key.
36-
* - `identify` Whether to identify user data stored in a session. This is
37-
* useful if you want to remotely end sessions that have a different password stored,
38-
* or if your identification logic needs additional conditions before a user can login.
3936
*
4037
* @var array
4138
*/
@@ -45,7 +42,6 @@ class SessionAuthenticator extends AbstractAuthenticator implements PersistenceI
4542
],
4643
'sessionKey' => 'Auth',
4744
'impersonateSessionKey' => 'AuthImpersonate',
48-
'identify' => false,
4945
'identityAttribute' => 'identity',
5046
];
5147

@@ -85,18 +81,6 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
8581
return new Result(null, Result::FAILURE_IDENTITY_NOT_FOUND);
8682
}
8783

88-
if ($this->getConfig('identify') === true) {
89-
$credentials = [];
90-
foreach ($this->getConfig('fields') as $key => $field) {
91-
$credentials[$key] = $user[$field];
92-
}
93-
$user = $this->getIdentifier()->identify($credentials);
94-
95-
if (!$user) {
96-
return new Result(null, Result::FAILURE_CREDENTIALS_INVALID);
97-
}
98-
}
99-
10084
if (!($user instanceof ArrayAccess)) {
10185
$user = new ArrayObject($user);
10286
}
@@ -168,7 +152,6 @@ public function impersonate(
168152
}
169153
$session->write($impersonateSessionKey, $impersonator);
170154
$session->write($sessionKey, $impersonated);
171-
$this->setConfig('identify', true);
172155

173156
return [
174157
'request' => $request,
@@ -193,7 +176,6 @@ public function stopImpersonating(ServerRequestInterface $request, ResponseInter
193176
$identity = $session->read($impersonateSessionKey);
194177
$session->delete($impersonateSessionKey);
195178
$session->write($sessionKey, $identity);
196-
$this->setConfig('identify', true);
197179
}
198180

199181
return [

tests/TestCase/AuthenticationServiceTest.php

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
use Cake\Http\Response;
3131
use Cake\Http\ServerRequest;
3232
use Cake\Http\ServerRequestFactory;
33-
use Cake\I18n\DateTime;
3433
use Cake\Routing\Router;
3534
use InvalidArgumentException;
3635
use PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations;
@@ -166,56 +165,6 @@ public function testAuthenticateWithChallengeDisabled()
166165
$this->assertFalse($result->isValid());
167166
}
168167

169-
/**
170-
* Integration test for session auth + identify always getting a fresh user record.
171-
*
172-
* @return void
173-
*/
174-
public function testAuthenticationWithSessionIdentify()
175-
{
176-
$users = $this->fetchTable('Users');
177-
$user = $users->get(1);
178-
179-
$request = ServerRequestFactory::fromGlobals([
180-
'SERVER_NAME' => 'example.com',
181-
'REQUEST_URI' => '/testpath',
182-
]);
183-
$request->getSession()->write('Auth', [
184-
'username' => $user->username,
185-
'password' => $user->password,
186-
]);
187-
188-
$factory = function () {
189-
return new AuthenticationService([
190-
'authenticators' => [
191-
'Authentication.Session' => [
192-
'identify' => true,
193-
'identifier' => 'Authentication.Password',
194-
],
195-
],
196-
]);
197-
};
198-
$service = $factory();
199-
$result = $service->authenticate($request);
200-
$this->assertTrue($result->isValid());
201-
202-
$dateValue = new DateTime('2022-01-01 10:11:12');
203-
$identity = $result->getData();
204-
$this->assertEquals($identity->username, $user->username);
205-
$this->assertNotEquals($identity->created, $dateValue);
206-
207-
// Update the user so that we can ensure session is reading from the db.
208-
$user->created = $dateValue;
209-
$users->saveOrFail($user);
210-
211-
$service = $factory();
212-
$result = $service->authenticate($request);
213-
$this->assertTrue($result->isValid());
214-
$identity = $result->getData();
215-
$this->assertEquals($identity->username, $user->username);
216-
$this->assertEquals($identity->created, $dateValue);
217-
}
218-
219168
/**
220169
* testLoadAuthenticatorException
221170
*/

tests/TestCase/Authenticator/SessionAuthenticatorTest.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -197,62 +197,6 @@ public function testAuthenticateFailure()
197197
$this->assertSame(Result::FAILURE_IDENTITY_NOT_FOUND, $result->getStatus());
198198
}
199199

200-
/**
201-
* Test successful session data verification by database lookup
202-
*
203-
* @return void
204-
*/
205-
public function testVerifyByDatabaseSuccess()
206-
{
207-
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
208-
209-
$this->sessionMock->expects($this->once())
210-
->method('read')
211-
->with('Auth')
212-
->willReturn([
213-
'username' => 'mariano',
214-
'password' => 'h45h',
215-
]);
216-
217-
$request = $request->withAttribute('session', $this->sessionMock);
218-
219-
$authenticator = new SessionAuthenticator($this->identifier, [
220-
'identify' => true,
221-
]);
222-
$result = $authenticator->authenticate($request);
223-
224-
$this->assertInstanceOf(Result::class, $result);
225-
$this->assertSame(Result::SUCCESS, $result->getStatus());
226-
}
227-
228-
/**
229-
* Test session data verification by database lookup failure
230-
*
231-
* @return void
232-
*/
233-
public function testVerifyByDatabaseFailure()
234-
{
235-
$request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/']);
236-
237-
$this->sessionMock->expects($this->once())
238-
->method('read')
239-
->with('Auth')
240-
->willReturn([
241-
'username' => 'does-not',
242-
'password' => 'exist',
243-
]);
244-
245-
$request = $request->withAttribute('session', $this->sessionMock);
246-
247-
$authenticator = new SessionAuthenticator($this->identifier, [
248-
'identify' => true,
249-
]);
250-
$result = $authenticator->authenticate($request);
251-
252-
$this->assertInstanceOf(Result::class, $result);
253-
$this->assertSame(Result::FAILURE_CREDENTIALS_INVALID, $result->getStatus());
254-
}
255-
256200
/**
257201
* testPersistIdentity
258202
*

0 commit comments

Comments
 (0)