2014-01-10 298 views
1

嗨我登錄後重定向循環使用fosuserbundle 它看起來如何? i型良好的用戶名和密碼,然後登錄我的,我可以用symfony profiller 看到它,並剖析說,This request redirects to http://web.dev/app_dev.php/admin/panel.我去那裏,它說This request redirects to http://web.dev/app_dev.php/admin/login.和IM在這個地方FosUserBundle如何修復重定向循環

這裏不再贅述認證爲我的安全:

jms_security_extra: 
    expressions: true 

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

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

    providers: 
     in_memory: 
      memory: 
       users: 
        "%api_username%": { password: "%api_password%", roles: [ 'ROLE_API' ] }  
     fos_userbundle: 
      id: fos_user.user_provider.username_email 
     ssoprovider: 
      id: sso_user_provider 

    firewalls: 
     dev: 
      pattern: ^/(_(profiler|wdt)|css|images|js)/ 
      security: false 
     login: 
      pattern: ^/demo/secured/login$ 
      security: false 
     admin: 
      pattern: ^/admin/ 
      form_login: 
       provider: fos_userbundle 
       csrf_provider: form.csrf_provider 
       login_path:      fos_user_security_login 
       check_path:      fos_user_security_check 
       default_target_path:    admin_main 
      logout:  
       path: fos_user_security_logout 
       invalidate_session: true #https://github.com/symfony/symfony/issues/5868 
      anonymous: true 
      remember_me: 
       name:  "web_remember_me" 
       key:  "%secret%" 
       lifetime: 864000 # 10 days 
       path:  /admin 
     secured_area: 
      pattern: ^/(?!admin)    
      form_login: 
       login_path : main_user_logout 
      stateless: false 
      anonymous: false 
      simple_preauth: 
       authenticator: sso_authenticator 
      logout: 
       path: main_user_logout 
       invalidate_session: true 
       success_handler: sso_authentication_handler 
     api: 
      pattern: ^/api 
      stateless: true 
      http_basic: 
       realm: "Secured API Area" 

    access_control: 
     - { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/admin/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY } 
     - { path: ^/admin/, role: ROLE_ADMIN } 
     - { path: ^/api/, roles: ROLE_API } 
     - { path: ^/, role: ROLE_USER } 
+0

你給了用戶'ROLE_SUPER_ADMIN'或'ROLE_ADMIN'的作用?除非另有說明,否則生成的用戶通常只具有「ROLE_USER」角色。 – qooplmao

+0

我得到了ROLE_ADMIN我覆蓋了方法,問題出現在我添加secured_area並寫入ssoprovider時 我使用fosuserbundle來驗證管理員和我自己的自定義驗證器來驗證用戶 – Vardius

+0

您正在使用哪個版本的PHP?我遇到了一個與此類似的問題,結果發現PHP是如何處理會話的。 – Flosculus

回答

0

有人致毒becouse我在config.yml已經定義cookie_domain

配置陽明:

framework: 
    session: 
     cookie_domain: .%domain% 

,我不得不增加對記得我domain配置

security.yml:

admin: 
    remember_me: 
     domain: ".%domain%"