从 symfony 2.4 升级到 2.6 后,FOSUserBundle 无法登录
FOSUserBundle no login possible after upgrade from symfony 2.4 to 2.6
最近我一直在将我的网站从 symfony 2.4 升级到 2.6。我遵循了我发现的所有升级说明,几乎所有的工作都找到了。但是,我现在无法再登录到我的网站。
我使用 FOSUserBundle,我的 composer.json 包括这一行:
"friendsofsymfony/user-bundle": "2.0.*@dev",
我至少阅读了所有教程三遍,比较了所有选项,现在我已经焦头烂额了,因为我找不到有效的解决方案!
在 2.4 中一切正常所以我认为这可能与 security.yml
中定义的选项有关。
问题是我在 apache/symfony 日志文件中没有收到任何异常、警告或任何可疑信息。
这是我的 security.yml:
parameters:
security.acl.permission.map.class:
Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
sonata.admin.security.mask.builder.class:
Sonata\AdminBundle\Security\Acl\Permission\MaskBuilder
security:
acl:
connection: default
encoders:
FOS\UserBundle\Model\UserInterface: sha512
access_denied_url: ~
always_authenticate_before_granting: false
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
ROLE_AUTHOR: [ROLE_USER, SONATA]
SONATA:
- ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT
providers:
fos_userbundle:
id: fos_user.user_provider.username
fos_facebook_provider:
id: fos_facebook.user.login
chain_provider:
chain:
providers: [fos_userbundle, fos_facebook_provider]
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
fos_facebook:
app_url: "http://apps.facebook.com/XXX/"
server_url: "http://XXX"
login_path: /user/login
check_path: /facebook/login_check
default_target_path: /Account
provider: fos_facebook_provider
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
remember_me: true
login_path: /user/login
default_target_path: /Account
use_forward: false
check_path: /user/login_check
failure_path: null
logout:
path: /user/logout
anonymous: true
provider: main
context: main_auth
remember_me:
key: XXX
lifetime: XXX
path: /
domain: ~
access_control:
- { path: ^/user/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured, role: ROLE_USER }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
# # The WDT has to be allowed to anonymous users to avoid requiring the login with the AJAX request
- { path: ^/wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profiler/, role: IS_AUTHENTICATED_ANONYMOUSLY }
## # AsseticBundle paths used when using the controller for assets
- { path: ^/js/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/css/, role: IS_AUTHENTICATED_ANONYMOUSLY }
# # URL of FOSUserBundle which need to be available to anonymous users
# - { path: ^/secured/.*, role: [ROLE_FACEBOOK] } # This is the route secured with fos_facebook
# - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } # for the case of a failed login
- { path: ^/user/new$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/check-confirmation-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/confirm/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/confirmed$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/request-reset-password$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/send-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/check-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/reset-password/, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with fos_facebook
# # Secured part of the site
# This config requires being logged for the whole site and having the admin role for the admin part.
# Change these rules to adapt them to your needs
- { path: ^/admin/.*, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN, ROLE_AUTHOR] }
# - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
输入凭据后,我被重定向到 login_check
url。在此请求中,我可以看到“302”重定向返回到我的登录页面。但我认为这是正常的。之后我将被重定向到我的登录页面而无需经过身份验证。
你看到我的配置有什么错误吗?
如果您需要更多代码,请告诉我!
app.yml
中的 FOS 配置
fos_user:
db_driver: orm
firewall_name: main
user_class: XXX\UserBundle\Entity\User
group:
group_class: XXX\UserBundle\Entity\Group
service:
mailer: fos_user.mailer.twig_swift
user_manager: fos_user.user_manager.default
registration:
form:
type: my_user_registration
confirmation:
enabled: true
template: MyBundle:Mail:registration.email.twig
twig 中的登录表单
<form class="login_formular" action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}"/>
<table>
<tr>
<td><label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label></td>
<td><input class="login_input" type="text" id="username" name="_username" value="{{ last_username }}"
required="required"/></td>
</tr>
<tr>
<td><label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label></td>
<td><input class="login_input" type="password" id="password" name="_password" required="required"/></td>
</tr>
<tr>
<td><label class="login_input" for="remember_me">Eingeloggt bleiben:</label></td>
<td><input type="checkbox" id="remember_me" name="_remember_me" value="on" style="margin-top: 5px;"/>
</td>
</tr>
{% if error %}
<tr>
<td colspan="2" id="login_form_errors">{{ error.messageKey|trans(error.messageData, 'security') }}</td>
</tr>
{% endif %}
<tr>
<td colspan="2">
<input type="submit" id="_submit" name="_submit"
value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}"/>
</td>
</tr>
</table>
<div class="clear"></div>
</form>
我认为您在 security.yml
中使用
{
encoders:
FOS\UserBundle\Model\UserInterface:
algorithm: sha512
encode_as_base64: false
iterations: 1
}
评论encode_as_base64
和iterations
然后它会解决。
我找到了问题和解决方案,但我对找到它的方式感到失望。
我的问题描述缺少导致错误的 config.yml。
这是我配置中的错误部分:
framework:
session:
save_path: %kernel.root_dir%/var/sessions
cookie_httponly: true
由于某些原因,我过去更改了 save_path
设置并激活了 cookie_httponly
。
在我看来,这种组合使框架无法保存 ANY 客户端相关数据。
但是我在 symfony 或 apache 日志中找不到任何错误,指出 save_path
下的路径是错误的并且不存在。只有这条消息可以节省我数小时的搜索时间。最后,我最终搜索了我的项目 git 历史记录,以查找可能导致问题的配置和源中的任何更改。
此配置正在运行:
framework:
session:
save_path: ~
# cookie_httponly: true
如果有人确切知道为什么这些参数会阻止登录,我欢迎任何评论!
最近我一直在将我的网站从 symfony 2.4 升级到 2.6。我遵循了我发现的所有升级说明,几乎所有的工作都找到了。但是,我现在无法再登录到我的网站。 我使用 FOSUserBundle,我的 composer.json 包括这一行:
"friendsofsymfony/user-bundle": "2.0.*@dev",
我至少阅读了所有教程三遍,比较了所有选项,现在我已经焦头烂额了,因为我找不到有效的解决方案!
在 2.4 中一切正常所以我认为这可能与 security.yml
中定义的选项有关。
问题是我在 apache/symfony 日志文件中没有收到任何异常、警告或任何可疑信息。 这是我的 security.yml:
parameters:
security.acl.permission.map.class:
Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
sonata.admin.security.mask.builder.class:
Sonata\AdminBundle\Security\Acl\Permission\MaskBuilder
security:
acl:
connection: default
encoders:
FOS\UserBundle\Model\UserInterface: sha512
access_denied_url: ~
always_authenticate_before_granting: false
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
ROLE_AUTHOR: [ROLE_USER, SONATA]
SONATA:
- ROLE_SONATA_PAGE_ADMIN_PAGE_EDIT
providers:
fos_userbundle:
id: fos_user.user_provider.username
fos_facebook_provider:
id: fos_facebook.user.login
chain_provider:
chain:
providers: [fos_userbundle, fos_facebook_provider]
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
fos_facebook:
app_url: "http://apps.facebook.com/XXX/"
server_url: "http://XXX"
login_path: /user/login
check_path: /facebook/login_check
default_target_path: /Account
provider: fos_facebook_provider
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
remember_me: true
login_path: /user/login
default_target_path: /Account
use_forward: false
check_path: /user/login_check
failure_path: null
logout:
path: /user/logout
anonymous: true
provider: main
context: main_auth
remember_me:
key: XXX
lifetime: XXX
path: /
domain: ~
access_control:
- { path: ^/user/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured, role: ROLE_USER }
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
# # The WDT has to be allowed to anonymous users to avoid requiring the login with the AJAX request
- { path: ^/wdt/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/profiler/, role: IS_AUTHENTICATED_ANONYMOUSLY }
## # AsseticBundle paths used when using the controller for assets
- { path: ^/js/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/css/, role: IS_AUTHENTICATED_ANONYMOUSLY }
# # URL of FOSUserBundle which need to be available to anonymous users
# - { path: ^/secured/.*, role: [ROLE_FACEBOOK] } # This is the route secured with fos_facebook
# - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY } # for the case of a failed login
- { path: ^/user/new$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/check-confirmation-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/confirm/, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/confirmed$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/request-reset-password$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/send-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/check-resetting-email$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/user/reset-password/, role: IS_AUTHENTICATED_ANONYMOUSLY }
# - { path: ^/secured/.*, role: [IS_AUTHENTICATED_FULLY] } # This is the route secured with fos_facebook
# # Secured part of the site
# This config requires being logged for the whole site and having the admin role for the admin part.
# Change these rules to adapt them to your needs
- { path: ^/admin/.*, role: [ROLE_ADMIN, ROLE_SONATA_ADMIN, ROLE_AUTHOR] }
# - { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
输入凭据后,我被重定向到 login_check
url。在此请求中,我可以看到“302”重定向返回到我的登录页面。但我认为这是正常的。之后我将被重定向到我的登录页面而无需经过身份验证。
你看到我的配置有什么错误吗? 如果您需要更多代码,请告诉我!
app.yml
中的 FOS 配置fos_user:
db_driver: orm
firewall_name: main
user_class: XXX\UserBundle\Entity\User
group:
group_class: XXX\UserBundle\Entity\Group
service:
mailer: fos_user.mailer.twig_swift
user_manager: fos_user.user_manager.default
registration:
form:
type: my_user_registration
confirmation:
enabled: true
template: MyBundle:Mail:registration.email.twig
twig 中的登录表单
<form class="login_formular" action="{{ path("fos_user_security_check") }}" method="post">
<input type="hidden" name="_csrf_token" value="{{ csrf_token }}"/>
<table>
<tr>
<td><label for="username">{{ 'security.login.username'|trans({}, 'FOSUserBundle') }}</label></td>
<td><input class="login_input" type="text" id="username" name="_username" value="{{ last_username }}"
required="required"/></td>
</tr>
<tr>
<td><label for="password">{{ 'security.login.password'|trans({}, 'FOSUserBundle') }}</label></td>
<td><input class="login_input" type="password" id="password" name="_password" required="required"/></td>
</tr>
<tr>
<td><label class="login_input" for="remember_me">Eingeloggt bleiben:</label></td>
<td><input type="checkbox" id="remember_me" name="_remember_me" value="on" style="margin-top: 5px;"/>
</td>
</tr>
{% if error %}
<tr>
<td colspan="2" id="login_form_errors">{{ error.messageKey|trans(error.messageData, 'security') }}</td>
</tr>
{% endif %}
<tr>
<td colspan="2">
<input type="submit" id="_submit" name="_submit"
value="{{ 'security.login.submit'|trans({}, 'FOSUserBundle') }}"/>
</td>
</tr>
</table>
<div class="clear"></div>
</form>
我认为您在 security.yml
中使用{
encoders:
FOS\UserBundle\Model\UserInterface:
algorithm: sha512
encode_as_base64: false
iterations: 1
}
评论encode_as_base64
和iterations
然后它会解决。
我找到了问题和解决方案,但我对找到它的方式感到失望。
我的问题描述缺少导致错误的 config.yml。
这是我配置中的错误部分:
framework:
session:
save_path: %kernel.root_dir%/var/sessions
cookie_httponly: true
由于某些原因,我过去更改了 save_path
设置并激活了 cookie_httponly
。
在我看来,这种组合使框架无法保存 ANY 客户端相关数据。
但是我在 symfony 或 apache 日志中找不到任何错误,指出 save_path
下的路径是错误的并且不存在。只有这条消息可以节省我数小时的搜索时间。最后,我最终搜索了我的项目 git 历史记录,以查找可能导致问题的配置和源中的任何更改。
此配置正在运行:
framework:
session:
save_path: ~
# cookie_httponly: true
如果有人确切知道为什么这些参数会阻止登录,我欢迎任何评论!