security.yml causes InvalidArgumentException: "You must at least add one authentication provider"
Asked Answered
U

1

1

I removed in-memory provider and DemoBundle, and added database provider, as per tutorial. But I'm getting InvalidArgumentException: "You must at least add one authentication provider".

My security.yml:

# you can read more about security in the related section of the documentation
# http://symfony.com/doc/current/book/security.html
security:
    # http://symfony.com/doc/current/book/security.html#encoding-the-user-s-password
  encoders:
    AppBundle\Entity\User:
      algorithm: bcrypt

  # http://symfony.com/doc/current/book/security.html#hierarchical-roles
  role_hierarchy:
    ROLE_GLOBAL_MODERATOR: ROLE_USER
    ROLE_ADMIN: ROLE_GLOBAL_MODERATOR

  # http://symfony.com/doc/current/book/security.html#where-do-users-come-from-user-providers
  providers:
    db:
      entity:
        class: AppBundle:User
        property: email
        # if you're using multiple entity managers
        # manager_name: customer

  # the main part of the security, where you can set up firewalls
  # for specific sections of your app
  firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
      pattern:  ^/(_(profiler|wdt)|css|images|js)/
      security: false
    default:
      pattern: ^/
      security: false

  # with these settings you can restrict or allow access for different parts
  # of your application based on roles, ip, host or methods
  # http://symfony.com/doc/current/cookbook/security/access_control.html
  access_control:
      #- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

I also tried using a YAML visualizer, to make sure, that I didn't screw up indentation, and it's correct.

Unsaid answered 27/3, 2015 at 19:58 Comment(2)
Shouldn't it be class: Ns\AppBundle\Entity\User rather than class: AppBundle:User?Upkeep
@Upkeep Replaced it, to no avail.Unsaid
N
9

This is because you don't have configured authentication provider yet. I mean under firewalls key. Authentication providers are anonymous, form_login, http_basic etc. It is not important for what pattern is provider configured but at least one of them must be configured.

firewalls:
    # disables authentication for assets and the profiler, adapt it according to your needs
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    default:
        pattern: ^/
        anonymous: ~
Northington answered 27/3, 2015 at 21:4 Comment(1)
Thanks a ton. That really made me pull my hair off.Unsaid

© 2022 - 2024 — McMap. All rights reserved.