Skip to content

Commit

Permalink
Symfony 6.4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
a-menshchikov committed Nov 11, 2023
1 parent fd733c7 commit 02cbecf
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
echo "::endgroup::"
- name: Auditor
uses: docker://nbgrp/auditor:0.20.0
uses: docker://nbgrp/auditor:0.21.0

- name: Tests
run: vendor/bin/simple-phpunit
Expand Down
21 changes: 11 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,27 @@
"php": "^8.1",
"onelogin/php-saml": "^4",
"psr/log": "^1 || ^2 || ^3",
"symfony/config": "^6",
"symfony/dependency-injection": "^6",
"symfony/config": "^6.4",
"symfony/dependency-injection": "^6.4",
"symfony/deprecation-contracts": "^3",
"symfony/event-dispatcher-contracts": "^3",
"symfony/http-foundation": "^6",
"symfony/http-kernel": "^6",
"symfony/routing": "^6",
"symfony/security-bundle": "^6",
"symfony/security-core": "^6",
"symfony/security-http": "^6"
"symfony/http-foundation": "^6.4",
"symfony/http-kernel": "^6.4",
"symfony/routing": "^6.4",
"symfony/security-bundle": "^6.4",
"symfony/security-core": "^6.4",
"symfony/security-http": "^6.4"
},
"require-dev": {
"doctrine/orm": "^2.3 || ^3",
"symfony/event-dispatcher": "^6",
"symfony/phpunit-bridge": "^6"
"symfony/event-dispatcher": "^6.4",
"symfony/phpunit-bridge": "^6.4"
},
"conflict": {
"symfony/http-kernel": "<6.2",
"symfony/security-core": "<6.2"
},
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"Nbgrp\\OneloginSamlBundle\\": "src/"
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ parameters:
- vendor/bin/.phpunit/phpunit/vendor/autoload.php

checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
10 changes: 5 additions & 5 deletions src/Controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

use Nbgrp\OneloginSamlBundle\Security\Http\Authenticator\SamlAuthenticator;
use OneLogin\Saml2\Auth;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Symfony\Component\Security\Http\SecurityRequestAttributes;

#[AsController]
class Login
Expand All @@ -27,16 +27,16 @@ public function __invoke(Request $request, Auth $auth): RedirectResponse
$targetPath = null;
$session = null;
/** @var \Throwable|null $error */
$error = $request->attributes->get(Security::AUTHENTICATION_ERROR);
$error = $request->attributes->get(SecurityRequestAttributes::AUTHENTICATION_ERROR);

if ($request->hasSession()) {
$session = $request->getSession();
$targetPath = $this->getTargetPath($request, $session);

if ($session->has(Security::AUTHENTICATION_ERROR)) {
if ($session->has(SecurityRequestAttributes::AUTHENTICATION_ERROR)) {
/** @var \Throwable|null $error */
$error = $session->get(Security::AUTHENTICATION_ERROR);
$session->remove(Security::AUTHENTICATION_ERROR);
$error = $session->get(SecurityRequestAttributes::AUTHENTICATION_ERROR);
$session->remove(SecurityRequestAttributes::AUTHENTICATION_ERROR);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ protected function determineTargetUrl(Request $request): string
return (string) $this->options['default_target_path'];
}

/** @psalm-suppress InvalidScalarArgument */
/** @psalm-suppress InvalidArgument */

Check failure on line 27 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.1)

UnusedPsalmSuppress

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:27:29: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)

Check failure on line 27 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.2)

UnusedPsalmSuppress

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:27:29: UnusedPsalmSuppress: This suppression is never used (see https://psalm.dev/207)
$relayState = $request->query->get(self::RELAY_STATE, $request->request->get(self::RELAY_STATE));

Check failure on line 28 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.1)

InvalidArgument

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:28:63: InvalidArgument: Argument 2 of Symfony\Component\HttpFoundation\InputBag::get expects null, but null|scalar provided (see https://psalm.dev/004)

Check failure on line 28 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.2)

InvalidArgument

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:28:63: InvalidArgument: Argument 2 of Symfony\Component\HttpFoundation\InputBag::get expects null, but null|scalar provided (see https://psalm.dev/004)
if ($relayState !== null && $this->httpUtils instanceof HttpUtils) {
/** @psalm-suppress RedundantCastGivenDocblockType */

Check failure on line 30 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.1)

RedundantCastGivenDocblockType

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:30:27: RedundantCastGivenDocblockType: Redundant cast to string given docblock-provided type (see https://psalm.dev/263)

Check failure on line 30 in src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php

View workflow job for this annotation

GitHub Actions / Audit (8.2)

RedundantCastGivenDocblockType

src/Security/Http/Authentication/SamlAuthenticationSuccessHandler.php:30:27: RedundantCastGivenDocblockType: Redundant cast to string given docblock-provided type (see https://psalm.dev/263)
$relayState = (string) $relayState;
if ($relayState !== $this->httpUtils->generateUri($request, (string) $this->options['login_path'])) {
return $relayState;
Expand Down
6 changes: 5 additions & 1 deletion src/Security/User/SamlUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@

/**
* Just instantiates user object with providing identifier and default roles.
*
* @template-covariant TUser of UserInterface
*
* @template-implements UserProviderInterface<TUser>
*/
class SamlUserProvider implements UserProviderInterface
{
/**
* @param class-string<UserInterface> $userClass
* @param class-string<TUser> $userClass
*/
public function __construct(
protected string $userClass,
Expand Down
6 changes: 3 additions & 3 deletions tests/Controller/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
use OneLogin\Saml2\Auth;
use OneLogin\Saml2\Settings;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
use Symfony\Component\Security\Http\SecurityRequestAttributes;

/**
* @covers \Nbgrp\OneloginSamlBundle\Controller\Login
Expand Down Expand Up @@ -130,7 +130,7 @@ public function provideErrorExceptionCases(): iterable
yield 'From attributes' => [
'request' => (static function () {
$request = Request::create('/login');
$request->attributes->set(Security::AUTHENTICATION_ERROR, new \Exception('Error from attributes'));
$request->attributes->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, new \Exception('Error from attributes'));

return $request;
})(),
Expand All @@ -141,7 +141,7 @@ public function provideErrorExceptionCases(): iterable
'request' => (static function () {
$request = Request::create('/login');
$session = new Session(new MockArraySessionStorage());
$session->set(Security::AUTHENTICATION_ERROR, new \Exception('Error from session'));
$session->set(SecurityRequestAttributes::AUTHENTICATION_ERROR, new \Exception('Error from session'));
$request->setSession($session);

return $request;
Expand Down

0 comments on commit 02cbecf

Please sign in to comment.