Skip to content

Commit 6e23634

Browse files
committed
Ignore validation errors caused by third-party user providers and authenticators
1 parent 58a29f2 commit 6e23634

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

UPGRADE-5.4.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ SecurityBundle
110110
* Deprecate passing an array of arrays as 1st argument to `MainConfiguration`, pass a sorted flat array of
111111
factories instead.
112112
* Deprecate the `always_authenticate_before_granting` option
113-
* XML configured user providers and authenticators not coming from Symfony must now declare their own namespace
114113

115114
Security
116115
--------

src/Symfony/Component/DependencyInjection/Loader/XmlFileLoader.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,36 @@ private function parseFileToDOM(string $file): \DOMDocument
404404
try {
405405
$dom = XmlUtils::loadFile($file, [$this, 'validateSchema']);
406406
} catch (\InvalidArgumentException $e) {
407-
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file).$e->getMessage(), $e->getCode(), $e);
407+
$allowedInvalidElements = [];
408+
$errors = explode("\n", $e->getMessage());
409+
foreach ($errors as $error) {
410+
if (preg_match("#^\[ERROR 1871] Element '\{http://symfony\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
411+
$allowedInvalidElements[] = $matches[1];
412+
}
413+
}
414+
if ($allowedInvalidElements) {
415+
$dom = XmlUtils::loadFile($file);
416+
417+
$allowedInvalidElements = array_filter(
418+
$allowedInvalidElements,
419+
static function (string $tagName) use ($dom): bool {
420+
foreach ($dom->getElementsByTagName($tagName) as $element) {
421+
if (!$parent = $element->parentElement) {
422+
return false;
423+
}
424+
if ('provider' === $parent->tagName || 'firewall' === $parent->tagName) {
425+
trigger_deprecation('symfony/security-bundle', '5.4.41', 'Third-party %s must now be namespaced; please update your security configuration "%s" tag.', 'provider' === $parent->tagName ? 'providers' : 'authenticators', $tagName);
426+
427+
return true;
428+
}
429+
}
430+
return false;
431+
}
432+
);
433+
}
434+
if (\count($allowedInvalidElements) !== \count($errors)) {
435+
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file) . $e->getMessage(), $e->getCode(), $e);
436+
}
408437
}
409438

410439
$this->validateExtensions($dom, $file);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy