IPListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Kaliop\IdentityManagementBundle\Security\Firewall;
4
5
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
6
use Symfony\Component\Security\Core\SecurityContextInterface;
7
use Symfony\Component\Security\Core\Authentication\AuthenticationManagerInterface;
8
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
9
use Symfony\Component\Security\Core\Exception\AuthenticationException;
10
use Kaliop\IdentityManagementBundle\Security\Authentication\Token\IPToken;
11
12
class IPListener implements ListenerInterface
13
{
14
    protected $securityContext;
15
    protected $authenticationManager;
16
17
    public function __construct(SecurityContextInterface $securityContext, AuthenticationManagerInterface $authenticationManager)
18
    {
19
        $this->securityContext = $securityContext;
20
        $this->authenticationManager = $authenticationManager;
21
    }
22
23
    public function handle(GetResponseEvent $event)
24
    {
25
        $token = new IPToken();
26
        $token->setClientIp($event->getRequest()->getClientIp());
27
28
        /// @todo check what to return exactly when auth-by-ip is not successful: return, throw, set 403 response?
29
30
        try {
31
            $authToken = $this->authenticationManager->authenticate($token);
32
            $this->securityContext->setToken($authToken);
33
34
            return;
35
        } catch (AuthenticationException $failed) {
0 ignored issues
show
Bug introduced by
The class Symfony\Component\Securi...AuthenticationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
36
            // ... you might log something here
37
38
            // To deny the authentication clear the token. This will redirect to the login page.
39
            // Make sure to only clear your token, not those of other authentication listeners.
40
            // $token = $this->securityContext->getToken();
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
41
            // if ($token instanceof WsseUserToken && $this->providerKey === $token->getProviderKey()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
42
            //     $this->securityContext->setToken(null);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
            // }
44
            // return;
45
        }
46
    }
47
}
48