Skip to content
Open
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
7 changes: 2 additions & 5 deletions spec/EcPhp/CasBundle/Controller/LoginSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Nyholm\Psr7\ServerRequest;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\ResponseInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;

class LoginSpec extends ObjectBehavior
Expand All @@ -29,7 +28,6 @@ public function it_is_initializable()

public function it_return_a_psr_response_in_case_of_success(
CasInterface $cas,
Security $security,
ResponseInterface $casResponse,
) {
$request = new ServerRequest('GET', '/');
Expand All @@ -42,22 +40,21 @@ public function it_return_a_psr_response_in_case_of_success(
->getHeaderLine('location')
->willReturn('https://foo.com');

$response = $this->__invoke($request, $cas, $security);
$response = $this->__invoke($request, $cas);
$response->shouldBeAnInstanceOf(ResponseInterface::class);
$response->getHeaderLine('location')->shouldBe('https://foo.com');
}

public function it_return_a_symfony_redirection_in_case_of_exception(
CasInterface $cas,
Security $security,
) {
$request = new ServerRequest('GET', '/');

$cas
->login($request)
->willThrow(new Exception('Unable to login'));

$response = $this->__invoke($request, $cas, $security);
$response = $this->__invoke($request, $cas);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldBe('/');
}
Expand Down
10 changes: 3 additions & 7 deletions spec/EcPhp/CasBundle/Controller/LogoutSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Nyholm\Psr7\ServerRequest;
use PhpSpec\ObjectBehavior;
use Psr\Http\Message\ResponseInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;

Expand All @@ -30,19 +29,17 @@ public function it_is_initializable()

public function it_redirects_to_index(
CasInterface $cas,
Security $security,
TokenStorageInterface $tokenStorage
) {
$request = new ServerRequest('GET', '/');

$response = $this->__invoke($request, $cas, $security, $tokenStorage);
$response = $this->__invoke($request, $cas, $tokenStorage);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldReturn('/');
}

public function it_return_a_psr_response_in_case_of_success(
CasInterface $cas,
Security $security,
TokenStorageInterface $tokenStorage,
ResponseInterface $casResponse,
) {
Expand All @@ -56,7 +53,7 @@ public function it_return_a_psr_response_in_case_of_success(
->getHeaderLine('location')
->willReturn('http://local/cas/logout');

$response = $this->__invoke($request, $cas, $security, $tokenStorage);
$response = $this->__invoke($request, $cas, $tokenStorage);
$response->shouldBeAnInstanceOf(ResponseInterface::class);
$response->getHeaderLine('location')->shouldBe('http://local/cas/logout');
$tokenStorage
Expand All @@ -66,7 +63,6 @@ public function it_return_a_psr_response_in_case_of_success(

public function it_return_a_symfony_redirection_in_case_of_exception(
CasInterface $cas,
Security $security,
TokenStorageInterface $tokenStorage
) {
$request = new ServerRequest('GET', '/');
Expand All @@ -75,7 +71,7 @@ public function it_return_a_symfony_redirection_in_case_of_exception(
->logout($request)
->willThrow(new Exception('Unable to login'));

$response = $this->__invoke($request, $cas, $security, $tokenStorage);
$response = $this->__invoke($request, $cas, $tokenStorage);
$response->shouldBeAnInstanceOf(RedirectResponse::class);
$response->headers->get('location')->shouldBe('/');
}
Expand Down
3 changes: 0 additions & 3 deletions src/Controller/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use EcPhp\CasLib\Contract\CasInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Throwable;
Expand All @@ -24,7 +23,6 @@ final class Logout
public function __invoke(
ServerRequestInterface $request,
CasInterface $cas,
Security $security,
TokenStorageInterface $tokenStorage
): RedirectResponse|ResponseInterface {
try {
Expand All @@ -36,7 +34,6 @@ public function __invoke(
return new RedirectResponse('/');
}

$security->getToken()?->eraseCredentials();
$tokenStorage->setToken(null);

return $response;
Expand Down
7 changes: 7 additions & 0 deletions src/Security/Core/User/CasUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public function __toString(): string
return (string) $this->get('user');
}

/**
* `eraseCredentials()` is still required by `UserInterface` on Symfony
* 6.4 and 7 (deprecated since 7.3, removed in 8.0). Keeping this empty
* method is harmless on Symfony 8, where it's no longer part of the
* interface. It can be removed once support for Symfony 6.4 and 7 is
* dropped.
*/
public function eraseCredentials(): void {}

public function get(string $key, mixed $default = null): mixed
Expand Down