我正忙着在Symfony 2.6.9上配置Fouserbundle。但是没有用,我收到了这条消息:
BaseNode.php第223行中的ForbiddenOverwriteException:无法覆盖配置路径“security.access_control”。您必须为此路径定义所有选项,并在一个配置部分中定义其任何子路径。
(我确实配置了,appkernel,配置,作曲家)
user.php的
<?php
namespace FLY\UserBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="FLY_user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
public function __construct()
{
parent::__construct();
// your own logic
}
}
应用/资源/配置/ security.yml
imports:
- { resource: "@FLYUserBundle/Resources/config/security.yml" }
security:
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
UserBundle /资源/配置/ security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_manager
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/demo/secured/login$
security: false
secured_area:
pattern: ^/demo/secured/
form_login:
check_path: /demo/secured/login_check
login_path: /demo/secured/login
logout:
path: /demo/secured/logout
target: /demo/
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
应用/资源/配置/ routing.yml中
FLY_Platform:
resource: "@FLYPlatformBundle/Resources/config/routing.yml"
prefix: /
mremi_contact_form:
resource: "@MremiContactBundle/Resources/config/routing.xml"
genemu_base64:
resource: "@GenemuFormBundle/Resources/config/routing/base64.xml"
_user_bundle:
resource: "@UserBundle/Resources/config/routing.yml"
UserBundle /资源/配置/ routing.yml中
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
谢谢
答案 0 :(得分:0)
在symfony中,正如错误消息所示,您无法覆盖大多数安全选项。您应该在app/config/security.yml
中定义所有与安全性相关的配置。
答案 1 :(得分:0)
我认为导入的安全文件是app / Resources / config / security.yml
这是我的app / config / config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: security.yml }
framework:
#esi: ~
translator: ~
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: %kernel.debug%
use_controller: false
bundles: [ ]
java: /usr/bin/java
filters:
cssrewrite: ~
cssembed:
jar: %kernel.root_dir%/Resources/java/cssembed-0.4.5.jar
yui_js:
jar: %kernel.root_dir%/Resources/java/yuicompressor.jar
lessphp:
file: %kernel.root_dir%/../vendor/leafo/lessphp/lessc.inc.php
apply_to: "\.less$"
assets:
jquery_js:
inputs:
- '%kernel.root_dir%/../components/jquery/jquery.min.js'
filters: [?yui_js]
bootstrap_js:
inputs:
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/transition.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/alert.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/modal.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/dropdown.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/scrollspy.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/tab.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/tooltip.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/popover.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/button.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/collapse.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/carousel.js'
- '%kernel.root_dir%/../vendor/twitter/bootstrap/js/affix.js'
filters: [?yui_js]
bootstrap_less:
inputs:
- '%kernel.root_dir%/../vendor/twitter/bootstrap/less/bootstrap.less'
filters: [lessphp,cssembed]
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
encryption: "%mailer_encryption%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
mremi_contact:
store_data: false
contact_class: Mremi\ContactBundle\Model\Contact
form:
type: mremi_contact
name: contact_form
validation_groups: [Default]
subject_provider: mremi_contact.subject_provider.noop
captcha_type: genemu_captcha
email:
mailer: mremi_contact.mailer.twig_swift
from: [{ address: xxxxxx@gmail.com, name: "Webmaster" } ]
to: [{ address: xxxxxx@hotmail.fr } ] # Required
template: MremiContactBundle:Contact:email.txt.twig
genemu_form:
captcha: ~
# fouser Configuration
fos_user:
db_driver: orm
firewall_name: main
user_class: FLY\UserBundle\Entity\User
&#13;
答案 2 :(得分:0)
我遇到了同样的问题。我在config_dev.php中评论了关于fos_user db_driver的一行,并帮助了
答案 3 :(得分:0)
我在symfony升级后得到了同样的错误
配置路径&#34; security.access_control&#34;不能被覆盖。您必须为此路径定义所有选项,并在一个配置部分中定义其任何子路径。
在我的情况下,我修补了旧的AppKernel.php并且有重复的configuraton load命令
public function registerContainerConfiguration(LoaderInterface $loader)
{
// this is old code
$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
// code above is new and copy-pasted from clean symfony 3.4 install
$loader->load(function (ContainerBuilder $container) {
$container->setParameter('container.autowiring.strict_mode', true);
$container->setParameter('container.dumper.inline_class_loader', true);
$container->addObjectResource($this);
});
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
}
删除第一个 - 一切正常。
答案 4 :(得分:0)
由于将单独的 security.yaml 用于开发 (config/dev/security.yaml
) 和测试 (config/test/security.yaml
) 环境(除了 config/security.yaml
),因此出现了相同的错误。
删除这些文件后,错误消息消失了。
答案 5 :(得分:0)
可能是一个简单的原因:我有这个错误,因为我将配置文件 security.yaml 备份到 _security.yaml。 Symfony 读取两者...