-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upon arrival, ArrivialAuthenticator creates a new user in the identity context and authenticates them in the session. The current implementation covers what AssignUserIdOnKernelRequest did before. It adds some complexity, but opens the way for #130 to secure the /metrics endpoint with basic auth, and #6 to eventually authenticate the user in any way.
- Loading branch information
Showing
15 changed files
with
201 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
|
||
web-interface.security: | ||
class: Gaming\WebInterface\Infrastructure\Security\Security | ||
arguments: | ||
- '@security.token_storage' | ||
|
||
web-interface.security.user_provider: | ||
class: Gaming\WebInterface\Infrastructure\Security\UserProvider | ||
public: false | ||
|
||
web-interface.security.arrival_authenticator: | ||
class: Gaming\WebInterface\Infrastructure\Security\ArrivalAuthenticator | ||
public: false | ||
arguments: | ||
- '@web-interface.identity-service' | ||
- '@security.token_storage' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/WebInterface/Infrastructure/EventListener/AssignUserIdOnKernelRequest.php
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
src/WebInterface/Infrastructure/Security/ArrivalAuthenticator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gaming\WebInterface\Infrastructure\Security; | ||
|
||
use Gaming\WebInterface\Application\IdentityService; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; | ||
use Symfony\Component\Security\Core\Exception\AuthenticationException; | ||
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\Passport; | ||
use Symfony\Component\Security\Http\Authenticator\Passport\SelfValidatingPassport; | ||
|
||
final class ArrivalAuthenticator extends AbstractAuthenticator | ||
{ | ||
public function __construct( | ||
private readonly IdentityService $identityService, | ||
private readonly TokenStorageInterface $tokenStorage | ||
) { | ||
} | ||
|
||
public function supports(Request $request): ?bool | ||
{ | ||
return $this->tokenStorage->getToken() === null; | ||
} | ||
|
||
public function authenticate(Request $request): Passport | ||
{ | ||
$currentUser = $this->tokenStorage->getToken()?->getUser() ?? new User( | ||
$this->identityService->arrive()['userId'] | ||
); | ||
|
||
return new SelfValidatingPassport( | ||
new UserBadge( | ||
$currentUser->getUserIdentifier() | ||
) | ||
); | ||
} | ||
|
||
public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response | ||
{ | ||
return null; | ||
} | ||
|
||
public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response | ||
{ | ||
throw $exception; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gaming\WebInterface\Infrastructure\Security; | ||
|
||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; | ||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Uid\NilUuid; | ||
|
||
final class Security | ||
{ | ||
public function __construct( | ||
private readonly TokenStorageInterface $tokenStorage | ||
) { | ||
} | ||
|
||
public function getUser(): UserInterface | ||
{ | ||
return $this->tokenStorage->getToken()?->getUser() ?? new User( | ||
(new NilUuid())->toRfc4122() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gaming\WebInterface\Infrastructure\Security; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
|
||
final class User implements UserInterface | ||
{ | ||
public function __construct( | ||
private readonly string $userIdentifier | ||
) { | ||
} | ||
|
||
public function getRoles(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function eraseCredentials(): void | ||
{ | ||
} | ||
|
||
public function getUserIdentifier(): string | ||
{ | ||
return $this->userIdentifier; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gaming\WebInterface\Infrastructure\Security; | ||
|
||
use Symfony\Component\Security\Core\User\UserInterface; | ||
use Symfony\Component\Security\Core\User\UserProviderInterface; | ||
|
||
final class UserProvider implements UserProviderInterface | ||
{ | ||
public function refreshUser(UserInterface $user): UserInterface | ||
{ | ||
return $this->loadUserByIdentifier($user->getUserIdentifier()); | ||
} | ||
|
||
public function supportsClass(string $class) | ||
{ | ||
return $class == User::class; | ||
} | ||
|
||
public function loadUserByIdentifier(string $identifier): UserInterface | ||
{ | ||
return new User($identifier); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.