File tree Expand file tree Collapse file tree 3 files changed +70
-3
lines changed Expand file tree Collapse file tree 3 files changed +70
-3
lines changed Original file line number Diff line number Diff line change 77 "psr-4" : {
88 "EzSystems\\ EzPlatformRestBundle\\ " : " src/bundle/" ,
99 "EzSystems\\ EzPlatformRest\\ " : " src/lib/" ,
10+ "Ibexa\\ Bundle\\ Rest\\ " : " src/bundle/" ,
11+ "Ibexa\\ Rest\\ " : " src/lib/"
12+ }
13+ },
14+ "autoload-dev" : {
15+ "psr-4" : {
1016 "EzSystems\\ EzPlatformRestBundle\\ Tests\\ " : " tests/bundle/" ,
11- "EzSystems\\ EzPlatformRest\\ Tests\\ " : " tests/lib/"
17+ "EzSystems\\ EzPlatformRest\\ Tests\\ " : " tests/lib/" ,
18+ "Ibexa\\ Tests\\ Rest\\ " : " tests/lib/" ,
19+ "Ibexa\\ Tests\\ Bundle\\ Rest\\ " : " tests/bundle/"
1220 }
1321 },
1422 "require" : {
Original file line number Diff line number Diff line change 1313use EzSystems \EzPlatformRest \Message ;
1414use EzSystems \EzPlatformRest \Server \Controller as RestController ;
1515use EzSystems \EzPlatformRest \Server \Values ;
16+ use Ibexa \Rest \Server \Security \JWTUser ;
1617use Lexik \Bundle \JWTAuthenticationBundle \Services \JWTTokenManagerInterface ;
1718use Symfony \Component \HttpFoundation \Request ;
1819use Symfony \Component \Security \Core \Exception \AuthenticationException ;
@@ -50,9 +51,11 @@ public function createToken(Request $request): Values\JWT
5051 $ request ->attributes ->set ('username ' , $ jwtTokenInput ->username );
5152 $ request ->attributes ->set ('password ' , (string ) $ jwtTokenInput ->password );
5253
53- $ token = $ this ->getAuthenticator ()->authenticate ($ request );
54+ $ user = $ this ->getAuthenticator ()->authenticate ($ request)-> getUser ( );
5455
55- $ jwtToken = $ this ->tokenManager ->create ($ token ->getUser ());
56+ $ jwtToken = $ this ->tokenManager ->create (
57+ new JWTUser ($ user , $ jwtTokenInput ->username )
58+ );
5659
5760 return new Values \JWT ($ jwtToken );
5861 } catch (AuthenticationException $ e ) {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5+ * @license For full copyright and license information view LICENSE file distributed with this source code.
6+ */
7+ declare (strict_types=1 );
8+
9+ namespace Ibexa \Rest \Server \Security ;
10+
11+ use Symfony \Component \Security \Core \User \UserInterface ;
12+
13+ final class JWTUser implements UserInterface
14+ {
15+ /** @var \Symfony\Component\Security\Core\User\UserInterface */
16+ private $ wrappedUser ;
17+
18+ /** @var string|null */
19+ private $ userIdentifier ;
20+
21+ public function __construct (UserInterface $ wrappedUser , ?string $ userIdentifier )
22+ {
23+ $ this ->wrappedUser = $ wrappedUser ;
24+ $ this ->userIdentifier = $ userIdentifier ;
25+ }
26+
27+ public function getPassword (): ?string
28+ {
29+ return $ this ->wrappedUser ->getPassword ();
30+ }
31+
32+ public function eraseCredentials (): void
33+ {
34+ $ this ->wrappedUser ->eraseCredentials ();
35+ }
36+
37+ public function getRoles (): array
38+ {
39+ return $ this ->wrappedUser ->getRoles ();
40+ }
41+
42+ public function getSalt (): ?string
43+ {
44+ return $ this ->wrappedUser ->getSalt ();
45+ }
46+
47+ public function getUsername (): string
48+ {
49+ return $ this ->userIdentifier ?? $ this ->wrappedUser ->getUsername ();
50+ }
51+
52+ public function getWrappedUser (): UserInterface
53+ {
54+ return $ this ->wrappedUser ;
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments