Skip to content
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
29 changes: 14 additions & 15 deletions docs/en/upgrade-3-to-4.rst
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ URL Checker Renamed and Restructured
URL checkers have been completely restructured:

- ``CakeRouterUrlChecker`` has been renamed to ``DefaultUrlChecker``
- The old ``DefaultUrlChecker`` (framework-agnostic) has been renamed to ``GenericUrlChecker``
- The old ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker``
- Auto-detection has been removed - ``DefaultUrlChecker`` is now hardcoded

**Before (3.x):**
Expand All @@ -127,7 +127,7 @@ URL checkers have been completely restructured:
],
]);

// Using DefaultUrlChecker explicitly (framework-agnostic)
// Using DefaultUrlChecker explicitly
$service->loadAuthenticator('Authentication.Form', [
'urlChecker' => 'Authentication.Default',
'loginUrl' => '/users/login',
Expand All @@ -150,9 +150,9 @@ URL checkers have been completely restructured:
],
]);

// For framework-agnostic projects, explicitly use GenericUrlChecker
// For string-only URL checking, explicitly use StringUrlChecker
$service->loadAuthenticator('Authentication.Form', [
'urlChecker' => 'Authentication.Generic',
'urlChecker' => 'Authentication.String',
'loginUrl' => '/users/login',
]);

Expand Down Expand Up @@ -207,11 +207,10 @@ Auto-Detection Removed
URL Checkers
^^^^^^^^^^^^

**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded
and assumes CakePHP is available.
**Important:** Auto-detection has been removed. ``DefaultUrlChecker`` is now hardcoded.

- **4.x default:** Always uses ``DefaultUrlChecker`` (formerly ``CakeUrlChecker``)
- **Framework-agnostic:** Must explicitly configure ``GenericUrlChecker``
- **String URLs only:** Must explicitly configure ``StringUrlChecker``
- **Multiple URLs:** Must explicitly configure ``MultiUrlChecker``

DefaultUrlChecker is Now CakePHP-Based
Expand All @@ -220,7 +219,7 @@ DefaultUrlChecker is Now CakePHP-Based
``DefaultUrlChecker`` is now the CakePHP checker (formerly ``CakeRouterUrlChecker``).
It requires CakePHP Router and supports both string and array URLs.

The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUrlChecker``.
The 3.x ``DefaultUrlChecker`` has been renamed to ``StringUrlChecker``.

.. code-block:: php

Expand All @@ -229,8 +228,8 @@ The 3.x framework-agnostic ``DefaultUrlChecker`` has been renamed to ``GenericUr
$checker->check($request, ['controller' => 'Users', 'action' => 'login']); // Works
$checker->check($request, '/users/login'); // Also works

// For framework-agnostic usage:
$checker = new GenericUrlChecker();
// For string URL only usage:
$checker = new StringUrlChecker();
$checker->check($request, '/users/login'); // Works
$checker->check($request, ['controller' => 'Users']); // Throws exception

Expand Down Expand Up @@ -285,17 +284,17 @@ Migration Tips
- ``IdentifierCollection`` → ``IdentifierFactory``
- ``'Authentication.CakeRouter'`` → Remove (no longer needed, default is now CakePHP-based)
- ``CakeRouterUrlChecker`` → ``DefaultUrlChecker``
- Old 3.x ``DefaultUrlChecker`` (framework-agnostic) → ``GenericUrlChecker``
- Old 3.x ``DefaultUrlChecker`` → ``StringUrlChecker``

2. **Framework-Agnostic Projects**:
2. **String URL Checking**:

If you're using this library without CakePHP, you **must** explicitly configure
``GenericUrlChecker``:
If you want to use string-only URL checking, explicitly configure
``StringUrlChecker``:

.. code-block:: php

$service->loadAuthenticator('Authentication.Form', [
'urlChecker' => 'Authentication.Generic',
'urlChecker' => 'Authentication.String',
'loginUrl' => '/users/login',
]);

Expand Down
16 changes: 7 additions & 9 deletions docs/en/url-checkers.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
URL Checkers
############

To provide an abstract and framework agnostic solution there are URL
checkers implemented that allow you to customize the comparison of the
current URL if needed. For example to another frameworks routing.
There are URL checkers implemented that allow you to customize the comparison
of the current URL if needed.

All checkers support single URLs in either string or array format (like ``Router::url()``).
For multiple login URLs, use ``MultiUrlChecker``.
Expand Down Expand Up @@ -43,16 +42,15 @@ Options:
- **checkFullUrl**: To compare the full URL, including protocol, host
and port or not. Default is ``false``.

GenericUrlChecker
------------------
StringUrlChecker
-----------------

Framework-agnostic checker for string URLs. Supports regex matching.
Use this for non-CakePHP projects.
Checker for string URLs. Supports regex matching.

.. code-block:: php

$service->loadAuthenticator('Authentication.Form', [
'urlChecker' => 'Authentication.Generic',
'urlChecker' => 'Authentication.String',
'loginUrl' => '/users/login',
]);

Expand All @@ -62,7 +60,7 @@ Using regex:

$service->loadAuthenticator('Authentication.Form', [
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
],
'loginUrl' => '%^/[a-z]{2}/users/login/?$%',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
use RuntimeException;

/**
* Generic URL checker for framework-agnostic usage. Supports also regex.
* URL checker for string URLs. Supports also regex.
*/
class GenericUrlChecker implements UrlCheckerInterface
class StringUrlChecker implements UrlCheckerInterface
{
/**
* Default Options
Expand All @@ -44,8 +44,7 @@ public function check(ServerRequestInterface $request, array|string $loginUrls,
{
if (is_array($loginUrls)) {
throw new RuntimeException(
'Array-based login URLs require CakePHP Router and DefaultUrlChecker. ' .
'Use string URLs instead.',
'Array-based login URLs require CakePHP Router and DefaultUrlChecker.',
);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/TestCase/Authenticator/EnvironmentAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public function testRegexLoginUrlSuccess()
$envAuth = new EnvironmentAuthenticator($this->identifier, [
'loginUrl' => '%^/[a-z]{2}/users/secure/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
],
'fields' => [
Expand Down Expand Up @@ -409,7 +409,7 @@ public function testFullRegexLoginUrlFailure()
$envAuth = new EnvironmentAuthenticator($this->identifier, [
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
'checkFullUrl' => true,
],
Expand Down Expand Up @@ -441,7 +441,7 @@ public function testFullRegexLoginUrlSuccess()
$envAuth = new EnvironmentAuthenticator($this->identifier, [
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/secure/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
'checkFullUrl' => true,
],
Expand Down
8 changes: 4 additions & 4 deletions tests/TestCase/Authenticator/FormAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ public function testRegexLoginUrlSuccess()
$form = new FormAuthenticator($identifier, [
'loginUrl' => '%^/[a-z]{2}/users/login/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
],
]);
Expand Down Expand Up @@ -345,7 +345,7 @@ public function testFullRegexLoginUrlFailure()
$form = new FormAuthenticator($identifier, [
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
'checkFullUrl' => true,
],
Expand Down Expand Up @@ -379,7 +379,7 @@ public function testFullRegexLoginUrlSuccess()
$form = new FormAuthenticator($identifier, [
'loginUrl' => '%auth\.localhost/[a-z]{2}/users/login/?$%',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
'useRegex' => true,
'checkFullUrl' => true,
],
Expand Down Expand Up @@ -410,7 +410,7 @@ public function testFullLoginUrlFailureWithoutCheckFullUrlOption()
$form = new FormAuthenticator($identifier, [
'loginUrl' => 'http://localhost/users/login',
'urlChecker' => [
'className' => 'Authentication.Generic',
'className' => 'Authentication.String',
],
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
namespace Authentication\Test\TestCase\UrlChecker;

use Authentication\Test\TestCase\AuthenticationTestCase as TestCase;
use Authentication\UrlChecker\GenericUrlChecker;
use Authentication\UrlChecker\StringUrlChecker;
use Cake\Http\ServerRequestFactory;

/**
* GenericUrlCheckerTest
* StringUrlCheckerTest
*/
class GenericUrlCheckerTest extends TestCase
class StringUrlCheckerTest extends TestCase
{
/**
* testCheckFailure
Expand All @@ -32,7 +32,7 @@ class GenericUrlCheckerTest extends TestCase
*/
public function testCheckFailure()
{
$checker = new GenericUrlChecker();
$checker = new StringUrlChecker();

$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/users/does-not-match'],
Expand All @@ -49,7 +49,7 @@ public function testCheckFailure()
*/
public function testCheckSimple()
{
$checker = new GenericUrlChecker();
$checker = new StringUrlChecker();
$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/users/login'],
);
Expand All @@ -67,7 +67,7 @@ public function testCheckSimple()
*/
public function testCheckRegexp()
{
$checker = new GenericUrlChecker();
$checker = new StringUrlChecker();
$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/en/users/login'],
);
Expand All @@ -85,7 +85,7 @@ public function testCheckRegexp()
*/
public function testCheckFull()
{
$checker = new GenericUrlChecker();
$checker = new StringUrlChecker();
$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/users/login'],
);
Expand All @@ -103,7 +103,7 @@ public function testCheckFull()
*/
public function testCheckBase()
{
$checker = new GenericUrlChecker();
$checker = new StringUrlChecker();
$request = ServerRequestFactory::fromGlobals(
['REQUEST_URI' => '/users/login'],
);
Expand Down