最近我一直在将我的网站从 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
树枝中的登录表单
<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>