Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9b50bc9

Browse files
committed
[SecurityBundle] register alias for argument for password hasher
1 parent5955b14 commit9b50bc9

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

‎src/Symfony/Bundle/SecurityBundle/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.4
5+
---
6+
7+
* Register alias for argument for password hasher when the key is not a class name
8+
49
7.3
510
---
611

‎src/Symfony/Bundle/SecurityBundle/DependencyInjection/SecurityExtension.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
useSymfony\Component\PasswordHasher\Hasher\Pbkdf2PasswordHasher;
5050
useSymfony\Component\PasswordHasher\Hasher\PlaintextPasswordHasher;
5151
useSymfony\Component\PasswordHasher\Hasher\SodiumPasswordHasher;
52+
useSymfony\Component\PasswordHasher\PasswordHasherInterface;
5253
useSymfony\Component\Routing\Loader\ContainerLoader;
5354
useSymfony\Component\Security\Core\Authorization\Strategy\AffirmativeStrategy;
5455
useSymfony\Component\Security\Core\Authorization\Strategy\ConsensusStrategy;
@@ -706,6 +707,17 @@ private function createHashers(array $hashers, ContainerBuilder $container): voi
706707
$hasherMap = [];
707708
foreach ($hashersas$class =>$hasher) {
708709
$hasherMap[$class] =$this->createHasher($hasher);
710+
// The key is not a class, so we register an alias for argument to
711+
// ease getting the hasher
712+
if (!class_exists($class) && !interface_exists($class)) {
713+
$id ='security.password_hasher.' .ContainerBuilder::hash($class);
714+
$container
715+
->register($id, PasswordHasherInterface::class)
716+
->setFactory([newReference('security.password_hasher_factory'),'getPasswordHasher'])
717+
->setArgument(0,$class)
718+
;
719+
$container->registerAliasForArgument($id, PasswordHasherInterface::class,$class);
720+
}
709721
}
710722

711723
$container

‎src/Symfony/Bundle/SecurityBundle/Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
useSymfony\Component\HttpFoundation\Request;
3030
useSymfony\Component\HttpFoundation\RequestMatcher\PathRequestMatcher;
3131
useSymfony\Component\HttpFoundation\Response;
32+
useSymfony\Component\PasswordHasher\PasswordHasherInterface;
3233
useSymfony\Component\Security\Core\Authentication\Token\TokenInterface;
3334
useSymfony\Component\Security\Core\Exception\AuthenticationException;
3435
useSymfony\Component\Security\Core\User\InMemoryUserChecker;
@@ -883,7 +884,7 @@ public function testCustomHasherWithMigrateFrom()
883884
$container->loadFromExtension('security', [
884885
'password_hashers' => [
885886
'legacy' =>'md5',
886-
'App\User' => [
887+
TestUserChecker::class => [
887888
'id' =>'App\Security\CustomHasher',
888889
'migrate_from' =>'legacy',
889890
],
@@ -895,11 +896,19 @@ public function testCustomHasherWithMigrateFrom()
895896

896897
$hashersMap =$container->getDefinition('security.password_hasher_factory')->getArgument(0);
897898

898-
$this->assertArrayHasKey('App\User',$hashersMap);
899-
$this->assertEquals($hashersMap['App\User'], [
899+
$this->assertArrayHasKey(TestUserChecker::class,$hashersMap);
900+
$this->assertEquals($hashersMap[TestUserChecker::class], [
900901
'instance' =>newReference('App\Security\CustomHasher'),
901902
'migrate_from' => ['legacy'],
902903
]);
904+
905+
$legacyAlias =\sprintf('%s $%s', PasswordHasherInterface::class,'legacy');
906+
$this->assertTrue($container->hasAlias($legacyAlias));
907+
$definition =$container->getDefinition((string)$container->getAlias($legacyAlias));
908+
$this->assertSame(PasswordHasherInterface::class,$definition->getClass());
909+
910+
$this->assertFalse($container->hasAlias(\sprintf('%s $%s', PasswordHasherInterface::class,'symfonyBundleSecurityBundleTestsDependencyInjectionTestUserChecker')));
911+
$this->assertFalse($container->hasAlias(\sprintf('.%s $%s', PasswordHasherInterface::class, TestUserChecker::class)));
903912
}
904913

905914
publicfunctiontestAuthenticatorsDecoration()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp