4
4
5
5
namespace Webstack \ApiPlatformExtensionsBundle \EventListener ;
6
6
7
- use ApiPlatform \Core \ Api \FormatMatcher ;
8
- use ApiPlatform \Core \ Util \ClassInfoTrait ;
7
+ use ApiPlatform \Api \FormatMatcher ;
8
+ use ApiPlatform \Util \ClassInfoTrait ;
9
9
use Doctrine \ORM \EntityManagerInterface ;
10
10
use Doctrine \ORM \NonUniqueResultException ;
11
11
use Doctrine \ORM \NoResultException ;
12
12
use Doctrine \ORM \Query \ResultSetMappingBuilder ;
13
13
use Negotiation \Exception \Exception as NeogationException ;
14
14
use Negotiation \Negotiator ;
15
- use ReflectionClass ;
16
- use ReflectionException ;
17
- use RuntimeException ;
15
+ use Symfony \Bundle \SecurityBundle \Security ;
18
16
use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
19
17
use Symfony \Component \HttpFoundation \Request ;
20
18
use Symfony \Component \HttpKernel \Event \RequestEvent ;
21
19
use Symfony \Component \HttpKernel \Exception \NotAcceptableHttpException ;
22
20
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
23
- use Symfony \Component \Security \Core \Security ;
24
21
use Symfony \Component \Security \Core \User \UserInterface ;
25
22
use Webstack \ApiPlatformExtensionsBundle \Util \MimeType \MimeTypeFlattener ;
26
23
@@ -44,7 +41,7 @@ public function __construct(Security $security, EntityManagerInterface $entityMa
44
41
}
45
42
46
43
/**
47
- * @throws ReflectionException
44
+ * @throws \ ReflectionException
48
45
* @throws NonUniqueResultException
49
46
* @throws NoResultException
50
47
* @throws NeogationException
@@ -57,21 +54,24 @@ public function onKernelRequest(RequestEvent $event): void
57
54
return ;
58
55
}
59
56
60
- if (null === $ this ->security ->getToken ()) {
57
+ if (! $ this ->security ->getToken () instanceof TokenInterface ) {
61
58
return ;
62
59
}
63
60
64
61
$ user = $ this ->security ->getToken ()->getUser ();
65
62
63
+ if (!$ user instanceof UserInterface) {
64
+ return ;
65
+ }
66
+
66
67
// League returns a NullUser instance when a non-user (e.g. client_credentials) is authenticated.
67
68
$ class = get_class ($ user );
68
- $ isUser = $ user instanceof UserInterface && $ class !== 'League\Bundle\OAuth2ServerBundle\Security\User\NullUser ' ;
69
69
70
- if ($ isUser ) {
71
- if (method_exists ($ class , 'getId ' )) {
70
+ if (' League\Bundle\OAuth2ServerBundle\Security\User\NullUser ' !== $ class ) {
71
+ if (method_exists ($ user , 'getId ' )) {
72
72
$ id = $ user ->getId ();
73
73
} else {
74
- throw new RuntimeException (sprintf ('Could not determine the user id, class "%s" must have a getId() method ' , $ class ));
74
+ throw new \ RuntimeException (sprintf ('Could not determine the user id, class "%s" must have a getId() method ' , $ class ));
75
75
}
76
76
} else {
77
77
$ subject = $ this ->getSubject ($ this ->security ->getToken ());
@@ -91,7 +91,7 @@ public function onKernelRequest(RequestEvent $event): void
91
91
}
92
92
93
93
/**
94
- * @throws ReflectionException
94
+ * @throws \ ReflectionException
95
95
* @throws NoResultException
96
96
* @throws NonUniqueResultException
97
97
*/
@@ -102,7 +102,7 @@ public function getSubject(TokenInterface $token): object
102
102
$ rsm = new ResultSetMappingBuilder ($ this ->entityManager );
103
103
$ rsm ->addRootEntityFromClassMetadata ($ class , 'subject ' );
104
104
105
- $ reflectionClass = new ReflectionClass ($ class );
105
+ $ reflectionClass = new \ ReflectionClass ($ class );
106
106
$ class = strtolower ($ reflectionClass ->getShortName ());
107
107
108
108
$ query = $ this ->entityManager ->createNativeQuery (sprintf ('
0 commit comments