登录后Symfony 2 FOSUserBundle匿名

时间:2014-07-22 12:07:51

标签: php security symfony fosuserbundle propel

我在Symfony 2.5安装上实现了FOSUserBundle。 我有两个问题:

  1. (已解决)当我登录时,我被重定向到调试器页面,我不知道为什么。难道我不会被导向我试图访问的最后一页没有有效的凭据吗? (解决)

  2. 调试器说我已登录,但是作为没有角色的匿名用户。这很奇怪,因为页面有" ROLE_USER"角色(用户也是如此)

  3. 当我 var_dump($ this-> getUser()) 时,我会获得一个完整的用户对象(我已登录的实际用户! )

    $ this-> getUser()对象:

    object(FOS\UserBundle\Propel\User)#244 (33) {
      ["plainPassword":protected]=>
      NULL
      ["startCopy":protected]=>
      bool(false)
      ["id":protected]=>
      int(4)
      ["username":protected]=>
      string(4) "user"
      ["username_canonical":protected]=>
      string(4) "user"
      ["email":protected]=>
      string(15) "user@domain.com"
      ["email_canonical":protected]=>
      string(15) "user@domain.com"
      ["enabled":protected]=>
      bool(true)
      ["salt":protected]=>
      string(31) "gfxdkl84d0ook0k8wow4c8s4w4owk8g"
      ["password":protected]=>
      string(88) "wYA5nYGe1vQYiiWIB9z9eFPlWG2V/BEts/60wbuwiL34FzDtFyb9TExNOpvbKL4DFt3Ruvm9+f2HW1mx850+Aw=="
      ["last_login":protected]=>
      string(19) "2014-07-22 12:55:25"
      ["locked":protected]=>
      bool(false)
      ["expired":protected]=>
      bool(false)
      ["expires_at":protected]=>
      NULL
      ["confirmation_token":protected]=>
      NULL
      ["password_requested_at":protected]=>
      NULL
      ["credentials_expired":protected]=>
      bool(false)
      ["credentials_expire_at":protected]=>
      NULL
      ["roles":protected]=>
      string(13) "| ROLE_USER |"
      ["roles_unserialized":protected]=>
      NULL
      ["collUserGroups":protected]=>
      NULL
      ["collUserGroupsPartial":protected]=>
      NULL
      ["collGroups":protected]=>
      NULL
      ["alreadyInSave":protected]=>
      bool(false)
      ["alreadyInValidation":protected]=>
      bool(false)
      ["alreadyInClearAllReferencesDeep":protected]=>
      bool(false)
      ["groupsScheduledForDeletion":protected]=>
      NULL
      ["userGroupsScheduledForDeletion":protected]=>
      NULL
      ["validationFailures":protected]=>
      array(0) {
      }
      ["_new":protected]=>
      bool(false)
      ["_deleted":protected]=>
      bool(false)
      ["modifiedColumns":protected]=>
      array(0) {
      }
      ["virtualColumns":protected]=>
      array(0) {
      }
    }
    

    security.yml

    security:
        encoders:
            FOS\UserBundle\Model\UserInterface: sha512
    
        role_hierarchy:
            ROLE_ADMIN:       ROLE_USER
            ROLE_SUPER_ADMIN: ROLE_ADMIN
    
        providers:
            fos_userbundle:
                id: fos_user.user_provider.username
    
        firewalls:
            main:
                pattern: ^/.*
                provider: fos_userbundle
                form_login:
                    check_path: /login_check
                    login_path: /login
                logout:
                    path: /logout
                    target: /
                anonymous: true        
    
        access_control:
            - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
            - { path: ^/, role: ROLE_USER }
    

    config.yml

    ...
    # FOS
    fos_user:
        db_driver: propel
        firewall_name: main
        user_class: FOS\UserBundle\Propel\User
    ...
    

    我是Symfony的新手,所以我有点迷失。

    提前致谢

    问题1已解决

    在登录表单twig模板中,我添加了:

     <input type="hidden" name="_target_path" value="g9_bo_homepage" />
    

    这是登录后的重定向页面。

0 个答案:

没有答案