Php 如何调试(和修复)Symfony2 | 3路由?
我在Symfony 2.8应用程序的Php 如何调试(和修复)Symfony2 | 3路由?,php,symfony,symfony-routing,Php,Symfony,Symfony Routing,我在Symfony 2.8应用程序的app/config/routing.yml中定义了此路由: platform_chat: resource: "@PlatformChatBundle/Controller/" type: annotation prefix: /chat platform_admin: resource: "@PlatformAdminBundle/Controller/" type: annotation
app/config/routing.yml
中定义了此路由:
platform_chat:
resource: "@PlatformChatBundle/Controller/"
type: annotation
prefix: /chat
platform_admin:
resource: "@PlatformAdminBundle/Controller/"
type: annotation
prefix: /admin
#----> this is part of routing.yml but I forgot to add it
easy_admin_bundle:
resource: "@PlatformAdminBundle/Controller/AdminController.php"
type: annotation
prefix: /admin
#FOSUser
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
您可能已经注意到,PlatformAdminBundle
是后端,PlatformChatBundle
是前端。考虑到这一点,我正在尝试设置并使用一个防火墙,然后在安全上。交互式登录
事件重定向到正确的路径。这就是防火墙的外观:
security:
...
role_hierarchy:
ROLE_CHATTER: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
...
firewalls:
...
ignored:
pattern: ^/(login(_check)?|logout|resetting)$
security: false
global:
pattern: ^/admin/(.*)|^/chat/(.*)
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
# if true, forward the user to the login form instead of redirecting
use_forward: true
# login success redirecting options (read further below)
always_use_default_target_path: true
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
platform_chat:
resource: "@PlatformChatBundle/Controller/"
type: annotation
prefix: /chat
options:
expose: true
platform_admin:
resource: "@PlatformAdminBundle/Controller/"
type: annotation
prefix: /admin
options:
expose: true
#EasyAdminBundle
easy_admin_bundle:
resource: "@PlatformAdminBundle/Controller/AdminController.php"
type: annotation
prefix: /admin
options:
expose: true
#FOSUser
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
#FOSUser Groups
fos_user_group:
resource: "@FOSUserBundle/Resources/config/routing/group.xml"
prefix: /group
#FOSJsRouting
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
security:
...
firewalls:
...
global:
pattern: /
anonymous: true
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
use_forward: true # if true, forward the user to the login form instead of redirecting
always_use_default_target_path: true # login success redirecting options (read further below)
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
但它不起作用,因为当我尝试以任何一个用户的身份登录时,我会出现以下错误:
您必须在安全防火墙配置中使用form_登录配置防火墙要处理的检查路径
这让我觉得路由或防火墙没有正确配置。我已经检查了调试工具栏下的路由,但没有匹配项,因此它们是错误的。我已经阅读了文档,但它一点帮助都没有,我也没有得到解决问题的方法。你可以把这篇文章作为文章的第二部分,但我不想改变老文章的主题,也不想改变内容,因为我认为这对其他人的未来会有帮助。伙计们,有什么建议吗?您会调试与路由相关的此类问题吗?我的问题有什么解决办法吗?我真的被困在这里了
更新
我已经按照@xabbuh的建议进行了更改,所以现在app/config/routing.yml
看起来像:
security:
...
role_hierarchy:
ROLE_CHATTER: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
...
firewalls:
...
ignored:
pattern: ^/(login(_check)?|logout|resetting)$
security: false
global:
pattern: ^/admin/(.*)|^/chat/(.*)
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
# if true, forward the user to the login form instead of redirecting
use_forward: true
# login success redirecting options (read further below)
always_use_default_target_path: true
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
platform_chat:
resource: "@PlatformChatBundle/Controller/"
type: annotation
prefix: /chat
options:
expose: true
platform_admin:
resource: "@PlatformAdminBundle/Controller/"
type: annotation
prefix: /admin
options:
expose: true
#EasyAdminBundle
easy_admin_bundle:
resource: "@PlatformAdminBundle/Controller/AdminController.php"
type: annotation
prefix: /admin
options:
expose: true
#FOSUser
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
#FOSUser Groups
fos_user_group:
resource: "@FOSUserBundle/Resources/config/routing/group.xml"
prefix: /group
#FOSJsRouting
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
security:
...
firewalls:
...
global:
pattern: /
anonymous: true
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
use_forward: true # if true, forward the user to the login form instead of redirecting
always_use_default_target_path: true # login success redirecting options (read further below)
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
而且看起来像:
security:
...
role_hierarchy:
ROLE_CHATTER: ROLE_USER
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
...
firewalls:
...
ignored:
pattern: ^/(login(_check)?|logout|resetting)$
security: false
global:
pattern: ^/admin/(.*)|^/chat/(.*)
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
# if true, forward the user to the login form instead of redirecting
use_forward: true
# login success redirecting options (read further below)
always_use_default_target_path: true
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
platform_chat:
resource: "@PlatformChatBundle/Controller/"
type: annotation
prefix: /chat
options:
expose: true
platform_admin:
resource: "@PlatformAdminBundle/Controller/"
type: annotation
prefix: /admin
options:
expose: true
#EasyAdminBundle
easy_admin_bundle:
resource: "@PlatformAdminBundle/Controller/AdminController.php"
type: annotation
prefix: /admin
options:
expose: true
#FOSUser
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
#FOSUser Groups
fos_user_group:
resource: "@FOSUserBundle/Resources/config/routing/group.xml"
prefix: /group
#FOSJsRouting
fos_js_routing:
resource: "@FOSJsRoutingBundle/Resources/config/routing/routing.xml"
security:
...
firewalls:
...
global:
pattern: /
anonymous: true
provider: fos_userbundle
form_login:
csrf_provider: security.csrf.token_manager
login_path: fos_user_security_login
check_path: fos_user_security_check
use_forward: true # if true, forward the user to the login form instead of redirecting
always_use_default_target_path: true # login success redirecting options (read further below)
default_target_path: /admin
target_path_parameter: _target_path
use_referer: true
remember_me: true
logout: ~
remember_me:
secret: '%secret%'
lifetime: 604800 # 1 week in seconds
path: /
access_control:
- { path: ^/chat/, role: ROLE_CHATTER }
- { path: ^/admin/, role: ROLE_ADMIN }
清除缓存后,以下是我的尝试和结果:
- 以
身份登录:我将进入ROL\u CHATTER
正如预期的那样,我得到了登录表单,并使用有效凭据得到以下消息:拒绝访问。你在唠叨。这是正确的,因为我在http://domain.tld/app_dev.php/chat/
上有一个侦听器,当用户使用这些凭据登录时,我就是这么做的security.interactive\u login
- 以
身份登录:我将进入ROL\u ADMIN
正如预期的那样,我得到了登录表单,使用有效的凭据,我得到了以下消息:错误的凭据。这是错误的,因为凭据是有效的,并且至少我应该收到另一条消息(访问被拒绝。您是管理员),因为侦听器在http://domain.tld/app_dev.php/admin/
上运行,但正如我所说,这不是正在发生的事情security.interactive\u login
与侦听器相关的信息已打开。怎么了?您的问题是用于匹配
全局
防火墙请求的正则表达式是/admin/(.*)^/chat/(.*)
,但您的检查路径是/login\u check
。正如您所看到的,您的防火墙不会匹配该路径,从而导致您发布的错误消息
如果我是你,我只需在登录相关的东西之前删除防火墙,并将
全局
防火墙的正则表达式更改为/
。然后,您只需添加anonymous:true
,以便未登录的用户能够访问登录表单。您的访问控制部分仍将拒绝访问您的受保护区域。您的问题是,用于匹配全局防火墙请求的正则表达式是/admin/(.*)^/chat/(.*)
,但您的检查路径是/login\u check
。正如您所看到的,您的防火墙不会匹配该路径,从而导致您发布的错误消息
如果我是你,我只需在登录相关的东西之前删除防火墙,并将全局
防火墙的正则表达式更改为/
。然后,您只需添加anonymous:true
,以便未登录的用户能够访问登录表单。访问您的保护区仍将被您的访问控制部分拒绝。与fos\u user\u security\u check
route关联的路径是什么?@xabbuh与该路径不匹配,即使在你以前的帖子中,你也有BadCredentialsException
,所以我认为你的管理员用户出了问题,或者你处理了它。尝试通过检查堆栈跟踪来调试您的问题,并查看异常实际引发的位置。与fos\u user\u security\u check
route关联的路径是什么?@xabbuh与该路径不匹配,即使在你以前的帖子中,你也有BadCredentialsException
,所以我认为你的管理员用户出了问题,或者你处理了它。尝试通过检查堆栈跟踪来调试您的问题,并查看异常实际抛出的位置。@malcolm我无法使其正常工作,我请求xabbuh是否有时间检查我的源代码?我可以通过Bitbucket共享,你可以吗?@xabbuh给我你的Bitbucket用户,这样我就可以给你源代码的权限。因此,请看我一分钟前的编辑,也许这就是问题所在,我不清楚。我的Bitbucket用户名是相同的,但请做我在回答中建议的更改。我已经按照你的建议做了更改,在回购协议上already@malcolm我不能让这个工作,我问xabbuh是否有一些空闲时间来检查我的来源?我可以通过Bitbucket分享,你可以吗?@xabbuh给我你的Bitbucket用户,这样我就可以给你源代码的权限。一分钟前请看我的编辑。也许这就是问题所在,我不清楚。我的Bitbucket用户名是一样的,但请做我在回答中建议的更改。我已经按照你的建议做了更改,已经在回购协议中了