1 | <?php |
||
18 | class ApiKeyAuthenticator extends AbstractGuardAuthenticator |
||
19 | { |
||
20 | /** |
||
21 | * @var ManagerRegistry |
||
22 | */ |
||
23 | private $registry; |
||
24 | /** |
||
25 | * @var Logger |
||
26 | */ |
||
27 | private $logger; |
||
28 | |||
29 | public function __construct(ManagerRegistry $registry, Logger $logger) |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | public function getCredentials(Request $request) |
||
39 | { |
||
40 | $client = $this->registry->getRepository('AppBundle:Client') |
||
41 | ->findIpBanned($request->getClientIp()); |
||
42 | |||
43 | if ($client) { |
||
44 | throw new HttpException(403, 'Forbidden. You\'re banned!'); |
||
45 | } |
||
46 | |||
47 | if (!$token = $request->headers->get('API-Key-Token')) { |
||
48 | return null; |
||
49 | } |
||
50 | |||
51 | return array( |
||
52 | 'token' => $token, |
||
53 | ); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function getUser($credentials, UserProviderInterface $userProvider) |
||
68 | |||
69 | /** |
||
70 | * {@inheritdoc} |
||
71 | */ |
||
72 | public function checkCredentials($credentials, UserInterface $user) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) |
||
84 | |||
85 | /** |
||
86 | * {@inheritdoc} |
||
87 | */ |
||
88 | public function onAuthenticationFailure(Request $request, AuthenticationException $exception) |
||
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function start(Request $request, AuthenticationException $authException = null) |
||
129 | |||
130 | /** |
||
131 | * {@inheritdoc} |
||
132 | */ |
||
133 | public function supportsRememberMe() |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | private function writeLogger($client) |
||
147 | } |
||
148 |