1

Symfony2 アプリケーション (バージョン 2.3) でログイン フォーム用のチェーン プロバイダーを作成しようとしています - これは私のセキュリティ Yaml です:

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\Controller\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

しかし、うまくいきませんでした。User クラスは、Symfony エンジンの多くの場所でハードコーディングされていることがわかりました。

だから私の質問は: セキュリティ yaml からその動作を変更する方法? 何か不足していますか?

4

2 に答える 2

0

申し訳ありませんが、メモリ ユーザーのプロファイルを表示することはできません。プロフィールはFOSユーザー専用です。そのため、実装する必要がありますFOS\UserBundle\Model\UserInterface

于 2013-07-23T04:07:29.003 に答える