2012-11-11 80 views
2
  • Symfony的2.1.3-dev的
  • SonataUserBundle
  • SonataAdminBundle
  • JMSI18nRoutingBundle

默认情况下的语言是法语,但我启用 “EN”更改语言

我安装了这个软件包,大部分工作都正常。

但我想做到以下几点:

  • 用户XXX(SonataUserBundle)已在该领域“区域设置”值“恩”
  • 当我这个用户登录希望现身英文页面。
  • 用户没有手动切换。

我认为这应该在autentification过程中完成。

的问题是,SonataUserBundle(基于FOSU​​ser)不做认证(看到HERE

于是,我就做THIS,但必须有一些配置问题。

当应用wsse_secured整个网站:

wsse_secured: 
    pattern: ^/ 
    wsse:  true 

我得到以下错误:令牌未在SecurityContext中找到。

当添加匿名我config.yml:

firewalls: 
    .... 
    main: 
     pattern: ^/ 
     wsse:  true 
     anonymous:  true 

我可以访问主页,但尝试登录时,我得到这个错误: 您必须配置支票路径被处理防火墙在您的安全防火墙配置中使用form_login。

当添加了它的工作原理,但系统不与我WSSE提供商合作FOS的的CheckPath(我在WsseProvider.php添加的代码,让我知道)

所以我的问题:我怎样才能找到工作这个WSSE认证。我严格遵循文档中的指示。

编辑:

我也许是在我自己的捆绑实现WSSE安全文件犯了一个错误。 现在我把它移到奏鸣曲用户捆绑,我得到以下错误:

ErrorException: Catchable Fatal Error: Argument 1 passed to Application\Sonata\UserBundle\Security\Authentication\Provider\WsseProvider::__construct() must implement interface Symfony\Component\Security\Core\User\UserProviderInterface, string given, called in ..\app\cache\dev\appDevDebugProjectContainer.php on line 4413 and defined in ..\src\Application\Sonata\UserBundle\Security\Authentication\Provider\WsseProvider.php line 17

这有什么错我的WsseProvider UserProviderInterface。PHP:

<?php 

namespace Application\Sonata\UserBundle\Security\Authentication\Provider; 

use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface; 
use Symfony\Component\Security\Core\User\UserProviderInterface; 
use Symfony\Component\Security\Core\Exception\AuthenticationException; 
use Symfony\Component\Security\Core\Exception\NonceExpiredException; 
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; 
use Application\Sonata\UserBundle\Security\Authentication\Token\WsseUserToken; 

class WsseProvider implements AuthenticationProviderInterface 
{ 
    private $userProvider; 
    private $cacheDir; 

    public function __construct(UserProviderInterface $userProvider, $cacheDir) 
    { 
     $this->userProvider = $userProvider; 
     $this->cacheDir  = $cacheDir; 
    } 
... 

回答

2

我已经解决了这个问题,一个简单的KernelRequestListener:

<?php 
namespace ACME\DemoBundle\Listener; 

use Symfony\Component\HttpKernel\Event\GetResponseEvent; 
use Symfony\Component\DependencyInjection\ContainerInterface; 


class RequestListener 
{ 
protected $container; 

public function __construct(ContainerInterface $container) 
{ 
    $this->container = $container; 
} 

public function onKernelRequest(GetResponseEvent $event) 
{ 
    $userlocale = null; 
    $request = $event->getRequest(); 
    $user = $this->container->get('security.context')->getToken()->getUser(); 

    if (!is_object($user)) { 
     return; 
    } 

    $userlocale = $user->getLocale(); 
    if($userlocale !== NULL AND $userlocale !== '') 
    { 
     $request->setLocale($userlocale); 
    } 
} 
} 

注册服务的Acme /演示/资源/ service.yml:

ACME.demo.listener.request: 
     class: ACME\DemoBundle\Listener\RequestListener 
     arguments: [ @service_container ] 
     tags: 
     - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest } 

其他解决方案,我已找到:Here