Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 访问Sulu Frontend中的安全服务:散列用户密码_Symfony_Sulu - Fatal编程技术网

Symfony 访问Sulu Frontend中的安全服务:散列用户密码

Symfony 访问Sulu Frontend中的安全服务:散列用户密码,symfony,sulu,Symfony,Sulu,我正在尝试为Sulu CMF前端进行用户注册。 我想散列密码。但不管什么原因,我都得不到服务 You have requested a non-existent service "security.encoder_factory". 或 如果我要求 app/console container:debug | grep encode 两种服务都有 $ app/console container:debug | grep encode 263: secur

我正在尝试为Sulu CMF前端进行用户注册。 我想散列密码。但不管什么原因,我都得不到服务

You have requested a non-existent service "security.encoder_factory".

如果我要求

app/console container:debug | grep encode
两种服务都有

$ app/console container:debug | grep encode                    
263: security.encoder_factory                                                      Symfony\Component\Security\Core\Encoder\EncoderFactory                                     
266: security.password_encoder                                                     Symfony\Component\Security\Core\Encoder\UserPasswordEncoder                                
你有给我的小费吗? 我的控制器知道该容器,我的代码如下:

$this->container->get('security.password_encoder')
下面是conainer的一些输出:debug

$ app/console container:debug security.password_encoder
[container] Information for service security.password_encoder
Service Id       security.password_encoder
Class            Symfony\Component\Security\Core\Encoder\UserPasswordEncoder
Tags             -
Scope            container
Public           yes
Synthetic        no
Lazy             no
Synchronized     no
Abstract         no


$ app/console container:debug security.encoder_factory 
[container] Information for service security.encoder_factory
Service Id       security.encoder_factory
Class            Symfony\Component\Security\Core\Encoder\EncoderFactory
Tags             -
Scope            container
Public           yes
Synthetic        no
Lazy             no
Synchronized     no
Abstract         no
我当前安装的symfony版本是v2.6.12

sulu提供的命令使用此方法。它在dev和prod两种环境中都能工作

/**
 * Encodes the given password, for the given password, with he given salt and returns the result.
 *
 * @param $user
 * @param $password
 * @param $salt
 *
 * @return mixed
 */
private function encodePassword($user, $password, $salt)
{
    /** @var PasswordEncoderInterface $encoder */
    $encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($user);

    return $encoder->encodePassword($password, $salt);
}

Sulu CMF有一个额外的控制台应用程序,名为app/console webconsole,它使用不同的内核:-)

我搜索的服务在那里不存在。 相反,我能够使用

$userManager = $this->container->get('sulu_security.user_manager');

正如xabbuh在评论中已经指出的,我们在Sulu中有两种不同的内核。如果您使用
app/webconsole
命令,则您正在使用网站的内核


在标准安装中,我们不包括
SecurityBundle
,因为它增加了一些开销,并且对于简单的网站来说不是必需的。但是,如果您正在构建一个更复杂的应用程序,您可能还需要保护您的网站。在这种情况下,您只需将
Symfony\Bundle\SecurityBundle\SecurityBundle
的新实例添加到
app/WebsiteKernel
中的
$bundles
数组中即可。之后还将提供您一直要求的服务。

我是从控制器打来的。这里有一个扩展Symfony\Bundle\FrameworkBundle\Controller\Controller(扩展containerware)的程序。您使用哪个Symfony版本?您能否显示
php应用程序/控制台容器:debug security.password\u encoder
php应用程序/控制台容器:debug security.encoder\u factory
的输出?谢谢您的回答。我在上面添加了更多详细信息。同时使用
--env=prod
选项时,输出是否有所不同?您确定CLI和web前端控制器实际上共享同一内核吗?这是一种可能的解决方案,具体取决于您想做什么。将添加另一个答案以实现您的实际要求。感谢您(所有人)的答案。A现在已经完成了我的任务。我的问题是,我没有看到苏鲁有不同的内核:-)
$userManager = $this->container->get('sulu_security.user_manager');