Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a075601

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

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-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: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,32 @@ 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+
$invalidSecurityElements = [];
408+
$errors = explode("\n", $e->getMessage());
409+
foreach ($errors as $i => $error) {
410+
if (preg_match("#^\[ERROR 1871] Element '\{http://symfony\.com/schema/dic/security}([^']+)'#", $error, $matches)) {
411+
$invalidSecurityElements[$i] = $matches[1];
412+
}
413+
}
414+
if ($invalidSecurityElements) {
415+
$dom = XmlUtils::loadFile($file);
416+
417+
foreach ($invalidSecurityElements as $errorIndex => $tagName) {
418+
foreach ($dom->getElementsByTagName($tagName) as $element) {
419+
if (!$parent = $element->parentElement) {
420+
continue;
421+
}
422+
if ('provider' === $parent->tagName || 'firewall' === $parent->tagName) {
423+
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);
424+
425+
unset($errors[$errorIndex]);
426+
}
427+
}
428+
}
429+
}
430+
if ($errors) {
431+
throw new InvalidArgumentException(sprintf('Unable to parse file "%s": ', $file) . implode("/n", $errors), $e->getCode(), $e);
432+
}
408433
}
409434

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

0 commit comments

Comments
 (0)