我想使用FOSFacebookBundle和FOSUserBundle来管理:
- 与facebook连接的前台
- 后台管理用户的经典登录/密码(这里没有facebook连接!)
我使用Propel作为ORM和AdminGeneratorGeneratorBundle来管理后台。我已经覆盖了FOSUserBundle的推进的schema.yml文件,以添加特定的"facebook字段"。
这个过程对前端来说很好,但当我试图访问"/admin"url时,它无法正常工作。我有"登录"页面,但当我输入登录名/密码时,我会重定向到facebook连接页面。。。
这只是配置文件配置错误,还是我的需求方式不对?
这是我的配置文件:
安全性.yml
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username
fos_facebook_provider:
id: my.facebook.user
encoders:
FOSUserBundleModelUserInterface: sha512
firewalls:
# Firewall public / FB Connect
public:
# since anonymous is allowed users will not be forced to login
pattern: ^/.*
fos_facebook:
provider: fos_facebook_provider
app_url: "http://apps.facebook.com/fb-localhost-testing/"
server_url: "http://localhost/fb-localhost-testing/"
anonymous: true
# Firewall zone admin
admin_area:
pattern: ^/admin
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /admin/login
check_path: /admin/login_check
default_target_path: /admin/
logout:
path: /admin/logout
target: /admin/login
anonymous: true
access_control:
- { path: ^/admin/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/connected/.*, role: [ROLE_FACEBOOK] }
- { path: ^/.*, role: [IS_AUTHENTICATED_ANONYMOUSLY] }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
config.yml
# FOSUser Configuration
fos_user:
user_class: FOSUserBundlePropelUser
db_driver: propel
firewall_name: main
# FOSFacebook Configuration
fos_facebook:
alias: fb-localhost-testing
app_id: mmyid
secret: mysecret
cookie: true
permissions: [email, user_birthday, user_location]
services:
my.facebook.user:
class: MyProjectSecurityUserProviderFacebookProvider
arguments:
facebook: "@fos_facebook.api"
userManager: "@fos_user.user_manager"
validator: "@validator"
解决方案:我们需要在全局模式之前定义特定模式。
为了解决我的问题,我只切换了两个防火墙块public&admin_area:
- 首先,adminrea防火墙及其特定的"^/admin"模式
- 第二,具有全局"^/.*"模式的公共模式