最近我一直在将我的网站从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
网址。在这个请求中,我可以看到" 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
在树枝中登录表格
<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>
答案 0 :(得分:0)
我发现了问题并找到了解决方案,但我对发现它的方式感到失望。
我的问题描述缺少导致错误的config.yml。
这是我配置中的错误部分:
framework:
session:
save_path: %kernel.root_dir%/var/sessions
cookie_httponly: true
由于某些原因,我更改了save_path
设置并在过去激活了cookie_httponly
。
在我看来,这种组合使得框架无法保存任何客户端相关数据。
但是我无法在symfony或apache日志中发现任何错误,说明save_path
下的路径错误且不存在。只有这条消息才能节省我数小时的搜索时间。最后,我最终在我的项目git历史记录中搜索可能导致问题的配置和源代码的任何更改。
此配置现在正在运行:
framework:
session:
save_path: ~
# cookie_httponly: true
如果有人确切知道这些参数阻止登录的原因,我欢迎任何评论!
答案 1 :(得分:-1)
我认为你在security.yml中使用
{
encoders:
FOS\UserBundle\Model\UserInterface:
algorithm: sha512
encode_as_base64: false
iterations: 1
}
评论encode_as_base64
和iterations
然后它将解决。