2013-07-22 82 views
1

我想在箱子我的Symfony2应用的登录表单链提供商(2.3版本) - 这是我的安全YAML:如何从用户更改Symfony2的安全明文编码器用户界面

jms_security_extra: 
    secure_all_services: false 
    expressions: true 

security: 
    encoders: 
    Symfony\Component\Security\Core\User\User: plaintext 
    FOS\UserBundle\Model\UserInterface: sha512 

    role_hierarchy: 
    ROLE_ADMIN:  ROLE_USER 
    ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] 

    providers: 
    chain_provider: 
     chain: 
     providers: [in_memory, fos_userbundle] 
    fos_userbundle: 
     id: fos_user.user_provider.username 
    in_memory: 
     memory: 
     users: 
      admin: { password: god, roles: [ 'ROLE_ADMIN' ] } 

    firewalls: 
    main: 
     pattern: ^/ 
     form_login: 
     provider: chain_provider 
     csrf_provider: form.csrf_provider 
     logout:  true 
     anonymous: true 
     security: true 

    access_control: 
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } 
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
    - { path: ^/admin/, role: ROLE_ADMIN } 
    - { path: ^/group/, role: ROLE_ADMIN } 

由于你可以看到,我使用FOSUserBundle(伟大的东西顺便说一句)。

问题是,我用in_memory管理员用户登录后,我无法进入/ profile/URL。我收到此错误信息:

AccessDeniedHttpException: This user does not have access to this section 

我找到了原因这 - 问题是在FOS \ UserBundle \控制器\ ProfileController可类:

public function showAction() 
{ 
    $user = $this->container->get('security.context')->getToken()->getUser(); 
    if (!is_object($user) || !$user instanceof UserInterface) { 
     throw new AccessDeniedException('This user does not have access to this section.'); 
    } 

    return $this->container->get('templating')->renderResponse('FOSUserBundle:Profile:show.html.'.$this->container->getParameter('fos_user.template.engine'), array('user' => $user)); 
} 

该控制器检查,如果$ USER对象是UserInterface的一个实例,它不是,因为它是Symfony \ Component \ Security \ Core \ User \ User(明文编码器类)的实例。

我试图改变编码器配置到这一点:

security: 
    encoders: 
    Symfony\Component\Security\Core\User\UserInterface: plaintext 

但没有奏效。我发现用户类在Symfony引擎的许多地方被硬编码。

所以我的问题是:如何从安全yaml更改该行为?我错过了什么吗?

回答

0

对不起,但你不能看到内存用户的配置文件。配置文件仅适用于FOS用户。这就是为什么它必须执行FOS\UserBundle\Model\UserInterface

+0

是的,你是对的。谢谢。 – schabluk