1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Xervice\Api\Business\Model\Authenticator; |
5
|
|
|
|
6
|
|
|
|
7
|
|
|
use DataProvider\ApiAuthDataProvider; |
|
|
|
|
8
|
|
|
use DataProvider\AuthenticatorDataProvider; |
|
|
|
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
10
|
|
|
use Xervice\Api\Business\Exception\AuthorizationException; |
11
|
|
|
use Xervice\Security\Business\Exception\SecurityException; |
12
|
|
|
use Xervice\Security\Business\SecurityFacade; |
13
|
|
|
|
14
|
|
|
class ApiAuthenticator implements ApiAuthenticatorInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var \Xervice\Security\Business\SecurityFacade |
18
|
|
|
*/ |
19
|
|
|
private $securityFacade; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* ApiAuthenticator constructor. |
23
|
|
|
* |
24
|
|
|
* @param \Xervice\Security\Business\SecurityFacade $securityFacade |
25
|
|
|
*/ |
26
|
3 |
|
public function __construct(SecurityFacade $securityFacade) |
27
|
|
|
{ |
28
|
3 |
|
$this->securityFacade = $securityFacade; |
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
33
|
|
|
* |
34
|
|
|
* @throws \Xervice\Api\Business\Exception\AuthorizationException |
35
|
|
|
*/ |
36
|
3 |
|
public function authenticate(Request $request) |
37
|
|
|
{ |
38
|
3 |
|
$authHeader = $request->headers->get('authorization'); |
39
|
|
|
|
40
|
3 |
|
if (!$authHeader) { |
41
|
1 |
|
throw new AuthorizationException('No HTTP_Authorization header found'); |
42
|
|
|
} |
43
|
|
|
|
44
|
2 |
|
$authParts = explode(' ', $authHeader); |
45
|
|
|
|
46
|
2 |
|
if (count($authParts) < 2) { |
47
|
1 |
|
throw new AuthorizationException( |
48
|
1 |
|
sprintf( |
49
|
1 |
|
'Wrong structure for HTTP_Authorization header %s', |
50
|
1 |
|
$authHeader |
51
|
|
|
) |
52
|
|
|
); |
53
|
|
|
} |
54
|
|
|
|
55
|
1 |
|
$apiAuth = new ApiAuthDataProvider(); |
56
|
1 |
|
$apiAuth->setAuthHeader($authHeader); |
57
|
|
|
|
58
|
1 |
|
$auth = new AuthenticatorDataProvider(); |
59
|
1 |
|
$auth->setAuthData($apiAuth); |
60
|
|
|
|
61
|
|
|
try { |
62
|
1 |
|
$this->securityFacade->authenticate($authParts[0], $auth); |
63
|
1 |
|
} catch (SecurityException $exception) { |
64
|
1 |
|
throw new AuthorizationException( |
65
|
1 |
|
$exception->getMessage(), |
66
|
1 |
|
0, |
67
|
1 |
|
$exception |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths