I'm busy trying to configurate Fouserbundle on Symfony 2.6.9. But doesn't work, i got this message:
ForbiddenOverwriteException in BaseNode.php line 223: Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.
(i did configurate, appkernel, config,composer)
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
}
}
app/Resources/config/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/Resources/config/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"
app/Resources/config/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/Resources/config/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
Thank you
Had the same error because of having used separate security.yaml for dev (config/dev/security.yaml) and test (config/test/security.yaml) environments (besides config/security.yaml).
After removal of these files, error message disappeared.
In symfony, as the error message says, you ca't override most security options. You should define all your security related configuration in app/config/security.yml.
i think the security file that is imported is app/Resources/config/security.yml
this is my 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
I had the same problem. I have commented in config_dev.php the line concerning the fos_user db_driver and it helped
I got the same error after symfony upgrade
Configuration path "security.access_control" cannot be overwritten. You have to define all options for this path, and any of its sub-paths in one configuration section.
In my case I patched old AppKernel.php and had duplicate configuraton load command
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');
}
After removing first one - everything works ok.
Might be a simple reason: i had this error because i backuped the config file security.yaml to _security.yaml. Symfony reads both...
Related
i can switch language of my web site correctly but when i log in, i lost my current language in the url. for exemple before login http://test.bu/app_dev.php/en/admin/slideshow/ and after login i have this http://test.bu/app_dev.php/fr/admin/slideshow/
symfony2.7 takes always locale: fr. i use FosUserBundle. i ggogled i find that i can use bundles to fix this but i think i can resolve this by editing confinguration.
after login i redirect the web site by the default_target_path: slideshow_index like this
app_slideshow:
resource: "#AppBundle/Resources/config/routing/slideshow.yml"
prefix: /{_locale}/admin/slideshow
this is my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
framework:
#esi: ~
translator: { fallback: %locale% }
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
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%'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
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%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
# app/config/config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: Gold\UserBundle\Entity\User
from_email:
address: "%mailer_user%"
sender_name: "%mailer_user%"
thanks stackoverflow
Link of JMS routing bundle https://github.com/schmittjoh/JMSI18nRoutingBundle
But before you install it please look at this short video tutorial. This tutorial helped me a lot to understand the problem you are having between fos user bundle and the locale in url.
https://codereviewvideos.com/course/getting-started-with-fosuserbundle/video/translations-and-internationalisation-in-fosuserbundle
If you don't want to install jms routing bundle with your composer.json file you can install it with this command php composer.phar require jms/i18n-routing-bundle "dev-master"
Here is my config:
jms_i18n_routing:
default_locale: "%locale%"
locales: ["fr", "en"]
strategy: prefix_except_default
Security.yml:
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
require_previous_session: false
login_path: fos_user_security_login
check_path: fos_user_security_check
default_target_path: your_route_name_homepage
logout:
path: fos_user_security_logout
target: your_route_name_homepage
anonymous: true
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY && !IS_AUTHENTICADED_FULLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY && !IS_AUTHENTICADED_FULLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
After having installed Jms routing bundle. Try to execute the commande debug/router (symfony 3) and watch the routes names and prefix.
You can handle the locale detection/switch with JMSI18nRoutingBundle
Add the required bundles to composer.json:
"require": {
...
"jms/i18n-routing-bundle": "1.1.*",
"jms/translation-bundle": "1.1.*",
"friendsofsymfony/user-bundle": "1.3.*"
},
http://jmsyst.com/bundles/JMSI18nRoutingBundle/master/installation
I have searched many stackoverflow pages and updated my source code to fix this problem. But i couldn't fix this problem. In think i have missed something in my code or i have changed something.
When i try to access "/login". it automatically redirected to "/login/"
Actually my website has three bundles installed.
FosUserBundle
EsayAdminBundle
HWI Bundle(removed later)
After removed HWI oauth bundle, It encounted this error
No route found for "GET /login/" (from "http://127.0.0.1:8000/")
This is my first project in Symfony. Anybody can give me your corrections and suggestions. i have mentioned
Config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#BlogBundle/Resources/config/services.yml" }
- { resource: "#UserBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: fr
framework:
#Annotation enabled here
#validation: { enabled: true, enable_annotations: true }
#esi: ~
translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
cache : false
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
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%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# app/config/config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb' and 'couchdb'
# other valid values are 'mongodb' and 'couchdb'
firewall_name: main
user_class: UserBundle\Entity\User
from_email:
address: "test#myblog.org"
sender_name: "My-first-blog"
registration:
form:
type: UserBundle\Form\RegistrationType
easy_admin:
site_name: '<i class="fa fa-th" aria-hidden="true"></i> Hexagone - Espace Admin'
entities:
User:
label : Utilisateurs
class : UserBundle\Entity\User
list:
fields: ['username', 'email', 'enabled', 'last_login', 'roles','code_postal']
Projet :
class: BlogBundle\ProjetBundle\Entity\projet
label : Projets
design:
brand_color: '#333333'
routing.yml
projet:
resource: "#ProjetBundle/Resources/config/routing.yml"
prefix: /
blog_bundle_user:
resource: "#UserBundle/Resources/config/routing.yml"
prefix: /
blog:
resource: "#BlogBundle/Resources/config/routing.yml"
prefix: /
app:
resource: "#AppBundle/Controller/"
type: annotation
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
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
easy_admin_bundle:
resource: "#EasyAdminBundle/Controller/AdminController.php"
type: annotation
prefix: /backoffice
security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
login_path: /login
check_path: /login_check
default_target_path: /profile
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
logout: true
anonymous: true
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 }
- { path: ^/backoffice, role: ROLE_ADMIN }
services.yml
services:
app.form.registration:
class: UserBundle\Form\RegistrationType
tags:
- { name: form.type, alias: app_user_registration }
ALL ROUTING
_wdt ANY ANY ANY /_wdt/{token}
_profiler_home ANY ANY ANY /_profiler/
_profiler_search ANY ANY ANY /_profiler/search
_profiler_search_bar ANY ANY ANY /_profiler/search_bar
_profiler_info ANY ANY ANY /_profiler/info/{about}
_profiler_phpinfo ANY ANY ANY /_profiler/phpinfo
_profiler_search_results ANY ANY ANY /_profiler/{token}/search/results
_profiler_open_file ANY ANY ANY /_profiler/open
_profiler ANY ANY ANY /_profiler/{token}
_profiler_router ANY ANY ANY /_profiler/{token}/router
_profiler_exception ANY ANY ANY /_profiler/{token}/exception
_profiler_exception_css ANY ANY ANY /_profiler/{token}/exception.css
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
projet_homepage ANY ANY ANY /projet
blog_bundle_user_homepage ANY ANY ANY /
blog_homepage ANY ANY ANY /
githut ANY ANY ANY /
homepage ANY ANY ANY /
fos_user_security_login GET|POST ANY ANY /login
fos_user_security_check POST ANY ANY /login_check
fos_user_security_logout GET|POST ANY ANY /logout
fos_user_profile_show GET ANY ANY /profile/
fos_user_profile_edit GET|POST ANY ANY /profile/edit
fos_user_registration_register GET|POST ANY ANY /register/
fos_user_registration_check_email GET ANY ANY /register/check-email
fos_user_registration_confirm GET ANY ANY /register/confirm/{token}
fos_user_registration_confirmed GET ANY ANY /register/confirmed
fos_user_resetting_request GET ANY ANY /resetting/request
fos_user_resetting_send_email POST ANY ANY /resetting/send-email
fos_user_resetting_check_email GET ANY ANY /resetting/check-email
fos_user_resetting_reset GET|POST ANY ANY /resetting/reset/{token}
fos_user_change_password GET|POST ANY ANY /profile/change-password
easyadmin ANY ANY ANY /backoffice/
admin ANY ANY ANY /backoffice/
Sorry for indentation, i might have missed when i paste the code. Whatelse are needed to fix this problem? i could paste here.
Note : And i have tried also my old version which was not hwi-oauth bundle isntalled. It encount the same problem.
I have gone again through the fosbundle installation pages. I don't have any clues.
Looks like you're trying to access path /login/ in your application but there is only a route defined fos_user_security_login with path /login (without trailing /).
/login/ is not matched by the RouteMatcher this way. You need to define a second route to match this path too.
I have problem with SonataBundle. I have error "Catchable Fatal Error: Argument 1 passed to Symfony\Component\Security\Core\Authentication\Provider\DaoAuthenticationProvider::__construct() must implement interface Symfony\Component\Security\Core\User\UserProviderInterface, instance of FOS\UserBundle\Doctrine\UserManager given, called in C:\xampp\htdocs\PizzaProject\var\cache\dev\appDevDebugProjectContainer.php on line 6047 and defined"
This is my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#PizzaBundle/Resources/config/services.yml" }
- { resource: "#PizzaBundle/Resources/config/admin.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: '%secret%'
router:
resource: '%kernel.root_dir%/config/routing.yml'
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: '%locale%'
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
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%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: '%database_path%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: '%mailer_transport%'
host: '%mailer_host%'
username: '%mailer_user%'
password: '%mailer_password%'
spool: { type: memory }
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
fos_user:
db_driver: orm
firewall_name: main
user_class: PizzaBundle\Entity\User
from_email:
address: you#example.com
sender_name: You
sonata_block:
default_contexts: [cms]
blocks:
# enable the SonataAdminBundle block
sonata.admin.block.admin_list:
contexts: [admin]
sonata_admin:
security:
handler: sonata.admin.security.handler.acl
# acl security information
information:
GUEST: [VIEW, LIST]
STAFF: [EDIT, LIST, CREATE]
EDITOR: [OPERATOR, EXPORT]
ADMIN: [MASTER]
# permissions not related to an object instance and also to be available when objects do not exist
# the DELETE admin permission means the user is allowed to batch delete objects
admin_permissions: [CREATE, LIST, DELETE, UNDELETE, EXPORT, OPERATOR, MASTER]
# permission related to the objects
object_permissions: [VIEW, EDIT, DELETE, UNDELETE, OPERATOR, MASTER, OWNER]
Security.yml
security:
# http://symfony.com/doc/current/security.html#b-configuring-how-users-are-loaded
role_hierarchy:
ROLE_SONATA_FOO_READER:
- ROLE_SONATA_ADMIN_DEMO_FOO_LIST
- ROLE_SONATA_ADMIN_DEMO_FOO_VIEW
ROLE_SONATA_FOO_EDITOR:
- ROLE_SONATA_ADMIN_DEMO_FOO_CREATE
- ROLE_SONATA_ADMIN_DEMO_FOO_EDIT
ROLE_SONATA_FOO_ADMIN:
- ROLE_SONATA_ADMIN_DEMO_FOO_DELETE
- ROLE_SONATA_ADMIN_DEMO_FOO_EXPORT
ROLE_STAFF: [ROLE_USER, ROLE_SONATA_FOO_READER]
ROLE_ADMIN: [ROLE_STAFF, ROLE_SONATA_FOO_EDITOR, ROLE_SONATA_FOO_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
ROLE_ALL_ADMIN: [ROLE_STAFF, ROLE_SONATA_FOO_ALL]
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
providers:
fos_userbundle:
id: fos_user.user_manager
firewalls:
main:
pattern: ^/
form-login:
provider: fos_userbundle
login_path: /login
use_forward: false
check_path: /login_check
failure_path: null
logout: true
anonymous: true
# disables authentication for assets and the profiler, adapt it according to your needs
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
# activate different ways to authenticate
# http://symfony.com/doc/current/security.html#a-configuring-how-your-users-will-authenticate
#http_basic: ~
# http://symfony.com/doc/current/cookbook/security/form_login_setup.html
#form_login: ~
access_control:
- { 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: ^/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 }
# 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 }
- { path: ^/.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
role_hierarchy:
ROLE_ADMIN: [ROLE_USER, ROLE_SONATA_ADMIN]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
access_decision_manager:
strategy: unanimous
acl:
connection: default
services.yml
parameters:
security.acl.permission.map:
class: Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap
routing.yml
pizza:
resource: "#PizzaBundle/Controller/"
type: annotation
prefix: /
admin:
resource: '#SonataAdminBundle/Resources/config/routing/sonata_admin.xml'
prefix: /admin
_sonata_admin:
resource: .
type: sonata_admin
prefix: /admin
fos_user:
resource: "#FOSUserBundle/Resources/config/routing/all.xml"
prefix: /
My entity
<?php
namespace PizzaBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
* #ORM\Table(name="fos_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
}
}
you try login with FOSUserBundle and FOSOAuthServerBundle So you use the default oAuth api as the default user provider, and you try to use the grant_type password (sending the user credentials in the parameters) an authentication error message is returned because your username parameter is the email/login of the user. This problem can be easily solved changing the user provider property in your security.yml file (and config.yml if you use FOSOAuthServerBundle
Change In your services.yml)
id: fos_user.user_manager to thes fos_user.user_provider.username
security:
providers:
fos_userbundle:
id: fos_user.user_provider.username
I'm trying to install the FOSUserBundle following the tutorial: https://symfony.com/doc/master/bundles/FOSUserBundle/index.html
but appears the error :
InvalidConfigurationException: Unrecognized options "csrf_token_generator" under "security.firewalls.main.form_login"
My config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
csrf_protection:
enabled: true
#esi: ~
#translator: { fallback: "%locale%" }
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
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Utilisateurs\UtilisateursBundle\Entity\Utilisateurs
# 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: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# 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%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
My security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: bcrypt
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
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: _security_check
login_path: _demo_login
logout:
path: _demo_logout
target: _demo
#anonymous: ~
#http_basic:
# realm: "Secured Demo Area"
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, role: ROLE_ADMIN }
enter code here
Can someone help me ?
The problem is in your security.yml file. You have listed two CSRF token managers.
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_token_generator: security.csrf.token_manager
# if you are using Symfony < 2.8, use the following config instead:
# csrf_provider: form.csrf_provider
Depending on what version of Symfony you are using you use either csrf_token_generator or csrf_provider if your version of Symfony is <2.8, not both.
You need to remove or comment one of the lines out.
Editing this post because I cannot comment on your new post.
My version symfony is 2.4 : "symfony/symfony": "2.4.*"
But i have these new error:
ServiceNotFoundException: You have requested a non-existent service "fos_user.doctrine_registry".
This could be due to your version of Symfony being <2.6.* and conflicting with the FOSUserBundle version you are using.
For a temporary work around edit your config.yml
services:
fos_user.doctrine_registry:
alias: doctrine
# or use this, unsure on which one for your version of Symfony
# alias: doctrine_mongodb
Other fixes could be using a particular pull (older version - not recommended) in your composer.json. This has been tested for Symfony 2.6.* and bypassing the same issue you posted.
"friendsofsymfony/user-bundle": "dev-master##6ccff96434c0ac7fee077d1dce90966341dfd278"
You can read more about this particular problem:
https://github.com/FriendsOfSymfony/FOSUserBundle/issues/2048
A Symfony branch exists as a temporary fix as well:
https://github.com/symfony/symfony/pull/17554
I am new to Symfony, and probably thats why i don't seem to be able to target where the certain bugs generate from.
A new problem popped up when i put my site on the production server, the FOSUserBundle Authentication doesn't seem to work
Note: This worked absolutely fine on localhost, but as soon as i put it on the distant server, it does not validate any user.
The web/config.php file recommends that i :
1) Install and enable the php_posix extension (used to colorize the CLI output).
2) Install and enable the intl extension (used for validators)
3) Install and enable a PHP accelerator like APC (highly recommended).
4) Set short_open_tag to off in php.ini*.
Could this cause problems in Authentication ?
my config.yml file
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
translator: { fallback: "%locale%" }
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: [ LesCouvertsBundle , LesRestaurantBundle , LesVirtualMarketBundle , LesShopBundle ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# 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, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
encryption: ssl
auth_mode: login
spool: { type: memory }
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: Les\UserBundle\Entity\User
registration:
confirmation:
from_email:
address: registration#lescouverts.com
sender_name: Lescouverts Registration
enabled: false
from_email:
address: noreply#lescouverts.com
sender_name: LesCouverts
services:
resto_module:
class: Les\RestoModule\Module
arguments: [module]
lists_module:
class: Les\RestoParam\Param
arguments: [parameters]
my security.yml file
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_CLIENT: ROLE_USER
ROLE_RESTO: ROLE_CLIENT
ROLE_SHOP: ROLE_CLIENT
ROLE_ADMIN: [ ROLE_USER, ROLE_CLIENT, ROLE_RESTO , ROLE_SHOP ]
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
login_path: fos_user_security_login
csrf_provider: form.csrf_provider
# check_path: /login_check
check_path: fos_user_security_check
default_target_path: /
csrf_provider: form.csrf_provider
logout:
path: fos_user_security_logout
anonymous: true
access_control:
- { path: ^/booking, role: ROLE_CLIENT }
- { path: ^/party_calendar, role: ROLE_CLIENT }
- { path: ^/restaurant_admin, role: ROLE_RESTO }
- { path: ^/shop_admin, role: ROLE_SHOP }
- { path: ^/virtual_market, role: [ ROLE_RESTO, ROLE_SHOP ] }
- { path: ^/root, role: ROLE_ADMIN }
- { path: ^/secure_area/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secure_area, role: ROLE_USER }
I am not sure how to debug this problem!
Plus in development mode i am getting the error
RuntimeException: Failed to write cache file
"/var/www/vhosts/httpdocs/app/cache/dev/classes.php".
So i cant even see if the profiler is indicating any errors!
One common issue is that the app/cache and app/logs directories must be writable both by the web server and the command line user.
http://symfony.com/doc/current/book/installation.html#configuration-and-setup