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
3 changes: 2 additions & 1 deletion .phive/phars.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpstan" version="2.3.0" installed="2.3.0" location="./tools/phpstan" copy="false"/>
<phar name="phpstan" version="2.3.7" installed="2.3.7" location="./tools/phpstan" copy="false"/>
<phar name="psalm" version="7.16.0" installed="7.16.0" location="./tools/psalm" copy="false"/>
</phive>
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
"docs": "https://book.cakephp.org/authentication/5/"
},
"require": {
"php": ">=8.4",
"php": ">=8.5",
"cakephp/http": "^6.0",
"cakephp/utility": "^6.0",
"laminas/laminas-diactoros": "^3.8",
"psr/http-client": "^1.0",
"psr/http-message": "^1.1 || ^2.0",
"psr/http-server-handler": "^1.0",
Expand Down
41 changes: 41 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="7.16.0@708bf98874d359acbdcedb84f8624e9ec215867d">
<file src="src/AbstractCollection.php">
<InvalidArgument>
<code><![CDATA[$configOptions]]></code>
</InvalidArgument>
</file>
<file src="src/Authenticator/AuthenticationRequiredException.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[array<string, mixed>]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Authenticator/HttpDigestAuthenticator.php">
<LessSpecificImplementedReturnType>
<code><![CDATA[array<string, string>]]></code>
</LessSpecificImplementedReturnType>
</file>
<file src="src/Controller/Component/AuthenticationComponent.php">
<InvalidArgument>
<code><![CDATA[$identity]]></code>
</InvalidArgument>
<InvalidReturnStatement>
<code><![CDATA[$controller->getRequest()->getAttribute($this->getConfig('identityAttribute'))]]></code>
</InvalidReturnStatement>
</file>
<file src="src/Identity.php">
<PossiblyInvalidArgument>
<code><![CDATA[$this->data]]></code>
</PossiblyInvalidArgument>
</file>
<file src="src/Middleware/AuthenticationMiddleware.php">
<PossiblyNullArgument>
<code><![CDATA[$result->getData()]]></code>
</PossiblyNullArgument>
</file>
<file src="src/View/Helper/IdentityHelper.php">
<PossiblyInvalidArgument>
<code><![CDATA[$this->identity->getOriginalData()]]></code>
</PossiblyInvalidArgument>
</file>
</files>
27 changes: 27 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
errorBaseline="psalm-baseline.xml"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<MissingOverrideAttribute errorLevel="suppress"/>
<UnusedClass errorLevel="suppress" />
<PossiblyUnusedMethod errorLevel="suppress" />
<UnusedFunctionCall errorLevel="suppress" />
<UndefinedConstant errorLevel="suppress" />
<PossiblyUnusedProperty errorLevel="suppress" />
</issueHandlers>
</psalm>
4 changes: 4 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\If_\ArrayExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector;
use Rector\CodeQuality\Rector\If_\ExplicitNullableObjectInstanceRector;
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
use Rector\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
Expand All @@ -23,6 +24,7 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveMixedDocblockOverruledByNativeTypeRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector;
use Rector\Php85\Rector\Property\AddOverrideAttributeToOverriddenPropertiesRector;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector;

Expand Down Expand Up @@ -72,4 +74,6 @@
RemoveUselessUnionReturnDocblockRector::class,
RemoveMixedDocblockOverruledByNativeTypeRector::class,
RemoveUselessReturnTagRector::class,
AddOverrideAttributeToOverriddenPropertiesRector::class,
ExplicitNullableObjectInstanceRector::class,
]);
2 changes: 0 additions & 2 deletions src/AuthenticationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ public function loadAuthenticator(string $name, array $config = []): Authenticat
public function authenticate(ServerRequestInterface $request): ResultInterface
{
$result = null;
/** @var \Authentication\Authenticator\AuthenticatorInterface $authenticator */
foreach ($this->authenticators() as $authenticator) {
$result = $authenticator->authenticate($request);
if ($result->isValid()) {
Expand Down Expand Up @@ -186,7 +185,6 @@ public function authenticate(ServerRequestInterface $request): ResultInterface
*
* @param \Psr\Http\Message\ServerRequestInterface $request The request.
* @param \Psr\Http\Message\ResponseInterface $response The response.
* @return array Return an array containing the request and response objects.
* @return array{request: \Psr\Http\Message\ServerRequestInterface, response: \Psr\Http\Message\ResponseInterface}
*/
public function clearIdentity(ServerRequestInterface $request, ResponseInterface $response): array
Expand Down
9 changes: 3 additions & 6 deletions src/Middleware/AuthenticationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
use Authentication\Authenticator\UnauthenticatedException;
use Cake\Container\ContainerInterface;
use Cake\Core\ContainerApplicationInterface;
use Cake\Http\Response;
use Cake\Http\Response\RedirectResponse;
use Cake\Http\ServerRequest;
use Cake\Routing\Router;
use Laminas\Diactoros\Response;
use Laminas\Diactoros\Response\RedirectResponse;
use Laminas\Diactoros\Stream;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
Expand Down Expand Up @@ -73,11 +72,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
try {
$result = $service->authenticate($request);
} catch (AuthenticationRequiredException $e) {
$body = new Stream('php://memory', 'rw');
$body->write($e->getBody());
$response = new Response();
$response = $response->withStatus($e->getCode())
->withBody($body);
->withStringBody($e->getBody());
foreach ($e->getHeaders() as $header => $value) {
$response = $response->withHeader($header, $value);
}
Expand Down
11 changes: 9 additions & 2 deletions src/View/Helper/IdentityHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
namespace Authentication\View\Helper;

use Authentication\Identity;
use Authentication\IdentityInterface;
use Cake\Utility\Hash;
use Cake\View\Helper;
Expand All @@ -23,6 +24,8 @@
* Identity Helper
*
* A convenience helper to access the identity data
*
* @extends \Cake\View\Helper<\Cake\View\View>
*/
class IdentityHelper extends Helper
{
Expand Down Expand Up @@ -112,15 +115,19 @@ public function is(int|string $id, string $field = 'id'): bool
*/
public function get(?string $key = null): mixed
{
if (!$this->identity instanceof IdentityInterface) {
if ($this->identity === null) {
return null;
}

if ($key === null) {
return $this->identity->getOriginalData();
}

return Hash::get($this->identity, $key);
if ($this->identity instanceof Identity) {
return $this->identity->get($key);
}

return Hash::get($this->identity->getOriginalData(), $key);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Identifier/LdapIdentifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class LdapIdentifierTest extends TestCase
public function testIdentify(): void
{
$host = 'ldap.example.com';
$bind = (fn(string $username): string => 'cn=' . $username . ',dc=example,dc=com');
$bind = fn(string $username): string => 'cn=' . $username . ',dc=example,dc=com';
$options = [
'foo' => 3,
'tls' => false,
Expand Down
Loading