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, |
|
|
|
|
34
|
|
|
$token->requestHost, |
|
|
|
|
35
|
|
|
$token->requestPathInfo, |
|
|
|
|
36
|
|
|
$token->requestContent, |
|
|
|
|
37
|
|
|
$token->signatureTime |
|
|
|
|
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$signedRequest->authenticateSignature($token->signature, $this->signatureConfig, $this->replayProtection); |
|
|
|
|
41
|
|
|
|
42
|
|
|
return new SignatureValidToken($token->signature, $token->signatureTime); |
|
|
|
|
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
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: