Merge branch '3.4' into 4.2
* 3.4: Fix json-encoding when JSON_THROW_ON_ERROR is used [HttpFoundation] work around PHP 7.3 bug related to json_encode() [Security] added support for updated \"distinguished name\" format in x509 authentication
This commit is contained in:
commit
eb41911d88
@ -185,6 +185,7 @@ class JsonDescriptor extends Descriptor
|
|||||||
private function writeData(array $data, array $options)
|
private function writeData(array $data, array $options)
|
||||||
{
|
{
|
||||||
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
$this->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,9 @@ class JsonDescriptor extends Descriptor
|
|||||||
*/
|
*/
|
||||||
private function writeData(array $data, array $options)
|
private function writeData(array $data, array $options)
|
||||||
{
|
{
|
||||||
$this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
|
$this->write(json_encode($data, $flags));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +94,8 @@ class JsonDescriptor extends Descriptor
|
|||||||
|
|
||||||
private function writeData(array $data, array $options)
|
private function writeData(array $data, array $options)
|
||||||
{
|
{
|
||||||
$flags = $options['json_encoding'] ?? 0;
|
$flags = isset($options['json_encoding']) ? $options['json_encoding'] : 0;
|
||||||
|
|
||||||
$this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
$this->output->write(json_encode($data, $flags | JSON_PRETTY_PRINT)."\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,10 @@ class JsonResponse extends Response
|
|||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $this->encodingOptions)) {
|
||||||
|
return $this->setJson($data);
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||||
throw new \InvalidArgumentException(json_last_error_msg());
|
throw new \InvalidArgumentException(json_last_error_msg());
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,10 @@ class X509AuthenticationListener extends AbstractPreAuthenticatedListener
|
|||||||
$user = null;
|
$user = null;
|
||||||
if ($request->server->has($this->userKey)) {
|
if ($request->server->has($this->userKey)) {
|
||||||
$user = $request->server->get($this->userKey);
|
$user = $request->server->get($this->userKey);
|
||||||
} elseif ($request->server->has($this->credentialKey) && preg_match('#/emailAddress=(.+\@.+\..+)(/|$)#', $request->server->get($this->credentialKey), $matches)) {
|
} elseif (
|
||||||
|
$request->server->has($this->credentialKey)
|
||||||
|
&& preg_match('#emailAddress=(.+\@.+\.[^,/]+)($|,|/)#', $request->server->get($this->credentialKey), $matches)
|
||||||
|
) {
|
||||||
$user = $matches[1];
|
$user = $matches[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,8 @@ class X509AuthenticationListenerTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider dataProviderGetPreAuthenticatedDataNoUser
|
* @dataProvider dataProviderGetPreAuthenticatedDataNoUser
|
||||||
*/
|
*/
|
||||||
public function testGetPreAuthenticatedDataNoUser($emailAddress)
|
public function testGetPreAuthenticatedDataNoUser($emailAddress, $credentials)
|
||||||
{
|
{
|
||||||
$credentials = 'CN=Sample certificate DN/emailAddress='.$emailAddress;
|
|
||||||
$request = new Request([], [], [], [], [], ['SSL_CLIENT_S_DN' => $credentials]);
|
$request = new Request([], [], [], [], [], ['SSL_CLIENT_S_DN' => $credentials]);
|
||||||
|
|
||||||
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
|
$tokenStorage = $this->getMockBuilder('Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface')->getMock();
|
||||||
@ -76,10 +75,12 @@ class X509AuthenticationListenerTest extends TestCase
|
|||||||
|
|
||||||
public static function dataProviderGetPreAuthenticatedDataNoUser()
|
public static function dataProviderGetPreAuthenticatedDataNoUser()
|
||||||
{
|
{
|
||||||
return [
|
yield ['cert@example.com', 'CN=Sample certificate DN/emailAddress=cert@example.com'];
|
||||||
'basicEmailAddress' => ['cert@example.com'],
|
yield ['cert+something@example.com', 'CN=Sample certificate DN/emailAddress=cert+something@example.com'];
|
||||||
'emailAddressWithPlusSign' => ['cert+something@example.com'],
|
yield ['cert@example.com', 'CN=Sample certificate DN,emailAddress=cert@example.com'];
|
||||||
];
|
yield ['cert+something@example.com', 'CN=Sample certificate DN,emailAddress=cert+something@example.com'];
|
||||||
|
yield ['cert+something@example.com', 'emailAddress=cert+something@example.com,CN=Sample certificate DN'];
|
||||||
|
yield ['cert+something@example.com', 'emailAddress=cert+something@example.com'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,7 +92,15 @@ class JsonDecode implements DecoderInterface
|
|||||||
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
|
$recursionDepth = $context[self::RECURSION_DEPTH] ?? $this->defaultContext[self::RECURSION_DEPTH];
|
||||||
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
|
$options = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
|
||||||
|
|
||||||
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
|
try {
|
||||||
|
$decodedData = json_decode($data, $associative, $recursionDepth, $options);
|
||||||
|
} catch (\JsonException $e) {
|
||||||
|
throw new NotEncodableValueException($e->getMessage(), 0, $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $options)) {
|
||||||
|
return $decodedData;
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error()) {
|
if (JSON_ERROR_NONE !== json_last_error()) {
|
||||||
throw new NotEncodableValueException(json_last_error_msg());
|
throw new NotEncodableValueException(json_last_error_msg());
|
||||||
|
@ -50,6 +50,10 @@ class JsonEncode implements EncoderInterface
|
|||||||
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
|
$jsonEncodeOptions = $context[self::OPTIONS] ?? $this->defaultContext[self::OPTIONS];
|
||||||
$encodedJson = json_encode($data, $jsonEncodeOptions);
|
$encodedJson = json_encode($data, $jsonEncodeOptions);
|
||||||
|
|
||||||
|
if (\PHP_VERSION_ID >= 70300 && (JSON_THROW_ON_ERROR & $jsonEncodeOptions)) {
|
||||||
|
return $encodedJson;
|
||||||
|
}
|
||||||
|
|
||||||
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
|
if (JSON_ERROR_NONE !== json_last_error() && (false === $encodedJson || !($jsonEncodeOptions & JSON_PARTIAL_OUTPUT_ON_ERROR))) {
|
||||||
throw new NotEncodableValueException(json_last_error_msg());
|
throw new NotEncodableValueException(json_last_error_msg());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user