Completed
Push — feature/EVO-6305_worker_authen... ( 11e94e )
by Bastian
08:06
created

SameSubnetStrategy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * strategy for validating auth through the ip address.
4
 */
5
6
namespace Graviton\SecurityBundle\Authentication\Strategies;
7
8
use Symfony\Component\HttpFoundation\IpUtils;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Class SameSubnetStrategy
13
 *
14
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
15
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
16
 * @link     http://swisscom.ch
17
 */
18
class SameSubnetStrategy extends AbstractHttpStrategy
19
{
20
    /** @var String */
21
    protected $subnet;
22
23
    /**
24
     * @param String $subnet Subnet to be checked (e.g. 10.2.0.0/24)
25
     */
26 4
    public function __construct($subnet)
27
    {
28 4
        $this->subnet= $subnet;
29 4
    }
30
31
    /**
32
     * Applies the defined strategy on the provided request.
33
     *
34
     * @param Request $request request to handle
35
     *
36
     * @return string
37
     */
38
    public function apply(Request $request)
39
    {
40
        if (IpUtils::checkIp($request->getClientIp(), $this->subnet)) {
0 ignored issues
show
Coding Style introduced by
Blank line found at start of control structure
Loading history...
41
42
            return 'graviton_subnet_user';
43
        }
44
45
        throw new \InvalidArgumentException('Provided request information are not valid.');
46
    }
47
48
    /**
49
     * Decider to stop other strategies running after from being considered.
50
     *
51
     * @return boolean
52
     */
53
    public function stopPropagation() {
54
        return false;
55
    }
56
}
57