它在dev
中效果很好,但在prod
中它会对我进行身份验证并重定向回登录:
[2015-03-02 15:01:48] request.INFO: Matched route "admin_auth" (parameters: "_controller": "DEV\AdminBundle\Controller\AuthController::loginAction", "_route": "admin_auth") [] []
[2015-03-02 15:01:49] request.INFO: Matched route "admin_login_check" (parameters: "_route": "admin_login_check") [] []
[2015-03-02 15:01:49] security.INFO: User "xxx@gmail.com" has been authenticated successfully [] []
[2015-03-02 15:01:49] security.DEBUG: Write SecurityContext in the session [] []
[2015-03-02 15:01:49] request.INFO: Matched route "admin_index" (parameters: "_controller": "DEV\AdminBundle\Controller\DefaultController::indexAction", "_route": "admin_index") [] []
[2015-03-02 15:01:49] security.INFO: Authentication exception occurred; redirecting to authentication entry point (A Token was not found in the SecurityContext.) [] []
[2015-03-02 15:01:49] security.DEBUG: Calling Authentication entry point [] []
[2015-03-02 15:01:49] security.DEBUG: Write SecurityContext in the session [] []
[2015-03-02 15:01:49] request.INFO: Matched route "admin_auth" (parameters: "_controller": "DEV\AdminBundle\Controller\AuthController::loginAction", "_route": "admin_auth") [] []
错误就在这里,我想,我不知道如何处理它:
[2015-03-02 15:01:49] security.INFO: Authentication exception occurred; redirecting to authentication entry point (A Token was not found in the SecurityContext.) [] []
我的security.yml
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
DEV\MainBundle\Model\User:
algorithm: sha1
iterations: 1
encode_as_base64: false
role_hierarchy:
ROLE_ADMIN: [ROLE_ADMIN, ROLE_USER]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
user_db:
propel:
class: DEV\MainBundle\Model\User
property: email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/admin/auth$
security: false
anonymous: true
admin:
pattern: ^/(admin|api)
form_login:
login_path: admin_auth
check_path: admin_login_check
default_target_path: admin_index
provider: user_db
logout:
path: admin_logout
target: admin_auth
switch_user: true
access_control:
- { path: ^/admin, roles: [ROLE_ADMIN] }
答案 0 :(得分:0)
也许这一行: ROLE_ADMIN:[ROLE_ADMIN,ROLE_USER]
我对symfony不是很有经验但可能:
ROLE_ADMIN: ROLE_USER