-
Notifications
You must be signed in to change notification settings - Fork 0
/
CertificateExpressionValidator.php
42 lines (31 loc) · 1.15 KB
/
CertificateExpressionValidator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
namespace Zim\CertAuthBundle;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class CertificateExpressionValidator
{
protected $expression = '';
protected $requestStack;
protected $tokenStorage;
public function __construct(RequestStack $requestStack, TokenStorageInterface $tokenStorage)
{
$this->requestStack = $requestStack;
$this->tokenStorage = $tokenStorage;
$this->expression = 'cert["subject"]["CN"] == token.getUserName() && request.server.get("CLIENT_CERT_OK") === "SUCCESS"';
}
public function validate(array $x509)
{
$request = $this->requestStack->getCurrentRequest();
$token = $this->tokenStorage->getToken();
$language = new ExpressionLanguage();
return $language->evaluate($this->expression, ['request' => $request, 'token' => $token, 'cert' => $x509]);
}
/**
* @param string $expression
*/
public function setExpression($expression)
{
$this->expression = $expression;
}
}