1: <?php
2:
3: namespace Mapbender\DrupalIntegrationBundle\Security\Firewall;
4:
5: use Symfony\Component\HttpFoundation\Response;
6: use Symfony\Component\HttpKernel\Event\GetResponseEvent;
7: use Symfony\Component\Security\Http\Firewall\ListenerInterface;
8: use Symfony\Component\Security\Core\Exception\AuthenticationException;
9: use Symfony\Component\Security\Core\SecurityContextInterface;
10: use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
11: use Mapbender\DrupalIntegrationBundle\Security\Authentication\Token\DrupalUserToken;
12: use Mapbender\DrupalIntegrationBundle\Security\User\DrupalUser;
13:
14:
15: class DrupalListener implements ListenerInterface
16: {
17: protected $securityContext;
18: protected $authenticationManager;
19:
20: public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager)
21: {
22: $this->securityContext = $securityContext;
23: $this->authenticationManager = $authenticationManager;
24: }
25:
26: public function handle(GetResponseEvent $event)
27: {
28: global $user;
29:
30: if(null !== $user && $user->uid != 0) {
31: $drupalUser = new DrupalUser($user);
32: $token = new DrupalUserToken($drupalUser);
33:
34: try {
35:
36: $this->securityContext->setToken($token);
37: } catch (AuthenticationException $failed) {
38:
39: $response = new Response();
40: $response->setStatusCode(403);
41: $event->setResponse($response);
42: }
43: }
44: }
45: }
46: