RequestSignatureProvider::authenticate()   A
last analyzed

Complexity

Conditions 3
Paths 7

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 14
nc 7
nop 1
1
<?php
2
3
namespace Rezzza\SecurityBundle\Security\Authentication\Provider;
4
5
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
6
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
7
use Symfony\Component\Security\Core\Exception\AuthenticationException;
8
use Symfony\Component\Security\Core\Exception\NonceExpiredException;
9
use Rezzza\SecurityBundle\Security\RequestSignatureToken;
10
use Rezzza\SecurityBundle\Security\SignatureValidToken;
11
use Rezzza\SecurityBundle\Security\Firewall\SignedRequest;
12
use Rezzza\SecurityBundle\Security\Firewall\SignatureConfig;
13
use Rezzza\SecurityBundle\Security\Firewall\ReplayProtection;
14
use Rezzza\SecurityBundle\Security\Firewall\InvalidSignatureException;
15
use Rezzza\SecurityBundle\Security\Firewall\ExpiredSignatureException;
16
17
class RequestSignatureProvider implements AuthenticationProviderInterface
18
{
19
    private $signatureConfig;
20
21
    private $replayProtection;
22
23
    public function __construct(SignatureConfig $signatureConfig, ReplayProtection $replayProtection)
24
    {
25
        $this->signatureConfig = $signatureConfig;
26
        $this->replayProtection = $replayProtection;
27
    }
28
29
    public function authenticate(TokenInterface $token)
30
    {
31
        try {
32
            $signedRequest = new SignedRequest(
33
                $token->requestMethod,
0 ignored issues
show
Bug introduced by
Accessing requestMethod on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
34
                $token->requestHost,
0 ignored issues
show
Bug introduced by
Accessing requestHost on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
35
                $token->requestPathInfo,
0 ignored issues
show
Bug introduced by
Accessing requestPathInfo on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
36
                $token->requestContent,
0 ignored issues
show
Bug introduced by
Accessing requestContent on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
37
                $token->signatureTime
0 ignored issues
show
Bug introduced by
Accessing signatureTime on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
38
            );
39
40
            $signedRequest->authenticateSignature($token->signature, $this->signatureConfig, $this->replayProtection);
0 ignored issues
show
Bug introduced by
Accessing signature on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
41
42
            return new SignatureValidToken($token->signature, $token->signatureTime);
0 ignored issues
show
Bug introduced by
Accessing signature on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
Bug introduced by
Accessing signatureTime on the interface Symfony\Component\Securi...on\Token\TokenInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
43
        } catch (InvalidSignatureException $e) {
44
            throw new AuthenticationException('Invalid signature', null, $e);
45
        } catch (ExpiredSignatureException $e) {
46
            throw new NonceExpiredException($e->getMessage(), null, $e);
47
        }
48
    }
49
50
    /**
51
     * @param TokenInterface $token token
52
     *
53
     * @return boolean
54
     */
55
    public function supports(TokenInterface $token)
56
    {
57
        return $token instanceof RequestSignatureToken;
58
    }
59
}
60