因此,我尝试创建一个新的 Silex 应用程序并使用包含的安全包。为了简单起见,我将使用基本的密码编码。
根据 Silex 文档http://silex.sensiolabs.org/doc/providers/security.html http://silex.sensiolabs.org/doc/providers/security.html我创建了一个自定义用户提供程序。然而,这个用户界面似乎没有使用默认的密码编码。
我可以成功获取密码
$password = $app['security.encoder.digest']->encodePassword('foo');
但是当我使用这个例子时
// find the encoder for a UserInterface instance
$encoder = $app['security.encoder_factory']->getEncoder($user);
// compute the encoded password for foo
$password = $encoder->encodePassword('foo', $user->getSalt());
我得到了
RuntimeException:尚未为帐户配置编码器
在 symfony2 中,我会使用类似以下的内容
encoders:
somename:
class: Acme\DemoBundle\Entity\User
Acme\DemoBundle\Entity\User: sha512
Acme\DemoBundle\Entity\User: plaintext
Acme\DemoBundle\Entity\User:
algorithm: sha512
encode_as_base64: true
iterations: 5000
Acme\DemoBundle\Entity\User:
id: my.custom.encoder.service.id
但这里的情况似乎并非如此。我似乎找不到任何类型的 setEncoder 方法,所以我有点困惑。
你需要重建EncoderFactory
添加您的自定义实现:
<?php
$app = new Silex\Application();
$app['myapp.encoder.base64'] = new Base64PasswordEncoder();
$app['security.encoder_factory'] = $app->share(function ($app) {
return new EncoderFactory(
array(
'Symfony\Component\Security\Core\User\UserInterface' => $app['security.encoder.digest'],
'MyApp\Model\UserInterface' => $app['myapp.encoder.base64'],
)
);
});
(哦,请不要使用 Base64Encoder() 作为密码;))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)